From 23e6c26c2bf7aeae15433f4695a229fd8abd9cb8 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 22 Feb 2025 17:15:32 +0100 Subject: [PATCH] Let ScClimate::type_get return a non-empty string again --- src/openrct2/object/ClimateObject.cpp | 7 +++++ src/openrct2/object/ClimateObject.h | 2 ++ .../scripting/bindings/world/ScClimate.hpp | 29 +++++-------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/openrct2/object/ClimateObject.cpp b/src/openrct2/object/ClimateObject.cpp index d17fa97def..4510934cc7 100644 --- a/src/openrct2/object/ClimateObject.cpp +++ b/src/openrct2/object/ClimateObject.cpp @@ -80,6 +80,8 @@ void ClimateObject::ReadJson(IReadObjectContext* context, json_t& root) Guard::Assert(root["weather"].is_object(), "ClimateObject::ReadJson expects weather key to be an object"); auto rawClimate = readWeatherTable(root["weather"]); _climate = convertRawClimate(rawClimate); + + _scriptName = Json::GetString(root["scriptName"], std::string(GetIdentifier())); } const WeatherPattern& ClimateObject::getPatternForMonth(uint8_t month) const @@ -87,6 +89,11 @@ const WeatherPattern& ClimateObject::getPatternForMonth(uint8_t month) const return _climate[month]; } +std::string ClimateObject::getScriptName() const +{ + return _scriptName; +} + YearlyDistribution ClimateObject::getYearlyDistribution() const { auto weatherTypeCount = [](const WeatherPattern& pattern, const WeatherType target) { diff --git a/src/openrct2/object/ClimateObject.h b/src/openrct2/object/ClimateObject.h index 3a965b8563..b900292781 100644 --- a/src/openrct2/object/ClimateObject.h +++ b/src/openrct2/object/ClimateObject.h @@ -20,6 +20,7 @@ class ClimateObject final : public Object { private: Climate _climate; + std::string _scriptName; public: static constexpr ObjectType kObjectType = ObjectType::climate; @@ -31,5 +32,6 @@ public: void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override; const WeatherPattern& getPatternForMonth(uint8_t month) const; + std::string getScriptName() const; YearlyDistribution getYearlyDistribution() const; }; diff --git a/src/openrct2/scripting/bindings/world/ScClimate.hpp b/src/openrct2/scripting/bindings/world/ScClimate.hpp index 7fd33773a6..32b05c2bf1 100644 --- a/src/openrct2/scripting/bindings/world/ScClimate.hpp +++ b/src/openrct2/scripting/bindings/world/ScClimate.hpp @@ -14,6 +14,8 @@ #include "../../../Context.h" #include "../../../GameState.h" #include "../../../core/StringTypes.h" + #include "../../../object/ClimateObject.h" + #include "../../../object/ObjectManager.h" #include "../../../world/Climate.h" #include "../../Duktape.hpp" #include "../../ScriptEngine.h" @@ -53,25 +55,6 @@ namespace OpenRCT2::Scripting class ScClimate { public: - // TODO: replace with climate object - static std::string ClimateTypeToString(ClimateType token) - { - switch (token) - { - case ClimateType::CoolAndWet: - return "coolAndWet"; - case ClimateType::Warm: - return "warm"; - case ClimateType::HotAndDry: - return "hotAndDry"; - case ClimateType::Cold: - return "cold"; - case ClimateType::Count: - return ""; - } - return ""; - } - static std::string WeatherTypeToString(WeatherType token) { switch (token) @@ -102,8 +85,12 @@ namespace OpenRCT2::Scripting std::string type_get() const { - // TODO: from climate object - return ""; + auto& objManager = GetContext()->GetObjectManager(); + auto* climateObj = objManager.GetLoadedObject(0); + if (climateObj == nullptr) + return ""; + + return climateObj->getScriptName(); } std::shared_ptr current_get() const