mirror of https://github.com/OpenRCT2/OpenRCT2.git
Implement expenditureType on GameActionResult plugin API (#11514)
* Implement expenditureType on GameActionResult plugin API * Update src/openrct2/scripting/ScriptEngine.cpp Co-Authored-By: Michael Steenbeek <m.o.steenbeek@gmail.com> * Improve formatting of ExpenditureTypes * Apply code review comments Co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
This commit is contained in:
parent
9960e4b563
commit
65a9c7a1b1
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2018 OpenRCT2 developers
|
||||
* 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
|
||||
|
@ -755,6 +755,16 @@ std::unique_ptr<GameActionResult> ScriptEngine::DukToGameActionResult(const DukV
|
|||
result->ErrorTitle = AsOrDefault<std::string>(d["errorTitle"]);
|
||||
result->ErrorMessage = AsOrDefault<std::string>(d["errorMessage"]);
|
||||
result->Cost = AsOrDefault<int32_t>(d["cost"]);
|
||||
|
||||
auto expenditureType = AsOrDefault<std::string>(d["expenditureType"]);
|
||||
if (!expenditureType.empty())
|
||||
{
|
||||
auto expenditure = StringToExpenditureType(expenditureType);
|
||||
if (expenditure != ExpenditureType::Count)
|
||||
{
|
||||
result->Expenditure = expenditure;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -772,6 +782,43 @@ DukValue ScriptEngine::PositionToDuk(const CoordsXYZ& position)
|
|||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
constexpr static const char* ExpenditureTypes[] = {
|
||||
"ride_construction",
|
||||
"ride_runningcosts",
|
||||
"land_purchase",
|
||||
"landscaping",
|
||||
"park_entrance_tickets",
|
||||
"park_ride_tickets",
|
||||
"shop_sales",
|
||||
"shop_stock",
|
||||
"food_drink_sales",
|
||||
"food_drink_stock",
|
||||
"wages",
|
||||
"marketing",
|
||||
"research",
|
||||
"interest",
|
||||
};
|
||||
|
||||
std::string_view ScriptEngine::ExpenditureTypeToString(ExpenditureType expenditureType)
|
||||
{
|
||||
auto index = static_cast<size_t>(expenditureType);
|
||||
if (index < std::size(ExpenditureTypes))
|
||||
{
|
||||
return ExpenditureTypes[index];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ExpenditureType ScriptEngine::StringToExpenditureType(const std::string_view& expenditureType)
|
||||
{
|
||||
auto it = std::find(std::begin(ExpenditureTypes), std::end(ExpenditureTypes), expenditureType);
|
||||
if (it != std::end(ExpenditureTypes))
|
||||
{
|
||||
return static_cast<ExpenditureType>(std::distance(std::begin(ExpenditureTypes), it));
|
||||
}
|
||||
return ExpenditureType::Count;
|
||||
}
|
||||
|
||||
DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std::unique_ptr<GameActionResult>& result)
|
||||
{
|
||||
DukStackFrame frame(_context);
|
||||
|
@ -791,6 +838,11 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std
|
|||
obj.Set("position", PositionToDuk(result->Position));
|
||||
}
|
||||
|
||||
if (result->Expenditure != ExpenditureType::Count)
|
||||
{
|
||||
obj.Set("expenditureType", ExpenditureTypeToString(result->Expenditure));
|
||||
}
|
||||
|
||||
if (action.GetType() == GAME_COMMAND_CREATE_RIDE)
|
||||
{
|
||||
auto& rideCreateResult = static_cast<RideCreateGameActionResult&>(*result.get());
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
# include "../common.h"
|
||||
# include "../core/FileWatcher.h"
|
||||
# include "../management/Finance.h"
|
||||
# include "../world/Location.hpp"
|
||||
# include "HookEngine.h"
|
||||
# include "Plugin.h"
|
||||
|
@ -201,6 +202,8 @@ namespace OpenRCT2::Scripting
|
|||
std::unique_ptr<GameActionResult> DukToGameActionResult(const DukValue& d);
|
||||
DukValue GameActionResultToDuk(const GameAction& action, const std::unique_ptr<GameActionResult>& result);
|
||||
DukValue PositionToDuk(const CoordsXYZ& position);
|
||||
static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType);
|
||||
static ExpenditureType StringToExpenditureType(const std::string_view& expenditureType);
|
||||
|
||||
void InitSharedStorage();
|
||||
void LoadSharedStorage();
|
||||
|
|
Loading…
Reference in New Issue