Class: StoredClassModel
Defined in: src/storage/classes/StoredClassModel.ts:33
StoredClassModel is a abstract class that contains the methods to store a class in the game. I suggest you extend this class to create your own stored class.
Example
export class CharacterBaseModel extends StoredClassModel implements CharacterBaseModelProps {
constructor(id: string, props: CharacterBaseModelProps) {
super("___character___", id)
this.defaultName = props.name
this.defaultSurname = props.surname
}
readonly defaultName: string = ""
get name(): string {
return this.getStorageProperty<string>("name") || this.defaultName
}
set name(value: string) {
this.setStorageProperty("name", value)
}
readonly defaultSurname?: string
get surname(): string | undefined {
return this.getStorageProperty<string>("surname") || this.defaultSurname
}
set surname(value: string | undefined) {
this.setStorageProperty("surname", value)
}
}
Extended by
Constructors
Constructor
> new StoredClassModel(categoryId, id): StoredClassModel
Defined in: src/storage/classes/StoredClassModel.ts:38
Parameters
categoryId
string
The id of the category. For example if you are storing a character class, you can use "characters" as categoryId. so all instances of the character class will be stored in the "characters" category.
id
string
The id of instance of the class. This id must be unique for the category.
Returns
StoredClassModel
Properties
id
> readonly id: string
Defined in: src/storage/classes/StoredClassModel.ts:63
Is id of the stored class. is unique for this class.
Methods
getStorageProperty()
> protected getStorageProperty<T>(propertyName, idToUse?): T | undefined
Defined in: src/storage/classes/StoredClassModel.ts:80
Get a property from the storage.
Type Parameters
T
Parameters
propertyName
string
The name of the property to get.
idToUse?
string = ...
The id of the instance to get the property.
Returns
T | undefined
The value of the property. If the property is not found, returns undefined.
Default
this.id
migrateOldStorage()
> protected migrateOldStorage(oldCategoryId?): void
Defined in: src/storage/classes/StoredClassModel.ts:43
Parameters
oldCategoryId?
string = ...
Returns
void
setStorageProperty()
> protected setStorageProperty<T>(propertyName, value): void
Defined in: src/storage/classes/StoredClassModel.ts:71
Update a property in the storage.
Type Parameters
T
T
The type of the value to set. (Deprecated, it is not necessary to specify the type of the value, it will be inferred from the value)
Parameters
propertyName
string
The name of the property to set.
value
The value to set. If is undefined, the property will be removed from the storage.
Returns
void