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



Defined in: [src/storage/interfaces/StorageManagerInterface.ts:8](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L8)

## Properties [#properties]

### base [#base]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:26](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L26)

The internal storage. **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:30](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L30)

The internal cache. **Do not modify this directly.**

***

### flags [#flags]

\> `readonly` **flags**: [`StorageFlagsInterface`](/pixi-vn/index/interfaces/StorageFlagsInterface)

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:93](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L93)

Namespace for operations on flags.

***

### temp [#temp]

\> `readonly` **temp**: [`StorageTempInterface`](/pixi-vn/index/interfaces/StorageTempInterface)

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:74](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L74)

Namespace for operations on temporary storage variables, whose lifespan is expressed in number of opened labels.

## Accessors [#accessors]

### default [#default]

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

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:36](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L36)

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 [#parameters]

###### value [#value]

##### Returns [#returns]

`void`

## Methods [#methods]

### clear() [#clear]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:132](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L132)

Clear the storage and the oidsUsed

#### Returns [#returns-1]

`void`

***

### export() [#export]

\> **export**(): `Promise`\<[`StorageGameState`](/pixi-vn/index/interfaces/StorageGameState)>

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:137](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L137)

Export the storage to an object

#### Returns [#returns-2]

`Promise`\<[`StorageGameState`](/pixi-vn/index/interfaces/StorageGameState)>

The object

***

### get() [#get]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:49](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L49)

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`](/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:89](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L89)

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

#### Deprecated [#deprecated]

Use [flags](#flags).get instead.

***

### remove() [#remove]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:55](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L55)

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:70](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L70)

Remove a temporary variable

#### Parameters [#parameters-4]

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

`string`

The key of the temporary variable

#### Returns [#returns-6]

`void`

#### Deprecated [#deprecated-1]

Use [temp](#temp).remove instead.

***

### restore() [#restore]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:142](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L142)

Restore the storage from an object

#### Parameters [#parameters-5]

##### data [#data]

[`StorageGameState`](/pixi-vn/index/interfaces/StorageGameState)

The object

#### Returns [#returns-7]

`void`

***

### set() [#set]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:43](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L43)

Set a variable in the storage

#### Parameters [#parameters-6]

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

`string`

The key of the variable

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

[`StorageElementType`](/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:82](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L82)

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`

#### Deprecated [#deprecated-2]

Use [flags](#flags).set instead.

***

### setStorageHandler() [#setstoragehandler]

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

Defined in: [src/storage/interfaces/StorageManagerInterface.ts:127](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L127)

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`](/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:64](https://github.com/DRincs-Productions/pixi-vn/blob/5bb5bb1f92e38998ea2f477b600168d8da3ece19/src/storage/interfaces/StorageManagerInterface.ts#L64)

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`](/pixi-vn/index/type-aliases/StorageElementType)

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

#### Returns [#returns-11]

`void`

#### Deprecated [#deprecated-3]

Use [temp](#temp).set instead.
