Compare commits

..

2 Commits

Author SHA1 Message Date
f1e4f91461 functional 2021-06-28 16:50:16 -05:00
18b3debb53 functional 2021-06-28 16:27:03 -05:00
3 changed files with 47 additions and 40 deletions

46
ts-lua/dist/test.lua vendored
View File

@@ -161,9 +161,6 @@ function FeatureParent.prototype.____constructor(self, name, parent)
self.parentid = parent.id self.parentid = parent.id
self.parent:addChild(self) self.parent:addChild(self)
end end
print(
self:type()
)
self.feat = menu.add_feature( self.feat = menu.add_feature(
name, name,
self:type(), self:type(),
@@ -176,9 +173,9 @@ function FeatureParent.prototype.type(self)
return "parent" return "parent"
end end
function FeatureParent.prototype.hidden(self) function FeatureParent.prototype.hidden(self)
return Boolean(nil, self.feat.hidden) return self.feat.hidden
end end
function FeatureParent.prototype.sethidden(self, val) function FeatureParent.prototype.setHidden(self, val)
self.feat.hidden = val self.feat.hidden = val
end end
function FeatureParent.prototype.select(self) function FeatureParent.prototype.select(self)
@@ -239,7 +236,7 @@ function FeatureToggle.prototype.____constructor(self, name, parent, defaultvalu
defaultvalue = false defaultvalue = false
end end
FeatureToggle.____super.prototype.____constructor(self, name, parent, handler) FeatureToggle.____super.prototype.____constructor(self, name, parent, handler)
self:setvalue(defaultvalue) self:setValue(defaultvalue)
end end
function FeatureToggle.prototype.type(self) function FeatureToggle.prototype.type(self)
return "toggle" return "toggle"
@@ -247,7 +244,7 @@ end
function FeatureToggle.prototype.value(self) function FeatureToggle.prototype.value(self)
return self.feat.on return self.feat.on
end end
function FeatureToggle.prototype.setvalue(self, val) function FeatureToggle.prototype.setValue(self, val)
self.feat.on = val self.feat.on = val
end end
function FeatureToggle.prototype.toggle(self) function FeatureToggle.prototype.toggle(self)
@@ -262,7 +259,7 @@ function FeatureNum.prototype.____constructor(self, name, parent, defaultnum, ha
defaultnum = 0 defaultnum = 0
end end
FeatureNum.____super.prototype.____constructor(self, name, parent, handler) FeatureNum.____super.prototype.____constructor(self, name, parent, handler)
self:setnum(defaultnum) self:setNum(defaultnum)
end end
function FeatureNum.prototype.type(self) function FeatureNum.prototype.type(self)
return "action_value_i" return "action_value_i"
@@ -270,25 +267,25 @@ end
function FeatureNum.prototype.num(self) function FeatureNum.prototype.num(self)
return self.feat.value_i return self.feat.value_i
end end
function FeatureNum.prototype.setnum(self, val) function FeatureNum.prototype.setNum(self, val)
self.feat.value_i = val self.feat.value_i = val
end end
function FeatureNum.prototype.min(self) function FeatureNum.prototype.min(self)
return self.feat.min_i return self.feat.min_i
end end
function FeatureNum.prototype.setmin(self, val) function FeatureNum.prototype.setMin(self, val)
self.feat.min_i = math.floor(val + 0.5) self.feat.min_i = math.floor(val + 0.5)
end end
function FeatureNum.prototype.max(self) function FeatureNum.prototype.max(self)
return self.feat.max_i return self.feat.max_i
end end
function FeatureNum.prototype.setmax(self, val) function FeatureNum.prototype.setMax(self, val)
self.feat.max_i = math.floor(val + 0.5) self.feat.max_i = math.floor(val + 0.5)
end end
function FeatureNum.prototype.step(self) function FeatureNum.prototype.step(self)
return self.feat.mod_i return self.feat.mod_i
end end
function FeatureNum.prototype.setstep(self, val) function FeatureNum.prototype.setStep(self, val)
self.feat.mod_i = math.floor(val + 0.5) self.feat.mod_i = math.floor(val + 0.5)
end end
____exports.FeatureNumToggle = __TS__Class() ____exports.FeatureNumToggle = __TS__Class()
@@ -303,7 +300,7 @@ function FeatureNumToggle.prototype.____constructor(self, name, parent, defaultn
defaultvalue = false defaultvalue = false
end end
FeatureNumToggle.____super.prototype.____constructor(self, name, parent, defaultnum, handler) FeatureNumToggle.____super.prototype.____constructor(self, name, parent, defaultnum, handler)
self:setvalue(defaultvalue) self:setValue(defaultvalue)
end end
function FeatureNumToggle.prototype.type(self) function FeatureNumToggle.prototype.type(self)
return "value_i" return "value_i"
@@ -311,7 +308,7 @@ end
function FeatureNumToggle.prototype.value(self) function FeatureNumToggle.prototype.value(self)
return self.feat.on return self.feat.on
end end
function FeatureNumToggle.prototype.setvalue(self, val) function FeatureNumToggle.prototype.setValue(self, val)
self.feat.on = val self.feat.on = val
end end
function FeatureNumToggle.prototype.toggle(self) function FeatureNumToggle.prototype.toggle(self)
@@ -333,17 +330,12 @@ local FeatureAction = ____Feature.FeatureAction
local FeatureParent = ____Feature.FeatureParent local FeatureParent = ____Feature.FeatureParent
local fps = 60 local fps = 60
local duration = 5 local duration = 5
local testParent = __TS__New(FeatureParent, "class") local testParent = __TS__New(FeatureParent, "test")
__TS__New( __TS__New(
FeatureAction, FeatureAction,
"testClass", "display box",
testParent, testParent,
function(____, f) function(____, f)
if f.parent then
print(
(("parent: " .. f.parent.name) .. "\nid: ") .. tostring(f.parent.id)
)
end
do do
local i = 0 local i = 0
while i < (fps * duration) do while i < (fps * duration) do
@@ -358,6 +350,18 @@ __TS__New(
end end
end end
) )
__TS__New(
FeatureAction,
"print parent data",
testParent,
function(____, f)
if f.parent then
print(
(("parent: " .. f.parent.name) .. "\nid: ") .. tostring(f.parent.id)
)
end
end
)
return ____exports return ____exports
end, end,
} }

View File

@@ -1,4 +1,4 @@
type AnyFeature = FeatureParent|FeatureAction|FeatureToggle|FeatureNum; type AnyFeature = FeatureParent|FeatureAction|FeatureToggle|FeatureNum|FeatureNumToggle;
export class FeatureParent { export class FeatureParent {
@@ -13,9 +13,9 @@ export class FeatureParent {
feat: Feat; feat: Feat;
hidden(): boolean { hidden(): boolean {
return Boolean(this.feat.hidden); return this.feat.hidden;
} }
sethidden(val: boolean) { setHidden(val: boolean) {
this.feat.hidden = val; this.feat.hidden = val;
} }
@@ -30,7 +30,6 @@ export class FeatureParent {
this.parent.addChild(this); this.parent.addChild(this);
} }
print(this.type());
this.feat = menu.add_feature(name, this.type(), this.parentid, () => this.select()); this.feat = menu.add_feature(name, this.type(), this.parentid, () => this.select());
this.id = this.feat.id; this.id = this.feat.id;
} }
@@ -89,7 +88,7 @@ export class FeatureToggle extends FeatureAction {
value(): boolean { value(): boolean {
return this.feat.on; return this.feat.on;
} }
setvalue(val: boolean) { setValue(val: boolean) {
this.feat.on = val; this.feat.on = val;
} }
toggle() { toggle() {
@@ -98,7 +97,7 @@ export class FeatureToggle extends FeatureAction {
constructor(name: string, parent?: FeatureParent|null, defaultvalue = false, handler?: (feat: AnyFeature) => void) { constructor(name: string, parent?: FeatureParent|null, defaultvalue = false, handler?: (feat: AnyFeature) => void) {
super(name, parent, handler); super(name, parent, handler);
this.setvalue(defaultvalue); this.setValue(defaultvalue);
} }
} }
@@ -110,34 +109,34 @@ export class FeatureNum extends FeatureAction {
num(): number { num(): number {
return this.feat.value_i; return this.feat.value_i;
} }
setnum(val: number) { setNum(val: number) {
this.feat.value_i = val; this.feat.value_i = val;
} }
min(): number { min(): number {
return this.feat.min_i; return this.feat.min_i;
} }
setmin(val: number) { setMin(val: number) {
this.feat.min_i = Math.round(val); this.feat.min_i = Math.round(val);
} }
max(): number { max(): number {
return this.feat.max_i; return this.feat.max_i;
} }
setmax(val: number) { setMax(val: number) {
this.feat.max_i = Math.round(val); this.feat.max_i = Math.round(val);
} }
step(): number { step(): number {
return this.feat.mod_i; return this.feat.mod_i;
} }
setstep(val: number) { setStep(val: number) {
this.feat.mod_i = Math.round(val); this.feat.mod_i = Math.round(val);
} }
constructor(name: string, parent?: FeatureParent|null, defaultnum = 0, handler?: (feat: AnyFeature) => void) { constructor(name: string, parent?: FeatureParent|null, defaultnum = 0, handler?: (feat: AnyFeature) => void) {
super(name, parent, handler); super(name, parent, handler);
this.setnum(defaultnum); this.setNum(defaultnum);
} }
} }
@@ -149,7 +148,7 @@ export class FeatureNumToggle extends FeatureNum {
value(): boolean { value(): boolean {
return this.feat.on; return this.feat.on;
} }
setvalue(val: boolean) { setValue(val: boolean) {
this.feat.on = val; this.feat.on = val;
} }
toggle() { toggle() {
@@ -158,7 +157,7 @@ export class FeatureNumToggle extends FeatureNum {
constructor(name: string, parent?: FeatureParent|null, defaultnum = 0, defaultvalue = false, handler?: (feat: AnyFeature) => void) { constructor(name: string, parent?: FeatureParent|null, defaultnum = 0, defaultvalue = false, handler?: (feat: AnyFeature) => void) {
super(name, parent, defaultnum, handler); super(name, parent, defaultnum, handler);
this.setvalue(defaultvalue); this.setValue(defaultvalue);
} }
} }

View File

@@ -1,14 +1,11 @@
const fps = 60, const fps = 60,
duration = 5 //seconds duration = 5 //seconds
import { FeatureAction, FeatureParent } from './classes/Feature'; import { FeatureAction, FeatureParent } from './classes/Feature'
let testParent = new FeatureParent('class'); let testParent = new FeatureParent('test')
new FeatureAction('testClass', testParent, (f) => { new FeatureAction('display box', testParent, f => {
if (f.parent)
print(`parent: ${f.parent.name}\nid: ${f.parent.id}`)
for (let i = 0; i < fps * duration; i++) { for (let i = 0; i < fps * duration; i++) {
@@ -18,3 +15,10 @@ new FeatureAction('testClass', testParent, (f) => {
} }
}) })
new FeatureAction('print parent data', testParent, f => {
if (f.parent)
print(`parent: ${f.parent.name}\nid: ${f.parent.id}`)
})