Storage Classes
Pixi’VN fornisce una classe astratta StoredClassModel
che puoi utilizzare per creare classi con proprietà salvate nello storage del gioco.
Storage key
Il costruttore della classe StoredClassModel
ha 2 parametri:
categoryId
: The id of the category. For example if you are storing a character class, you can use "characters" ascategoryId
. So all instances of the character class will be stored in the "characters" category.id
: The id of instance of the class. This id must be unique for its category.
const MY_CLASS_CATEGORY = "__MyClass__"
export default class MyClass extends StoredClassModel {
constructor(id: string, props: IMyClass) {
super(MY_CLASS_CATEGORY, id)
// ...
}
}
Storate properties
To save the properties of the class in the game storage you must use the getStorageProperty
and setStorageProperty
methods.
For example, if you have a property test
that you want to save in the game storage, you can add a getter and setter like this:
export default class MyClass extends StoredClassModel {
constructor(id: string, props: IMyClass) {
// ...
}
get test(): string {
return this.getStorageProperty<string>("test") || ""
}
set test(value: string) {
this.setStorageProperty<string>("test", value)
}
}