Test integration of FPSGraph
This commit is contained in:
@@ -5,12 +5,14 @@
|
||||
|
||||
#include <Data/Format.hpp>
|
||||
|
||||
#include "JUI/Widgets/FpsGraph.hpp"
|
||||
|
||||
|
||||
JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
{
|
||||
// TODO: Implement JUI structure that makes blocks of text easy to impelement.
|
||||
auto window = new JUI::Window(parent);
|
||||
window->SetTitle("About Editor2D");
|
||||
window->Title("About Editor2D");
|
||||
window->Size({350_px, 375_px});
|
||||
window->MinSize({350, 375});
|
||||
|
||||
@@ -21,9 +23,9 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
auto line_item = [&] (const std::string& text, int size = 20, const Color4& color = Colors::White) {
|
||||
auto* content = new JUI::TextRect(layout);
|
||||
content->Size({100_percent, JUI::UDim(size+5, 0)});
|
||||
content->SetContent(text);
|
||||
content->SetTextSize(size);
|
||||
content->SetTextColor(color);
|
||||
content->Content(text);
|
||||
content->TextSize(size);
|
||||
content->TextColor(color);
|
||||
content->BGColor(Colors::Transparent);
|
||||
content->AlignCenterHorizontally();
|
||||
content->BorderWidth(0);
|
||||
@@ -59,10 +61,10 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
|
||||
btn_layout->Padding(8_px);
|
||||
|
||||
auto btn_item = [&] (const std::string& text) -> JUI::TextButton* {
|
||||
JUI::TextButton* btn = new JUI::TextButton(btn_layout);
|
||||
btn->SetContent(text);
|
||||
auto* btn = new JUI::TextButton(btn_layout);
|
||||
btn->Content(text);
|
||||
btn->Size({32_percent, 100_percent});
|
||||
btn->SetTextColor(Colors::Black);
|
||||
btn->TextColor(Colors::Black);
|
||||
btn->Center();
|
||||
return btn;
|
||||
};
|
||||
@@ -188,10 +190,13 @@ void EditorApp::SavePreferences()
|
||||
|
||||
void EditorApp::LoadTestFile()
|
||||
{
|
||||
LoadLevel("level.json");
|
||||
if (std::filesystem::exists("level.json"))
|
||||
LoadLevel("level.json");
|
||||
else
|
||||
CreateTestLevel();
|
||||
}
|
||||
|
||||
void EditorApp::SaveTestFile()
|
||||
void EditorApp::SaveCurrentLevel() const
|
||||
{
|
||||
|
||||
for (auto layer : loaded_level->layers)
|
||||
@@ -207,6 +212,7 @@ void EditorApp::SaveTestFile()
|
||||
|
||||
void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
|
||||
{
|
||||
|
||||
loaded_level = new Level(level_meta_path);
|
||||
|
||||
loaded_tileset = new Tileset(std::filesystem::path(loaded_level->tileset_path));
|
||||
@@ -216,7 +222,7 @@ void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
|
||||
for (auto layer : loaded_level->layers)
|
||||
layer->Load();
|
||||
|
||||
layer_view->UpdateComponents(loaded_level);
|
||||
//layer_view->UpdateComponents(loaded_level);
|
||||
|
||||
data_ready = true;
|
||||
}
|
||||
@@ -233,7 +239,7 @@ JUI::Window* EditorApp::CreateTilesetViewerWindow(JUI::Widget* parent)
|
||||
using namespace JUI;
|
||||
|
||||
auto* wind = new Window(parent);
|
||||
wind->SetTitle("Tileset Viewer");
|
||||
wind->Title("Tileset Viewer");
|
||||
wind->Size(JUI::UDim2::FromPixels(loaded_tilesheet->GetDimensions().x, loaded_tilesheet->GetDimensions().y+20));
|
||||
wind->SetResizable(false);
|
||||
|
||||
@@ -330,6 +336,10 @@ void EditorApp::CreateWidgets()
|
||||
|
||||
app_info_dialog = CreateAppInfoDialogWindow(scene);
|
||||
|
||||
auto* fpsgraphwindow = new JUI::Window(scene);
|
||||
auto* fpsgraph = new JUI::FpsGraph(scene);
|
||||
|
||||
|
||||
console = new JUI::CommandLine(scene);
|
||||
console->Close();
|
||||
BindConsoleCallbacks();
|
||||
@@ -342,8 +352,13 @@ void EditorApp::CreateWidgets()
|
||||
|
||||
topbar = new JUI::UtilityBar(scene);
|
||||
|
||||
topbar_stats = new JUI::Text(topbar);
|
||||
topbar_stats->HorizontalTextAlign(JUI::TextAlign::H::Left);
|
||||
topbar_stats->TextColor(Colors::Black);
|
||||
|
||||
|
||||
auto* file = topbar->AddSubmenu("File");
|
||||
file->SetFont(JGL::Fonts::Jupiteroid);
|
||||
file->Font(JGL::Fonts::Jupiteroid);
|
||||
|
||||
|
||||
auto* new_map = file->AddButton("New Map", [this] () mutable {
|
||||
@@ -351,7 +366,7 @@ void EditorApp::CreateWidgets()
|
||||
});
|
||||
|
||||
file->AddButton("Open");
|
||||
file->AddButton("Save", [this]{SaveTestFile();});
|
||||
file->AddButton("Save", [this]{SaveCurrentLevel();});
|
||||
file->AddButton("Save As");
|
||||
file->AddSeparator(2_px);
|
||||
file->AddButton("About", [this]{app_info_dialog->Toggle(); });
|
||||
@@ -427,7 +442,7 @@ bool EditorApp::Open()
|
||||
LoadTestFile();
|
||||
CreateWidgets();
|
||||
|
||||
|
||||
layer_view->UpdateComponents(loaded_level);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -793,7 +808,7 @@ void EditorApp::Draw()
|
||||
void EditorApp::OnClosing()
|
||||
{
|
||||
SavePreferences();
|
||||
SaveTestFile();
|
||||
SaveCurrentLevel();
|
||||
}
|
||||
|
||||
void EditorApp::OnRefresh(float elapsed)
|
||||
|
@@ -7,7 +7,21 @@ Level::Level(): rows(0), cols(0)
|
||||
|
||||
Level::Level(const std::filesystem::path& path)
|
||||
{
|
||||
if (path.empty())
|
||||
throw std::runtime_error(std::format("Level::Level({}: blank file path provided!", path.string()));;
|
||||
if (!std::filesystem::exists(path))
|
||||
throw std::runtime_error(std::format("Level::Level({}): file does not exist!", path.string()));
|
||||
|
||||
std::string file_contents = read_file_contents(path);
|
||||
|
||||
if (file_contents.empty())
|
||||
throw std::runtime_error(std::format("Level::Level({}): file contents are empty!", path.string()));
|
||||
|
||||
auto [json, err] = json::parse(read_file_contents(path));
|
||||
|
||||
if (err != "")
|
||||
throw std::runtime_error(std::format("Level::Level({}): file contains invalid JSON: {}", path.string(), err));
|
||||
|
||||
Deserialize(json);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user