Storage classes
How to create classes whose properties are stored using `StoredClassModel`.
Pixi’VN provides an abstract class StoredClassModel that you can use to create classes with properties saved in the game storage.
const CITY_CATEGORY = "city";
export default class City extends StoredClassModel {
constructor(id: string, props: CityProps) {
super(CITY_CATEGORY, id);
// ...
}
}const milan = new City("milan", {
// ...
});Storate properties
To stored class properties in the game storage use the getStorageProperty and setStorageProperty helpers.
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;