import FSUtil from "../FSUtil";
import { LOG_DYNAMIC_PROPERTY_WRITES } from "../FSConstants";
export default class FSDynamicProperty {
    constructor(entity) {
        this.entity = entity;
    }
    clear(property) {
        FSDynamicProperty.clear(this.entity, property);
    }
    setBoolean(property, boolean, noopIfSame = true) {
        FSDynamicProperty.setBoolean(this.entity, property, boolean, noopIfSame);
    }
    getBoolean(property) {
        return FSDynamicProperty.getBoolean(this.entity, property);
    }
    setNumber(property, number) {
        FSDynamicProperty.setNumber(this.entity, property, number);
    }
    getNumber(property) {
        return FSDynamicProperty.getNumber(this.entity, property);
    }
    incrementNumber(property, increment) {
        FSDynamicProperty.incrementNumber(this.entity, property, increment);
    }
    setString(property, string) {
        FSDynamicProperty.setString(this.entity, property, string);
    }
    getString(property) {
        return FSDynamicProperty.getString(this.entity, property);
    }
    setVector3(property, vector3) {
        FSDynamicProperty.setVector3(this.entity, property, vector3);
    }
    getVector3(property) {
        return FSDynamicProperty.getVector3(this.entity, property);
    }
    static getArray(entity, property) {
        let value = FSDynamicProperty.getString(entity, FSUtil.namespacedString(property, "_"));
        if (value === "") {
            return [];
        }
        try {
            return JSON.parse(value);
        }
        catch (e) {
            console.error("Failed to get array property: " + e);
            return [];
        }
    }
    static setArray(entity, property, array) {
        try {
            this.setString(entity, FSUtil.namespacedString(property, "_"), JSON.stringify(array));
        }
        catch (e) {
            console.error("Failed to set array property: " + e);
        }
    }
    static clear(entity, property) {
        if (LOG_DYNAMIC_PROPERTY_WRITES) {
            console.error(`Clearing dynamic property: ${FSUtil.namespacedString(property, "_")}`);
        }
        entity.setDynamicProperty(FSUtil.namespacedString(property, "_"), undefined);
    }
    static setBoolean(entity, property, boolean, noopIfSame = true) {
        if (noopIfSame && FSDynamicProperty.getBoolean(entity, property) === boolean) {
            return;
        }
        if (LOG_DYNAMIC_PROPERTY_WRITES) {
            console.error(`Setting dynamic property: ${FSUtil.namespacedString(property, "_")} = ${boolean}`);
        }
        entity.setDynamicProperty(FSUtil.namespacedString(property, "_"), boolean);
    }
    static getBoolean(entity, property) {
        return entity.getDynamicProperty(FSUtil.namespacedString(property, "_")) || false;
    }
    static setNumber(entity, property, number, noopIfSame = true) {
        if (noopIfSame && FSDynamicProperty.getNumber(entity, property) === number) {
            return;
        }
        if (LOG_DYNAMIC_PROPERTY_WRITES) {
            console.error(`Setting dynamic property: ${FSUtil.namespacedString(property, "_")} = ${number}`);
        }
        entity.setDynamicProperty(FSUtil.namespacedString(property, "_"), number);
    }
    static getNumber(entity, property) {
        let number = parseInt(entity.getDynamicProperty(FSUtil.namespacedString(property, "_"))) || 0;
        if (isNaN(number)) {
            number = 0;
        }
        return number;
    }
    static incrementNumber(entity, property, increment) {
        if (isNaN(increment) || increment === 0) {
            return;
        }
        if (LOG_DYNAMIC_PROPERTY_WRITES) {
            console.error(`Incrementing dynamic property: ${FSUtil.namespacedString(property, "_")} by ${increment}`);
        }
        let number = FSDynamicProperty.getNumber(entity, property) || 0;
        if (isNaN(number)) {
            number = 0;
        }
        entity.setDynamicProperty(FSUtil.namespacedString(property, "_"), number + increment);
    }
    static setString(entity, property, string, noopIfSame = true) {
        if (noopIfSame && FSDynamicProperty.getString(entity, property) === string) {
            return;
        }
        if (LOG_DYNAMIC_PROPERTY_WRITES) {
            console.error(`Setting dynamic property: ${FSUtil.namespacedString(property, "_")} = ${string}`);
        }
        entity.setDynamicProperty(FSUtil.namespacedString(property, "_"), string);
    }
    static getString(entity, property) {
        return entity.getDynamicProperty(FSUtil.namespacedString(property, "_"))?.toString() || "";
    }
    static setVector3(entity, property, vector3, noopIfSame = true) {
        if (noopIfSame && FSDynamicProperty.getVector3(entity, property) === vector3) {
            return;
        }
        if (LOG_DYNAMIC_PROPERTY_WRITES) {
            console.error(`Setting dynamic property: ${FSUtil.namespacedString(property, "_")} = ${vector3}`);
        }
        entity.setDynamicProperty(FSUtil.namespacedString(property, "_"), vector3);
    }
    static getVector3(entity, property) {
        return entity.getDynamicProperty(FSUtil.namespacedString(property, "_"));
    }
    static exists(entity, property) {
        return entity.getDynamicProperty(FSUtil.namespacedString(property, "_")) !== undefined;
    }
    static has(entity, property) {
        return FSDynamicProperty.exists(entity, property);
    }
}

//# sourceMappingURL=../../../../../_SBUNK_BPDebug/fs_sbunk/fs/libs/FSDynamicProperty.js.map
