| 1 | #include "Project/Action/ActionFlagCtrl.h" |
| 2 | |
| 3 | #include "Library/Base/StringUtil.h" |
| 4 | #include "Library/LiveActor/ActorResourceFunction.h" |
| 5 | #include "Library/LiveActor/LiveActor.h" |
| 6 | |
| 7 | namespace al { |
| 8 | ActionFlagCtrl::ActionFlagCtrl(LiveActor* actor, const char* name) |
| 9 | : mParentActor(actor), mName(createStringIfInStack(str: name)) {} |
| 10 | |
| 11 | ActionFlagCtrl* ActionFlagCtrl::tryCreate(LiveActor* actor, const char* name) { |
| 12 | if (!isExistModelResource(actor)) |
| 13 | return nullptr; |
| 14 | |
| 15 | sead::FixedSafeString<128> initFileName; |
| 16 | if (!tryGetActorInitFileName(&initFileName, actor, "ActionFlagCtrl" , name)) |
| 17 | createFileNameBySuffix(out: &initFileName, name: "ActionFlagCtrl" , suffix: name); |
| 18 | |
| 19 | if (!isExistModelResourceYaml(actor, initFileName.cstr(), nullptr)) |
| 20 | return nullptr; |
| 21 | |
| 22 | return new ActionFlagCtrl(actor, name); |
| 23 | } |
| 24 | |
| 25 | void ActionFlagCtrl::start(const char* name) { |
| 26 | mLastFlag = findFlagInfo(name); |
| 27 | mIsBool = false; |
| 28 | if (!mLastFlag) |
| 29 | return; |
| 30 | |
| 31 | startCtrlFlag(); |
| 32 | startCtrlSensor(); |
| 33 | } |
| 34 | |
| 35 | ActionFlagCtrlInfo* ActionFlagCtrl::findFlagInfo(const char* name) const { |
| 36 | for (s32 i = 0; i < mInfoCount; i++) { |
| 37 | ActionFlagCtrlInfo* flagInfo = mInfos[i]; |
| 38 | if (isEqualStringCase(str1: flagInfo->name, str2: name)) |
| 39 | return flagInfo; |
| 40 | } |
| 41 | return nullptr; |
| 42 | } |
| 43 | |
| 44 | void ActionFlagCtrl::update(f32 frame, f32 frameRate, f32 frameMax, bool isStop) { |
| 45 | if (!mLastFlag || !mIsBool) |
| 46 | return; |
| 47 | if (!mHitSensorKeeper) |
| 48 | return; |
| 49 | |
| 50 | updateCtrlSensor(frame, frameRate, frameMax, isStop); |
| 51 | } |
| 52 | } // namespace al |
| 53 | |