Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ComponentManager.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | if (!skipScriptFunctions) | ||||
m_ScriptInterface.RegisterFunction<std::vector<IComponent*>, int, CComponentManager::Script_GetComponentsWithInterface> ("GetComponentsWithInterface"); | m_ScriptInterface.RegisterFunction<std::vector<IComponent*>, int, CComponentManager::Script_GetComponentsWithInterface> ("GetComponentsWithInterface"); | ||||
m_ScriptInterface.RegisterFunction<void, int, int, JS::HandleValue, CComponentManager::Script_PostMessage> ("PostMessage"); | m_ScriptInterface.RegisterFunction<void, int, int, JS::HandleValue, CComponentManager::Script_PostMessage> ("PostMessage"); | ||||
m_ScriptInterface.RegisterFunction<void, int, JS::HandleValue, CComponentManager::Script_BroadcastMessage> ("BroadcastMessage"); | m_ScriptInterface.RegisterFunction<void, int, JS::HandleValue, CComponentManager::Script_BroadcastMessage> ("BroadcastMessage"); | ||||
m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddEntity> ("AddEntity"); | m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddEntity> ("AddEntity"); | ||||
m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddLocalEntity> ("AddLocalEntity"); | m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddLocalEntity> ("AddLocalEntity"); | ||||
m_ScriptInterface.RegisterFunction<void, int, CComponentManager::Script_DestroyEntity> ("DestroyEntity"); | m_ScriptInterface.RegisterFunction<void, int, CComponentManager::Script_DestroyEntity> ("DestroyEntity"); | ||||
m_ScriptInterface.RegisterFunction<void, CComponentManager::Script_FlushDestroyedEntities> ("FlushDestroyedEntities"); | m_ScriptInterface.RegisterFunction<void, CComponentManager::Script_FlushDestroyedEntities> ("FlushDestroyedEntities"); | ||||
m_ScriptInterface.RegisterFunction<bool, std::wstring, CComponentManager::Script_DataFileExists> ("DataFileExists"); | m_ScriptInterface.RegisterFunction<bool, std::wstring, CComponentManager::Script_DataFileExists> ("DataFileExists"); | ||||
m_ScriptInterface.RegisterFunction<std::vector<std::string>, std::wstring, bool, CComponentManager::Script_FindJSONFiles> ("FindJSONFiles"); | |||||
} | } | ||||
// Define MT_*, IID_* as script globals, and store their names | // Define MT_*, IID_* as script globals, and store their names | ||||
#define MESSAGE(name) m_ScriptInterface.SetGlobal("MT_" #name, (int)MT_##name); | #define MESSAGE(name) m_ScriptInterface.SetGlobal("MT_" #name, (int)MT_##name); | ||||
#define INTERFACE(name) \ | #define INTERFACE(name) \ | ||||
m_ScriptInterface.SetGlobal("IID_" #name, (int)IID_##name); \ | m_ScriptInterface.SetGlobal("IID_" #name, (int)IID_##name); \ | ||||
m_InterfaceIdsByName[#name] = IID_##name; | m_InterfaceIdsByName[#name] = IID_##name; | ||||
#define COMPONENT(name) | #define COMPONENT(name) | ||||
▲ Show 20 Lines • Show All 1,088 Lines • ▼ Show 20 Lines | std::string CComponentManager::GenerateSchema() const | ||||
return schema; | return schema; | ||||
} | } | ||||
bool CComponentManager::Script_DataFileExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& fileName) | bool CComponentManager::Script_DataFileExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& fileName) | ||||
{ | { | ||||
VfsPath path = VfsPath(L"simulation/data") / fileName; | VfsPath path = VfsPath(L"simulation/data") / fileName; | ||||
return VfsFileExists(path); | return VfsFileExists(path); | ||||
} | } | ||||
Status CComponentManager::FindJSONFilesCallback(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) | |||||
s0600204: Don't forget to remove appropriate definitions in `ComponentManager.h` if they're no longer… | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsFAK elexis: FAK | |||||
{ | |||||
FindJSONFilesCallbackData* data = (FindJSONFilesCallbackData*)cbData; | |||||
VfsPath pathstem = pathname.ChangeExtension(L""); | |||||
// Strip the root from the path | |||||
std::wstring name = pathstem.string().substr(data->path.string().length()); | |||||
data->templates.push_back(std::string(name.begin(), name.end())); | |||||
return INFO::OK; | |||||
} | |||||
std::vector<std::string> CComponentManager::Script_FindJSONFiles(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& subPath, bool recursive) | |||||
{ | |||||
FindJSONFilesCallbackData cbData; | |||||
cbData.path = VfsPath(L"simulation/data/" + subPath + L"/"); | |||||
int dir_flags = 0; | |||||
if (recursive) { | |||||
dir_flags = vfs::DIR_RECURSIVE; | |||||
} | |||||
// Find all simulation/data/{subPath}/*.json recursively | |||||
Status ret = vfs::ForEachFile(g_VFS, cbData.path, FindJSONFilesCallback, (uintptr_t)&cbData, L"*.json", dir_flags); | |||||
if (ret != INFO::OK) | |||||
{ | |||||
// Some error reading directory | |||||
wchar_t error[200]; | |||||
LOGERROR("Error reading directory '%s': %s", cbData.path.string8(), utf8_from_wstring(StatusDescription(ret, error, ARRAY_SIZE(error)))); | |||||
} | |||||
return cbData.templates; | |||||
} |
Wildfire Games · Phabricator
Don't forget to remove appropriate definitions in ComponentManager.h if they're no longer being used. (lines 118-22, 336-9)