Lit reorganizing and adding command parser.
This commit is contained in:
@@ -237,7 +237,13 @@ void EditorApp::LoadLevel(const std::filesystem::path& level_meta_path)
|
||||
layer->Load();
|
||||
|
||||
|
||||
tileset_view = new TilesetView(loaded_tileset, loaded_tilesheet);
|
||||
tileset_view = new TilesetView(loaded_tileset, loaded_tilesheet, scene);
|
||||
|
||||
tileset_view->TileSelected += [this](int id) mutable {
|
||||
selected_quad = id;
|
||||
};
|
||||
|
||||
layer_view->UpdateComponents(loaded_level);
|
||||
|
||||
data_ready = true;
|
||||
}
|
||||
@@ -357,31 +363,37 @@ namespace misc {
|
||||
|
||||
}
|
||||
|
||||
void EditorApp::ParseCmdLineMessage(const std::string &message) {
|
||||
auto tokens = misc::string_expand(message);
|
||||
struct Arg {
|
||||
std::string name;
|
||||
std::string type;
|
||||
bool optional;
|
||||
};
|
||||
|
||||
if (tokens.size() == 0) {
|
||||
console->Log("No command input!", Colors::Red);
|
||||
return;
|
||||
}
|
||||
struct Command {
|
||||
std::string name;
|
||||
std::vector<std::string> aliases;
|
||||
std::vector<Arg> args;
|
||||
std::string err_msg = "ERROR: Invalid command syntax!";
|
||||
};
|
||||
|
||||
std::string cmd = tokens[0];
|
||||
|
||||
// Remove 0th element from tokens before passing to command delegates.
|
||||
tokens.erase(tokens.begin());
|
||||
|
||||
|
||||
|
||||
if (misc::string_matches(cmd, {"reset"})) {
|
||||
|
||||
}
|
||||
|
||||
console->Log(std::format("No such command: {}", cmd), Colors::Red);
|
||||
void EditorApp::LogHelpInfo() {
|
||||
console->Log("Redacted Software 2D Level Editor - Command Line");
|
||||
console->Log("Type `cmds` to see a list of all commands!");
|
||||
}
|
||||
|
||||
std::string tolower(const std::string& s) {
|
||||
std::string copy = "";
|
||||
for (auto elem : s) {
|
||||
copy += std::tolower(elem);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
void EditorApp::BindConsoleCallbacks()
|
||||
{
|
||||
|
||||
|
||||
// TODO: This parsing pattern is duplicated between at least 2 other projects at this point.
|
||||
// TODO: Move up into JUI or a separate package.
|
||||
console->OnInput += [this] (const std::string& input)
|
||||
@@ -390,21 +402,36 @@ void EditorApp::BindConsoleCallbacks()
|
||||
|
||||
std::string cmd = tokens[0];
|
||||
|
||||
tokens.erase(tokens.begin());
|
||||
|
||||
if (cmd == "help") {
|
||||
return LogHelpInfo();
|
||||
}
|
||||
if (cmd == "cmds" || cmd == "commandlist") {
|
||||
|
||||
}
|
||||
if (cmd == "q" || cmd == "quit") { return this->Close(); }
|
||||
if (cmd == "framegraph") {
|
||||
// TODO: Add FpsGraph::Toggle().
|
||||
fps_graph->Visible(!fps_graph->IsVisible());
|
||||
}
|
||||
if (cmd == "load") {
|
||||
LoadLevel(tokens[1]);
|
||||
if (tokens.size() >= 1) {
|
||||
return LoadLevel(tokens[0]);
|
||||
}
|
||||
return console->Log("ERROR: Must provide file name!");
|
||||
}
|
||||
if (cmd == "save") {
|
||||
SaveCurrentLevel();
|
||||
}
|
||||
if (cmd == "save-as") {
|
||||
if (tokens.size() >= 2)
|
||||
SaveCurrentLevelAs(tokens[1]);
|
||||
if (tokens.size() >= 1)
|
||||
return SaveCurrentLevelAs(tokens[0]);
|
||||
else
|
||||
console->Log(std::format("ERROR: Must provide file name: {}", cmd));
|
||||
return console->Log(std::format("ERROR: Must provide file name: {}", cmd));
|
||||
}
|
||||
if (cmd == "new") {
|
||||
SaveCurrentLevel();
|
||||
|
||||
}
|
||||
|
||||
if (cmd == "info") {
|
||||
@@ -416,7 +443,7 @@ void EditorApp::BindConsoleCallbacks()
|
||||
if (cmd == "tileset") {
|
||||
|
||||
}
|
||||
|
||||
console->Log(std::format("No such command: {}", cmd), Colors::Red);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -426,7 +453,7 @@ void EditorApp::CreateWidgets()
|
||||
|
||||
app_info_dialog = CreateAppInfoDialogWindow(scene);
|
||||
|
||||
auto* fps_graph = new JUI::FpsGraph(scene);
|
||||
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});
|
||||
@@ -891,11 +918,6 @@ void EditorApp::Draw()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if (data_ready) {
|
||||
|
Reference in New Issue
Block a user