summaryrefslogtreecommitdiff
path: root/include/d/flag/dungeonflag_manager.h
blob: 0f652968d26fd676aec75d83842507c72e476754 (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
#ifndef D_FLAG_DUNGEONFLAG_MANAGER_H
#define D_FLAG_DUNGEONFLAG_MANAGER_H

#include "d/flag/flag_index.h"
#include "d/flag/flag_space.h"
#include "toBeSorted/file_manager.h"

class DungeonflagManager {
private:
    bool mShouldCommit;
    u16 mStageIndex;
    FlagIndex *mpFlagIndex;
    FlagSpace mFlagSpace;

    static u16 sDungeonFlags[8];

public:
    static DungeonflagManager *sInstance;

    void copyFromSave(u32 flag);
    void copyFromSave_Internal(u16 flagIndex);
    void setCommitFlag(u16 flag);
    DungeonflagManager();
    void init();
    void setToValue(u16 flag, u32 value);
    void setFlag(u16 flag);
    u16 getDungeonFlag(u16 flag);
    bool commit();

    /** inline shenanigans to get copyFromSave to match */
    static inline u16 *saveFilePtr(u16 flagIndex) {
        u32 offset = (flagIndex & 0x1fff) * 8;
        return FileManager::GetInstance()->getDungeonFlagsConst() + offset;
    }

    u16 getCounterOrFlag(u32 idx, u32 count) const {
        u16 offset = mStageIndex * 8;
        const u16 *space = FileManager::GetInstance()->getDungeonFlagsConst() + offset;
        return mpFlagIndex->getCounterOrFlag(idx, space, count);
    }
};

#endif