Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/ICmpAIManager.cpp
/* Copyright (C) 2017 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 49 Lines • ▼ Show 20 Lines | static Status Callback(const VfsPath& pathname, const CFileInfo& UNUSED(fileInfo), const uintptr_t cbData) | ||||
// 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(cx); | JS::RootedValue ai(cx); | ||||
self->m_ScriptInterface.CreateObject(&ai); | |||||
JS::RootedValue data(cx); | JS::RootedValue data(cx); | ||||
self->m_ScriptInterface.ReadJSONFile(pathname, &data); | self->m_ScriptInterface.ReadJSONFile(pathname, &data); | ||||
self->m_ScriptInterface.Eval("({})", &ai); | |||||
self->m_ScriptInterface.SetProperty(ai, "id", dirname, true); | self->m_ScriptInterface.SetProperty(ai, "id", dirname, true); | ||||
self->m_ScriptInterface.SetProperty(ai, "data", data, true); | self->m_ScriptInterface.SetProperty(ai, "data", data, true); | ||||
u32 length; | u32 length; | ||||
JS_GetArrayLength(cx, self->m_AIs, &length); | JS_GetArrayLength(cx, self->m_AIs, &length); | ||||
JS_SetElement(cx, self->m_AIs, length, ai); | JS_SetElement(cx, self->m_AIs, length, ai); | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
Show All 11 Lines |
Wildfire Games · Phabricator