Interface: StorageManagerInterface
Defined in: src/storage/interfaces/StorageManagerInterface.ts:6
Properties
base
> readonly base: Map<string, StorageElementType>
Defined in: src/storage/interfaces/StorageManagerInterface.ts:24
The internal storage. Do not modify this directly.
ATTENTION: If you edit this directly, the cache will not be updated.
You can use Keyv with Pixi’VN by creating a new instance of Keyv and passing the storage object as a parameter.
import { storage } from '@drincs/pixi-vn'
import Keyv from 'keyv';
const keyvStorage = new Keyv({ store: storage.base });
keyvStorage.get<string>("myValue").then((value) => {
console.log(value);
});
cache
> readonly cache: LRUCache<string, any, unknown>
Defined in: src/storage/interfaces/StorageManagerInterface.ts:28
The internal cache. Do not modify this directly.
Accessors
default
Set Signature
> set default(value): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:34
Set the starting storage. The starting storage that will be used when the game starts. If variables are defined inside it, they can be edited during the game, but if you delete them, they will be restored to the starting storage. By default, the starting storage is empty.
Parameters
value
Returns
void
Methods
clear()
> clear(): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:118
Clear the storage and the oidsUsed
Returns
void
export()
> export(): StorageGameState
Defined in: src/storage/interfaces/StorageManagerInterface.ts:123
Export the storage to an object
Returns
The object
get()
> get<T>(key): T | undefined
Defined in: src/storage/interfaces/StorageManagerInterface.ts:47
Get a variable from the storage. If the variable is a temporary variable, it will return the temporary variable
Type Parameters
T
Parameters
key
string
The key of the variable
Returns
T | undefined
The value of the variable. If the variable does not exist, it will return undefined
getFlag()
> getFlag(key): boolean
Defined in: src/storage/interfaces/StorageManagerInterface.ts:79
Get the value of a flag
Parameters
key
string
The name of the flag
Returns
boolean
The value of the flag
remove()
> remove(key): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:53
Remove a variable from the storage
Parameters
key
string
The key of the variable
Returns
void
removeTempVariable()
> removeTempVariable(key): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:66
Remove a temporary variable
Parameters
key
string
The key of the temporary variable
Returns
void
restore()
> restore(data): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:128
Restore the storage from an object
Parameters
data
The object
Returns
void
set()
> set(key, value): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:41
Set a variable in the storage
Parameters
key
string
The key of the variable
value
The value of the variable. If undefined, the variable will be removed
Returns
void
setFlag()
> setFlag(key, value): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:73
Set a flag to true or false.
Parameters
key
string
The name of the flag
value
boolean
The value of the flag.
Returns
void
setStorageHandler()
> setStorageHandler(value?): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:113
Configure the handler used to mirror game storage changes into an external reactive store. Call this at any time to start/stop mirroring.
Parameters
value?
The handler to set. If undefined, the handler will be removed.
Returns
void
Example
import { Store } from '@tanstack/store'
// Create a TanStack store that mirrors the game storage variables
const gameStore = new Store<Record<string, unknown>>({})
storage.setStorageHandler({
onSetVariable: (key, value) => {
gameStore.setState((state) => ({ ...state, [key]: value }))
},
onRemoveVariable: (key) => {
gameStore.setState((state) => {
const next = { ...state }
delete next[key]
return next
})
},
onClearOldTempVariable: (key) => {
gameStore.setState((state) => {
const next = { ...state }
delete next[key]
return next
})
},
})
setTempVariable()
> setTempVariable(key, value): void
Defined in: src/storage/interfaces/StorageManagerInterface.ts:61
Set a variable in the temporary storage. The lifespan of the variable is the number of opened labels. To get the temporary variable, use get
Parameters
key
string
The key of the temporary variable
value
The value of the temporary variable. If undefined, the variable will be removed
Returns
void