mirror of https://github.com/OpenRCT2/OpenRCT2.git
Move ScParkMessage into its own files
This commit is contained in:
parent
437321ac8f
commit
d558920606
|
@ -790,6 +790,8 @@
|
||||||
63858E295E3F451283987982 /* ScRideStation.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */; };
|
63858E295E3F451283987982 /* ScRideStation.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */; };
|
||||||
705A4B342C7D4F38B26BAFA4 /* ScRide.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3B00C9900ED42AFA72764ED /* ScRide.cpp */; };
|
705A4B342C7D4F38B26BAFA4 /* ScRide.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3B00C9900ED42AFA72764ED /* ScRide.cpp */; };
|
||||||
2B8F76B32C944D3C97F0FFAF /* ScMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4BE60702D7549488A32CC0B /* ScMap.cpp */; };
|
2B8F76B32C944D3C97F0FFAF /* ScMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4BE60702D7549488A32CC0B /* ScMap.cpp */; };
|
||||||
|
BE55C1C86BFE4A0DA61260E2 /* ScParkMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1939C9C3CFDB4FB6BA5DE47E /* ScParkMessage.cpp */; };
|
||||||
|
AD5EC8B5EBF240B3874BC581 /* ScParkMessage.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56E37ADCDBD440BD8AC35446 /* ScParkMessage.hpp */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
@ -1882,6 +1884,8 @@
|
||||||
1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScRideStation.hpp; path = src/openrct2/scripting/bindings/ride/ScRideStation.hpp; sourceTree = SOURCE_ROOT; };
|
1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScRideStation.hpp; path = src/openrct2/scripting/bindings/ride/ScRideStation.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
F3B00C9900ED42AFA72764ED /* ScRide.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScRide.cpp; path = src/openrct2/scripting/bindings/ride/ScRide.cpp; sourceTree = SOURCE_ROOT; };
|
F3B00C9900ED42AFA72764ED /* ScRide.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScRide.cpp; path = src/openrct2/scripting/bindings/ride/ScRide.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
E4BE60702D7549488A32CC0B /* ScMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScMap.cpp; path = src/openrct2/scripting/bindings/world/ScMap.cpp; sourceTree = SOURCE_ROOT; };
|
E4BE60702D7549488A32CC0B /* ScMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScMap.cpp; path = src/openrct2/scripting/bindings/world/ScMap.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
|
1939C9C3CFDB4FB6BA5DE47E /* ScParkMessage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScParkMessage.cpp; path = src/openrct2/scripting/bindings/world/ScParkMessage.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
|
56E37ADCDBD440BD8AC35446 /* ScParkMessage.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScParkMessage.hpp; path = src/openrct2/scripting/bindings/world/ScParkMessage.hpp; sourceTree = SOURCE_ROOT; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -3463,6 +3467,8 @@
|
||||||
A9F55F2291284217BA0E4E51 /* ScScenario.hpp */,
|
A9F55F2291284217BA0E4E51 /* ScScenario.hpp */,
|
||||||
22D7DD798F054A068273739B /* ScTile.hpp */,
|
22D7DD798F054A068273739B /* ScTile.hpp */,
|
||||||
E4BE60702D7549488A32CC0B /* ScMap.cpp */,
|
E4BE60702D7549488A32CC0B /* ScMap.cpp */,
|
||||||
|
1939C9C3CFDB4FB6BA5DE47E /* ScParkMessage.cpp */,
|
||||||
|
56E37ADCDBD440BD8AC35446 /* ScParkMessage.hpp */,
|
||||||
);
|
);
|
||||||
name = world;
|
name = world;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -3618,6 +3624,7 @@
|
||||||
97C222A2A4F543E9AEC3912B /* ScPlayerGroup.hpp in Headers */,
|
97C222A2A4F543E9AEC3912B /* ScPlayerGroup.hpp in Headers */,
|
||||||
2D0A43F28D5747C9B617F342 /* ScPlayer.hpp in Headers */,
|
2D0A43F28D5747C9B617F342 /* ScPlayer.hpp in Headers */,
|
||||||
63858E295E3F451283987982 /* ScRideStation.hpp in Headers */,
|
63858E295E3F451283987982 /* ScRideStation.hpp in Headers */,
|
||||||
|
AD5EC8B5EBF240B3874BC581 /* ScParkMessage.hpp in Headers */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -4433,6 +4440,7 @@
|
||||||
CDC72A71A28542F4AD73A91C /* ScRideStation.cpp in Sources */,
|
CDC72A71A28542F4AD73A91C /* ScRideStation.cpp in Sources */,
|
||||||
705A4B342C7D4F38B26BAFA4 /* ScRide.cpp in Sources */,
|
705A4B342C7D4F38B26BAFA4 /* ScRide.cpp in Sources */,
|
||||||
2B8F76B32C944D3C97F0FFAF /* ScMap.cpp in Sources */,
|
2B8F76B32C944D3C97F0FFAF /* ScMap.cpp in Sources */,
|
||||||
|
BE55C1C86BFE4A0DA61260E2 /* ScParkMessage.cpp in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -413,6 +413,7 @@
|
||||||
<ClInclude Include="scripting\bindings\network\ScPlayer.hpp" />
|
<ClInclude Include="scripting\bindings\network\ScPlayer.hpp" />
|
||||||
<ClInclude Include="scripting\bindings\network\ScPlayerGroup.hpp" />
|
<ClInclude Include="scripting\bindings\network\ScPlayerGroup.hpp" />
|
||||||
<ClInclude Include="scripting\bindings\ride\ScRideStation.hpp" />
|
<ClInclude Include="scripting\bindings\ride\ScRideStation.hpp" />
|
||||||
|
<ClInclude Include="scripting\bindings\world\ScParkMessage.hpp" />
|
||||||
<ClInclude Include="scripting\Duktape.hpp" />
|
<ClInclude Include="scripting\Duktape.hpp" />
|
||||||
<ClInclude Include="scripting\HookEngine.h" />
|
<ClInclude Include="scripting\HookEngine.h" />
|
||||||
<ClInclude Include="scripting\Plugin.h" />
|
<ClInclude Include="scripting\Plugin.h" />
|
||||||
|
@ -867,6 +868,7 @@
|
||||||
<ClCompile Include="scripting\bindings\ride\ScRide.cpp" />
|
<ClCompile Include="scripting\bindings\ride\ScRide.cpp" />
|
||||||
<ClCompile Include="scripting\bindings\ride\ScRideStation.cpp" />
|
<ClCompile Include="scripting\bindings\ride\ScRideStation.cpp" />
|
||||||
<ClCompile Include="scripting\bindings\world\ScMap.cpp" />
|
<ClCompile Include="scripting\bindings\world\ScMap.cpp" />
|
||||||
|
<ClCompile Include="scripting\bindings\world\ScParkMessage.cpp" />
|
||||||
<ClCompile Include="scripting\HookEngine.cpp" />
|
<ClCompile Include="scripting\HookEngine.cpp" />
|
||||||
<ClCompile Include="scripting\Plugin.cpp" />
|
<ClCompile Include="scripting\Plugin.cpp" />
|
||||||
<ClCompile Include="scripting\ScriptEngine.cpp" />
|
<ClCompile Include="scripting\ScriptEngine.cpp" />
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
# include "bindings/world/ScDate.hpp"
|
# include "bindings/world/ScDate.hpp"
|
||||||
# include "bindings/world/ScMap.hpp"
|
# include "bindings/world/ScMap.hpp"
|
||||||
# include "bindings/world/ScPark.hpp"
|
# include "bindings/world/ScPark.hpp"
|
||||||
|
# include "bindings/world/ScParkMessage.hpp"
|
||||||
# include "bindings/world/ScScenario.hpp"
|
# include "bindings/world/ScScenario.hpp"
|
||||||
# include "bindings/world/ScTile.hpp"
|
# include "bindings/world/ScTile.hpp"
|
||||||
|
|
||||||
|
|
|
@ -22,211 +22,12 @@
|
||||||
# include "../../../world/Park.h"
|
# include "../../../world/Park.h"
|
||||||
# include "../../Duktape.hpp"
|
# include "../../Duktape.hpp"
|
||||||
# include "../../ScriptEngine.h"
|
# include "../../ScriptEngine.h"
|
||||||
|
# include "ScParkMessage.hpp"
|
||||||
|
|
||||||
# include <algorithm>
|
# include <algorithm>
|
||||||
|
|
||||||
namespace OpenRCT2::Scripting
|
namespace OpenRCT2::Scripting
|
||||||
{
|
{
|
||||||
static constexpr const char* ParkMessageTypeStrings[] = {
|
|
||||||
"attraction", "peep_on_attraction", "peep", "money", "blank", "research", "guests", "award", "chart",
|
|
||||||
};
|
|
||||||
|
|
||||||
inline News::ItemType GetParkMessageType(const std::string& key)
|
|
||||||
{
|
|
||||||
// Get the first ItemType that appears in ParkMessageTypeStrings that isn't Null
|
|
||||||
auto firstType = static_cast<uint8_t>(News::ItemType::Ride);
|
|
||||||
|
|
||||||
auto begin = std::begin(ParkMessageTypeStrings);
|
|
||||||
auto end = std::end(ParkMessageTypeStrings);
|
|
||||||
|
|
||||||
auto it = std::find(begin, end, key);
|
|
||||||
return it != end ? static_cast<News::ItemType>(firstType + std::distance(begin, it)) : News::ItemType::Blank;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string GetParkMessageType(News::ItemType type)
|
|
||||||
{
|
|
||||||
// Decrement 1 as ParkMessageTypeStrings doesn't contain the null type
|
|
||||||
auto scriptType = static_cast<size_t>(type) - 1;
|
|
||||||
|
|
||||||
if (scriptType < std::size(ParkMessageTypeStrings))
|
|
||||||
{
|
|
||||||
return ParkMessageTypeStrings[scriptType];
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> inline News::Item FromDuk(const DukValue& value)
|
|
||||||
{
|
|
||||||
News::Item result{};
|
|
||||||
result.Type = GetParkMessageType(value["type"].as_string());
|
|
||||||
result.Assoc = value["subject"].as_int();
|
|
||||||
result.Ticks = value["tickCount"].as_int();
|
|
||||||
result.MonthYear = value["month"].as_int();
|
|
||||||
result.Day = value["day"].as_int();
|
|
||||||
result.Text = value["text"].as_string();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ScParkMessage
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
size_t _index{};
|
|
||||||
|
|
||||||
public:
|
|
||||||
ScParkMessage(size_t index)
|
|
||||||
: _index(index)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Register(duk_context* ctx)
|
|
||||||
{
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::isArchived_get, nullptr, "isArchived");
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::month_get, &ScParkMessage::month_set, "month");
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::day_get, &ScParkMessage::day_set, "day");
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::tickCount_get, &ScParkMessage::tickCount_set, "tickCount");
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::type_get, &ScParkMessage::type_set, "type");
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::subject_get, &ScParkMessage::subject_set, "subject");
|
|
||||||
dukglue_register_property(ctx, &ScParkMessage::text_get, &ScParkMessage::text_set, "text");
|
|
||||||
dukglue_register_method(ctx, &ScParkMessage::remove, "remove");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
News::Item* GetMessage() const
|
|
||||||
{
|
|
||||||
return &gNewsItems[_index];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isArchived_get() const
|
|
||||||
{
|
|
||||||
return _index >= News::ItemHistoryStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t month_get() const
|
|
||||||
{
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
return msg->MonthYear;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void month_set(uint16_t value)
|
|
||||||
{
|
|
||||||
ThrowIfGameStateNotMutable();
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
msg->MonthYear = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t day_get() const
|
|
||||||
{
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
return msg->Day;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void day_set(uint8_t value)
|
|
||||||
{
|
|
||||||
ThrowIfGameStateNotMutable();
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
msg->Day = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t tickCount_get() const
|
|
||||||
{
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
return msg->Ticks;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tickCount_set(uint16_t value)
|
|
||||||
{
|
|
||||||
ThrowIfGameStateNotMutable();
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
msg->Ticks = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string type_get() const
|
|
||||||
{
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
return GetParkMessageType(msg->Type);
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void type_set(const std::string& value)
|
|
||||||
{
|
|
||||||
ThrowIfGameStateNotMutable();
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
msg->Type = GetParkMessageType(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t subject_get() const
|
|
||||||
{
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
return msg->Assoc;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void subject_set(uint32_t value)
|
|
||||||
{
|
|
||||||
ThrowIfGameStateNotMutable();
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
msg->Assoc = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string text_get() const
|
|
||||||
{
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
return msg->Text;
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void text_set(const std::string& value)
|
|
||||||
{
|
|
||||||
ThrowIfGameStateNotMutable();
|
|
||||||
auto msg = GetMessage();
|
|
||||||
if (msg != nullptr)
|
|
||||||
{
|
|
||||||
msg->Text = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove()
|
|
||||||
{
|
|
||||||
News::RemoveItem(static_cast<int32_t>(_index));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const DukEnumMap<uint64_t> ParkFlagMap({
|
static const DukEnumMap<uint64_t> ParkFlagMap({
|
||||||
{ "open", PARK_FLAGS_PARK_OPEN },
|
{ "open", PARK_FLAGS_PARK_OPEN },
|
||||||
{ "scenarioCompleteNameInput", PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT },
|
{ "scenarioCompleteNameInput", PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT },
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef ENABLE_SCRIPTING
|
||||||
|
|
||||||
|
# include "ScParkMessage.hpp"
|
||||||
|
|
||||||
|
# include "../../../Context.h"
|
||||||
|
# include "../../../GameState.h"
|
||||||
|
# include "../../../common.h"
|
||||||
|
# include "../../../core/String.hpp"
|
||||||
|
# include "../../../management/Finance.h"
|
||||||
|
# include "../../../management/NewsItem.h"
|
||||||
|
# include "../../../peep/Peep.h"
|
||||||
|
# include "../../../windows/Intent.h"
|
||||||
|
# include "../../../world/Park.h"
|
||||||
|
# include "../../Duktape.hpp"
|
||||||
|
# include "../../ScriptEngine.h"
|
||||||
|
|
||||||
|
# include <algorithm>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Scripting
|
||||||
|
{
|
||||||
|
ScParkMessage::ScParkMessage(size_t index)
|
||||||
|
: _index(index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::Register(duk_context* ctx)
|
||||||
|
{
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::isArchived_get, nullptr, "isArchived");
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::month_get, &ScParkMessage::month_set, "month");
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::day_get, &ScParkMessage::day_set, "day");
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::tickCount_get, &ScParkMessage::tickCount_set, "tickCount");
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::type_get, &ScParkMessage::type_set, "type");
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::subject_get, &ScParkMessage::subject_set, "subject");
|
||||||
|
dukglue_register_property(ctx, &ScParkMessage::text_get, &ScParkMessage::text_set, "text");
|
||||||
|
dukglue_register_method(ctx, &ScParkMessage::remove, "remove");
|
||||||
|
}
|
||||||
|
|
||||||
|
News::Item* ScParkMessage::GetMessage() const
|
||||||
|
{
|
||||||
|
return &gNewsItems[_index];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScParkMessage::isArchived_get() const
|
||||||
|
{
|
||||||
|
return _index >= News::ItemHistoryStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ScParkMessage::month_get() const
|
||||||
|
{
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
return msg->MonthYear;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::month_set(uint16_t value)
|
||||||
|
{
|
||||||
|
ThrowIfGameStateNotMutable();
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
msg->MonthYear = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ScParkMessage::day_get() const
|
||||||
|
{
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
return msg->Day;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::day_set(uint8_t value)
|
||||||
|
{
|
||||||
|
ThrowIfGameStateNotMutable();
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
msg->Day = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ScParkMessage::tickCount_get() const
|
||||||
|
{
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
return msg->Ticks;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::tickCount_set(uint16_t value)
|
||||||
|
{
|
||||||
|
ThrowIfGameStateNotMutable();
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
msg->Ticks = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ScParkMessage::type_get() const
|
||||||
|
{
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
return GetParkMessageType(msg->Type);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::type_set(const std::string& value)
|
||||||
|
{
|
||||||
|
ThrowIfGameStateNotMutable();
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
msg->Type = GetParkMessageType(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ScParkMessage::subject_get() const
|
||||||
|
{
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
return msg->Assoc;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::subject_set(uint32_t value)
|
||||||
|
{
|
||||||
|
ThrowIfGameStateNotMutable();
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
msg->Assoc = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ScParkMessage::text_get() const
|
||||||
|
{
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
return msg->Text;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::text_set(const std::string& value)
|
||||||
|
{
|
||||||
|
ThrowIfGameStateNotMutable();
|
||||||
|
auto msg = GetMessage();
|
||||||
|
if (msg != nullptr)
|
||||||
|
{
|
||||||
|
msg->Text = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScParkMessage::remove()
|
||||||
|
{
|
||||||
|
News::RemoveItem(static_cast<int32_t>(_index));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace OpenRCT2::Scripting
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* Copyright (c) 2014-2020 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 "../../../management/NewsItem.h"
|
||||||
|
# include "../../Duktape.hpp"
|
||||||
|
# include "../../ScriptEngine.h"
|
||||||
|
|
||||||
|
# include <algorithm>
|
||||||
|
|
||||||
|
namespace OpenRCT2::Scripting
|
||||||
|
{
|
||||||
|
static constexpr const char* ParkMessageTypeStrings[] = {
|
||||||
|
"attraction", "peep_on_attraction", "peep", "money", "blank", "research", "guests", "award", "chart",
|
||||||
|
};
|
||||||
|
|
||||||
|
inline News::ItemType GetParkMessageType(const std::string& key)
|
||||||
|
{
|
||||||
|
// Get the first ItemType that appears in ParkMessageTypeStrings that isn't Null
|
||||||
|
auto firstType = static_cast<uint8_t>(News::ItemType::Ride);
|
||||||
|
|
||||||
|
auto begin = std::begin(ParkMessageTypeStrings);
|
||||||
|
auto end = std::end(ParkMessageTypeStrings);
|
||||||
|
|
||||||
|
auto it = std::find(begin, end, key);
|
||||||
|
return it != end ? static_cast<News::ItemType>(firstType + std::distance(begin, it)) : News::ItemType::Blank;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string GetParkMessageType(News::ItemType type)
|
||||||
|
{
|
||||||
|
// Decrement 1 as ParkMessageTypeStrings doesn't contain the null type
|
||||||
|
auto scriptType = static_cast<size_t>(type) - 1;
|
||||||
|
|
||||||
|
if (scriptType < std::size(ParkMessageTypeStrings))
|
||||||
|
{
|
||||||
|
return ParkMessageTypeStrings[scriptType];
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> inline News::Item FromDuk(const DukValue& value)
|
||||||
|
{
|
||||||
|
News::Item result{};
|
||||||
|
result.Type = GetParkMessageType(value["type"].as_string());
|
||||||
|
result.Assoc = value["subject"].as_int();
|
||||||
|
result.Ticks = value["tickCount"].as_int();
|
||||||
|
result.MonthYear = value["month"].as_int();
|
||||||
|
result.Day = value["day"].as_int();
|
||||||
|
result.Text = value["text"].as_string();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScParkMessage
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
size_t _index{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
ScParkMessage(size_t index);
|
||||||
|
|
||||||
|
static void Register(duk_context* ctx);
|
||||||
|
|
||||||
|
private:
|
||||||
|
News::Item* GetMessage() const;
|
||||||
|
|
||||||
|
bool isArchived_get() const;
|
||||||
|
|
||||||
|
uint16_t month_get() const;
|
||||||
|
void month_set(uint16_t value);
|
||||||
|
|
||||||
|
uint8_t day_get() const;
|
||||||
|
void day_set(uint8_t value);
|
||||||
|
|
||||||
|
uint16_t tickCount_get() const;
|
||||||
|
void tickCount_set(uint16_t value);
|
||||||
|
|
||||||
|
std::string type_get() const;
|
||||||
|
void type_set(const std::string& value);
|
||||||
|
|
||||||
|
uint32_t subject_get() const;
|
||||||
|
void subject_set(uint32_t value);
|
||||||
|
|
||||||
|
std::string text_get() const;
|
||||||
|
void text_set(const std::string& value);
|
||||||
|
|
||||||
|
void remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace OpenRCT2::Scripting
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue