1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 23:33:04 +01:00

Fix Linux build

This commit is contained in:
Ted John
2020-03-04 00:01:17 +00:00
parent 83fe0cf5c5
commit 49b155d178
4 changed files with 27 additions and 10 deletions

View File

@@ -21,16 +21,16 @@ template<typename T> DukValue GetObjectAsDukValue(duk_context* ctx, const std::s
}
template<typename T>
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;
}

View File

@@ -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<ScTileElement> insertElement(size_t index)
{
ThrowIfGameStateNotMutable();
std::shared_ptr<ScTileElement> result;
auto first = GetFirstElement();
auto origNumElements = GetNumElements(first);
if (index >= 0 && index <= origNumElements)
if (index <= origNumElements)
{
std::vector<TileElement> data(first, first + origNumElements);
@@ -782,7 +798,7 @@ namespace OpenRCT2::Scripting
}
first[origNumElements].SetLastForTile(true);
map_invalidate_tile_full(_coords);
return std::make_shared<ScTileElement>(_coords, &first[index]);
result = std::make_shared<ScTileElement>(_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)

View File

@@ -712,11 +712,11 @@ std::unique_ptr<GameActionResult> 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>& plugin
{
for (auto it = _customActions.begin(); it != _customActions.end();)
{
if (it->second.Plugin == plugin)
if (it->second.Owner == plugin)
{
it = _customActions.erase(it);
}

View File

@@ -121,7 +121,7 @@ namespace OpenRCT2::Scripting
struct CustomAction
{
std::shared_ptr<Plugin> Plugin;
std::shared_ptr<Plugin> Owner;
std::string Name;
DukValue Query;
DukValue Execute;