mirror of
https://github.com/zeldaret/botw
synced 2026-07-03 04:03:02 -04:00
ksys: Finish implementing ParamIO
This commit is contained in:
@@ -1,8 +1,65 @@
|
||||
#include "KingSystem/Utils/ParamIO.h"
|
||||
#include <agl/Utils/aglParameter.h>
|
||||
#include "KingSystem/ActorSystem/actActorParamMgr.h"
|
||||
|
||||
namespace ksys {
|
||||
|
||||
void ParamIO::applyParameter(char* data, char* data1, agl::utl::ParameterBase* param,
|
||||
const sead::SafeString& parent_name, bool* applied) {
|
||||
sead::FixedSafeString<128> name;
|
||||
name.format("%s/%s", parent_name.cstr(), param->getName().cstr());
|
||||
if (name != data)
|
||||
return;
|
||||
|
||||
if (param->getParameterType() == agl::utl::ParameterBase::ParameterType::StringRef) {
|
||||
auto* heap = act::ActorParamMgr::instance()->getDebugHeap();
|
||||
const auto len = sead::SafeString(data1).calcLength();
|
||||
auto* copy = new (heap) char[len + 1];
|
||||
std::memcpy(copy, data1, len);
|
||||
data1 = copy;
|
||||
data1[len] = '\0';
|
||||
}
|
||||
|
||||
param->applyString(data1, false);
|
||||
*applied = true;
|
||||
}
|
||||
|
||||
void ParamIO::applyParameterObj(char* data, char* data1, agl::utl::IParameterObj* obj,
|
||||
const sead::SafeString& parent_name, bool* applied) {
|
||||
sead::FixedSafeString<128> name;
|
||||
name.format("%s/%s", parent_name.cstr(), obj->getName().cstr());
|
||||
|
||||
if (obj->getNext())
|
||||
applyParameterObj(data, data1, obj->getNext(), parent_name, applied);
|
||||
|
||||
for (auto param = obj->getParamListHead(); param; param = param->getNext()) {
|
||||
applyParameter(data, data1, param, name, applied);
|
||||
if (param == obj->getParamListTail())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ParamIO::applyParameterList(char* data, char* data1, agl::utl::IParameterList* list,
|
||||
const sead::SafeString& parent_name, bool* applied) {
|
||||
sead::FixedSafeString<128> name;
|
||||
name.format("%s/%s", parent_name.cstr(), list->getName().cstr());
|
||||
|
||||
if (auto* obj = list->getChildObjHead())
|
||||
applyParameterObj(data, data1, obj, name, applied);
|
||||
|
||||
if (auto* next = list->getNext())
|
||||
applyParameterList(data, data1, next, parent_name, applied);
|
||||
|
||||
if (auto* child = list->getChildListHead())
|
||||
applyParameterList(data, data1, child, name, applied);
|
||||
}
|
||||
|
||||
bool ParamIO::applyResourceUpdate(char* data, char* data1) {
|
||||
bool applied = false;
|
||||
applyParameterList(data, data1, this, "", &applied);
|
||||
return applied;
|
||||
}
|
||||
|
||||
const char* ParamIO::getString(const agl::utl::ResParameterObj& obj, const char* key,
|
||||
const char* default_value, void*) const {
|
||||
const auto param = agl::utl::getResParameter(obj, key);
|
||||
|
||||
Reference in New Issue
Block a user