Skip to content
On this page

Module: game/persistence

Type Aliases

NonPersistent

Ƭ NonPersistent<T>: WritableComputedRef<T> & { [DefaultValue]: T }

Type parameters

NameType
Textends State = State

Defined in

profectus/src/game/persistence.ts:38

profectus/src/game/persistence.ts:98


Persistent

Ƭ Persistent<T>: Ref<T> & { [CheckNaN]: boolean ; [DefaultValue]: T ; [Deleted]: boolean ; [NonPersistent]: NonPersistent<T> ; [PersistentState]: Ref<T> ; [SaveDataPath]: string[] | undefined ; [StackTrace]: string ; value: T }

A Ref that has been augmented with properties to allow it to be saved and loaded within the player save data object.

Type parameters

NameType
Textends State = State

Defined in

profectus/src/game/persistence.ts:71


State

Ƭ State: string | number | boolean | DecimalSource | { [key: string]: State; } | { [key: number]: State; }

This is a union of things that should be safely stringifiable without needing special processes or knowing what to load them in as.

  • Decimals aren't allowed because we'd need to know to parse them back.
  • DecimalSources are allowed because the string is a valid value for them

Defined in

profectus/src/game/persistence.ts:60

Variables

CheckNaN

Const CheckNaN: typeof CheckNaN

A symbol used in Persistent objects.

See

[CheckNaN]

Defined in

profectus/src/game/persistence.ts:48


DefaultValue

Const DefaultValue: typeof DefaultValue

A symbol used in Persistent objects.

See

[DefaultValue]

Defined in

profectus/src/game/persistence.ts:23


Deleted

Const Deleted: typeof Deleted

A symbol used in Persistent objects.

See

[Deleted]

Defined in

profectus/src/game/persistence.ts:33


NonPersistent

Const NonPersistent: typeof NonPersistent

A symbol used in Persistent objects.

See

[NonPersistent]

Defined in

profectus/src/game/persistence.ts:38

profectus/src/game/persistence.ts:98


PersistentState

Const PersistentState: typeof PersistentState

A symbol used in Persistent objects.

See

[PersistentState]

Defined in

profectus/src/game/persistence.ts:18


SaveDataPath

Const SaveDataPath: typeof SaveDataPath

A symbol used in Persistent objects.

See

[SaveDataPath]

Defined in

profectus/src/game/persistence.ts:43


SkipPersistence

Const SkipPersistence: typeof SkipPersistence

A symbol used to flag objects that should not be checked for persistent values.

Defined in

profectus/src/game/persistence.ts:53


StackTrace

Const StackTrace: typeof StackTrace

A symbol used in Persistent objects.

See

[StackTrace]

Defined in

profectus/src/game/persistence.ts:28

Functions

deletePersistent

deletePersistent(persistent): void

Mark a Persistent as deleted, so it won't be saved and loaded. Since persistent refs must be created during a layer's options func, features can not create persistent refs after evaluating their own options funcs. As a result, it must create any persistent refs it might need. This function can then be called after the options func is evaluated to mark the persistent ref to not be saved or loaded.

Parameters
NameType
persistentPersistent<State>
Returns

void

Defined in

profectus/src/game/persistence.ts:244


isPersistent

isPersistent(value): value is Persistent<State>

Type guard for whether an arbitrary value is a persistent ref

Parameters
NameTypeDescription
valueunknownThe value that may or may not be a persistent ref
Returns

value is Persistent<State>

Defined in

profectus/src/game/persistence.ts:194


noPersist

noPersist<T, S>(persistent): T[typeof NonPersistent]

Unwraps the non-persistent ref inside of persistent refs, to be passed to other features without duplicating values in the save data object.

Type parameters
NameType
Textends Ref<S, T> & { [CheckNaN]: boolean ; [DefaultValue]: S ; [Deleted]: boolean ; [NonPersistent]: NonPersistent<S> ; [PersistentState]: Ref<S> ; [SaveDataPath]: undefined | string[] ; [StackTrace]: string ; value: S }
Sextends State
Parameters
NameTypeDescription
persistentTThe persistent ref to unwrap, or an object to ignore all persistent refs within
Returns

T[typeof NonPersistent]

Other signatures

noPersist<T>(persistent): T

NameType
persistentT

Defined in

profectus/src/game/persistence.ts:202

profectus/src/game/persistence.ts:205

profectus/src/game/persistence.ts:206


persistent

persistent<T>(defaultValue, checkNaN?): Persistent<T>

Create a persistent ref, which can be saved and loaded. All (non-deleted) persistent refs must be included somewhere within the layer object returned by that layer's options func.

Type parameters
NameType
Textends State
Parameters
NameTypeDefault valueDescription
defaultValueT | Ref<T>undefinedThe value the persistent ref should start at on fresh saves or when reset.
checkNaNbooleantrueWhether or not to check this ref for being NaN on set. Only use on refs that should always be DecimalSources.
Returns

Persistent<T>

Defined in

profectus/src/game/persistence.ts:130