From 371bbc0675643ea76339c2cfa7765451b985708d Mon Sep 17 00:00:00 2001 From: ZehMatt Date: Mon, 9 Aug 2021 20:32:20 +0300 Subject: [PATCH] Move ScLitter to its own files --- OpenRCT2.xcodeproj/project.pbxproj | 8 ++ src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/scripting/ScriptEngine.cpp | 1 + .../scripting/bindings/entity/ScEntity.hpp | 68 ---------------- .../scripting/bindings/entity/ScLitter.cpp | 80 +++++++++++++++++++ .../scripting/bindings/entity/ScLitter.hpp | 36 +++++++++ 6 files changed, 127 insertions(+), 68 deletions(-) create mode 100644 src/openrct2/scripting/bindings/entity/ScLitter.cpp create mode 100644 src/openrct2/scripting/bindings/entity/ScLitter.hpp diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index 8550bdd4c8..7b4962d138 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -779,6 +779,8 @@ D7B575F07C4D4E42887C72AA /* ScPeep.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2B63F2F751A3427C9CE9B214 /* ScPeep.hpp */; }; 7A06F880718F49CA9FB71F52 /* ScStaff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EFAF58A62B44C4B887559B7 /* ScStaff.cpp */; }; 9DF65BAE250C4307AE5794DB /* ScStaff.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C30AB6C640464647ABE90EC4 /* ScStaff.hpp */; }; + 8E6484F6C43644F4B644D361 /* ScLitter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36C67B84754D4FEFA3678AA9 /* ScLitter.cpp */; }; + 359328A3A65D49578912CA40 /* ScLitter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C30388F4F6D34DF59EF7072C /* ScLitter.hpp */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -1860,6 +1862,8 @@ 2B63F2F751A3427C9CE9B214 /* ScPeep.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScPeep.hpp; path = src/openrct2/scripting/bindings/entity/ScPeep.hpp; sourceTree = SOURCE_ROOT; }; 3EFAF58A62B44C4B887559B7 /* ScStaff.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScStaff.cpp; path = src/openrct2/scripting/bindings/entity/ScStaff.cpp; sourceTree = SOURCE_ROOT; }; C30AB6C640464647ABE90EC4 /* ScStaff.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScStaff.hpp; path = src/openrct2/scripting/bindings/entity/ScStaff.hpp; sourceTree = SOURCE_ROOT; }; + 36C67B84754D4FEFA3678AA9 /* ScLitter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScLitter.cpp; path = src/openrct2/scripting/bindings/entity/ScLitter.cpp; sourceTree = SOURCE_ROOT; }; + C30388F4F6D34DF59EF7072C /* ScLitter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScLitter.hpp; path = src/openrct2/scripting/bindings/entity/ScLitter.hpp; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -3380,6 +3384,8 @@ 2B63F2F751A3427C9CE9B214 /* ScPeep.hpp */, 3EFAF58A62B44C4B887559B7 /* ScStaff.cpp */, C30AB6C640464647ABE90EC4 /* ScStaff.hpp */, + 36C67B84754D4FEFA3678AA9 /* ScLitter.cpp */, + C30388F4F6D34DF59EF7072C /* ScLitter.hpp */, ); name = entity; sourceTree = ""; @@ -3581,6 +3587,7 @@ 428B1DADD66C4829894AD0A1 /* ScGuest.hpp in Headers */, D7B575F07C4D4E42887C72AA /* ScPeep.hpp in Headers */, 9DF65BAE250C4307AE5794DB /* ScStaff.hpp in Headers */, + 359328A3A65D49578912CA40 /* ScLitter.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -4389,6 +4396,7 @@ 73FB2E7C254144D9BAE4925A /* ScVehicle.cpp in Sources */, BC39D70B9A2249E4B14E99FA /* ScGuest.cpp in Sources */, 7A06F880718F49CA9FB71F52 /* ScStaff.cpp in Sources */, + 8E6484F6C43644F4B644D361 /* ScLitter.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 8f2773e65e..6e68b44c43 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -406,6 +406,7 @@ + @@ -854,6 +855,7 @@ + diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 4a01eb97fb..bc3fe0ee34 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -26,6 +26,7 @@ # include "Duktape.hpp" # include "bindings/entity/ScEntity.hpp" # include "bindings/entity/ScGuest.hpp" +# include "bindings/entity/ScLitter.hpp" # include "bindings/entity/ScPeep.hpp" # include "bindings/entity/ScStaff.hpp" # include "bindings/game/ScCheats.hpp" diff --git a/src/openrct2/scripting/bindings/entity/ScEntity.hpp b/src/openrct2/scripting/bindings/entity/ScEntity.hpp index ba9a176bef..6531862fdf 100644 --- a/src/openrct2/scripting/bindings/entity/ScEntity.hpp +++ b/src/openrct2/scripting/bindings/entity/ScEntity.hpp @@ -14,14 +14,11 @@ # include "../../../Context.h" # include "../../../common.h" # include "../../../peep/Peep.h" -# include "../../../peep/Staff.h" # include "../../../util/Util.h" # include "../../../world/EntityList.h" -# include "../../../world/Litter.h" # include "../../../world/Sprite.h" # include "../../Duktape.hpp" # include "../../ScriptEngine.h" -# include "../ride/ScRide.hpp" # include # include @@ -210,71 +207,6 @@ namespace OpenRCT2::Scripting } }; - static const DukEnumMap LitterTypeMap({ - { "vomit", Litter::Type::Vomit }, - { "vomit_alt", Litter::Type::VomitAlt }, - { "empty_can", Litter::Type::EmptyCan }, - { "rubbish", Litter::Type::Rubbish }, - { "burger_box", Litter::Type::BurgerBox }, - { "empty_cup", Litter::Type::EmptyCup }, - { "empty_box", Litter::Type::EmptyBox }, - { "empty_bottle", Litter::Type::EmptyBottle }, - { "empty_bowl_red", Litter::Type::EmptyBowlRed }, - { "empty_drink_carton", Litter::Type::EmptyDrinkCarton }, - { "empty_juice_cup", Litter::Type::EmptyJuiceCup }, - { "empty_bowl_blue", Litter::Type::EmptyBowlBlue }, - }); - - class ScLitter : public ScEntity - { - public: - ScLitter(uint16_t Id) - : ScEntity(Id) - { - } - - static void Register(duk_context* ctx) - { - dukglue_set_base_class(ctx); - dukglue_register_property(ctx, &ScLitter::litterType_get, &ScLitter::litterType_set, "litterType"); - dukglue_register_property(ctx, &ScLitter::creationTick_get, nullptr, "creationTick"); - } - - private: - Litter* GetLitter() const - { - return ::GetEntity(_id); - } - - std::string litterType_get() const - { - auto* litter = GetLitter(); - auto it = LitterTypeMap.find(litter->SubType); - if (it == LitterTypeMap.end()) - return ""; - return std::string{ it->first }; - } - - void litterType_set(const std::string& litterType) - { - ThrowIfGameStateNotMutable(); - - auto it = LitterTypeMap.find(litterType); - if (it == LitterTypeMap.end()) - return; - auto* litter = GetLitter(); - litter->SubType = it->second; - } - - uint32_t creationTick_get() const - { - auto* litter = GetLitter(); - if (litter == nullptr) - return 0; - return litter->creationTick; - } - }; - } // namespace OpenRCT2::Scripting #endif diff --git a/src/openrct2/scripting/bindings/entity/ScLitter.cpp b/src/openrct2/scripting/bindings/entity/ScLitter.cpp new file mode 100644 index 0000000000..1163666230 --- /dev/null +++ b/src/openrct2/scripting/bindings/entity/ScLitter.cpp @@ -0,0 +1,80 @@ +/***************************************************************************** + * 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 "ScLitter.hpp" + +namespace OpenRCT2::Scripting +{ + static const DukEnumMap LitterTypeMap({ + { "vomit", Litter::Type::Vomit }, + { "vomit_alt", Litter::Type::VomitAlt }, + { "empty_can", Litter::Type::EmptyCan }, + { "rubbish", Litter::Type::Rubbish }, + { "burger_box", Litter::Type::BurgerBox }, + { "empty_cup", Litter::Type::EmptyCup }, + { "empty_box", Litter::Type::EmptyBox }, + { "empty_bottle", Litter::Type::EmptyBottle }, + { "empty_bowl_red", Litter::Type::EmptyBowlRed }, + { "empty_drink_carton", Litter::Type::EmptyDrinkCarton }, + { "empty_juice_cup", Litter::Type::EmptyJuiceCup }, + { "empty_bowl_blue", Litter::Type::EmptyBowlBlue }, + }); + + ScLitter::ScLitter(uint16_t Id) + : ScEntity(Id) + { + } + + void ScLitter::Register(duk_context* ctx) + { + dukglue_set_base_class(ctx); + dukglue_register_property(ctx, &ScLitter::litterType_get, &ScLitter::litterType_set, "litterType"); + dukglue_register_property(ctx, &ScLitter::creationTick_get, nullptr, "creationTick"); + } + + Litter* ScLitter::GetLitter() const + { + return ::GetEntity(_id); + } + + std::string ScLitter::litterType_get() const + { + auto* litter = GetLitter(); + auto it = LitterTypeMap.find(litter->SubType); + if (it == LitterTypeMap.end()) + return ""; + return std::string{ it->first }; + } + + void ScLitter::litterType_set(const std::string& litterType) + { + ThrowIfGameStateNotMutable(); + + auto it = LitterTypeMap.find(litterType); + if (it == LitterTypeMap.end()) + return; + auto* litter = GetLitter(); + litter->SubType = it->second; + } + + uint32_t ScLitter::creationTick_get() const + { + auto* litter = GetLitter(); + if (litter == nullptr) + return 0; + return litter->creationTick; + } + +} // namespace OpenRCT2::Scripting + +#endif diff --git a/src/openrct2/scripting/bindings/entity/ScLitter.hpp b/src/openrct2/scripting/bindings/entity/ScLitter.hpp new file mode 100644 index 0000000000..d2184b1075 --- /dev/null +++ b/src/openrct2/scripting/bindings/entity/ScLitter.hpp @@ -0,0 +1,36 @@ +/***************************************************************************** + * 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 "ScEntity.hpp" + +namespace OpenRCT2::Scripting +{ + class ScLitter : public ScEntity + { + public: + ScLitter(uint16_t Id); + + static void Register(duk_context* ctx); + + private: + Litter* GetLitter() const; + + std::string litterType_get() const; + void litterType_set(const std::string& litterType); + + uint32_t creationTick_get() const; + }; + +} // namespace OpenRCT2::Scripting + +#endif