# Interface: StorageManagerInterface (/jsdoc/pixi-vn/index/interfaces/StorageManagerInterface)



Defined in: [src/storage/interfaces/StorageManagerInterface.ts:6](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L6)

## Properties [#properties]

### base [#base]

\> `readonly` **base**: `Map`\<`string`, [`StorageElementType`](/jsdoc/pixi-vn/index/type-aliases/StorageElementType)>

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:24](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L24)

The internal storage. &#x2A;*Do not modify this directly.**

ATTENTION: If you edit this directly, the [cache](#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.

```ts
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 [#cache]

\> `readonly` **cache**: `LRUCache`\<`string`, `any`, `unknown`>

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:28](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L28)

The internal cache. &#x2A;*Do not modify this directly.**

## Accessors [#accessors]

### default [#default]

#### Set Signature [#set-signature]

\> **set** **default**(`value`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:34](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L34)

Set the starting storage. The starting storage that will be used when the game starts.
&#x2A;*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 [#parameters]

###### value [#value]

##### Returns [#returns]

`void`

## Methods [#methods]

### clear() [#clear]

\> **clear**(): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:118](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L118)

Clear the storage and the oidsUsed

#### Returns [#returns-1]

`void`

***

### export() [#export]

\> **export**(): [`StorageGameState`](/jsdoc/pixi-vn/index/type-aliases/StorageGameState)

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:123](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L123)

Export the storage to an object

#### Returns [#returns-2]

[`StorageGameState`](/jsdoc/pixi-vn/index/type-aliases/StorageGameState)

The object

***

### get() [#get]

\> **get**\<`T`>(`key`): `T` | `undefined`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:47](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L47)

Get a variable from the storage. If the variable is a temporary variable, it will return the temporary variable

#### Type Parameters [#type-parameters]

##### T [#t]

`T` = [`StorageElementType`](/jsdoc/pixi-vn/index/type-aliases/StorageElementType)

#### Parameters [#parameters-1]

##### key [#key]

`string`

The key of the variable

#### Returns [#returns-3]

`T` | `undefined`

The value of the variable. If the variable does not exist, it will return undefined

***

### getFlag() [#getflag]

\> **getFlag**(`key`): `boolean`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:79](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L79)

Get the value of a flag

#### Parameters [#parameters-2]

##### key [#key-1]

`string`

The name of the flag

#### Returns [#returns-4]

`boolean`

The value of the flag

***

### remove() [#remove]

\> **remove**(`key`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:53](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L53)

Remove a variable from the storage

#### Parameters [#parameters-3]

##### key [#key-2]

`string`

The key of the variable

#### Returns [#returns-5]

`void`

***

### removeTempVariable() [#removetempvariable]

\> **removeTempVariable**(`key`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:66](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L66)

Remove a temporary variable

#### Parameters [#parameters-4]

##### key [#key-3]

`string`

The key of the temporary variable

#### Returns [#returns-6]

`void`

***

### restore() [#restore]

\> **restore**(`data`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:128](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L128)

Restore the storage from an object

#### Parameters [#parameters-5]

##### data [#data]

[`StorageGameState`](/jsdoc/pixi-vn/index/type-aliases/StorageGameState)

The object

#### Returns [#returns-7]

`void`

***

### set() [#set]

\> **set**(`key`, `value`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:41](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L41)

Set a variable in the storage

#### Parameters [#parameters-6]

##### key [#key-4]

`string`

The key of the variable

##### value [#value-1]

[`StorageElementType`](/jsdoc/pixi-vn/index/type-aliases/StorageElementType)

The value of the variable. If undefined, the variable will be removed

#### Returns [#returns-8]

`void`

***

### setFlag() [#setflag]

\> **setFlag**(`key`, `value`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:73](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L73)

Set a flag to true or false.

#### Parameters [#parameters-7]

##### key [#key-5]

`string`

The name of the flag

##### value [#value-2]

`boolean`

The value of the flag.

#### Returns [#returns-9]

`void`

***

### setStorageHandler() [#setstoragehandler]

\> **setStorageHandler**(`value?`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:113](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L113)

Configure the handler used to mirror game storage changes into an external reactive store.
Call this at any time to start/stop mirroring.

#### Parameters [#parameters-8]

##### value? [#value-3]

[`StorageExternalStoreHandler`](/jsdoc/pixi-vn/index/interfaces/StorageExternalStoreHandler)

The handler to set. If undefined, the handler will be removed.

#### Returns [#returns-10]

`void`

#### Example [#example]

```ts
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]

\> **setTempVariable**(`key`, `value`): `void`

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:61](https://github.com/DRincs-Productions/pixi-vn/blob/efc9536feda21bc17c50370f5e35fd8d8d88843a/src/storage/interfaces/StorageManagerInterface.ts#L61)

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](#get)

#### Parameters [#parameters-9]

##### key [#key-6]

`string`

The key of the temporary variable

##### value [#value-4]

[`StorageElementType`](/jsdoc/pixi-vn/index/type-aliases/StorageElementType)

The value of the temporary variable. If undefined, the variable will be removed

#### Returns [#returns-11]

`void`
