1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
import{_ as e,c as t,o as a,N as r}from"./chunks/framework.0799945b.js";const b=JSON.parse('{"title":"Module: game/persistence","description":"","frontmatter":{"editLink":false},"headers":[],"relativePath":"api/modules/game/persistence.md","lastUpdated":null}'),s={name:"api/modules/game/persistence.md"},n=r('<h1 id="module-game-persistence" tabindex="-1">Module: game/persistence <a class="header-anchor" href="#module-game-persistence" aria-label="Permalink to "Module: game/persistence""></a></h1><h2 id="type-aliases" tabindex="-1">Type Aliases <a class="header-anchor" href="#type-aliases" aria-label="Permalink to "Type Aliases""></a></h2><h3 id="nonpersistent" tabindex="-1">NonPersistent <a class="header-anchor" href="#nonpersistent" aria-label="Permalink to "NonPersistent""></a></h3><p>Ƭ <strong>NonPersistent</strong><<code>T</code>>: <code>WritableComputedRef</code><<code>T</code>> & { <code>[DefaultValue]</code>: <code>T</code> }</p><h4 id="type-parameters" tabindex="-1">Type parameters <a class="header-anchor" href="#type-parameters" aria-label="Permalink to "Type parameters""></a></h4><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th></tr></thead><tbody><tr><td style="text-align:left;"><code>T</code></td><td style="text-align:left;">extends <a href="./persistence#state"><code>State</code></a> = <a href="./persistence#state"><code>State</code></a></td></tr></tbody></table><h4 id="defined-in" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L38" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:38</a></p><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L98" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:98</a></p><hr><h3 id="persistent" tabindex="-1">Persistent <a class="header-anchor" href="#persistent" aria-label="Permalink to "Persistent""></a></h3><p>Ƭ <strong>Persistent</strong><<code>T</code>>: <code>Ref</code><<code>T</code>> & { <code>[CheckNaN]</code>: <code>boolean</code> ; <code>[DefaultValue]</code>: <code>T</code> ; <code>[Deleted]</code>: <code>boolean</code> ; <code>[NonPersistent]</code>: <a href="./persistence#nonpersistent-1"><code>NonPersistent</code></a><<code>T</code>> ; <code>[PersistentState]</code>: <code>Ref</code><<code>T</code>> ; <code>[SaveDataPath]</code>: <code>string</code>[] | <code>undefined</code> ; <code>[StackTrace]</code>: <code>string</code> ; <code>value</code>: <code>T</code> }</p><p>A Ref that has been augmented with properties to allow it to be saved and loaded within the player save data object.</p><h4 id="type-parameters-1" tabindex="-1">Type parameters <a class="header-anchor" href="#type-parameters-1" aria-label="Permalink to "Type parameters""></a></h4><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th></tr></thead><tbody><tr><td style="text-align:left;"><code>T</code></td><td style="text-align:left;">extends <a href="./persistence#state"><code>State</code></a> = <a href="./persistence#state"><code>State</code></a></td></tr></tbody></table><h4 id="defined-in-1" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-1" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L71" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:71</a></p><hr><h3 id="state" tabindex="-1">State <a class="header-anchor" href="#state" aria-label="Permalink to "State""></a></h3><p>Ƭ <strong>State</strong>: <code>string</code> | <code>number</code> | <code>boolean</code> | <a href="./../util/bignum#decimalsource"><code>DecimalSource</code></a> | { <code>[key: string]</code>: <a href="./persistence#state"><code>State</code></a>; } | { <code>[key: number]</code>: <a href="./persistence#state"><code>State</code></a>; }</p><p>This is a union of things that should be safely stringifiable without needing special processes or knowing what to load them in as.</p><ul><li>Decimals aren't allowed because we'd need to know to parse them back.</li><li>DecimalSources are allowed because the string is a valid value for them</li></ul><h4 id="defined-in-2" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-2" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L60" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:60</a></p><h2 id="variables" tabindex="-1">Variables <a class="header-anchor" href="#variables" aria-label="Permalink to "Variables""></a></h2><h3 id="checknan" tabindex="-1">CheckNaN <a class="header-anchor" href="#checknan" aria-label="Permalink to "CheckNaN""></a></h3><p>• <code>Const</code> <strong>CheckNaN</strong>: typeof <a href="./persistence#checknan"><code>CheckNaN</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[CheckNaN]</a></p><h4 id="defined-in-3" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-3" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L48" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:48</a></p><hr><h3 id="defaultvalue" tabindex="-1">DefaultValue <a class="header-anchor" href="#defaultvalue" aria-label="Permalink to "DefaultValue""></a></h3><p>• <code>Const</code> <strong>DefaultValue</strong>: typeof <a href="./persistence#defaultvalue"><code>DefaultValue</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[DefaultValue]</a></p><h4 id="defined-in-4" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-4" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L23" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:23</a></p><hr><h3 id="deleted" tabindex="-1">Deleted <a class="header-anchor" href="#deleted" aria-label="Permalink to "Deleted""></a></h3><p>• <code>Const</code> <strong>Deleted</strong>: typeof <a href="./persistence#deleted"><code>Deleted</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[Deleted]</a></p><h4 id="defined-in-5" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-5" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L33" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:33</a></p><hr><h3 id="nonpersistent-1" tabindex="-1">NonPersistent <a class="header-anchor" href="#nonpersistent-1" aria-label="Permalink to "NonPersistent""></a></h3><p>• <code>Const</code> <strong>NonPersistent</strong>: typeof <a href="./persistence#nonpersistent-1"><code>NonPersistent</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[NonPersistent]</a></p><h4 id="defined-in-6" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-6" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L38" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:38</a></p><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L98" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:98</a></p><hr><h3 id="persistentstate" tabindex="-1">PersistentState <a class="header-anchor" href="#persistentstate" aria-label="Permalink to "PersistentState""></a></h3><p>• <code>Const</code> <strong>PersistentState</strong>: typeof <a href="./persistence#persistentstate"><code>PersistentState</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[PersistentState]</a></p><h4 id="defined-in-7" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-7" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L18" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:18</a></p><hr><h3 id="savedatapath" tabindex="-1">SaveDataPath <a class="header-anchor" href="#savedatapath" aria-label="Permalink to "SaveDataPath""></a></h3><p>• <code>Const</code> <strong>SaveDataPath</strong>: typeof <a href="./persistence#savedatapath"><code>SaveDataPath</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[SaveDataPath]</a></p><h4 id="defined-in-8" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-8" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L43" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:43</a></p><hr><h3 id="skippersistence" tabindex="-1">SkipPersistence <a class="header-anchor" href="#skippersistence" aria-label="Permalink to "SkipPersistence""></a></h3><p>• <code>Const</code> <strong>SkipPersistence</strong>: typeof <a href="./persistence#skippersistence"><code>SkipPersistence</code></a></p><p>A symbol used to flag objects that should not be checked for persistent values.</p><h4 id="defined-in-9" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-9" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L53" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:53</a></p><hr><h3 id="stacktrace" tabindex="-1">StackTrace <a class="header-anchor" href="#stacktrace" aria-label="Permalink to "StackTrace""></a></h3><p>• <code>Const</code> <strong>StackTrace</strong>: typeof <a href="./persistence#stacktrace"><code>StackTrace</code></a></p><p>A symbol used in <a href="./persistence#persistent">Persistent</a> objects.</p><p><strong><code>See</code></strong></p><p><a href="./persistence#persistent">[StackTrace]</a></p><h4 id="defined-in-10" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-10" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L28" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:28</a></p><h2 id="functions" tabindex="-1">Functions <a class="header-anchor" href="#functions" aria-label="Permalink to "Functions""></a></h2><h3 id="deletepersistent" tabindex="-1">deletePersistent <a class="header-anchor" href="#deletepersistent" aria-label="Permalink to "deletePersistent""></a></h3><p>▸ <strong>deletePersistent</strong>(<code>persistent</code>): <code>void</code></p><p>Mark a <a href="./persistence#persistent">Persistent</a> 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 <em>might</em> need. This function can then be called after the options func is evaluated to mark the persistent ref to not be saved or loaded.</p><h5 id="parameters" tabindex="-1">Parameters <a class="header-anchor" href="#parameters" aria-label="Permalink to "Parameters""></a></h5><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th></tr></thead><tbody><tr><td style="text-align:left;"><code>persistent</code></td><td style="text-align:left;"><a href="./persistence#persistent"><code>Persistent</code></a><<a href="./persistence#state"><code>State</code></a>></td></tr></tbody></table><h5 id="returns" tabindex="-1">Returns <a class="header-anchor" href="#returns" aria-label="Permalink to "Returns""></a></h5><p><code>void</code></p><h4 id="defined-in-11" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-11" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L244" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:244</a></p><hr><h3 id="ispersistent" tabindex="-1">isPersistent <a class="header-anchor" href="#ispersistent" aria-label="Permalink to "isPersistent""></a></h3><p>▸ <strong>isPersistent</strong>(<code>value</code>): value is Persistent<State></p><p>Type guard for whether an arbitrary value is a persistent ref</p><h5 id="parameters-1" tabindex="-1">Parameters <a class="header-anchor" href="#parameters-1" aria-label="Permalink to "Parameters""></a></h5><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th><th style="text-align:left;">Description</th></tr></thead><tbody><tr><td style="text-align:left;"><code>value</code></td><td style="text-align:left;"><code>unknown</code></td><td style="text-align:left;">The value that may or may not be a persistent ref</td></tr></tbody></table><h5 id="returns-1" tabindex="-1">Returns <a class="header-anchor" href="#returns-1" aria-label="Permalink to "Returns""></a></h5><p>value is Persistent<State></p><h4 id="defined-in-12" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-12" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L194" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:194</a></p><hr><h3 id="nopersist" tabindex="-1">noPersist <a class="header-anchor" href="#nopersist" aria-label="Permalink to "noPersist""></a></h3><p>▸ <strong>noPersist</strong><<code>T</code>, <code>S</code>>(<code>persistent</code>): <code>T</code>[typeof <a href="./persistence#nonpersistent-1"><code>NonPersistent</code></a>]</p><p>Unwraps the non-persistent ref inside of persistent refs, to be passed to other features without duplicating values in the save data object.</p><h5 id="type-parameters-2" tabindex="-1">Type parameters <a class="header-anchor" href="#type-parameters-2" aria-label="Permalink to "Type parameters""></a></h5><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th></tr></thead><tbody><tr><td style="text-align:left;"><code>T</code></td><td style="text-align:left;">extends <code>Ref</code><<code>S</code>, <code>T</code>> & { <code>[CheckNaN]</code>: <code>boolean</code> ; <code>[DefaultValue]</code>: <code>S</code> ; <code>[Deleted]</code>: <code>boolean</code> ; <code>[NonPersistent]</code>: <a href="./persistence#nonpersistent-1"><code>NonPersistent</code></a><<code>S</code>> ; <code>[PersistentState]</code>: <code>Ref</code><<code>S</code>> ; <code>[SaveDataPath]</code>: <code>undefined</code> | <code>string</code>[] ; <code>[StackTrace]</code>: <code>string</code> ; <code>value</code>: <code>S</code> }</td></tr><tr><td style="text-align:left;"><code>S</code></td><td style="text-align:left;">extends <a href="./persistence#state"><code>State</code></a></td></tr></tbody></table><h5 id="parameters-2" tabindex="-1">Parameters <a class="header-anchor" href="#parameters-2" aria-label="Permalink to "Parameters""></a></h5><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th><th style="text-align:left;">Description</th></tr></thead><tbody><tr><td style="text-align:left;"><code>persistent</code></td><td style="text-align:left;"><code>T</code></td><td style="text-align:left;">The persistent ref to unwrap, or an object to ignore all persistent refs within</td></tr></tbody></table><h5 id="returns-2" tabindex="-1">Returns <a class="header-anchor" href="#returns-2" aria-label="Permalink to "Returns""></a></h5><p><code>T</code>[typeof <a href="./persistence#nonpersistent-1"><code>NonPersistent</code></a>]</p><h4 id="other-signatures" tabindex="-1">Other signatures <a class="header-anchor" href="#other-signatures" aria-label="Permalink to "Other signatures""></a></h4><p>▸ <strong>noPersist</strong><<code>T</code>>(<code>persistent</code>): <code>T</code></p><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th></tr></thead><tbody><tr><td style="text-align:left;"><code>persistent</code></td><td style="text-align:left;"><code>T</code></td></tr></tbody></table><h4 id="defined-in-13" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-13" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L202" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:202</a></p><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L205" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:205</a></p><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L206" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:206</a></p><hr><h3 id="persistent-1" tabindex="-1">persistent <a class="header-anchor" href="#persistent-1" aria-label="Permalink to "persistent""></a></h3><p>▸ <strong>persistent</strong><<code>T</code>>(<code>defaultValue</code>, <code>checkNaN?</code>): <a href="./persistence#persistent"><code>Persistent</code></a><<code>T</code>></p><p>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.</p><h5 id="type-parameters-3" tabindex="-1">Type parameters <a class="header-anchor" href="#type-parameters-3" aria-label="Permalink to "Type parameters""></a></h5><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th></tr></thead><tbody><tr><td style="text-align:left;"><code>T</code></td><td style="text-align:left;">extends <a href="./persistence#state"><code>State</code></a></td></tr></tbody></table><h5 id="parameters-3" tabindex="-1">Parameters <a class="header-anchor" href="#parameters-3" aria-label="Permalink to "Parameters""></a></h5><table><thead><tr><th style="text-align:left;">Name</th><th style="text-align:left;">Type</th><th style="text-align:left;">Default value</th><th style="text-align:left;">Description</th></tr></thead><tbody><tr><td style="text-align:left;"><code>defaultValue</code></td><td style="text-align:left;"><code>T</code> | <code>Ref</code><<code>T</code>></td><td style="text-align:left;"><code>undefined</code></td><td style="text-align:left;">The value the persistent ref should start at on fresh saves or when reset.</td></tr><tr><td style="text-align:left;"><code>checkNaN</code></td><td style="text-align:left;"><code>boolean</code></td><td style="text-align:left;"><code>true</code></td><td style="text-align:left;">Whether or not to check this ref for being NaN on set. Only use on refs that should always be DecimalSources.</td></tr></tbody></table><h5 id="returns-3" tabindex="-1">Returns <a class="header-anchor" href="#returns-3" aria-label="Permalink to "Returns""></a></h5><p><a href="./persistence#persistent"><code>Persistent</code></a><<code>T</code>></p><h4 id="defined-in-14" tabindex="-1">Defined in <a class="header-anchor" href="#defined-in-14" aria-label="Permalink to "Defined in""></a></h4><p><a href="https://github.com/profectus-engine/Profectus/blob/5c11524/src/game/persistence.ts#L130" target="_blank" rel="noreferrer">profectus/src/game/persistence.ts:130</a></p>',136),o=[n];function i(d,c,l,h,p,f){return a(),t("div",null,o)}const g=e(s,[["render",i]]);export{b as __pageData,g as default};
|