Add climate information to Park API (#14636)

This commit is contained in:
Ryan 2021-05-16 20:06:36 -04:00 committed by GitHub
parent 1fef332f6a
commit d309a7c871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 177 additions and 1 deletions

View File

@ -5,6 +5,7 @@
- Feature: [#14296] Allow using early scenario completion in multiplayer.
- Feature: [#14538] [Plugin] Add property for getting current plugin api version.
- Feature: [#14620] [Plugin] Add properties related to guest generation.
- Feature: [#14636] [Plugin] Add properties related to climate and weather.
- Change: [#14496] [Plugin] Rename Object to LoadedObject to fix conflicts with Typescript's Object interface.
- Change: [#14536] [Plugin] Rename ListView to ListViewWidget to make it consistent with names of other widgets.
- Fix: [#11829] Visual glitches and crashes when using RCT1 assets from mismatched or corrupt CSG1.DAT and CSG1i.DAT files.

View File

@ -37,6 +37,8 @@ declare global {
var park: Park;
/** APIs for the current scenario. */
var scenario: Scenario;
/** APIs for the climate and weather. */
var climate: Climate;
/**
* APIs for creating and editing title sequences.
* These will only be available to clients that are not running headless mode.
@ -1819,6 +1821,45 @@ declare global {
companyValueRecord: number;
}
type ClimateType =
"coolAndWet" |
"warm" |
"hotAndDry" |
"cold";
type WeatherType =
"sunny" |
"partiallyCloudy" |
"cloudy" |
"rain" |
"heavyRain" |
"thunder" |
"snow" |
"heavySnow" |
"blizzard";
interface ClimateState {
readonly weather: WeatherType;
readonly temperature: number;
}
interface Climate {
/**
* The climate of the park.
*/
readonly type: ClimateType;
/**
* The current weather in the park.
*/
readonly current: ClimateState;
/**
* The next weather the park will experience.
*/
readonly future: ClimateState;
}
interface Cheats {
allowArbitraryRideTypeChanges: boolean;
allowTrackPlaceInvalidHeights: boolean;

View File

@ -408,6 +408,7 @@
<ClInclude Include="scripting\HookEngine.h" />
<ClInclude Include="scripting\Plugin.h" />
<ClInclude Include="scripting\ScCheats.hpp" />
<ClInclude Include="scripting\ScClimate.hpp" />
<ClInclude Include="scripting\ScConfiguration.hpp" />
<ClInclude Include="scripting\ScConsole.hpp" />
<ClInclude Include="scripting\ScContext.hpp" />

View File

@ -0,0 +1,129 @@
/*****************************************************************************
* Copyright (c) 2014-2021 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#ifdef ENABLE_SCRIPTING
# include "../Context.h"
# include "../common.h"
# include "../core/String.hpp"
# include "../world/Climate.h"
# include "Duktape.hpp"
# include "ScriptEngine.h"
namespace OpenRCT2::Scripting
{
class ScClimateState
{
private:
std::string _weather;
int8_t _temperature;
public:
ScClimateState(std::string weather, int8_t temperature)
: _weather(weather)
, _temperature(temperature)
{
}
std::string weather_get() const
{
return _weather;
}
int8_t temperature_get() const
{
return _temperature;
}
static void Register(duk_context* ctx)
{
dukglue_register_property(ctx, &ScClimateState::weather_get, nullptr, "weather");
dukglue_register_property(ctx, &ScClimateState::temperature_get, nullptr, "temperature");
}
};
class ScClimate
{
public:
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)
{
case WeatherType::Sunny:
return "sunny";
case WeatherType::PartiallyCloudy:
return "partiallyCloudy";
case WeatherType::Cloudy:
return "cloudy";
case WeatherType::Rain:
return "rain";
case WeatherType::HeavyRain:
return "heavyRain";
case WeatherType::Thunder:
return "thunder";
case WeatherType::Snow:
return "snow";
case WeatherType::HeavySnow:
return "heavySnow";
case WeatherType::Blizzard:
return "blizzard";
case WeatherType::Count:
return "";
}
return "";
}
std::string type_get() const
{
return ClimateTypeToString(gClimate);
}
std::shared_ptr<ScClimateState> current_get() const
{
std::string weatherType = WeatherTypeToString(gClimateCurrent.Weather);
return std::make_shared<ScClimateState>(weatherType, gClimateCurrent.Temperature);
}
std::shared_ptr<ScClimateState> future_get() const
{
std::string weatherType = WeatherTypeToString(gClimateNext.Weather);
return std::make_shared<ScClimateState>(weatherType, gClimateNext.Temperature);
}
static void Register(duk_context* ctx)
{
dukglue_register_property(ctx, &ScClimate::type_get, nullptr, "type");
dukglue_register_property(ctx, &ScClimate::current_get, nullptr, "current");
dukglue_register_property(ctx, &ScClimate::future_get, nullptr, "future");
}
};
} // namespace OpenRCT2::Scripting
#endif

View File

@ -24,6 +24,7 @@
# include "../platform/Platform2.h"
# include "Duktape.hpp"
# include "ScCheats.hpp"
# include "ScClimate.hpp"
# include "ScConsole.hpp"
# include "ScContext.hpp"
# include "ScDate.hpp"
@ -377,6 +378,8 @@ void ScriptEngine::Initialise()
{
auto ctx = static_cast<duk_context*>(_context);
ScCheats::Register(ctx);
ScClimate::Register(ctx);
ScClimateState::Register(ctx);
ScConfiguration::Register(ctx);
ScConsole::Register(ctx);
ScContext::Register(ctx);
@ -409,6 +412,7 @@ void ScriptEngine::Initialise()
ScStaff::Register(ctx);
dukglue_register_global(ctx, std::make_shared<ScCheats>(), "cheats");
dukglue_register_global(ctx, std::make_shared<ScClimate>(), "climate");
dukglue_register_global(ctx, std::make_shared<ScConsole>(_console), "console");
dukglue_register_global(ctx, std::make_shared<ScContext>(_execInfo, _hookEngine), "context");
dukglue_register_global(ctx, std::make_shared<ScDate>(), "date");

View File

@ -46,7 +46,7 @@ namespace OpenRCT2
namespace OpenRCT2::Scripting
{
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 29;
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 30;
# ifndef DISABLE_NETWORK
class ScSocketBase;