From a5ebd8dafd758a71b4140680102a81c07427c72d Mon Sep 17 00:00:00 2001 From: leper Date: Tue, 22 Jul 2014 23:30:27 +0000 Subject: [PATCH] Load trigger scripts in serialization test mode. This was SVN commit r15549. --- .../public/simulation/components/Trigger.js | 2 +- source/simulation2/Simulation2.cpp | 42 ++++++++++++------- .../simulation2/system/ComponentManager.cpp | 1 - 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Trigger.js b/binaries/data/mods/public/simulation/components/Trigger.js index 5fd45e5cfb..99bbddb2a4 100644 --- a/binaries/data/mods/public/simulation/components/Trigger.js +++ b/binaries/data/mods/public/simulation/components/Trigger.js @@ -85,7 +85,7 @@ Trigger.prototype.RegisterTrigger = function(event, action, data) } if (this[eventString][action]) { - warn("Trigger.js: Trigger has been registered before. Aborting..."); + warn("Trigger.js: Trigger \"" + action + "\" has been registered before. Aborting..."); return; } // clone the data to be sure it's only modified locally diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index a62a38f210..7c9c936ea4 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -101,6 +101,7 @@ public: static bool LoadDefaultScripts(CComponentManager& componentManager, std::set* loadedScripts); static bool LoadScripts(CComponentManager& componentManager, std::set* loadedScripts, const VfsPath& path); + static bool LoadTriggerScripts(CComponentManager& componentManager, const CScriptValRooted& mapSettings); Status ReloadChangedFile(const VfsPath& path); static Status ReloadChangedFileCB(void* param, const VfsPath& path) @@ -183,12 +184,30 @@ bool CSimulation2Impl::LoadScripts(CComponentManager& componentManager, std::set if (loadedScripts) loadedScripts->insert(filename); LOGMESSAGE(L"Loading simulation script '%ls'", filename.string().c_str()); - if (! componentManager.LoadScript(filename)) + if (!componentManager.LoadScript(filename)) ok = false; } return ok; } +bool CSimulation2Impl::LoadTriggerScripts(CComponentManager& componentManager, const CScriptValRooted& mapSettings) +{ + bool ok = true; + if (componentManager.GetScriptInterface().HasProperty(mapSettings.get(), "TriggerScripts")) + { + std::vector scriptNames; + componentManager.GetScriptInterface().GetProperty(mapSettings.get(), "TriggerScripts", scriptNames); + for (u32 i = 0; i < scriptNames.size(); ++i) + { + std::string scriptName = "maps/" + scriptNames[i]; + LOGMESSAGE(L"Loading trigger script '%hs'", scriptName.c_str()); + if (!componentManager.LoadScript(scriptName.data())) + ok = false; + } + } + return ok; +} + Status CSimulation2Impl::ReloadChangedFile(const VfsPath& path) { // Ignore if this file wasn't loaded as a script @@ -335,6 +354,9 @@ void CSimulation2Impl::Update(int turnLength, const std::vectorm_StartupScript.empty()) GetScriptInterface().LoadScript(L"map startup script", m->m_StartupScript); - - // Load the trigger script after we have loaded the simulation and the map. - if (GetScriptInterface().HasProperty(m->m_MapSettings.get(), "TriggerScripts")) - { - std::vector scriptNames; - GetScriptInterface().GetProperty(m->m_MapSettings.get(), "TriggerScripts", scriptNames); - for (u32 i = 0; i < scriptNames.size(); i++) - { - std::string scriptName = "maps/" + scriptNames[i]; - LOGMESSAGE(L"Loading trigger script '%hs'", scriptName.c_str()); - m->m_ComponentManager.LoadScript(scriptName.data()); - } - } + + // Load the trigger scripts after we have loaded the simulation and the map. + m->LoadTriggerScripts(m->m_ComponentManager, m->m_MapSettings); } int CSimulation2::ProgressiveLoad() diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 465dcc18f8..a153e6fbe1 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -697,7 +697,6 @@ void CComponentManager::AddSystemComponents(bool skipScriptedComponents, bool sk // Add scripted system components: if (!skipScriptedComponents) { - for (uint32_t i = 0; i < m_ScriptedSystemComponents.size(); ++i) AddComponent(m_SystemEntity, m_ScriptedSystemComponents[i], noParam); if (!skipAI)