LogoPixi’VN

ストレージクラス

`StoredClassModel` を使用してプロパティを保存するクラスを作成する方法。

Pixi’VN は、ゲームストレージに保存されるプロパティを持つクラスを作成するために使用できる抽象クラス StoredClassModel を提供します。

const CITY_CATEGORY = "city";

export default class City extends StoredClassModel {
    constructor(id: string, props: CityProps) {
        super(CITY_CATEGORY, id);
        // ...
    }
}
const milan = new City("milan", {
    // ...
});

ストレージプロパティ

クラスのプロパティをゲームストレージに保存するには、getStoragePropertysetStorageProperty ヘルパーを使用します。

export default class City extends StoredClassModel {
    constructor(id: string, props: CityProps) {
        // ...
    }

    get inhabitants(): number {
        return this.getStorageProperty<string>("inhabitants") || "";
    }
    set inhabitants(value: number) {
        this.setStorageProperty("inhabitants", value);
    }
}
const milan = new City("milan", {
    // ...
});

milan.inhabitants = 100000;

このページの内容