mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Separate map.change and map.changed events
Also fix network plugin logic.
This commit is contained in:
3
distribution/openrct2.d.ts
vendored
3
distribution/openrct2.d.ts
vendored
@@ -292,6 +292,7 @@ declare global {
|
||||
subscribe(hook: "guest.generation", callback: (e: GuestGenerationArgs) => void): IDisposable;
|
||||
subscribe(hook: "vehicle.crash", callback: (e: VehicleCrashArgs) => void): IDisposable;
|
||||
subscribe(hook: "map.save", callback: () => void): IDisposable;
|
||||
subscribe(hook: "map.change", callback: () => void): IDisposable;
|
||||
|
||||
/**
|
||||
* Can only be used in intransient plugins.
|
||||
@@ -405,7 +406,7 @@ declare global {
|
||||
"interval.tick" | "interval.day" |
|
||||
"network.chat" | "network.action" | "network.join" | "network.leave" |
|
||||
"ride.ratings.calculate" | "action.location" | "vehicle.crash" |
|
||||
"map.changed" | "map.save";
|
||||
"map.change" | "map.changed" | "map.save";
|
||||
|
||||
type ExpenditureType =
|
||||
"ride_construction" |
|
||||
|
||||
@@ -286,6 +286,7 @@ private:
|
||||
auto parkHandle = TitleSequenceGetParkHandle(*_sequence, saveIndex);
|
||||
if (parkHandle != nullptr)
|
||||
{
|
||||
game_notify_map_change();
|
||||
loadSuccess = LoadParkFromStream(parkHandle->Stream.get(), parkHandle->HintPath);
|
||||
}
|
||||
if (loadSuccess)
|
||||
@@ -309,6 +310,7 @@ private:
|
||||
auto scenario = GetScenarioRepository()->GetByInternalName(command.Scenario);
|
||||
if (scenario != nullptr)
|
||||
{
|
||||
game_notify_map_change();
|
||||
loadSuccess = LoadParkFromFile(scenario->path);
|
||||
}
|
||||
if (loadSuccess)
|
||||
|
||||
@@ -337,6 +337,7 @@ public:
|
||||
}
|
||||
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
||||
{
|
||||
game_notify_map_change();
|
||||
game_unload_scripts();
|
||||
title_load();
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ static void WindowServerStartClose(rct_window* w)
|
||||
|
||||
static void WindowServerStartScenarioselectCallback(const utf8* path)
|
||||
{
|
||||
network_set_password(_password);
|
||||
game_notify_map_change();
|
||||
if (context_load_park_from_file(path))
|
||||
{
|
||||
network_begin_server(gConfigNetwork.default_port, gConfigNetwork.listen_address.c_str());
|
||||
@@ -135,8 +135,10 @@ static void WindowServerStartScenarioselectCallback(const utf8* path)
|
||||
|
||||
static void WindowServerStartLoadsaveCallback(int32_t result, const utf8* path)
|
||||
{
|
||||
if (result == MODAL_RESULT_OK && context_load_park_from_file(path))
|
||||
if (result == MODAL_RESULT_OK)
|
||||
{
|
||||
game_notify_map_change();
|
||||
context_load_park_from_file(path);
|
||||
network_begin_server(gConfigNetwork.default_port, gConfigNetwork.listen_address.c_str());
|
||||
}
|
||||
}
|
||||
@@ -185,6 +187,7 @@ static void WindowServerStartMouseup(rct_window* w, rct_widgetindex widgetIndex)
|
||||
w->Invalidate();
|
||||
break;
|
||||
case WIDX_START_SERVER:
|
||||
network_set_password(_password);
|
||||
WindowScenarioselectOpen(WindowServerStartScenarioselectCallback, false);
|
||||
break;
|
||||
case WIDX_LOAD_SERVER:
|
||||
|
||||
@@ -117,6 +117,7 @@ rct_window* WindowTitleMenuOpen()
|
||||
|
||||
static void WindowTitleMenuScenarioselectCallback(const utf8* path)
|
||||
{
|
||||
game_notify_map_change();
|
||||
OpenRCT2::GetContext()->LoadParkFromFile(path, false, true);
|
||||
game_load_scripts();
|
||||
game_notify_map_changed();
|
||||
|
||||
@@ -535,6 +535,7 @@ static void WindowTopToolbarMousedown(rct_window* w, rct_widgetindex widgetIndex
|
||||
static void WindowTopToolbarScenarioselectCallback(const utf8* path)
|
||||
{
|
||||
window_close_by_class(WC_EDITOR_OBJECT_SELECTION);
|
||||
game_notify_map_change();
|
||||
GetContext()->LoadParkFromFile(path, false, true);
|
||||
game_load_scripts();
|
||||
game_notify_map_changed();
|
||||
|
||||
@@ -89,6 +89,10 @@ uint32_t gCurrentRealTimeTicks;
|
||||
rct_string_id gGameCommandErrorTitle;
|
||||
rct_string_id gGameCommandErrorText;
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
static bool _mapChangedExpected;
|
||||
#endif
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
void game_reset_speed()
|
||||
@@ -513,6 +517,22 @@ void game_unload_scripts()
|
||||
#endif
|
||||
}
|
||||
|
||||
void game_notify_map_change()
|
||||
{
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
// Ensure we don't get a two lots of change events
|
||||
if (_mapChangedExpected)
|
||||
return;
|
||||
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
auto& hookEngine = scriptEngine.GetHookEngine();
|
||||
hookEngine.Call(HOOK_TYPE::MAP_CHANGE, false);
|
||||
_mapChangedExpected = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void game_notify_map_changed()
|
||||
{
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
@@ -520,7 +540,8 @@ void game_notify_map_changed()
|
||||
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
auto& hookEngine = scriptEngine.GetHookEngine();
|
||||
hookEngine.Call(HOOK_TYPE::MAP_CHANGE, false);
|
||||
hookEngine.Call(HOOK_TYPE::MAP_CHANGED, false);
|
||||
_mapChangedExpected = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -703,6 +724,7 @@ static void game_load_or_quit_no_save_prompt_callback(int32_t result, const utf8
|
||||
{
|
||||
if (result == MODAL_RESULT_OK)
|
||||
{
|
||||
game_notify_map_change();
|
||||
game_unload_scripts();
|
||||
window_close_by_class(WC_EDITOR_OBJECT_SELECTION);
|
||||
context_load_park_from_file(path);
|
||||
@@ -748,6 +770,7 @@ void game_load_or_quit_no_save_prompt()
|
||||
}
|
||||
gGameSpeed = 1;
|
||||
gFirstTimeSaving = true;
|
||||
game_notify_map_change();
|
||||
game_unload_scripts();
|
||||
title_load();
|
||||
break;
|
||||
|
||||
@@ -160,6 +160,7 @@ void load_from_sv6(const char* path);
|
||||
void game_load_init();
|
||||
void game_load_scripts();
|
||||
void game_unload_scripts();
|
||||
void game_notify_map_change();
|
||||
void game_notify_map_changed();
|
||||
void pause_toggle();
|
||||
bool game_is_paused();
|
||||
|
||||
@@ -203,6 +203,11 @@ void NetworkBase::Close()
|
||||
_pendingPlayerLists.clear();
|
||||
_pendingPlayerInfo.clear();
|
||||
|
||||
# ifdef ENABLE_SCRIPTING
|
||||
auto& scriptEngine = GetContext().GetScriptEngine();
|
||||
scriptEngine.RemoveNetworkPlugins();
|
||||
# endif
|
||||
|
||||
gfx_invalidate_screen();
|
||||
|
||||
_requireClose = false;
|
||||
@@ -2681,6 +2686,9 @@ void NetworkBase::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connecti
|
||||
GameActions::ResumeQueue();
|
||||
|
||||
context_force_close_window_by_class(WC_NETWORK_STATUS);
|
||||
game_unload_scripts();
|
||||
game_notify_map_change();
|
||||
|
||||
bool has_to_free = false;
|
||||
uint8_t* data = &chunk_buffer[0];
|
||||
size_t data_size = size;
|
||||
|
||||
@@ -32,6 +32,7 @@ static const EnumMap<HOOK_TYPE> HooksLookupTable({
|
||||
{ "guest.generation", HOOK_TYPE::GUEST_GENERATION },
|
||||
{ "vehicle.crash", HOOK_TYPE::VEHICLE_CRASH },
|
||||
{ "map.change", HOOK_TYPE::MAP_CHANGE },
|
||||
{ "map.changed", HOOK_TYPE::MAP_CHANGED },
|
||||
{ "map.save", HOOK_TYPE::MAP_SAVE },
|
||||
});
|
||||
|
||||
@@ -100,7 +101,7 @@ bool HookEngine::HasSubscriptions(HOOK_TYPE type) const
|
||||
|
||||
bool HookEngine::IsValidHookForPlugin(HOOK_TYPE type, Plugin& plugin) const
|
||||
{
|
||||
if (type == HOOK_TYPE::MAP_CHANGE && plugin.GetMetadata().Type != PluginType::Intransient)
|
||||
if (type == HOOK_TYPE::MAP_CHANGED && plugin.GetMetadata().Type != PluginType::Intransient)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace OpenRCT2::Scripting
|
||||
GUEST_GENERATION,
|
||||
VEHICLE_CRASH,
|
||||
MAP_CHANGE,
|
||||
MAP_CHANGED,
|
||||
MAP_SAVE,
|
||||
COUNT,
|
||||
UNDEFINED = -1,
|
||||
|
||||
@@ -455,7 +455,10 @@ void ScriptEngine::RefreshPlugins()
|
||||
std::vector<std::string> addedPlugins;
|
||||
for (const auto& plugin : _plugins)
|
||||
{
|
||||
plugins.push_back(std::string(plugin->GetPath()));
|
||||
if (plugin->HasPath())
|
||||
{
|
||||
plugins.push_back(std::string(plugin->GetPath()));
|
||||
}
|
||||
}
|
||||
std::set_difference(
|
||||
plugins.begin(), plugins.end(), pluginFiles.begin(), pluginFiles.end(), std::back_inserter(removedPlugins));
|
||||
@@ -919,7 +922,23 @@ void ScriptEngine::AddNetworkPlugin(std::string_view code)
|
||||
{
|
||||
auto plugin = std::make_shared<Plugin>(_context, std::string());
|
||||
plugin->SetCode(code);
|
||||
LoadPlugin(plugin);
|
||||
_plugins.push_back(plugin);
|
||||
}
|
||||
|
||||
void ScriptEngine::RemoveNetworkPlugins()
|
||||
{
|
||||
auto it = _plugins.begin();
|
||||
while (it != _plugins.end())
|
||||
{
|
||||
if (!(*it)->HasPath())
|
||||
{
|
||||
it = _plugins.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameActions::Result ScriptEngine::QueryOrExecuteCustomGameAction(std::string_view id, std::string_view args, bool isExecute)
|
||||
|
||||
@@ -232,6 +232,7 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
|
||||
void AddNetworkPlugin(std::string_view code);
|
||||
void RemoveNetworkPlugins();
|
||||
|
||||
[[nodiscard]] GameActions::Result QueryOrExecuteCustomGameAction(
|
||||
std::string_view id, std::string_view args, bool isExecute);
|
||||
|
||||
Reference in New Issue
Block a user