1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-24 07:14:31 +01:00

Let ScClimate::type_get return a non-empty string again

This commit is contained in:
Aaron van Geffen
2025-02-22 17:15:32 +01:00
parent e2ae2904be
commit 23e6c26c2b
3 changed files with 17 additions and 21 deletions

View File

@@ -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) {

View File

@@ -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;
};

View File

@@ -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<ClimateObject>(0);
if (climateObj == nullptr)
return "";
return climateObj->getScriptName();
}
std::shared_ptr<ScWeatherState> current_get() const