diff --git a/src/KingSystem/GameData/gdtFlag.h b/src/KingSystem/GameData/gdtFlag.h index d7e5f4bf..96d63377 100644 --- a/src/KingSystem/GameData/gdtFlag.h +++ b/src/KingSystem/GameData/gdtFlag.h @@ -146,7 +146,29 @@ struct FlagConfig { }; template -class Flag : public FlagBase { +class FlagT : public FlagBase { +public: + using ConfigType = FlagConfig; + using RawValueType = std::conditional_t, u8, T>; + + virtual u32 getRandomResetData() const; + + virtual const ConfigType& getConfig() const = 0; + virtual void setConfig(const ConfigType& config) = 0; + + virtual T getValue() const = 0; + + virtual RawValueType& getValueRef() = 0; + virtual const RawValueType& getValueRef() const = 0; + + virtual bool hasValue(const T& value) const = 0; + virtual bool setValue(T value) = 0; + + virtual FlagDebugData* getDebugData() const = 0; +}; + +template +class Flag : public FlagT { public: using ConfigType = FlagConfig; using RawValueType = std::conditional_t, u8, T>; @@ -172,20 +194,18 @@ public: const sead::SafeString& getName() const override; s32 getDeleteRev() const override; - virtual u32 getRandomResetData() const; + const ConfigType& getConfig() const override; + void setConfig(const ConfigType& config) override; - virtual const ConfigType& getConfig() const; - virtual void setConfig(const ConfigType& config); + T getValue() const override; - virtual T getValue() const; + RawValueType& getValueRef() override; + const RawValueType& getValueRef() const override; - virtual RawValueType& getValueRef(); - virtual const RawValueType& getValueRef() const; + bool hasValue(const T& value) const override; + bool setValue(T value) override; - virtual bool hasValue(const T& value) const; - virtual bool setValue(T value); - - virtual FlagDebugData* getDebugData() const; + FlagDebugData* getDebugData() const override; void setDebugData(FlagDebugData* data); private: @@ -284,16 +304,16 @@ inline bool Flag::isInitialValue() const { template inline u32 Flag::getCategory() const { - if (!isBoolean_()) + if (!this->isBoolean_()) return 0; - return getCategoryForBool_(&mValue); + return this->getCategoryForBool_(&mValue); } template inline void Flag::setCategory(u32 category) { - if (!isBoolean_()) + if (!this->isBoolean_()) return; - setCategoryForBool_(&mValue, category); + this->setCategoryForBool_(&mValue, category); } template @@ -307,7 +327,7 @@ inline s32 Flag::getDeleteRev() const { } template -inline u32 Flag::getRandomResetData() const { +inline u32 FlagT::getRandomResetData() const { const auto& initial_value = getConfig().initial_value; if constexpr (std::is_same()) return initial_value >> 1; @@ -367,7 +387,7 @@ inline bool Flag::setValue(T value) { T max_value; min_value = getConfig().min_value; max_value = getConfig().max_value; - clampValue_(min_value, &value, max_value); + this->clampValue_(min_value, &value, max_value); if (mValue != value) { mValue = value;