Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUI.cpp
Show First 20 Lines • Show All 846 Lines • ▼ Show 20 Lines | if (!AddObject(*pParent, *object)) | ||||
delete object; | delete object; | ||||
} | } | ||||
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth) | void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth) | ||||
{ | { | ||||
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x) | #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) | ||||
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) | #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) | ||||
ELMT(object); | ELMT(object); | ||||
ELMT(count); | |||||
ATTR(count); | ATTR(count); | ||||
ATTR(var); | ATTR(var); | ||||
XMBAttributeList attributes = Element.GetAttributes(); | XMBAttributeList attributes = Element.GetAttributes(); | ||||
int count = CStr(attributes.GetNamedItem(attr_count)).ToInt(); | int count = 0; | ||||
if (!attributes.GetNamedItem(attr_count).empty()) | |||||
count = CStr(attributes.GetNamedItem(attr_count)).ToInt(); | |||||
else | |||||
{ | |||||
for (XMBElement child : Element.GetChildNodes()) | |||||
{ | |||||
if (child.GetNodeName() != elmt_count) | |||||
break; | |||||
JSContext* cx = m_ScriptInterface->GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue result(cx); | |||||
if (m_ScriptInterface->Eval(child.GetText().c_str(), &result)) | |||||
if (result.isNumber()) | |||||
count = result.toNumber(); | |||||
break; | |||||
} | |||||
} | |||||
wraitii: This is rather hacky. If you have to make it dynamic, just hardcode a "ENGINEPLAYERCOUNT"… | |||||
Done Inline ActionsThat's what I thought too at first but if you see the XML changes you can observe why it isn't enough. nani: That's what I thought too at first but if you see the XML changes you can observe why it isn't… | |||||
CStr var("["+attributes.GetNamedItem(attr_var)+"]"); | CStr var("["+attributes.GetNamedItem(attr_var)+"]"); | ||||
if (var.size() < 3) | if (var.size() < 3) | ||||
var = "[n]"; | var = "[n]"; | ||||
for (int n = 0; n < count; ++n) | for (int n = 0; n < count; ++n) | ||||
{ | { | ||||
NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]"); | NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]"); | ||||
▲ Show 20 Lines • Show All 415 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This is rather hacky. If you have to make it dynamic, just hardcode a "ENGINEPLAYERCOUNT" constant and don't run JS.
But it seems just as simple to keep it hardcoded tbh.