Compare commits
4 Commits
a6bfb8e8c7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f1e4f91461 | |||
| 18b3debb53 | |||
| 79bd47ff0c | |||
| f284a27ded |
8
_test.lua
Normal file
8
_test.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
local rootPath = utils.get_appdata_path("PopstarDevs", "2Take1Menu") .. "\\scripts\\"
|
||||
|
||||
function load(file)
|
||||
local chunk, status = loadfile(rootPath .. file)
|
||||
if chunk then chunk() end
|
||||
end
|
||||
|
||||
load("ts-lua\\dist\\test.lua")
|
||||
22
test.lua
22
test.lua
@@ -1,22 +0,0 @@
|
||||
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
fps = 60
|
||||
duration = 5
|
||||
menu.add_feature(
|
||||
"test",
|
||||
"action",
|
||||
0,
|
||||
function()
|
||||
do
|
||||
local i = 0
|
||||
while i < (fps * duration) do
|
||||
scriptdraw.draw_rect(
|
||||
v2(0, 0),
|
||||
v2(1, 1),
|
||||
4294967295
|
||||
)
|
||||
system.wait(0)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
360
ts-lua/dist/test.lua
vendored
360
ts-lua/dist/test.lua
vendored
@@ -1,11 +1,341 @@
|
||||
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
fps = 60
|
||||
duration = 5
|
||||
menu.add_feature(
|
||||
"test",
|
||||
"action",
|
||||
0,
|
||||
function()
|
||||
|
||||
local ____modules = {}
|
||||
local ____moduleCache = {}
|
||||
local ____originalRequire = require
|
||||
local function require(file)
|
||||
if ____moduleCache[file] then
|
||||
return ____moduleCache[file]
|
||||
end
|
||||
if ____modules[file] then
|
||||
____moduleCache[file] = ____modules[file]()
|
||||
return ____moduleCache[file]
|
||||
else
|
||||
if ____originalRequire then
|
||||
return ____originalRequire(file)
|
||||
else
|
||||
error("module '" .. file .. "' not found")
|
||||
end
|
||||
end
|
||||
end
|
||||
____modules = {
|
||||
["index"] = function() --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
end,
|
||||
["classes.Feature"] = function() --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
-- Lua Library inline imports
|
||||
function __TS__Class(self)
|
||||
local c = {prototype = {}}
|
||||
c.prototype.__index = c.prototype
|
||||
c.prototype.constructor = c
|
||||
return c
|
||||
end
|
||||
|
||||
function __TS__ArrayPush(arr, ...)
|
||||
local items = {...}
|
||||
for ____, item in ipairs(items) do
|
||||
arr[#arr + 1] = item
|
||||
end
|
||||
return #arr
|
||||
end
|
||||
|
||||
function __TS__ArraySplice(list, ...)
|
||||
local len = #list
|
||||
local actualArgumentCount = select("#", ...)
|
||||
local start = select(1, ...)
|
||||
local deleteCount = select(2, ...)
|
||||
local actualStart
|
||||
if start < 0 then
|
||||
actualStart = math.max(len + start, 0)
|
||||
else
|
||||
actualStart = math.min(start, len)
|
||||
end
|
||||
local itemCount = math.max(actualArgumentCount - 2, 0)
|
||||
local actualDeleteCount
|
||||
if actualArgumentCount == 0 then
|
||||
actualDeleteCount = 0
|
||||
elseif actualArgumentCount == 1 then
|
||||
actualDeleteCount = len - actualStart
|
||||
else
|
||||
actualDeleteCount = math.min(
|
||||
math.max(deleteCount or 0, 0),
|
||||
len - actualStart
|
||||
)
|
||||
end
|
||||
local out = {}
|
||||
do
|
||||
local k = 0
|
||||
while k < actualDeleteCount do
|
||||
local from = actualStart + k
|
||||
if list[from + 1] then
|
||||
out[k + 1] = list[from + 1]
|
||||
end
|
||||
k = k + 1
|
||||
end
|
||||
end
|
||||
if itemCount < actualDeleteCount then
|
||||
do
|
||||
local k = actualStart
|
||||
while k < (len - actualDeleteCount) do
|
||||
local from = k + actualDeleteCount
|
||||
local to = k + itemCount
|
||||
if list[from + 1] then
|
||||
list[to + 1] = list[from + 1]
|
||||
else
|
||||
list[to + 1] = nil
|
||||
end
|
||||
k = k + 1
|
||||
end
|
||||
end
|
||||
do
|
||||
local k = len
|
||||
while k > ((len - actualDeleteCount) + itemCount) do
|
||||
list[k] = nil
|
||||
k = k - 1
|
||||
end
|
||||
end
|
||||
elseif itemCount > actualDeleteCount then
|
||||
do
|
||||
local k = len - actualDeleteCount
|
||||
while k > actualStart do
|
||||
local from = (k + actualDeleteCount) - 1
|
||||
local to = (k + itemCount) - 1
|
||||
if list[from + 1] then
|
||||
list[to + 1] = list[from + 1]
|
||||
else
|
||||
list[to + 1] = nil
|
||||
end
|
||||
k = k - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
local j = actualStart
|
||||
for i = 3, actualArgumentCount do
|
||||
list[j + 1] = select(i, ...)
|
||||
j = j + 1
|
||||
end
|
||||
do
|
||||
local k = #list - 1
|
||||
while k >= ((len - actualDeleteCount) + itemCount) do
|
||||
list[k + 1] = nil
|
||||
k = k - 1
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
function __TS__ClassExtends(target, base)
|
||||
target.____super = base
|
||||
local staticMetatable = setmetatable({__index = base}, base)
|
||||
setmetatable(target, staticMetatable)
|
||||
local baseMetatable = getmetatable(base)
|
||||
if baseMetatable then
|
||||
if type(baseMetatable.__index) == "function" then
|
||||
staticMetatable.__index = baseMetatable.__index
|
||||
end
|
||||
if type(baseMetatable.__newindex) == "function" then
|
||||
staticMetatable.__newindex = baseMetatable.__newindex
|
||||
end
|
||||
end
|
||||
setmetatable(target.prototype, base.prototype)
|
||||
if type(base.prototype.__index) == "function" then
|
||||
target.prototype.__index = base.prototype.__index
|
||||
end
|
||||
if type(base.prototype.__newindex) == "function" then
|
||||
target.prototype.__newindex = base.prototype.__newindex
|
||||
end
|
||||
if type(base.prototype.__tostring) == "function" then
|
||||
target.prototype.__tostring = base.prototype.__tostring
|
||||
end
|
||||
end
|
||||
|
||||
local ____exports = {}
|
||||
____exports.FeatureParent = __TS__Class()
|
||||
local FeatureParent = ____exports.FeatureParent
|
||||
FeatureParent.name = "FeatureParent"
|
||||
function FeatureParent.prototype.____constructor(self, name, parent)
|
||||
self.parentid = 0
|
||||
self.children = {}
|
||||
self.name = name
|
||||
if parent then
|
||||
self.parent = parent
|
||||
self.parentid = parent.id
|
||||
self.parent:addChild(self)
|
||||
end
|
||||
self.feat = menu.add_feature(
|
||||
name,
|
||||
self:type(),
|
||||
self.parentid,
|
||||
function() return self:select() end
|
||||
)
|
||||
self.id = self.feat.id
|
||||
end
|
||||
function FeatureParent.prototype.type(self)
|
||||
return "parent"
|
||||
end
|
||||
function FeatureParent.prototype.hidden(self)
|
||||
return self.feat.hidden
|
||||
end
|
||||
function FeatureParent.prototype.setHidden(self, val)
|
||||
self.feat.hidden = val
|
||||
end
|
||||
function FeatureParent.prototype.select(self)
|
||||
end
|
||||
function FeatureParent.prototype.addChild(self, feat)
|
||||
do
|
||||
local i = 0
|
||||
while i < #self.children do
|
||||
if self.children[i + 1]:equals(feat) then
|
||||
return
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
__TS__ArrayPush(self.children, feat)
|
||||
end
|
||||
function FeatureParent.prototype.removeChild(self, feat)
|
||||
do
|
||||
local i = 0
|
||||
while i < #self.children do
|
||||
if self.children[i + 1]:equals(feat) then
|
||||
__TS__ArraySplice(self.children, i, 1)
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
function FeatureParent.prototype.equals(self, feat)
|
||||
return self.id == feat.id
|
||||
end
|
||||
____exports.FeatureAction = __TS__Class()
|
||||
local FeatureAction = ____exports.FeatureAction
|
||||
FeatureAction.name = "FeatureAction"
|
||||
__TS__ClassExtends(FeatureAction, ____exports.FeatureParent)
|
||||
function FeatureAction.prototype.____constructor(self, name, parent, handler)
|
||||
FeatureAction.____super.prototype.____constructor(self, name, parent)
|
||||
if handler then
|
||||
self.handler = handler
|
||||
end
|
||||
end
|
||||
function FeatureAction.prototype.type(self)
|
||||
return "action"
|
||||
end
|
||||
function FeatureAction.prototype.select(self)
|
||||
if self.handler then
|
||||
self:handler(self)
|
||||
end
|
||||
end
|
||||
function FeatureAction.prototype.setHandler(self, handler)
|
||||
self.handler = handler
|
||||
end
|
||||
____exports.FeatureToggle = __TS__Class()
|
||||
local FeatureToggle = ____exports.FeatureToggle
|
||||
FeatureToggle.name = "FeatureToggle"
|
||||
__TS__ClassExtends(FeatureToggle, ____exports.FeatureAction)
|
||||
function FeatureToggle.prototype.____constructor(self, name, parent, defaultvalue, handler)
|
||||
if defaultvalue == nil then
|
||||
defaultvalue = false
|
||||
end
|
||||
FeatureToggle.____super.prototype.____constructor(self, name, parent, handler)
|
||||
self:setValue(defaultvalue)
|
||||
end
|
||||
function FeatureToggle.prototype.type(self)
|
||||
return "toggle"
|
||||
end
|
||||
function FeatureToggle.prototype.value(self)
|
||||
return self.feat.on
|
||||
end
|
||||
function FeatureToggle.prototype.setValue(self, val)
|
||||
self.feat.on = val
|
||||
end
|
||||
function FeatureToggle.prototype.toggle(self)
|
||||
self.feat.on = not self.feat.on
|
||||
end
|
||||
____exports.FeatureNum = __TS__Class()
|
||||
local FeatureNum = ____exports.FeatureNum
|
||||
FeatureNum.name = "FeatureNum"
|
||||
__TS__ClassExtends(FeatureNum, ____exports.FeatureAction)
|
||||
function FeatureNum.prototype.____constructor(self, name, parent, defaultnum, handler)
|
||||
if defaultnum == nil then
|
||||
defaultnum = 0
|
||||
end
|
||||
FeatureNum.____super.prototype.____constructor(self, name, parent, handler)
|
||||
self:setNum(defaultnum)
|
||||
end
|
||||
function FeatureNum.prototype.type(self)
|
||||
return "action_value_i"
|
||||
end
|
||||
function FeatureNum.prototype.num(self)
|
||||
return self.feat.value_i
|
||||
end
|
||||
function FeatureNum.prototype.setNum(self, val)
|
||||
self.feat.value_i = val
|
||||
end
|
||||
function FeatureNum.prototype.min(self)
|
||||
return self.feat.min_i
|
||||
end
|
||||
function FeatureNum.prototype.setMin(self, val)
|
||||
self.feat.min_i = math.floor(val + 0.5)
|
||||
end
|
||||
function FeatureNum.prototype.max(self)
|
||||
return self.feat.max_i
|
||||
end
|
||||
function FeatureNum.prototype.setMax(self, val)
|
||||
self.feat.max_i = math.floor(val + 0.5)
|
||||
end
|
||||
function FeatureNum.prototype.step(self)
|
||||
return self.feat.mod_i
|
||||
end
|
||||
function FeatureNum.prototype.setStep(self, val)
|
||||
self.feat.mod_i = math.floor(val + 0.5)
|
||||
end
|
||||
____exports.FeatureNumToggle = __TS__Class()
|
||||
local FeatureNumToggle = ____exports.FeatureNumToggle
|
||||
FeatureNumToggle.name = "FeatureNumToggle"
|
||||
__TS__ClassExtends(FeatureNumToggle, ____exports.FeatureNum)
|
||||
function FeatureNumToggle.prototype.____constructor(self, name, parent, defaultnum, defaultvalue, handler)
|
||||
if defaultnum == nil then
|
||||
defaultnum = 0
|
||||
end
|
||||
if defaultvalue == nil then
|
||||
defaultvalue = false
|
||||
end
|
||||
FeatureNumToggle.____super.prototype.____constructor(self, name, parent, defaultnum, handler)
|
||||
self:setValue(defaultvalue)
|
||||
end
|
||||
function FeatureNumToggle.prototype.type(self)
|
||||
return "value_i"
|
||||
end
|
||||
function FeatureNumToggle.prototype.value(self)
|
||||
return self.feat.on
|
||||
end
|
||||
function FeatureNumToggle.prototype.setValue(self, val)
|
||||
self.feat.on = val
|
||||
end
|
||||
function FeatureNumToggle.prototype.toggle(self)
|
||||
self.feat.on = not self.feat.on
|
||||
end
|
||||
return ____exports
|
||||
end,
|
||||
["test"] = function() --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
-- Lua Library inline imports
|
||||
function __TS__New(target, ...)
|
||||
local instance = setmetatable({}, target.prototype)
|
||||
instance:____constructor(...)
|
||||
return instance
|
||||
end
|
||||
|
||||
local ____exports = {}
|
||||
local ____Feature = require("classes.Feature")
|
||||
local FeatureAction = ____Feature.FeatureAction
|
||||
local FeatureParent = ____Feature.FeatureParent
|
||||
local fps = 60
|
||||
local duration = 5
|
||||
local testParent = __TS__New(FeatureParent, "test")
|
||||
__TS__New(
|
||||
FeatureAction,
|
||||
"display box",
|
||||
testParent,
|
||||
function(____, f)
|
||||
do
|
||||
local i = 0
|
||||
while i < (fps * duration) do
|
||||
@@ -20,3 +350,19 @@ menu.add_feature(
|
||||
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
|
||||
end,
|
||||
}
|
||||
return require("test")
|
||||
|
||||
4
ts-lua/package-lock.json
generated
4
ts-lua/package-lock.json
generated
@@ -124,7 +124,7 @@
|
||||
},
|
||||
"node_modules/types-ts-2take1": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "git+https://git@git.zomo.dev/zomo/types-ts-2take1#39850d8660e101c26dd793f7464340bcfd4ed723",
|
||||
"resolved": "git+https://git@git.zomo.dev/zomo/types-ts-2take1#dc5f38b2321b7c6d8adecf8c037c7a5650d48a1d",
|
||||
"dev": true,
|
||||
"license": "UNLICENSED"
|
||||
},
|
||||
@@ -252,7 +252,7 @@
|
||||
"dev": true
|
||||
},
|
||||
"types-ts-2take1": {
|
||||
"version": "git+https://git@git.zomo.dev/zomo/types-ts-2take1#39850d8660e101c26dd793f7464340bcfd4ed723",
|
||||
"version": "git+https://git@git.zomo.dev/zomo/types-ts-2take1#dc5f38b2321b7c6d8adecf8c037c7a5650d48a1d",
|
||||
"dev": true,
|
||||
"from": "types-ts-2take1@git+https://git@git.zomo.dev/zomo/types-ts-2take1"
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tstl && $npm_package_scripts_postbuild",
|
||||
"postbuild": "cp dist/test.lua ../test.lua",
|
||||
"postbuild": "cp ./dist/test.lua ../",
|
||||
"dev": "tstl --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
163
ts-lua/src/classes/Feature.ts
Normal file
163
ts-lua/src/classes/Feature.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
type AnyFeature = FeatureParent|FeatureAction|FeatureToggle|FeatureNum|FeatureNumToggle;
|
||||
|
||||
export class FeatureParent {
|
||||
|
||||
type(): menu.featureTypes { return "parent"; }
|
||||
|
||||
name: string;
|
||||
id: number;
|
||||
parent?: FeatureParent|null;
|
||||
parentid: number = 0;
|
||||
children: AnyFeature[] = [];
|
||||
|
||||
feat: Feat;
|
||||
|
||||
hidden(): boolean {
|
||||
return this.feat.hidden;
|
||||
}
|
||||
setHidden(val: boolean) {
|
||||
this.feat.hidden = val;
|
||||
}
|
||||
|
||||
select() {}
|
||||
|
||||
constructor(name: string, parent?: FeatureParent|null) {
|
||||
this.name = name;
|
||||
|
||||
if (parent) {
|
||||
this.parent = parent;
|
||||
this.parentid = parent.id;
|
||||
this.parent.addChild(this);
|
||||
}
|
||||
|
||||
this.feat = menu.add_feature(name, this.type(), this.parentid, () => this.select());
|
||||
this.id = this.feat.id;
|
||||
}
|
||||
|
||||
/* children */
|
||||
|
||||
addChild(feat: AnyFeature) {
|
||||
for (let i = 0; i < this.children.length; i++)
|
||||
if (this.children[i].equals(feat))
|
||||
return;
|
||||
this.children.push(feat);
|
||||
}
|
||||
|
||||
removeChild(feat: AnyFeature) {
|
||||
for (let i = 0; i < this.children.length; i++)
|
||||
if (this.children[i].equals(feat))
|
||||
this.children.splice(i, 1);
|
||||
}
|
||||
|
||||
/* util */
|
||||
|
||||
equals(feat: AnyFeature): boolean {
|
||||
return this.id === feat.id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FeatureAction extends FeatureParent {
|
||||
|
||||
type(): menu.featureTypes { return "action"; }
|
||||
|
||||
handler?: (feat: this) => void;
|
||||
|
||||
select() {
|
||||
if (this.handler)
|
||||
this.handler(this);
|
||||
}
|
||||
|
||||
constructor(name: string, parent?: FeatureParent|null, handler?: (feat: AnyFeature) => void) {
|
||||
super(name, parent);
|
||||
|
||||
if (handler)
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
setHandler(handler: (feat: AnyFeature) => void) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FeatureToggle extends FeatureAction {
|
||||
|
||||
type(): menu.featureTypes { return "toggle"; }
|
||||
|
||||
value(): boolean {
|
||||
return this.feat.on;
|
||||
}
|
||||
setValue(val: boolean) {
|
||||
this.feat.on = val;
|
||||
}
|
||||
toggle() {
|
||||
this.feat.on = !this.feat.on;
|
||||
}
|
||||
|
||||
constructor(name: string, parent?: FeatureParent|null, defaultvalue = false, handler?: (feat: AnyFeature) => void) {
|
||||
super(name, parent, handler);
|
||||
this.setValue(defaultvalue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FeatureNum extends FeatureAction {
|
||||
|
||||
type(): menu.featureTypes { return "action_value_i"; }
|
||||
|
||||
num(): number {
|
||||
return this.feat.value_i;
|
||||
}
|
||||
setNum(val: number) {
|
||||
this.feat.value_i = val;
|
||||
}
|
||||
|
||||
min(): number {
|
||||
return this.feat.min_i;
|
||||
}
|
||||
setMin(val: number) {
|
||||
this.feat.min_i = Math.round(val);
|
||||
}
|
||||
|
||||
max(): number {
|
||||
return this.feat.max_i;
|
||||
}
|
||||
setMax(val: number) {
|
||||
this.feat.max_i = Math.round(val);
|
||||
}
|
||||
|
||||
step(): number {
|
||||
return this.feat.mod_i;
|
||||
}
|
||||
setStep(val: number) {
|
||||
this.feat.mod_i = Math.round(val);
|
||||
}
|
||||
|
||||
constructor(name: string, parent?: FeatureParent|null, defaultnum = 0, handler?: (feat: AnyFeature) => void) {
|
||||
super(name, parent, handler);
|
||||
this.setNum(defaultnum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FeatureNumToggle extends FeatureNum {
|
||||
|
||||
type(): menu.featureTypes { return "value_i"; }
|
||||
|
||||
value(): boolean {
|
||||
return this.feat.on;
|
||||
}
|
||||
setValue(val: boolean) {
|
||||
this.feat.on = val;
|
||||
}
|
||||
toggle() {
|
||||
this.feat.on = !this.feat.on;
|
||||
}
|
||||
|
||||
constructor(name: string, parent?: FeatureParent|null, defaultnum = 0, defaultvalue = false, handler?: (feat: AnyFeature) => void) {
|
||||
super(name, parent, defaultnum, handler);
|
||||
this.setValue(defaultvalue);
|
||||
}
|
||||
|
||||
}
|
||||
0
ts-lua/src/index.ts
Normal file
0
ts-lua/src/index.ts
Normal file
@@ -1,7 +1,11 @@
|
||||
const fps = 60,
|
||||
duration = 5 //seconds
|
||||
|
||||
menu.add_feature('test', 'action', 0, () => {
|
||||
import { FeatureAction, FeatureParent } from './classes/Feature'
|
||||
|
||||
let testParent = new FeatureParent('test')
|
||||
|
||||
new FeatureAction('display box', testParent, f => {
|
||||
|
||||
for (let i = 0; i < fps * duration; i++) {
|
||||
|
||||
@@ -11,3 +15,10 @@ menu.add_feature('test', 'action', 0, () => {
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
new FeatureAction('print parent data', testParent, f => {
|
||||
|
||||
if (f.parent)
|
||||
print(`parent: ${f.parent.name}\nid: ${f.parent.id}`)
|
||||
|
||||
})
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
"target": "esnext",
|
||||
"lib": ["esnext"],
|
||||
"moduleResolution": "node",
|
||||
"types": ["lua-types/5.4"],
|
||||
"types": ["lua-types/5.4", "types-ts-2take1"],
|
||||
"strict": true,
|
||||
"typeRoots": [
|
||||
"./types"
|
||||
]
|
||||
"typeRoots": []
|
||||
},
|
||||
"tstl": {
|
||||
"luaTarget": "JIT"
|
||||
"luaTarget": "universal",
|
||||
"luaLibImport": "inline",
|
||||
"luaBundle": "test.lua",
|
||||
"luaBundleEntry": "./src/test.ts",
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user