diff options
| author | Léo Lam <leo@leolam.fr> | 2021-04-25 15:29:03 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2021-04-25 17:03:28 +0200 |
| commit | 33b2c465942d6a1a29bde3b025dbaf8ef9ae3fd4 (patch) | |
| tree | 460f44085dc7a1737e32b80ccb731323331e88ef /src/KingSystem/Resource/resResourceAttClient.cpp | |
| parent | edcfc9b7abc3261e4f93663d572a6fb6b196b667 (diff) | |
ksys/res: Start implementing AttClient
Diffstat (limited to 'src/KingSystem/Resource/resResourceAttClient.cpp')
| -rw-r--r-- | src/KingSystem/Resource/resResourceAttClient.cpp | 124 |
1 files changed, 123 insertions, 1 deletions
diff --git a/src/KingSystem/Resource/resResourceAttClient.cpp b/src/KingSystem/Resource/resResourceAttClient.cpp index 9dd52f21..a1e18a8f 100644 --- a/src/KingSystem/Resource/resResourceAttClient.cpp +++ b/src/KingSystem/Resource/resResourceAttClient.cpp @@ -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 |
