1#include "Library/Stage/StageSwitchKeeper.h"
2
3#include "Library/Base/StringUtil.h"
4#include "Library/Placement/PlacementFunction.h"
5#include "Library/Placement/PlacementId.h"
6#include "Library/Placement/PlacementInfo.h"
7#include "Project/Stage/StageSwitchAccesser.h"
8
9namespace al {
10StageSwitchAccesserList::StageSwitchAccesserList() = default;
11
12StageSwitchAccesserList::StageSwitchAccesserList(const StageSwitchAccesser* accessers)
13 : accessers(accessers) {}
14
15StageSwitchKeeper::StageSwitchKeeper() = default;
16
17void StageSwitchKeeper::init(StageSwitchDirector* director, const PlacementInfo& placementInfo) {
18 mAccesserSize = calcLinkCountClassName(placementInfo, className: "StageSwitch");
19 mAccessers = new StageSwitchAccesser[mAccesserSize];
20
21 PlacementInfo links;
22 tryGetPlacementInfoByKey(outPlacementInfo: &links, placementInfo, key: "Links");
23
24 s32 linkCount = getCountPlacementInfo(placementInfo: links);
25 for (s32 validIndex = 0, i = 0; i < linkCount; i++) {
26 PlacementInfo link;
27 const char* linkName = nullptr;
28 tryGetPlacementInfoAndKeyNameByIndex(outPlacementInfo: &link, outKey: &linkName, links, index: i);
29 PlacementInfo linkData;
30 tryGetPlacementInfoByIndex(outPlacementInfo: &linkData, placementInfo: link, index: 0);
31 if (isClassName(placementInfo: linkData, name: "StageSwitch")) {
32 PlacementId placementId;
33 tryGetPlacementId(placementId: &placementId, placementInfo: linkData);
34 mAccessers[validIndex].setUseName(mUseName);
35 mAccessers[validIndex].init(director, linkName, placementId);
36 validIndex++;
37 }
38 }
39}
40
41StageSwitchAccesser* StageSwitchKeeper::tryGetStageSwitchAccesser(const char* linkName) const {
42 for (s32 i = 0; i < mAccesserSize; i++)
43 if (isEqualString(str1: linkName, str2: mAccessers[i].getLinkName()))
44 return &mAccessers[i];
45
46 return nullptr;
47}
48} // namespace al
49