Confusing refactor of library (Trust me it'll come out making sense)

This commit is contained in:
2025-06-30 18:39:36 -05:00
parent edb0f8cf68
commit 7916983d34
45 changed files with 245 additions and 154 deletions

View File

@@ -1,7 +0,0 @@
#pragma once
namespace LevelFormat
{
};

View File

@@ -1,5 +0,0 @@
#include <Data/Entity.hpp>
#include <Data/Layer.hpp>
#include <Data/Tileset.hpp>
#include <Data/Level.hpp>
#include <Data/Tile.hpp>

View File

@@ -1,5 +1,5 @@
#pragma once
#include "Data/Entity.hpp"
#include "Format/Entity.hpp"
namespace TestGame {

View File

@@ -1,7 +1,7 @@
#include "GameEntity.hpp"
#include "Player.hpp"
#include "App/EditorCamera.hpp"
#include "Data/Level.hpp"
#include "Editor/EditorCamera.hpp"
#include "Format/Level.hpp"
#include "JUI/Widgets/Scene.hpp"
#include "ReWindow/types/Window.h"

View File

@@ -13,11 +13,11 @@
#include "NewMapDialog.hpp"
#include "JUI/Widgets/ColorPicker.hpp"
#include "Preferences.hpp"
#include <Data/Level.hpp>
#include <Data/Tileset.hpp>
#include <Format/Level.hpp>
#include <Format/Tileset.hpp>
#include <JUI/Widgets/Checkbox.hpp>
#include <App/LayerView.hpp>
#include <App/TilesetView.hpp>
#include <Editor/LayerView.hpp>
#include <Editor/TilesetView.hpp>
#include "JUI/Widgets/FpsGraph.hpp"
@@ -27,7 +27,7 @@
using namespace ReWindow;
using namespace JUI::UDimLiterals;
#include <App/EditorCamera.hpp>
#include <Editor/EditorCamera.hpp>
// TODO: Support loading an entity_prefab.json file which defines template entities to copy.
// TODO: Support sprites for these?

View File

@@ -1,7 +1,7 @@
#pragma once
#include <J3ML/LinearAlgebra.hpp>
#include <Utils.hpp>
#include <Re2DLevelAPI.hpp>
struct EditorCamera {
Lerped<Vector2> translation;

View File

@@ -6,7 +6,7 @@
#include <JUI/Widgets/ListLayout.hpp>
#include <JUI/Widgets/Checkbox.hpp>
#include <Data/Level.hpp>
#include <Format/Level.hpp>
using namespace JUI::UDimLiterals;

View File

@@ -1,5 +1,5 @@
#pragma once
#include <Data/Tileset.hpp>
#include <Format/Tileset.hpp>
#include <JUI/Base/Widget.hpp>
#include <JUI/Widgets/Window.hpp>
#include <JUI/Widgets/Checkbox.hpp>

View File

@@ -1,6 +1,6 @@
#pragma once
#include <App/Grid.hpp>
#include <Editor/Grid.hpp>
#include "TileMetaDialog.hpp"

View File

@@ -1,11 +1,9 @@
#pragma once
#include <string>
#include <JJX/JSON.hpp>
#include <json.hpp>
#include <Color4.hpp>
#include <Utils.hpp>
using namespace JJX;
#include <Re2DLevelAPI.hpp>
enum class EntityRepresentativeShape {
Point, AABB, Sphere, OBB

View File

@@ -0,0 +1,5 @@
#include <Format/Entity.hpp>
#include <Format/Layer.hpp>
#include <Format/Tileset.hpp>
#include <Format/Level.hpp>
#include <Format/Tile.hpp>

View File

@@ -1,12 +1,12 @@
#pragma once
#include <string>
#include <vector>
#include <Data/Layer.hpp>
#include <JJX/JSON.hpp>
#include <Colors.hpp>
#include <Utils.hpp>
#include <json.hpp>
#include <Format/Layer.hpp>
#include <Re2DLevelAPI.hpp>
using namespace JJX;
enum class DataFormat
{

View File

@@ -1,15 +1,12 @@
#pragma once
#include <string>
#include <vector>
#include <Data/Layer.hpp>
#include <Data/Entity.hpp>
#include <JJX/JSON.hpp>
#include <Colors.hpp>
#include <Utils.hpp>
#include <Format/Layer.hpp>
#include <Format/Entity.hpp>
#include <json.hpp>
#include <Re2DLevelAPI.hpp>
#include <Format/Tileset.hpp>
#include "Tileset.hpp"
using namespace JJX;
const float REDACTED_EDITOR_LIB_VERSION = 1;

View File

@@ -0,0 +1,2 @@
#pragma once

View File

@@ -1,28 +1,52 @@
/// Redacted Software 2D Level Library
/// Level File Format Specification
///
#pragma once
#include <vector>
#include <JJX/JSON.hpp>
#include <json.hpp>
#include <filesystem>
#include <format>
#include <Utils.hpp>
#include <Re2DLevelAPI.hpp>
#include <J3ML/Geometry/AABB2D.hpp>
/// Represents a rectangular sub-region of a larger space, such as a texture.
/// @see J2D::DrawPartialSprite();
struct Quad {
int x; int y;
int w; int h;
#ifdef QUAD_EXTENDED_API
Vector2i Position() const { return {x, y};}
Vector2i Size() const { return {w, h};}
void Position(const Vector2i& value) { x = value.x; y = value.y; }
void Size(const Vector2i& value) { w = value.x; h = value.y; }
void Set(AABB2D& rect) { }
Quad Translated(const Vector2i& translation) {
Quad copy;
}
void Translate(const Vector2i& translation) {
x += translation.x;
y += translation.y;
}
#endif
};
#include <J3ML/Math.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include "JGL/types/Texture.h"
using namespace JJX;
struct Quad {
int x;
int y;
int w;
int h;
};
struct Tile
{
int id;
std::string name;
/// The portion of the Tilesheet that corresponds to this tile-object.
/// @note Non-uniform tile width and height are technically possible, but not generally designed for.\n
/// The quad.w, quad.h should match the Tileset.tile_width, and Tileseh.tile_height.
Quad quad;
json::value metadata;
bool collides;
@@ -30,8 +54,6 @@ struct Tile
bool persistent = false;
};
/// TODO: Only generate tile entry for tiles that are used in the level, or have been assigned custom metadata.
/// TODO: Large tilesets generate unwieldy file sizes and cause our rudimentary json parser to crash out.
/// @class Tileset
/// @brief Represents a collection of tiles, typically from a single texture atlas, used in a level.
@@ -39,6 +61,9 @@ struct Tile
/// The Tileset class defines the properties of a set of tiles, including their dimensions,
/// spacing, and how they are arranged within a source texture. It also provides metadata
/// about the tileset itself, such as its name and author.
///
/// @note As a space-saving measure, tiles are only saved to file if they contain non-generic metadata, or a custom name or ID. Otherwise, tiles are simply generated in incrementing order at runtime.
///
class Tileset {
public:
#pragma region json fields

View File

@@ -2,7 +2,7 @@
#include <Color4.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <JJX/JSON.hpp>
#include <json.hpp>
#include <filesystem>
#include <fstream>
@@ -11,6 +11,7 @@
#pragma once
inline int CellToIndex(Vector2i cell, int width)
{
return cell.y*width + cell.x;
@@ -18,14 +19,12 @@ inline int CellToIndex(Vector2i cell, int width)
namespace JsonConversions
{
using namespace JJX;
Color4 parse_color(const JJX::json::value& v);
Color4 parse_color(const json::value& v);
json::value deparse_color_to_hex(const Color4& color);
JJX::json::value deparse_color_to_hex(const Color4& color);
std::vector<std::string> parse_string_list(const json::value& v);
std::vector<std::string> parse_string_list(const JJX::json::value& v);
JJX::json::value deparse_string_list(const std::vector<std::string>& list);
json::value deparse_string_list(const std::vector<std::string>& list);
} // namespace JsonConversions
template <typename T>