1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00

scripting: don't need $$reset (i think?)

This commit is contained in:
Steven Hugg 2021-08-22 14:46:57 -05:00
parent 8fc94aad25
commit 65a16db7b7
2 changed files with 11 additions and 21 deletions

View File

@ -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<T> 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;

View File

@ -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<T> 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<T> extends ScriptUISelectType<T> 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 };
}