Uploading Edits

This commit is contained in:
2025-02-16 20:07:19 -05:00
parent fba1546a9b
commit 6ba265e9e2
7 changed files with 104 additions and 65 deletions

View File

@@ -107,6 +107,12 @@ namespace CaveGame::Client
unsigned int GetRenderTargetCount() const;
void SaveAndExit() override
{
World::SaveAndExit();
}
void RenderTile(const Core::TileID &tid, int wx, int wy, int tx, int ty);
protected:

View File

@@ -5,6 +5,7 @@ void CaveGame::Client::Console::OnInputEvent(const std::string &msg) {
Log(std::format(">{}", msg));
OnInput.Invoke(msg);
// TODO: Handle within JUI
input_box->SetAutoCompleteText("");
input_box->SetContent("");
}
@@ -21,14 +22,17 @@ CaveGame::Client::Console::Console(JUI::Widget *parent) : JUI::Window(parent)
//message_log_view->Position(JUI::UDim2());
input_box = new JUI::TextInputForm(this->ViewportInstance());
input_box->SetContent("Test");
input_box->Size(JUI::UDim2(0, 20, 1, 0));
input_box->Position(JUI::UDim2(0, -20, 0, 1));
input_box->BGColor(Colors::Grays::DarkSlateGray);
input_box->SetTextSize(16);
input_box->SetAutoCompleteText("");
// TODO: input_box->ClearTextOnReturn(true);
input_box->OnReturn += [this] (const std::string& msg) {
OnInputEvent(msg);
};
CaveGame::Logs::Info.OnLog += [this](std::string m, Color4 c) {Log(m, c); };

View File

@@ -22,8 +22,7 @@ namespace CaveGame::ClientApp {
using CommandArgs = std::vector<std::string>;
struct Command
{
struct Command {
std::string name;
std::vector<std::string> aliases;
std::function<void(CommandArgs)> callback;
@@ -34,32 +33,25 @@ namespace CaveGame::ClientApp {
/// This class is derived from RWindow class.
class CaveGameWindow : public ReWindow::OpenGLWindow, public SceneManager {
public:
[[nodiscard]] bool InGameSession() const;
[[nodiscard]] bool InMainMenu() const;
Client::AssetService assets;
CaveGame::Client::Splash* splash_ctx;
CaveGame::Client::MainMenu* menu_ctx;
CaveGame::Client::GameSession* game_ctx;
JUI::Scene* wm;
JUI::Window* settings_window;
JUI::Window* credits_window;
Client::TileTool* tile_tool;
Client::Console* console_window;
JUI::Window* stats_window;
//Scene* current_scene = nullptr;
bool render_grid = true;
bool generate_grid = true;
bool mbd = false;
float our_avg = 0.f;
/// Returns the game's console GUI, which accepts commands and displays log messages.
Client::Console* Console();
/// Returns the Scene that holds global menu windows, which can appear in any game-context.
JUI::Scene* WindowManager();
/// Returns the active game-world session, if it exists.
Client::GameSession* GameSession();
/// Constructs and returns an instance of the game program.
/// @param title
CaveGameWindow(const std::string& title, int width, int height);
~CaveGameWindow();
~CaveGameWindow() override;
Vector2 GetMouseV2() const;
Vector2 GetSizeV2() const;
bool InGame() const;
[[nodiscard]] bool InGameSession() const;
[[nodiscard]] bool InMainMenu() const;
/// This function runs the totality of the game loop, start to finish.
/// @note The game loop runs until Die() is called, at which point final cleanup is performed.
void Run();
@@ -100,49 +92,71 @@ namespace CaveGame::ClientApp {
void Step();
void InGameControls(float elapsed);
void OnConsoleCommandInput(const std::string &command);
protected:
float tool_radius = 8.f;
float tool_percent = 100.f;
bool wanna_die = false; // This field indicates the program is ready to close.
void DrawTileToolOverlayCursor();
/// Forwards a message to the console log.
void Log(const std::string& msg, const Color4& color = Colors::White);
bool HelpCommand(const CommandArgs& args);
bool ListCommand(const CommandArgs& args);
bool ToggleTileSim(const CommandArgs& args);
#define callback [this](const auto& args)
// What is this dog shit?
std::vector<Command> commands {
{"help", {}, callback{}},
{"list", {}, callback { return ListCommand(args); }},
{"quit", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"worldedit", {"q"}, [this](auto args) { tile_tool->Enable(!tile_tool->IsEnabled()); return true;}},
{"tilesim", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"grid", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"credits", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"settings", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"spawn", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"settings", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"give", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"tp", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"freecam", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"noclip", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"god", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"fullbright", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"connect", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"disconnect", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"server", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"sandbox", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"crash", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"time", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"jui_debug", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
{"jui_debug", {"q"}, std::bind(&CaveGameWindow::HelpCommand, this, std::placeholders::_1)},
};
{"help", {}, [this](const auto& args) {return HelpCommand(args); }},
{"list", {}, [this](const auto& args) { return ListCommand(args); }},
{"quit", {"q"}, [this](const auto& args) {
Close();
return true;
}},
{"worldedit", {"we"}, [this](const auto& args) {
tile_tool->Enable(!tile_tool->IsEnabled());
return true;
}},
{"tilesim", {"q"}, [this](const auto& args) { return ToggleTileSim(args);}},
{"grid", {"q"}, [this](const auto& args) {}},
{"credits", {"q"}, [this](const auto& args) {credits_window->Visible(!credits_window->IsVisible()); }},
{"settings", {"q"}, [this](const auto& args) {}},
{"spawn", {"q"}, [this](const auto& args) {}},
{"settings", {"q"}, [this](const auto& args) {}},
{"give", {"q"}, [this](const auto& args) {}},
{"tp", {"q"}, [this](const auto& args) {}},
{"freecam", {"q"}, [this](const auto& args) {}},
{"noclip", {"q"}, [this](const auto& args) {}},
{"god", {"q"}, [this](const auto& args) {}},
{"fullbright", {"q"}, [this](const auto& args) {}},
{"connect", {"q"}, [this](const auto& args) {}},
{"disconnect", {"q"}, [this](const auto& args) {}},
{"server", {"q"}, [this](const auto& args) {}},
{"sandbox", {"q"}, [this](const auto& args) {}},
{"crash", {"q"}, [this](const auto& args) {}},
{"time", {"q"}, [this](const auto& args) {}},
{"jui_debug", {"q"}, [this](const auto& args) {}},
};
bool HasCommand(const std::string &command);
Command GetCommand(const std::string &command);
protected:
Client::AssetService assets;
CaveGame::Client::Splash* splash_ctx;
CaveGame::Client::MainMenu* menu_ctx;
CaveGame::Client::GameSession* game_ctx;
JUI::Scene* wm;
JUI::Window* settings_window;
JUI::Window* credits_window;
Client::TileTool* tile_tool;
Client::Console* console_window;
float tool_radius = 8.f;
float tool_percent = 100.f;
bool wanna_die = false; // This field indicates the program is ready to close.
JUI::Window* stats_window;
bool render_grid = true;
bool generate_grid = true;
bool mbd = false;
float our_avg = 0.f;
bool HasCommand(const std::string &command);
Command GetCommand(const std::string &command);
};
}

View File

@@ -422,6 +422,7 @@ namespace CaveGame::ClientApp
if (ev.key == Keys::Escape) {
game_ctx->SaveAndExit();
// TODO: GameContext needs mechanism to **inform** the higher-level object that we are done.
ChangeScene(menu_ctx);
}
@@ -633,7 +634,6 @@ namespace CaveGame::ClientApp
bool CaveGameWindow::HelpCommand(const CommandArgs &args) {
return true;
}
@@ -645,6 +645,23 @@ namespace CaveGame::ClientApp
return true;
}
Client::GameSession *CaveGameWindow::GameSession() { return game_ctx; }
JUI::Scene *CaveGameWindow::WindowManager() { return wm;}
Client::Console *CaveGameWindow::Console() { return console_window; }
bool CaveGameWindow::ToggleTileSim(const CommandArgs &args) {
if (InGame())
{
GameSession()->world->SetTileSimulationEnabled(!GameSession()->world->GetTileSimulationEnabled());
return true;
}
Log("ERROR: Not in game context!", Colors::Red);
return false;
}
}

View File

@@ -11,8 +11,7 @@ namespace CaveGame::Logs
std::string format_source_location(const std::source_location & location);
class CaveGameLogger : public GenericLogger
{
class CaveGameLogger : public GenericLogger {
public:
Event<std::string, Color4> OnLog;

View File

@@ -181,6 +181,6 @@ namespace CaveGame::Core {
private:
void Save();
};
}

View File

@@ -423,22 +423,21 @@ namespace CaveGame::Core
}
}
void World::Save() {
for (auto& [coords, chunk] : loaded_chunks)
SaveChunkToFile(coords, chunk);
}
void World::AutoSave() {
OnAutosave.Invoke();
Logs::Info("Autosaving...");
for (auto& [coords, chunk] : loaded_chunks)
{
SaveChunkToFile(coords, chunk);
}
Save();
Logs::Info("Autosave successful!");
}
void World::SaveAndExit() {
Logs::Info("Saving before exiting...");
for (auto&[coords, chunk] : loaded_chunks)
{
SaveChunkToFile(coords, chunk);
}
Save();
Logs::Info("Saving successful!");
}