#pragma once #include "KingSystem/GameData/gdtFlag.h" namespace ksys::gdt { template class FlagProxy : public FlagT { public: using ConfigType = FlagConfig; using RawValueType = typename Flag::RawValueType; FlagProxy() = default; explicit FlagProxy(Flag* flag) : mFlag(flag) {} ~FlagProxy() override = default; Flag* getFlag() const { return mFlag; } void setFlag(Flag* flag) { mFlag = flag; } u32 getHash() const override { return mFlag->getHash(); } void setHash(u32 hash) override { mFlag->setHash(hash); } FlagType getType() const override { return mFlag->getType(); } void setType(FlagType type) override { mFlag->setType(type); } const FlagProperties& getProperties() const override { return mFlag->getProperties(); } void setProperties(const FlagProperties& properties) override { mFlag->setProperties(properties); } void resetToInitialValue() override; bool isInitialValue() const override; u32 getCategory() const override; void setCategory(u32 category) override; const sead::SafeString& getName() const override { return mFlag->getName(); } s32 getDeleteRev() const override { return mFlag->getDeleteRev(); } const ConfigType& getConfig() const override { return mFlag->getConfig(); } void setConfig(const ConfigType& config) override { mFlag->setConfig(config); } T getValue() const override; RawValueType& getValueRef() override; const RawValueType& getValueRef() const override; bool hasValue(const T& value) const override; bool setValue(T value) override; FlagDebugData* getDebugData() const override { return mFlag->getDebugData(); } void setDebugData(FlagDebugData* data) { mFlag->setDebugData(data); } private: Flag* mFlag = nullptr; RawValueType mValue{}; }; template inline void FlagProxy::resetToInitialValue() { if constexpr (std::is_same()) { const auto category = getCategory(); mValue = getConfig().initial_value & 1; setCategory(category); } else { mValue = getConfig().initial_value; } } template inline bool FlagProxy::isInitialValue() const { if constexpr (std::is_same()) { const bool initial_value = getConfig().initial_value & 1; return getValue() == initial_value; } else { T initial_value; initial_value = getConfig().initial_value; return getValue() == initial_value; } } template inline u32 FlagProxy::getCategory() const { if (!this->isBoolean_()) return 0; return this->getCategoryForBool_(&mValue); } template inline void FlagProxy::setCategory(u32 category) { if (!this->isBoolean_()) return; this->setCategoryForBool_(&mValue, category); } template inline T FlagProxy::getValue() const { if constexpr (std::is_same()) return mValue & 1; else return mValue; } template inline typename FlagProxy::RawValueType& FlagProxy::getValueRef() { return mValue; } template inline const typename FlagProxy::RawValueType& FlagProxy::getValueRef() const { return mValue; } template inline bool FlagProxy::hasValue(const T& value) const { return value == getValue(); } template inline bool FlagProxy::setValue(T value) { if constexpr (std::is_same()) { if (value == getValue()) return false; if (value) mValue |= 1; else mValue &= ~1; return true; } else { [[maybe_unused]] const T new_value = value; T min_value; T max_value; min_value = getConfig().min_value; max_value = getConfig().max_value; this->clampValue_(min_value, &value, max_value); if (mValue != value) { mValue = value; return true; } return false; } } } // namespace ksys::gdt