From 65a16db7b73ef36794b3e0602708c975041d350c Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 22 Aug 2021 14:46:57 -0500 Subject: [PATCH] scripting: don't need $$reset (i think?) --- src/common/script/lib/io.ts | 14 ++++---------- src/common/script/lib/scriptui.ts | 18 +++++++----------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/common/script/lib/io.ts b/src/common/script/lib/io.ts index eb1baf0e..710f5184 100644 --- a/src/common/script/lib/io.ts +++ b/src/common/script/lib/io.ts @@ -25,7 +25,6 @@ export function $$loadData(data: {}) { // object that can load state from backing store export interface Loadable { // called during script, from io.data.load() - $$reset() : void; $$setstate?(newstate: {}) : void; // called after script, from io.data.save() $$getstate() : {}; @@ -39,9 +38,8 @@ export namespace data { object.$$setstate(override); } else if (override) { Object.assign(object, override); - } else if (object.$$reset) { - object.$$reset(); - data.save(object, key); + } else if (object.$$getstate) { + save(object, key); // $$reset not needed } return object; } @@ -155,9 +153,6 @@ export class InteractionRecord implements Loadable { private $$callback ) { } - $$reset() { - this.$$setstate({interactid: ++$$seq}) - } $$setstate(newstate: {interactid: number}) { this.interactid = newstate.interactid; this.interacttarget.$$interact = this; @@ -193,9 +188,8 @@ export function interact(object: any, callback) : InteractionRecord { // TODO: what if this isn't top level? export class Mutable implements Loadable { value : T; - constructor(public readonly initial : T) { } - $$reset() { - this.value = this.initial; + constructor(public readonly initial : T) { + this.value = initial; } $$setstate(newstate) { this.value = newstate.value; diff --git a/src/common/script/lib/scriptui.ts b/src/common/script/lib/scriptui.ts index 5ae3e764..3c8a38c7 100644 --- a/src/common/script/lib/scriptui.ts +++ b/src/common/script/lib/scriptui.ts @@ -13,18 +13,16 @@ export class ScriptUISliderType implements ScriptUIType { readonly max: number, readonly step: number ) { + this.value = min; } } export class ScriptUISlider extends ScriptUISliderType implements io.Loadable { initvalue: number; initial(value: number) { - this.initvalue = value; + this.value = value; return this; } - $$reset() { - this.value = this.initvalue != null ? this.initvalue : this.min; - } $$getstate() { return { value: this.value }; } @@ -39,23 +37,21 @@ export function slider(min: number, max: number, step?: number) { export class ScriptUISelectType implements ScriptUIType { readonly uitype = 'select'; value: T; - index: number = -1; + index: number; constructor( readonly options: T[] ) { + this.value = null; + this.index = -1; } } export class ScriptUISelect extends ScriptUISelectType implements io.Loadable { - initindex : number; initial(index: number) { - this.initindex = index; + this.index = index; + this.value = this.options[index]; return this; } - $$reset() { - this.index = this.initindex >= 0 ? this.initindex : -1; - this.value = null; - } $$getstate() { return { value: this.value, index: this.index }; }