UNPKG

@drincs/pixi-vn

Version:

Pixi'VN is a npm package that provides various features for creating visual novels.

139 lines (133 loc) 4.74 kB
import { LRUCache } from 'lru-cache'; import { a as StorageElementType } from './StorageElementType-dAIVJeiw.cjs'; export { S as StorageObjectType } from './StorageElementType-dAIVJeiw.cjs'; export { S as StoredClassModel } from './StoredClassModel-CUrGRJi0.cjs'; import { C as CachedMap } from './CachedMap-DZLvJAnA.cjs'; interface StorageGameStateItem<T = StorageElementType> { key: string; value: T; } /** * Interface exported storage data */ type StorageGameState = { /** * @deprecated */ base?: StorageGameStateItem[]; /** * @deprecated */ temp?: StorageGameStateItem[]; tempDeadlines: StorageGameStateItem<number>[]; /** * @deprecated */ flags?: string[]; main: StorageGameStateItem[]; }; interface StorageManagerInterface { /** * The internal storage. **Do not modify this directly.** * * ATTENTION: If you edit this directly, the {@link 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); * }); * ``` */ readonly base: Map<string, StorageElementType>; /** * The internal cache. **Do not modify this directly.** */ readonly cache: LRUCache<string, any, unknown>; /** * 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 {@link delete} them, they will be restored to the starting storage.** * By default, the starting storage is empty. */ set default(value: { [key: string]: StorageElementType; }); /** * Set a variable in the storage * @param key The key of the variable * @param value The value of the variable. If undefined, the variable will be removed * @returns */ set(key: string, value: StorageElementType): void; /** * Get a variable from the storage. If the variable is a temporary variable, it will return the temporary variable * @param key The key of the variable * @returns The value of the variable. If the variable does not exist, it will return undefined */ get<T extends StorageElementType>(key: string): T | undefined; /** * Remove a variable from the storage * @param key The key of the variable * @returns */ remove(key: string): void; /** * Set a variable in the temporary storage. The lifespan of the variable is the number of opened labels. * To get the temporary variable, use {@link get} * @param key The key of the temporary variable * @param value The value of the temporary variable. If undefined, the variable will be removed * @returns */ setTempVariable(key: string, value: StorageElementType): void; /** * Remove a temporary variable * @param key The key of the temporary variable */ removeTempVariable(key: string): void; /** * Set a flag to true or false. * @param key The name of the flag * @param value The value of the flag. */ setFlag(key: string, value: boolean): void; /** * Get the value of a flag * @param key The name of the flag * @returns The value of the flag */ getFlag(key: string): boolean; /** * Clear the storage and the oidsUsed * @returns */ clear(): void; /** * Export the storage to an object * @returns The object */ export(): StorageGameState; /** * Restore the storage from an object * @param data The object */ restore(data: StorageGameState): void; } declare class StorageManagerStatic { static storage: CachedMap<string, any>; static default: CachedMap<string, any>; static tempStorageDeadlines: Map<string, number>; private constructor(); static clearOldTempVariables(openedLabelsNumber: number): void; static setVariable(prefix: string, key: string, value: StorageElementType): void; static getVariable<T extends StorageElementType>(prefix: string, key: string): T | undefined; static removeVariable(prefix: string, key: string): void; static setFlag(key: string, value: boolean): void; static getFlag(key: string): boolean; } declare const storage: StorageManagerInterface; export { StorageElementType, type StorageGameState, type StorageManagerInterface, StorageManagerStatic, storage };