mirror of
https://github.com/zeldaret/botw
synced 2026-07-29 23:38:20 -04:00
ksys/res: Start implementing AttClient
This commit is contained in:
@@ -193,7 +193,7 @@ AttCheck* AttCheck::make(const CreateArg& arg) {
|
||||
|
||||
bool AttCheck::init(const AttCheck::CreateArg& arg) {
|
||||
mList.addObj(&mObj, "Parameters");
|
||||
mUserData = arg.user_data;
|
||||
mClient = arg.client;
|
||||
return parse(arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,15 @@ enum class AttCheckType {
|
||||
UnderWater,
|
||||
};
|
||||
|
||||
class AttClient;
|
||||
|
||||
class AttCheck {
|
||||
SEAD_RTTI_BASE(AttCheck)
|
||||
public:
|
||||
struct CreateArg {
|
||||
agl::utl::ResParameterList res_list;
|
||||
sead::Heap* heap;
|
||||
void* user_data;
|
||||
AttClient* client;
|
||||
};
|
||||
|
||||
static AttCheck* make(const CreateArg& arg);
|
||||
@@ -53,10 +55,13 @@ public:
|
||||
|
||||
virtual bool parse(const CreateArg& arg);
|
||||
|
||||
// For internal use by AttClient.
|
||||
agl::utl::ParameterList& getList_() { return mList; }
|
||||
|
||||
protected:
|
||||
bool init(const CreateArg& arg);
|
||||
|
||||
void* mUserData = nullptr;
|
||||
AttClient* mClient = nullptr;
|
||||
AttCheckType mType{};
|
||||
agl::utl::ParameterObj mObj;
|
||||
agl::utl::ParameterList mList;
|
||||
|
||||
@@ -1,12 +1,134 @@
|
||||
#include "KingSystem/Resource/resResourceAttClient.h"
|
||||
#include <container/seadSafeArray.h>
|
||||
#include "KingSystem/Resource/resResourceAttCheck.h"
|
||||
|
||||
namespace ksys::res {
|
||||
|
||||
AttClient::~AttClient() {
|
||||
// TODO
|
||||
for (int i = 0; i < mChecks.size(); ++i) {
|
||||
if (mChecks[i]) {
|
||||
delete mChecks[i];
|
||||
mChecks[i] = nullptr;
|
||||
}
|
||||
}
|
||||
mChecks.freeBuffer();
|
||||
}
|
||||
|
||||
void AttClient::doCreate_(u8*, u32, sead::Heap*) {}
|
||||
|
||||
namespace {
|
||||
|
||||
// Keep this in sync with ksys::act::AttType!
|
||||
sead::SafeArray<const char*, 8> sAttTypes = {{
|
||||
"Action",
|
||||
"Lock",
|
||||
"SwordSearch",
|
||||
"Attack",
|
||||
"Appeal",
|
||||
"JumpRide",
|
||||
"NameBalloon",
|
||||
"LookOnly",
|
||||
}};
|
||||
|
||||
void parseAttType(const agl::utl::ResParameterObj& AttClientParams, act::AttType* type) {
|
||||
const sead::SafeString AttType =
|
||||
agl::utl::getResParameter(AttClientParams, "AttType").getData<char>();
|
||||
|
||||
*type = act::AttType::Invalid;
|
||||
|
||||
for (int i = 0; i < sAttTypes.size(); ++i) {
|
||||
if (AttType == sAttTypes[i]) {
|
||||
*type = static_cast<act::AttType>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*type == act::AttType::Invalid)
|
||||
*type = act::AttType::Action;
|
||||
}
|
||||
|
||||
void parseActionType(const agl::utl::ResParameterObj& AttClientParams, act::AttActionCode* code) {
|
||||
const sead::SafeString ActionType =
|
||||
agl::utl::getResParameter(AttClientParams, "ActionType").getData<char>();
|
||||
|
||||
*code = act::AttActionCode::Dummy;
|
||||
|
||||
for (int i = int(act::AttActionCode::None); i < int(act::AttActionCode::Dummy); ++i) {
|
||||
if (ActionType == act::AttActionType::text(i - int(act::AttActionCode::None))) {
|
||||
*code = static_cast<act::AttActionCode>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*code == act::AttActionCode::Dummy)
|
||||
*code = act::AttActionCode::None;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool AttClient::parse_(u8* data, size_t size, sead::Heap* heap) {
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
agl::utl::ResParameterArchive archive{data};
|
||||
const auto root = archive.getRootList();
|
||||
const auto AttClientParams = root.getResParameterObj(0);
|
||||
|
||||
parseAttType(AttClientParams, &mAttType);
|
||||
parseActionType(AttClientParams, &mActionCode);
|
||||
addObj(&mAttClientParamsObj, "AttClientParams");
|
||||
|
||||
mAttTypeParam.init({sAttTypes[0]}, "AttType", "", &mAttClientParamsObj);
|
||||
mActionTypeParam.init({act::AttActionType(act::AttActionType::None).text()}, "ActionType", "",
|
||||
&mAttClientParamsObj);
|
||||
mPriorityTypeParam.init({act::AttPriorityType(act::AttPriorityType::Obj).text()},
|
||||
"PriorityType", "", &mAttClientParamsObj);
|
||||
|
||||
const int num_checks = root.getResParameterListNum();
|
||||
if (num_checks != 0) {
|
||||
mChecks.allocBufferAssert(num_checks, heap);
|
||||
for (int i = 0; i < num_checks; ++i)
|
||||
mChecks[i] = nullptr;
|
||||
|
||||
AttCheck::CreateArg arg{};
|
||||
arg.heap = heap;
|
||||
arg.client = this;
|
||||
|
||||
auto it = mChecks.begin(), end = mChecks.end();
|
||||
auto res_it = root.listBegin(), res_end = root.listEnd();
|
||||
for (; it != end && res_it != res_end; ++res_it, ++it) {
|
||||
arg.res_list = res_it.getList();
|
||||
|
||||
auto* check = *it = AttCheck::make(arg);
|
||||
if (check == nullptr)
|
||||
return false;
|
||||
|
||||
addList(&check->getList_(),
|
||||
sead::FormatFixedSafeString<32>("%s%d", "Check_", it.getIndex()));
|
||||
}
|
||||
}
|
||||
|
||||
applyResParameterArchive(archive);
|
||||
|
||||
const sead::SafeString PriorityType = mPriorityTypeParam.ref();
|
||||
for (auto priority : act::AttPriorityType{}) {
|
||||
if (PriorityType == priority.text()) {
|
||||
mPriorityType = priority;
|
||||
mPriorityTypeStr = PriorityType;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
mPriorityType = act::AttPriorityType::Obj;
|
||||
mPriorityTypeStr = mPriorityType.text();
|
||||
return true;
|
||||
}
|
||||
|
||||
int AttClient::getNumChecks() const {
|
||||
return mChecks.size();
|
||||
}
|
||||
|
||||
void AttClient::appendPriority(sead::BufferedSafeString* str) {
|
||||
str->append(mPriorityTypeStr);
|
||||
}
|
||||
|
||||
} // namespace ksys::res
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
|
||||
namespace ksys::res {
|
||||
|
||||
class AttCheck;
|
||||
|
||||
class AttClient : public ParamIO, public Resource {
|
||||
SEAD_RTTI_OVERRIDE(AttClient, Resource)
|
||||
public:
|
||||
struct Check {};
|
||||
|
||||
AttClient() : ParamIO("atcl", 0) {}
|
||||
~AttClient() override;
|
||||
|
||||
@@ -25,7 +25,13 @@ public:
|
||||
act::AttActionCode getActionCode() const { return mActionCode; }
|
||||
act::AttPriorityType getPriorityType() const { return mPriorityType; }
|
||||
const sead::SafeString& getPriorityTypeStr() const { return mPriorityTypeStr; }
|
||||
const sead::Buffer<Check*>& getChecks() const { return mChecks; }
|
||||
const sead::Buffer<AttCheck*>& getChecks() const { return mChecks; }
|
||||
|
||||
int getNumChecks() const;
|
||||
|
||||
// TODO: check functions
|
||||
|
||||
void appendPriority(sead::BufferedSafeString* str);
|
||||
|
||||
void doCreate_(u8*, u32, sead::Heap*) override;
|
||||
bool needsParse() const override { return true; }
|
||||
@@ -40,7 +46,7 @@ private:
|
||||
agl::utl::Parameter<sead::FixedSafeString<32>> mAttTypeParam;
|
||||
agl::utl::Parameter<sead::FixedSafeString<32>> mActionTypeParam;
|
||||
agl::utl::Parameter<sead::FixedSafeString<32>> mPriorityTypeParam;
|
||||
sead::Buffer<Check*> mChecks;
|
||||
sead::Buffer<AttCheck*> mChecks;
|
||||
};
|
||||
KSYS_CHECK_SIZE_NX150(AttClient, 0x428);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user