1 /***************************************************************************** 2 * Copyright (c) 2014-2021 OpenRCT2 developers 3 * 4 * For a complete list of all authors, please refer to contributors.md 5 * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 6 * 7 * OpenRCT2 is licensed under the GNU General Public License version 3. 8 *****************************************************************************/ 9 10 #pragma once 11 12 #ifdef ENABLE_SCRIPTING 13 14 # include "../../../Context.h" 15 # include "../../../common.h" 16 # include "../../../core/String.hpp" 17 # include "../../../world/Climate.h" 18 # include "../../Duktape.hpp" 19 # include "../../ScriptEngine.h" 20 21 namespace OpenRCT2::Scripting 22 { 23 class ScClimateState 24 { 25 private: 26 std::string _weather; 27 int8_t _temperature; 28 29 public: ScClimateState(std::string weather,int8_t temperature)30 ScClimateState(std::string weather, int8_t temperature) 31 : _weather(weather) 32 , _temperature(temperature) 33 { 34 } 35 weather_get() const36 std::string weather_get() const 37 { 38 return _weather; 39 } 40 temperature_get() const41 int8_t temperature_get() const 42 { 43 return _temperature; 44 } 45 Register(duk_context * ctx)46 static void Register(duk_context* ctx) 47 { 48 dukglue_register_property(ctx, &ScClimateState::weather_get, nullptr, "weather"); 49 dukglue_register_property(ctx, &ScClimateState::temperature_get, nullptr, "temperature"); 50 } 51 }; 52 53 class ScClimate 54 { 55 public: ClimateTypeToString(ClimateType token)56 static std::string ClimateTypeToString(ClimateType token) 57 { 58 switch (token) 59 { 60 case ClimateType::CoolAndWet: 61 return "coolAndWet"; 62 case ClimateType::Warm: 63 return "warm"; 64 case ClimateType::HotAndDry: 65 return "hotAndDry"; 66 case ClimateType::Cold: 67 return "cold"; 68 case ClimateType::Count: 69 return ""; 70 } 71 return ""; 72 } 73 WeatherTypeToString(WeatherType token)74 static std::string WeatherTypeToString(WeatherType token) 75 { 76 switch (token) 77 { 78 case WeatherType::Sunny: 79 return "sunny"; 80 case WeatherType::PartiallyCloudy: 81 return "partiallyCloudy"; 82 case WeatherType::Cloudy: 83 return "cloudy"; 84 case WeatherType::Rain: 85 return "rain"; 86 case WeatherType::HeavyRain: 87 return "heavyRain"; 88 case WeatherType::Thunder: 89 return "thunder"; 90 case WeatherType::Snow: 91 return "snow"; 92 case WeatherType::HeavySnow: 93 return "heavySnow"; 94 case WeatherType::Blizzard: 95 return "blizzard"; 96 case WeatherType::Count: 97 return ""; 98 } 99 return ""; 100 } 101 type_get() const102 std::string type_get() const 103 { 104 return ClimateTypeToString(gClimate); 105 } 106 current_get() const107 std::shared_ptr<ScClimateState> current_get() const 108 { 109 std::string weatherType = WeatherTypeToString(gClimateCurrent.Weather); 110 return std::make_shared<ScClimateState>(weatherType, gClimateCurrent.Temperature); 111 } 112 future_get() const113 std::shared_ptr<ScClimateState> future_get() const 114 { 115 std::string weatherType = WeatherTypeToString(gClimateNext.Weather); 116 return std::make_shared<ScClimateState>(weatherType, gClimateNext.Temperature); 117 } 118 Register(duk_context * ctx)119 static void Register(duk_context* ctx) 120 { 121 dukglue_register_property(ctx, &ScClimate::type_get, nullptr, "type"); 122 dukglue_register_property(ctx, &ScClimate::current_get, nullptr, "current"); 123 dukglue_register_property(ctx, &ScClimate::future_get, nullptr, "future"); 124 } 125 }; 126 127 } // namespace OpenRCT2::Scripting 128 129 #endif 130