1
0
forked from 0ad/0ad

Load trigger scripts in serialization test mode.

This was SVN commit r15549.
This commit is contained in:
leper 2014-07-22 23:30:27 +00:00
parent bfe1e9f182
commit a5ebd8dafd
3 changed files with 28 additions and 17 deletions

View File

@ -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

View File

@ -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<VfsPath>* loadedScripts);
static bool LoadScripts(CComponentManager& componentManager, std::set<VfsPath>* 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<std::string> 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::vector<SimulationComman
ENSURE(LoadDefaultScripts(secondaryComponentManager, NULL));
ResetComponentState(secondaryComponentManager, false, false);
// Load the trigger scripts after we have loaded the simulation.
ENSURE(LoadTriggerScripts(secondaryComponentManager, m_MapSettings));
// Load the map into the secondary simulation
LDR_BeginRegistering();
@ -702,19 +724,9 @@ void CSimulation2::LoadMapSettings()
if (!m->m_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<std::string> 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()

View File

@ -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)