diff --git a/src/openrct2/scripting/Duktape.hpp b/src/openrct2/scripting/Duktape.hpp index d6e695d482..996d7ac0b7 100644 --- a/src/openrct2/scripting/Duktape.hpp +++ b/src/openrct2/scripting/Duktape.hpp @@ -21,16 +21,16 @@ template DukValue GetObjectAsDukValue(duk_context* ctx, const std::s } template -const T AsOrDefault(const DukValue& value, const T& defaultValue = {}) = delete; +T AsOrDefault(const DukValue& value, const T& defaultValue = {}) = delete; template<> -inline const std::string AsOrDefault(const DukValue& value, const std::string& defaultValue) +inline std::string AsOrDefault(const DukValue& value, const std::string& defaultValue) { return value.type() == DukValue::STRING ? value.as_string() : defaultValue; } template<> -inline const int32_t AsOrDefault(const DukValue& value, const int32_t& defaultValue) +inline int32_t AsOrDefault(const DukValue& value, const int32_t& defaultValue) { return value.type() == DukValue::NUMBER ? value.as_int() : defaultValue; } diff --git a/src/openrct2/scripting/ScTile.hpp b/src/openrct2/scripting/ScTile.hpp index 07c9676de8..55746dacaf 100644 --- a/src/openrct2/scripting/ScTile.hpp +++ b/src/openrct2/scripting/ScTile.hpp @@ -313,11 +313,13 @@ namespace OpenRCT2::Scripting { auto el = _element->AsTrack(); el->SetSequenceIndex(value); + break; } case TILE_ELEMENT_TYPE_ENTRANCE: { auto el = _element->AsEntrance(); el->SetSequenceIndex(value); + break; } } } @@ -348,11 +350,13 @@ namespace OpenRCT2::Scripting { auto el = _element->AsTrack(); el->SetRideIndex(value); + break; } case TILE_ELEMENT_TYPE_ENTRANCE: { auto el = _element->AsEntrance(); el->SetRideIndex(value); + break; } } } @@ -383,11 +387,13 @@ namespace OpenRCT2::Scripting { auto el = _element->AsTrack(); el->SetStationIndex(value); + break; } case TILE_ELEMENT_TYPE_ENTRANCE: { auto el = _element->AsEntrance(); el->SetStationIndex(value); + break; } } } @@ -450,26 +456,31 @@ namespace OpenRCT2::Scripting { auto el = _element->AsPath(); el->SetPathEntryIndex(value & 0xFF); + break; } case TILE_ELEMENT_TYPE_SMALL_SCENERY: { auto el = _element->AsSmallScenery(); el->SetEntryIndex(value & 0xFF); + break; } case TILE_ELEMENT_TYPE_LARGE_SCENERY: { auto el = _element->AsLargeScenery(); el->SetEntryIndex(value); + break; } case TILE_ELEMENT_TYPE_WALL: { auto el = _element->AsWall(); el->SetEntryIndex(value & 0xFFFF); + break; } case TILE_ELEMENT_TYPE_ENTRANCE: { auto el = _element->AsEntrance(); el->SetEntranceType(value & 0xFF); + break; } } } @@ -517,11 +528,13 @@ namespace OpenRCT2::Scripting { auto el = _element->AsSmallScenery(); el->SetPrimaryColour(value); + break; } case TILE_ELEMENT_TYPE_LARGE_SCENERY: { auto el = _element->AsLargeScenery(); el->SetPrimaryColour(value); + break; } } } @@ -552,11 +565,13 @@ namespace OpenRCT2::Scripting { auto el = _element->AsSmallScenery(); el->SetSecondaryColour(value); + break; } case TILE_ELEMENT_TYPE_LARGE_SCENERY: { auto el = _element->AsLargeScenery(); el->SetSecondaryColour(value); + break; } } } @@ -747,9 +762,10 @@ namespace OpenRCT2::Scripting std::shared_ptr insertElement(size_t index) { ThrowIfGameStateNotMutable(); + std::shared_ptr result; auto first = GetFirstElement(); auto origNumElements = GetNumElements(first); - if (index >= 0 && index <= origNumElements) + if (index <= origNumElements) { std::vector data(first, first + origNumElements); @@ -782,7 +798,7 @@ namespace OpenRCT2::Scripting } first[origNumElements].SetLastForTile(true); map_invalidate_tile_full(_coords); - return std::make_shared(_coords, &first[index]); + result = std::make_shared(_coords, &first[index]); } } else @@ -790,6 +806,7 @@ namespace OpenRCT2::Scripting auto ctx = GetDukContext(); duk_error(ctx, DUK_ERR_RANGE_ERROR, "Index must be between zero and the number of elements on the tile."); } + return result; } void removeElement(size_t index) diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 981bae7005..5665298914 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -712,11 +712,11 @@ std::unique_ptr ScriptEngine::QueryOrExecuteCustomGameAction( DukValue dukResult; if (!isExecute) { - dukResult = ExecutePluginCall(customAction.Plugin, customAction.Query, { dukArgs }, false); + dukResult = ExecutePluginCall(customAction.Owner, customAction.Query, { dukArgs }, false); } else { - dukResult = ExecutePluginCall(customAction.Plugin, customAction.Execute, { dukArgs }, true); + dukResult = ExecutePluginCall(customAction.Owner, customAction.Execute, { dukArgs }, true); } return DukToGameActionResult(dukResult); } @@ -749,7 +749,7 @@ bool ScriptEngine::RegisterCustomAction( } CustomAction customAction; - customAction.Plugin = plugin; + customAction.Owner = plugin; customAction.Name = std::move(actionz); customAction.Query = query; customAction.Execute = execute; @@ -761,7 +761,7 @@ void ScriptEngine::RemoveCustomGameActions(const std::shared_ptr& plugin { for (auto it = _customActions.begin(); it != _customActions.end();) { - if (it->second.Plugin == plugin) + if (it->second.Owner == plugin) { it = _customActions.erase(it); } diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 9a6981771c..871c40bea4 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -121,7 +121,7 @@ namespace OpenRCT2::Scripting struct CustomAction { - std::shared_ptr Plugin; + std::shared_ptr Owner; std::string Name; DukValue Query; DukValue Execute;