Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/Simulation2.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | return ( | ||||
LoadScripts(componentManager, loadedScripts, L"simulation/components/interfaces/") && | LoadScripts(componentManager, loadedScripts, L"simulation/components/interfaces/") && | ||||
LoadScripts(componentManager, loadedScripts, L"simulation/helpers/") && | LoadScripts(componentManager, loadedScripts, L"simulation/helpers/") && | ||||
LoadScripts(componentManager, loadedScripts, L"simulation/components/") | LoadScripts(componentManager, loadedScripts, L"simulation/components/") | ||||
); | ); | ||||
} | } | ||||
bool CSimulation2Impl::LoadScripts(CComponentManager& componentManager, std::set<VfsPath>* loadedScripts, const VfsPath& path) | bool CSimulation2Impl::LoadScripts(CComponentManager& componentManager, std::set<VfsPath>* loadedScripts, const VfsPath& path) | ||||
{ | { | ||||
// Sort simulation scripts, so that modders can extend code from previously loaded files. | |||||
VfsPaths pathnames; | VfsPaths pathnames; | ||||
if (vfs::GetPathnames(g_VFS, path, L"*.js", pathnames) < 0) | if (vfs::GetPathnames(g_VFS, path, L"*.js", pathnames, true) < 0) | ||||
return false; | return false; | ||||
bool ok = true; | bool ok = true; | ||||
for (const VfsPath& path : pathnames) | for (const VfsPath& path : pathnames) | ||||
{ | { | ||||
if (loadedScripts) | if (loadedScripts) | ||||
loadedScripts->insert(path); | loadedScripts->insert(path); | ||||
LOGMESSAGE("Loading simulation script '%s'", path.string8()); | LOGMESSAGE("Loading simulation script '%s'", path.string8()); | ||||
▲ Show 20 Lines • Show All 692 Lines • ▼ Show 20 Lines | |||||
std::string CSimulation2::GenerateSchema() | std::string CSimulation2::GenerateSchema() | ||||
{ | { | ||||
return m->m_ComponentManager.GenerateSchema(); | return m->m_ComponentManager.GenerateSchema(); | ||||
} | } | ||||
static std::vector<std::string> GetJSONData(const VfsPath& path) | static std::vector<std::string> GetJSONData(const VfsPath& path) | ||||
{ | { | ||||
VfsPaths pathnames; | VfsPaths pathnames; | ||||
Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames); | // Sort so as to ensure that simulation data is passed on in a platform-independent order. | ||||
Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames, true); | |||||
if (ret != INFO::OK) | if (ret != INFO::OK) | ||||
{ | { | ||||
// Some error reading directory | // Some error reading directory | ||||
wchar_t error[200]; | wchar_t error[200]; | ||||
LOGERROR("Error reading directory '%s': %s", path.string8(), utf8_from_wstring(StatusDescription(ret, error, ARRAY_SIZE(error)))); | LOGERROR("Error reading directory '%s': %s", path.string8(), utf8_from_wstring(StatusDescription(ret, error, ARRAY_SIZE(error)))); | ||||
return std::vector<std::string>(); | return std::vector<std::string>(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator