Minor code cleanup.

This commit is contained in:
2025-06-16 23:56:46 -05:00
parent f40fd7e840
commit 62b035a0c2
5 changed files with 65 additions and 66 deletions

View File

@@ -86,21 +86,21 @@ public:
#pragma endregion
#pragma region Map Data
Level* loaded_level;
Tileset* loaded_tileset;
JGL::Texture* loaded_tilesheet;
Level* loaded_level = nullptr;
Tileset* loaded_tileset = nullptr;
JGL::Texture* loaded_tilesheet = nullptr;
#pragma endregion
EditorCamera camera;
JUI::Window * CreateAppInfoDialogWindow(JUI::Widget *parent);
Preferences preferences;
int focus_layer_index = 0;
JUI::Window * CreateAppInfoDialogWindow(JUI::Widget *parent);
Layer* GetLayer(int index)
{
return loaded_level->layers[index];
@@ -160,46 +160,7 @@ public:
/// @note Placeholder until FileDialogs are added.
void SaveCurrentLevel() const;
void LoadLevel(const std::filesystem::path& level_meta_path);
void CreateTestLevel() {
loaded_level = new Level();
loaded_level->name = "TestLevel";
loaded_level->author = "dawsh";
loaded_level->cols = 64;
loaded_level->rows = 64;
loaded_level->tileset_path = "tileset.json";
auto layer = new Layer();
layer->name = "Layer 1";
layer->cols = 64;
layer->rows = 64;
layer->cell_height = 16;
layer->cell_width = 16;
layer->binary_path = "layers/1.bin";
layer->InitGrid();
layer->Save();
loaded_level->layers.push_back(layer);
loaded_tileset = new Tileset();
loaded_tileset->name = "MegaCommando";
loaded_tileset->author = "dawsh";
loaded_tileset->tex_height = 1280;
loaded_tileset->tex_width = 1024;
loaded_tileset->tile_width = 16;
loaded_tileset->tile_height = 16;
loaded_tileset->tile_spacing = 0;
loaded_tileset->cols = 80;
loaded_tileset->rows = 60;
loaded_tileset->file_path = "tileset.json";
loaded_tileset->texture_path = "assets/megacommando.png";
loaded_tilesheet = new JGL::Texture("assets/megacommando.png");
write_file_contents("tileset.json", json::deparse(loaded_tileset->Serialize()));
//layer_view->UpdateComponents(loaded_level);
data_ready = true;
SaveCurrentLevel();
}
void CreateTestLevel();
void SizeCellIndicatorToTilesetSize();

View File

@@ -15,7 +15,7 @@ struct RecentCameraState
json::value Serialize() const
{
json::object json;
json["tx"] = translation.x;
json["tx"] = json::number(translation.x);
json["ty"] = translation.y;
json["rot"] = rotation;
json["scale"] = scale;
@@ -33,10 +33,12 @@ struct RecentCameraState
class Preferences {
public:
#pragma region Member Variables
RecentCameraState recent_camera_state;
#pragma endregion
public:
explicit Preferences() : recent_camera_state()
Preferences() : recent_camera_state()
{
}
@@ -61,10 +63,4 @@ public:
}
public:
Color4 GridColor() const;
bool ShowBackgroundGrid() const;
bool ShowForegroundGrid() const;
bool AutoSave() const;
};

View File

@@ -224,6 +224,46 @@ void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
data_ready = true;
}
void EditorApp::CreateTestLevel() {
loaded_level = new Level();
loaded_level->name = "TestLevel";
loaded_level->author = "dawsh";
loaded_level->cols = 64;
loaded_level->rows = 64;
loaded_level->tileset_path = "tileset.json";
auto layer = new Layer();
layer->name = "Layer 1";
layer->cols = 64;
layer->rows = 64;
layer->cell_height = 16;
layer->cell_width = 16;
layer->binary_path = "layers/1.bin";
layer->InitGrid();
layer->Save();
loaded_level->layers.push_back(layer);
loaded_tileset = new Tileset();
loaded_tileset->name = "MegaCommando";
loaded_tileset->author = "dawsh";
loaded_tileset->tex_height = 1280;
loaded_tileset->tex_width = 1024;
loaded_tileset->tile_width = 16;
loaded_tileset->tile_height = 16;
loaded_tileset->tile_spacing = 0;
loaded_tileset->cols = 80;
loaded_tileset->rows = 60;
loaded_tileset->file_path = "tileset.json";
loaded_tileset->texture_path = "assets/megacommando.png";
loaded_tilesheet = new JGL::Texture("assets/megacommando.png");
write_file_contents("tileset.json", json::deparse(loaded_tileset->Serialize()));
//layer_view->UpdateComponents(loaded_level);
data_ready = true;
SaveCurrentLevel();
}
void EditorApp::SizeCellIndicatorToTilesetSize()
@@ -333,9 +373,14 @@ void EditorApp::CreateWidgets()
app_info_dialog = CreateAppInfoDialogWindow(scene);
auto* fpsgraphwindow = new JUI::Window(scene);
auto* fpsgraph = new JUI::FpsGraph(scene);
auto* fps_graph = new JUI::FpsGraph(scene);
// TODO: Revise to use PseudoDockedElementAtBottomOfViewport coming in the next JUI release.
fps_graph->Size({100_percent, 50_px});
fps_graph->AnchorPoint({1, 1});
fps_graph->Position({100_percent, 100_percent});
fps_graph->BGColor(Colors::Transparent);
fps_graph->BorderColor(Colors::Transparent);
fps_graph->ZIndex(10);
console = new JUI::CommandLine(scene);
console->Close();

View File

@@ -7,8 +7,6 @@ Tileset::Tileset():
{ }
Tileset::Tileset(const std::string& name, const std::filesystem::path& texture_path, int tex_width, int tex_height, int tile_width, int tile_height,
int tile_spacing)
{

View File

@@ -159,14 +159,13 @@ public:
player_tex = new JGL::Texture("assets/player.png", FilteringMode::NEAREST);
//auto* fps_graph_window = new JUI::Window(scene);
//fps_graph_window->Size({500_px, 50_px});
//fps_graph_window->AnchorPoint({1, 0.f});
//fps_graph_window->Position({100_percent, 0_percent});
auto* fps_graph = new JUI::FpsGraph(scene);
// TODO: Revise to use PseudoDockedElementAtBottomOfViewport coming in the next JUI release.
fps_graph->Size({100_percent, 50_px});
fps_graph->AnchorPoint({1, 1});
fps_graph->Position({100_percent, 100_percent});
fps_graph->BGColor(Colors::Transparent);
fps_graph->BorderColor(Colors::Transparent);
auto* phys_params_slider_window = new JUI::Window(scene);