Beispiel #1
0
bool CSimulation2Impl::LoadScripts(const VfsPath& path)
{
	VfsPaths pathnames;
	if (vfs::GetPathnames(g_VFS, path, L"*.js", pathnames) < 0)
		return false;

	bool ok = true;
	for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
	{
		VfsPath filename = *it;
		m_LoadedScripts.insert(filename);
		LOGMESSAGE(L"Loading simulation script '%ls'", filename.string().c_str());
		if (! m_ComponentManager.LoadScript(filename))
			ok = false;
	}
	return ok;
}
Beispiel #2
0
bool CSimulation2Impl::LoadScripts(CComponentManager& componentManager, std::set<VfsPath>* loadedScripts, const VfsPath& path)
{
	VfsPaths pathnames;
	if (vfs::GetPathnames(g_VFS, path, L"*.js", pathnames) < 0)
		return false;

	bool ok = true;
	for (const VfsPath& path : pathnames)
	{
		if (loadedScripts)
			loadedScripts->insert(path);
		LOGMESSAGE("Loading simulation script '%s'", path.string8());
		if (!componentManager.LoadScript(path))
			ok = false;
	}
	return ok;
}
Beispiel #3
0
Status CSimulation2Impl::ReloadChangedFile(const VfsPath& path)
{
	// Ignore if this file wasn't loaded as a script
	// (TODO: Maybe we ought to load in any new .js files that are created in the right directories)
	if (m_LoadedScripts.find(path) == m_LoadedScripts.end())
		return INFO::OK;

	// If the file doesn't exist (e.g. it was deleted), don't bother loading it since that'll give an error message.
	// (Also don't bother trying to 'unload' it from the component manager, because that's not possible)
	if (!VfsFileExists(path))
		return INFO::OK;

	LOGMESSAGE(L"Reloading simulation script '%ls'", path.string().c_str());
	if (!m_ComponentManager.LoadScript(path, true))
		return ERR::FAIL;

	return INFO::OK;
}
Beispiel #4
0
bool CSimulation2Impl::LoadTriggerScripts(CComponentManager& componentManager, JS::HandleValue mapSettings, std::set<VfsPath>* loadedScripts)
{
	bool ok = true;
	if (componentManager.GetScriptInterface().HasProperty(mapSettings, "TriggerScripts"))
	{
		std::vector<std::string> scriptNames;
		componentManager.GetScriptInterface().GetProperty(mapSettings, "TriggerScripts", scriptNames);
		for (const std::string& triggerScript : scriptNames)
		{
			std::string scriptName = "maps/" + triggerScript;
			if (loadedScripts)
			{
				if (loadedScripts->find(scriptName) != loadedScripts->end())
					continue;
				loadedScripts->insert(scriptName);
			}
			LOGMESSAGE("Loading trigger script '%s'", scriptName.c_str());
			if (!componentManager.LoadScript(scriptName.data()))
				ok = false;
		}
	}
	return ok;
}