1#include "Library/Stage/StageSwitchDirector.h"
2
3#include "Library/Execute/ExecuteTableHolderUpdate.h"
4#include "Library/Placement/PlacementId.h"
5#include "Library/Stage/StageSwitchInfo.h"
6#include "Library/Stage/StageSwitchWatcher.h"
7#include "Library/Stage/StageSwitchWatcherHolder.h"
8#include "Project/Stage/StageSwitchAccesser.h"
9
10namespace al {
11
12StageSwitchDirector::StageSwitchDirector(ExecuteDirector* executeDirector) {
13 mSwitchInfos = new StageSwitchInfo[mSwitchInfoCapacity];
14 mSwitchWatcherHolder = new StageSwitchWatcherHolder(1024);
15 registerExecutorUser(user: this, director: executeDirector, listName: "ステージスイッチディレクター");
16}
17
18s32 StageSwitchDirector::useSwitch(const StageSwitchAccesser* accesser) {
19 PlacementId* placementId = accesser->getPlacementId();
20
21 s32 index = findSwitchNoFromObjId(placementId);
22 if (index > -1)
23 return index;
24
25 if (mSwitchInfoCount >= mSwitchInfoCapacity)
26 return -1;
27
28 mSwitchInfos[mSwitchInfoCount].placementId = placementId;
29 return mSwitchInfoCount++;
30}
31
32s32 StageSwitchDirector::findSwitchNoFromObjId(const PlacementId* placementId) {
33 if (!placementId)
34 return 0;
35
36 for (s32 i = 0; i < mSwitchInfoCount; i++)
37 if (PlacementId::isEqual(selfId: *mSwitchInfos[i].placementId, otherId: *placementId))
38 return i;
39
40 return -1;
41}
42
43void StageSwitchDirector::onSwitch(const StageSwitchAccesser* accesser) {
44 s32 index = accesser->getInfoIndex();
45 if (index < 0 || mSwitchInfoCount <= index)
46 return;
47
48 mSwitchInfos[index].isSwitchOn = true;
49}
50
51void StageSwitchDirector::offSwitch(const StageSwitchAccesser* accesser) {
52 s32 index = accesser->getInfoIndex();
53 if (index < 0 || mSwitchInfoCount <= index)
54 return;
55
56 mSwitchInfos[index].isSwitchOn = false;
57}
58
59bool StageSwitchDirector::isOnSwitch(const StageSwitchAccesser* accesser) {
60 s32 index = accesser->getInfoIndex();
61 if (index < 0 || mSwitchInfoCount <= index)
62 return false;
63
64 return mSwitchInfos[index].isSwitchOn;
65}
66
67void StageSwitchDirector::addListener(StageSwitchListener* listener,
68 StageSwitchAccesser* accesser) {
69 StageSwitchWatcher* watcher = new StageSwitchWatcher(listener, accesser);
70 mSwitchWatcherHolder->add(watcher);
71}
72
73void StageSwitchDirector::execute() {
74 mSwitchWatcherHolder->movement();
75}
76
77} // namespace al
78