summaryrefslogtreecommitdiff
path: root/src/d/flag/tboxflag_manager.inc
blob: 78c308c4051d10d27a55bd86b3d313de6da6f143 (plain)
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
#include "d/flag/tboxflag_manager.h"
#include "toBeSorted/file_manager.h"

TBoxflagManager *TBoxflagManager::sInstance = nullptr;
u16 TBoxflagManager::sTBoxFlags[2] = {};

/* 0x800BE810 */
void TBoxflagManager::doCommit() {
    if (mSceneIndex != 0xFFFF) {
        FileManager::GetInstance()->setTBoxFlags(mFlagSpace.getFlagPtrUnchecked(), mSceneIndex * 2, 2);
    }
}

/* 0x800BE870 */
bool TBoxflagManager::checkUncommittedFlag(u16 flag) {
    return mFlagHelper.checkFlag(flag / 16, flag % 16, mFlagSpace.getFlagPtrUnchecked(), mFlagSpace.mCount);
}

/* 0x800BE8E0 */
TBoxflagManager::TBoxflagManager() : CommittableFlagManager(false), mFlagSpace(sTBoxFlags, ARRAY_LENGTH(sTBoxFlags)) {
    mSceneIndex = 0xFFFF;
}

/* 0x800BE920 */
void TBoxflagManager::init() {}

/* 0x800BE930 */
void TBoxflagManager::copyFromSave(u32 sceneIndex) {
    u16 idx = sceneIndex;
    mSceneIndex = idx;
    u16 *flags = FileManager::GetInstance()->getTBoxFlagsConst();
    mFlagSpace.copyFromSaveFile2(flags + (idx * 2), 0, 2);
}

/* 0x800BE990 */
u16 TBoxflagManager::checkFlag(u16 sceneIndex, u16 flag) {
    s32 actualFlag = (flag + sceneIndex * 0x20);
    return mFlagHelper.checkFlag(
        actualFlag / 16, flag % 16, FileManager::GetInstance()->getTBoxFlagsConst(), getFlagCount()
    );
}

/* 0x800BEA30 */
u16 TBoxflagManager::getFlagCount() const {
    return 0x200;
}

/* 0x800BEA40 */
void TBoxflagManager::setFlag(u16 flag) {
    if (checkUncommittedFlag2(flag) != 1) {
        mFlagHelper.setFlag(flag / 16, flag % 16, mFlagSpace.getFlagPtrChecked(), mFlagSpace.mCount);
        setNeedsCommit(true);
    }
}