1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include "d/flag/dungeonflag_manager.h"
#include "d/flag/flag_index.h"
// TODO move
extern "C" FlagDefinition DungeonflagManager__FLAG_DEFINITIONS[];
DungeonflagManager *DungeonflagManager::sInstance = nullptr;
u16 DungeonflagManager::sDungeonFlags[8] = {};
void DungeonflagManager::copyFromSave_Internal(u16 flagIndex) {
mFlagSpace.copyFromSaveFile(saveFilePtr(flagIndex), 0, 0x8);
}
void DungeonflagManager::setCommitFlag(u16 flag) {
mShouldCommit = true;
}
DungeonflagManager::DungeonflagManager()
: mShouldCommit(false),
mStageIndex(-1),
mpFlagIndex(nullptr),
mFlagSpace(sDungeonFlags, ARRAY_LENGTH(sDungeonFlags)) {}
void DungeonflagManager::init() {
mpFlagIndex = new FlagIndex(0x11, DungeonflagManager__FLAG_DEFINITIONS);
mShouldCommit = false;
}
void DungeonflagManager::copyFromSave(u32 flag) {
mStageIndex = flag;
copyFromSave_Internal(flag);
}
void DungeonflagManager::setToValue(u16 flag, u32 value) {
u16 *data = mFlagSpace.getFlagPtrChecked();
mpFlagIndex->setCounterOrFlag(flag, data, 8, value);
setCommitFlag(flag);
}
void DungeonflagManager::setFlag(u16 flag) {
u16 *data = mFlagSpace.getFlagPtrChecked();
mpFlagIndex->setCounterOrFlag(flag, data, 8, 1);
setCommitFlag(flag);
}
u16 DungeonflagManager::getDungeonFlag(u16 flag) {
u16 *data = mFlagSpace.getFlagPtrUnchecked();
return mpFlagIndex->getCounterOrFlag(flag, data, 8);
}
bool DungeonflagManager::commit() {
FileManager *instance;
u16 idx = mStageIndex;
if (idx == 0xFFFF) {
return false;
} else if (mShouldCommit) {
instance = FileManager::GetInstance();
u16 *ptr = mFlagSpace.getFlagPtrUnchecked();
instance->setDungeonFlags(ptr, (idx & 0x1fff) * 8, 0x08);
mShouldCommit = false;
return true;
}
return false;
}
|