From 95b13f670d8ce1de5c71c35ce475de165b53cc4f Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:32:23 +1000 Subject: [PATCH] code clean-up --- assets/opensb/help.config.patch | 2 +- .../frontend/StarClientCommandProcessor.cpp | 43 +++++-------------- source/game/StarWorldClient.cpp | 7 +-- source/game/StarWorldClient.hpp | 3 +- 4 files changed, 15 insertions(+), 40 deletions(-) diff --git a/assets/opensb/help.config.patch b/assets/opensb/help.config.patch index b3f31a6..ad1da12 100644 --- a/assets/opensb/help.config.patch +++ b/assets/opensb/help.config.patch @@ -11,6 +11,6 @@ "openSbCommands": { "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required.", - "respawninworld": "Usage /respawnInWorld. Sets the respawn flag for the current world until you teleport away." + "respawninworld": "Usage /respawninworld. Sets the respawn flag for the current world until you teleport away." } } diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 0237735..8a7e543 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -15,9 +15,9 @@ namespace Star { ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, CinematicPtr cinematicOverlay, - MainInterfacePaneManager* paneManager, StringMap macroCommands) - : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), - m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { + MainInterfacePaneManager* paneManager, StringMap macroCommands) + : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), + m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { m_builtinCommands = { {"reload", bind(&ClientCommandProcessor::reload, this)}, {"whoami", bind(&ClientCommandProcessor::whoami, this)}, @@ -58,7 +58,7 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, bool ClientCommandProcessor::adminCommandAllowed() const { return Root::singleton().configuration()->get("allowAdminCommandsFromAnyone").toBool() || - m_universeClient->mainPlayer()->isAdmin(); + m_universeClient->mainPlayer()->isAdmin(); } String ClientCommandProcessor::previewQuestPane(StringList const& arguments, function createPane) { @@ -187,7 +187,7 @@ String ClientCommandProcessor::setGravity(String const& argumentsString) { return "You must be an admin to use this command."; m_universeClient->worldClient()->overrideGravity(lexicalCast(arguments.at(0))); - return strf("Gravity set to {}, the change is LOCAL ONLY", arguments.at(0)); + return strf("Gravity set to {} (This is client-side!)", arguments.at(0)); } String ClientCommandProcessor::resetGravity() { @@ -431,34 +431,13 @@ String ClientCommandProcessor::swap(String const& argumentsString) { String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { auto arguments = m_parser.tokenizeToStringList(argumentsString); + if (arguments.size() == 0) + return strf("Respawn in this world is currently {}", worldClient->respawnInWorld() ? "true" : "false"); - WorldClientPtr worldClient = m_universeClient->worldClient(); - - - if (arguments.size() == 0) { - const std::string stringResult = worldClient->respawnInWorld() ? "true" : "false"; - return "Respawn in this world is currently " + stringResult; // return the current state of the respawn value when no argument is given - } - if (arguments.size() > 1) { - return "Too many arguments for this command!"; // we dont wanna have too much, right? - } - - // behold: probably one of the least efficient ways to convert a Star::String to a boolean - bool value; - if (arguments[0].toLower() == "true") { - value = true; - } else if(arguments[0].toLower() == "false") { - value = false; - } - else { - return "Invalid argument!"; // at least we get validation if it was not a boolean - } - - bool result = worldClient->setRespawnInWorld(value); - // Convert boolean to string for the response - const std::string stringResult = result ? "true" : "false"; - - return "Successfully set respawn in this world to " + stringResult; + bool respawnInWorld = Json::parse(arguments.at(0)).toBool(); + auto worldClient = m_universeClient->worldClient(); + worldClient->setRespawnInWorld(respawnInWorld); + return strf("Respawn in this world set to {} (This is client-side!)", respawnInWorld ? "true" : "false"); } } \ No newline at end of file diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 3e85c79..8abfcdf 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -142,11 +142,8 @@ bool WorldClient::respawnInWorld() const { return m_respawnInWorld; } -bool WorldClient::setRespawnInWorld(bool value) { - - m_respawnInWorld = value; - - return m_respawnInWorld; +void WorldClient::setRespawnInWorld(bool respawnInWorld) { + m_respawnInWorld = respawnInWorld; } void WorldClient::removeEntity(EntityId entityId, bool andDie) { diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index 9f15e0e..1616b10 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -108,8 +108,7 @@ public: bool mainPlayerDead() const; void reviveMainPlayer(); bool respawnInWorld() const; - - bool setRespawnInWorld(bool value); + void setRespawnInWorld(bool respawnInWorld); void removeEntity(EntityId entityId, bool andDie);