1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-07-18 19:24:06 +00:00

scripting: started on interact(), ui.select, chromas

This commit is contained in:
Steven Hugg
2021-08-20 18:09:16 -05:00
parent 6cee4e26e4
commit 8fc94aad25
8 changed files with 330 additions and 125 deletions

View File

@@ -1,7 +1,11 @@
import * as io from "./io";
export class ScriptUISliderType {
export interface ScriptUIType {
uitype : string;
}
export class ScriptUISliderType implements ScriptUIType {
readonly uitype = 'slider';
value: number;
constructor(
@@ -18,7 +22,7 @@ export class ScriptUISlider extends ScriptUISliderType implements io.Loadable {
this.initvalue = value;
return this;
}
reset() {
$$reset() {
this.value = this.initvalue != null ? this.initvalue : this.min;
}
$$getstate() {
@@ -29,3 +33,34 @@ export class ScriptUISlider extends ScriptUISliderType implements io.Loadable {
export function slider(min: number, max: number, step?: number) {
return new ScriptUISlider(min, max, step || 1);
}
///
export class ScriptUISelectType<T> implements ScriptUIType {
readonly uitype = 'select';
value: T;
index: number = -1;
constructor(
readonly options: T[]
) {
}
}
export class ScriptUISelect<T> extends ScriptUISelectType<T> implements io.Loadable {
initindex : number;
initial(index: number) {
this.initindex = index;
return this;
}
$$reset() {
this.index = this.initindex >= 0 ? this.initindex : -1;
this.value = null;
}
$$getstate() {
return { value: this.value, index: this.index };
}
}
export function select(options: any[]) {
return new ScriptUISelect(options);
}