Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/ICmpAIManager.cpp
Show All 35 Lines | |||||
struct GetAIsHelper | struct GetAIsHelper | ||||
{ | { | ||||
NONCOPYABLE(GetAIsHelper); | NONCOPYABLE(GetAIsHelper); | ||||
public: | public: | ||||
GetAIsHelper(const ScriptInterface& scriptInterface) : | GetAIsHelper(const ScriptInterface& scriptInterface) : | ||||
m_ScriptInterface(scriptInterface), | m_ScriptInterface(scriptInterface), | ||||
m_AIs(scriptInterface.GetJSRuntime()) | m_AIs(scriptInterface.GetJSRuntime()) | ||||
{ | { | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
m_AIs = JS_NewArrayObject(rq.cx, 0); | m_AIs = JS_NewArrayObject(rq.cx, 0); | ||||
} | } | ||||
void Run() | void Run() | ||||
{ | { | ||||
vfs::ForEachFile(g_VFS, L"simulation/ai/", Callback, (uintptr_t)this, L"*.json", vfs::DIR_RECURSIVE); | vfs::ForEachFile(g_VFS, L"simulation/ai/", Callback, (uintptr_t)this, L"*.json", vfs::DIR_RECURSIVE); | ||||
} | } | ||||
static Status Callback(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) | static Status Callback(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) | ||||
{ | { | ||||
GetAIsHelper* self = (GetAIsHelper*)cbData; | GetAIsHelper* self = (GetAIsHelper*)cbData; | ||||
ScriptInterface::Request rq(self->m_ScriptInterface); | ScriptRequest rq(self->m_ScriptInterface); | ||||
// Extract the 3rd component of the path (i.e. the directory after simulation/ai/) | // Extract the 3rd component of the path (i.e. the directory after simulation/ai/) | ||||
fs::wpath components = pathname.string(); | fs::wpath components = pathname.string(); | ||||
fs::wpath::iterator it = components.begin(); | fs::wpath::iterator it = components.begin(); | ||||
std::advance(it, 2); | std::advance(it, 2); | ||||
std::wstring dirname = GetWstringFromWpath(*it); | std::wstring dirname = GetWstringFromWpath(*it); | ||||
JS::RootedValue ai(rq.cx); | JS::RootedValue ai(rq.cx); | ||||
Show All 23 Lines |
Wildfire Games · Phabricator