1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +01:00

Expose monthly expenditure history to plug-in API

This commit is contained in:
Arnold Zhou
2024-06-24 06:49:49 +10:00
committed by GitHub
parent f9a06ae01b
commit a0f5d09408
6 changed files with 35 additions and 4 deletions

View File

@@ -119,7 +119,7 @@ Appreciation for contributors who have provided substantial work, but are no lon
* Tiago Reul (reul) - Misc.
* Fredrik Tegnell (fredriktegnell) - Misc.
* Alex Parisi (alex-parisi) - Added API for returning metadata from all registered plugins.
* Arnold Zhou (mrmagic2020) - Added plugin API for getting and setting guests' favourite rides, new game option, misc.
* Arnold Zhou (mrmagic2020) - Various plugin additions, new game option, misc.
## Bug fixes & Refactors
* Claudio Tiecher (janclod)

View File

@@ -10,6 +10,7 @@
- Feature: [#22085] [Plugin] The result of actions that create banners now includes the bannerIndex.
- Feature: [#22087] [Plugin] Expose guests favourite rides to the plugin API.
- Feature: [#22140] Add option to automatically close dropdown menus if Enlarged UI is enabled.
- Feature: [#22150] [Plugin] Expose monthly expenditure history to the plugin API.
- Improved: [#19870] Allow using new colours in UI themes.
- Improved: [#21853] Dropdowns now automatically use multiple columns if they are too tall for the screen.
- Improved: [#21981] Rendering performance of the map window has been improved considerably.

View File

@@ -3799,6 +3799,14 @@ declare global {
postMessage(message: string): void;
postMessage(message: ParkMessageDesc): void;
/**
* Gets the monthly expenditure history for a given type.
* Index 0 represents the current month, index 1 the previous month, etc.
* The maximum length of the array is 16.
* @param type The type of expenditure to get.
*/
getMonthlyExpenditure(type: ExpenditureType): number[]
}
interface Research {

View File

@@ -47,7 +47,7 @@ namespace OpenRCT2
namespace OpenRCT2::Scripting
{
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 92;
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 93;
// Versions marking breaking changes.
static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;
@@ -262,6 +262,9 @@ namespace OpenRCT2::Scripting
IntervalHandle AddInterval(const std::shared_ptr<Plugin>& plugin, int32_t delay, bool repeat, DukValue&& callback);
void RemoveInterval(const std::shared_ptr<Plugin>& plugin, IntervalHandle handle);
static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType);
static ExpenditureType StringToExpenditureType(std::string_view expenditureType);
# ifndef DISABLE_NETWORK
void AddSocket(const std::shared_ptr<ScSocketBase>& socket);
# endif
@@ -289,8 +292,6 @@ namespace OpenRCT2::Scripting
void ProcessREPL();
void RemoveCustomGameActions(const std::shared_ptr<Plugin>& plugin);
[[nodiscard]] GameActions::Result DukToGameActionResult(const DukValue& d);
static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType);
static ExpenditureType StringToExpenditureType(std::string_view expenditureType);
void InitSharedStorage();
void LoadSharedStorage();

View File

@@ -12,6 +12,7 @@
# include "ScPark.hpp"
# include "../../../Context.h"
# include "../../../Date.h"
# include "../../../GameState.h"
# include "../../../common.h"
# include "../../../core/String.hpp"
@@ -401,6 +402,23 @@ namespace OpenRCT2::Scripting
}
}
std::vector<int32_t> ScPark::getMonthlyExpenditure(const std::string& expenditureType) const
{
auto recordedMonths = std::clamp(
GetDate().GetMonthsElapsed() + 1, static_cast<uint32_t>(0), static_cast<uint32_t>(kExpenditureTableMonthCount));
std::vector<int32_t> result(recordedMonths, 0);
auto type = ScriptEngine::StringToExpenditureType(expenditureType);
if (type != ExpenditureType::Count)
{
auto& gameState = GetGameState();
for (size_t i = 0; i < recordedMonths; ++i)
{
result[i] = gameState.ExpenditureTable[i][EnumValue(type)];
}
}
return result;
}
void ScPark::Register(duk_context* ctx)
{
dukglue_register_property(ctx, &ScPark::cash_get, &ScPark::cash_set, "cash");
@@ -432,6 +450,7 @@ namespace OpenRCT2::Scripting
dukglue_register_method(ctx, &ScPark::getFlag, "getFlag");
dukglue_register_method(ctx, &ScPark::setFlag, "setFlag");
dukglue_register_method(ctx, &ScPark::postMessage, "postMessage");
dukglue_register_method(ctx, &ScPark::getMonthlyExpenditure, "getMonthlyExpenditure");
}
} // namespace OpenRCT2::Scripting

View File

@@ -98,6 +98,8 @@ namespace OpenRCT2::Scripting
void postMessage(DukValue message);
std::vector<int32_t> getMonthlyExpenditure(const std::string& expenditureType) const;
static void Register(duk_context* ctx);
};
} // namespace OpenRCT2::Scripting