Compare commits

...

26 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
79bd47ff0c functional 2021-06-28 16:26:38 -05:00
f284a27ded functional 2021-06-28 16:25:53 -05:00
a6bfb8e8c7 separated types 2021-06-27 20:48:25 -05:00
4a8c91a4ec minor changes 2021-06-25 20:53:01 -05:00
57594aebbd missed one thing 2021-06-25 20:45:00 -05:00
df29e4d0ef finished (?) 2021-06-25 20:12:25 -05:00
cf00c7c212 "Any" should be "any" not "number" 2021-06-25 18:34:32 -05:00
805a116e59 added task enum 2021-06-25 17:54:33 -05:00
70afcad526 all types 2021-06-24 23:56:08 -05:00
2fc2fdec28 functional 2021-06-23 23:30:07 -05:00
3a4dcbee61 updates 2021-06-23 23:24:10 -05:00
128e58151b fix 2021-06-23 22:58:30 -05:00
8ce294291c it compiles 2021-06-23 22:48:54 -05:00
d125696058 system 2021-06-23 22:14:30 -05:00
96555f71d1 dumb 2021-06-23 22:12:00 -05:00
c7dffb0727 changed types and added utils/sw 2021-06-23 22:11:41 -05:00
22b23f39cd added types 2021-06-23 21:57:30 -05:00
85ea2d81a0 improved type names 2021-06-23 21:55:39 -05:00
5171baedd7 untest 2021-06-23 21:31:27 -05:00
03ecf4ce7f test 2021-06-23 21:31:21 -05:00
655edc3d16 ts ini 2021-06-23 21:29:51 -05:00
3b0ee59f47 updated example 2021-06-23 14:15:51 -05:00
13705aa0bd added example 2021-06-23 13:58:11 -05:00
c347a4fd6e update 2021-06-21 23:35:14 -05:00
13 changed files with 1026 additions and 63 deletions

146
_autoexec.lua Normal file
View File

@@ -0,0 +1,146 @@
simulated_resolution = v2(1920, 1080)
function round(n)
return n + 0.5 - (n + 0.5) % 1
end
function coords_to_screenwriter(coord1, coord2)
local x_left, x_right, y_top, y_bottom, width, height
x_left = math.min(coord1.x, coord2.x)
x_right = math.max(coord1.x, coord2.x)
y_top = math.min(coord1.y, coord2.y)
y_bottom = math.max(coord1.y, coord2.y)
width = x_right - x_left
height = y_bottom - y_top
return coords_partial_to_screenwriter(v2(x_left, x_top), v2(width, height), 1)
end
function coords_partial_to_screenwriter(pos_px, scale_px, anchor)
local x_px, y_px, x, y, width, height
if anchor == 1 then --top left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 2 then --top right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 3 then --bottom right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
elseif anchor == 4 then --bottom left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
else --center
x_px = pos_px.x
y_px = pos_px.y
end
x = x_px / simulated_resolution.x * 2 - 1
y = y_px / simulated_resolution.y * 2 - 1
width = scale_px.x / simulated_resolution.x * 2
height = scale_px.y / simulated_resolution.y * 2
return v2(x, y), v2(width, height)
end
function action_value_input(f)
local resp, str = input.get(f.name, bgcolor, 64, 3)
while (resp ~= 0) do system.wait(0) end
f.value_i = tonumber(resp)
end
local bgcolor = '000000'
local bgopacity = '000000'
local menu_options = menu.add_feature('session info', 'parent')
local menu_enable = menu.add_feature('enable', 'toggle', menu_options.id)
menu_enable.on = true
local menu_blank0 = menu.add_feature('', 'action', menu_options.id)
local options_textshadow = menu.add_feature('text shadow', 'toggle', menu_options.id)
local options_disablebg = menu.add_feature('disable background', 'toggle', menu_options.id)
local options_bgcolor = menu.add_feature('background color', 'action', menu_options.id, function(f)
local resp, str = input.get('background color', bgcolor, 6, 2)
while (resp ~= 0) do system.wait(0) end
local r = Regex('^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$')
local m = r:search(str)
if m.count > 0 then
str = m.matches[1]
if (str:len() == 3) then
str = str:sub(1,1)..str:sub(1,1)..str:sub(2,2)..str:sub(2,2)..str:sub(3,3)..str:sub(3,3)
end
bgcolor = str
ui.notify_above_map(str, 'set background color to #' .. str, 140)
end
end)
local options_opacity = menu.add_feature('background opacity', 'action_value_i', menu_options.id, action_value_input)
options_opacity.min_i = 0
options_opacity.max_i = 100
options_opacity.value_i = 100
local options_pos = menu.add_feature('position', 'parent', menu_options.id)
local options_pos_x = menu.add_feature('x', 'action_value_i', options_pos.id, action_value_input)
options_pos_x.min_i = 0
options_pos_x.max_i = simulated_resolution.x
options_pos_x.value_i = 320
local options_pos_y = menu.add_feature('y', 'action_value_i', options_pos.id, action_value_input)
options_pos_y.min_i = 0
options_pos_y.max_i = simulated_resolution.y
options_pos_y.value_i = 20
local options_pos_width = menu.add_feature('width', 'action_value_i', options_pos.id, action_value_input)
options_pos_width.min_i = 0
options_pos_width.max_i = simulated_resolution.x
options_pos_width.value_i = 200
local options_pos_height = menu.add_feature('height', 'action_value_i', options_pos.id, action_value_input)
options_pos_height.min_i = 0
options_pos_height.max_i = simulated_resolution.y
options_pos_height.value_i = 200
local options_disp = menu.add_feature('display', 'parent', menu_options.id)
local options_disp_host = menu.add_feature('host', 'toggle', options_pos.id, action_value_input)
options_disp_host.on = true
menu.create_thread(function(f)
while true do
if menu_enable.on then
local base = v2(options_pos_x.value_i, options_pos_y.value_i)
if (not(options_disablebg.on)) then
local pos, scale = coords_partial_to_screenwriter(base, v2(options_pos_width.value_i, options_pos_height.value_i), 4)
local opacity = string.format('%x', round(options_opacity.value_i * 2.55))
while opacity:len() < 2 do
opacity = '0'..opacity
end
scriptdraw.draw_rect(pos, scale, tonumber('0x'..opacity..bgcolor))
end
local textFlags = 0
if options_textshadow.on then
textFlags = 2
end
local
--scriptdraw.draw_text(scale, v2(0, 0), v2(1, 1), 1, 0XFFFFFFFF, textFlags)
end
system.wait(0)
end
end, nil)

8
_test.lua Normal file
View 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")

View File

@@ -1,63 +0,0 @@
simulated_resolution = v2(1920, 1080)
function coords_to_screenwriter(coord1, coord2)
local x_left, x_right, y_top, y_bottom, width, height
x_left = math.min(coord1.x, coord2.x)
x_right = math.max(coord1.x, coord2.x)
y_top = math.min(coord1.y, coord2.y)
y_bottom = math.max(coord1.y, coord2.y)
width = x_right - x_left
height = y_bottom - y_top
return coords_partial_to_screenwriter(v2(x_left, x_top), v2(width, height), 1)
end
function coords_partial_to_screenwriter(pos_px, scale_px, anchor)
local x_px, y_px, x, y, width, height
if anchor == 1 then --top left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 2 then --top right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 3 then --bottom right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
elseif anchor == 4 then --bottom left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
else --center
x_px = pos_px.x
y_px = pos_px.y
end
x = x_px / simulated_resolution.x * 2 - 1
y = y_px / simulated_resolution.y * 2 - 1
width = scale_px.x / simulated_resolution.x * 2
height = scale_px.y / simulated_resolution.y * 2
return v2(x, y), v2(width, height)
end
local disable_bg = menu.add_feature("disable background", "toggle")
menu.create_thread(function()
while true do
local base = v2(320, 20)
if (not(disable_bg.on)) then
local pos, scale = coords_partial_to_screenwriter(base, v2(200, 200), 4)
scriptdraw.draw_rect(pos, scale, 0xFF000000)
end
--scriptdraw.draw_text(scale, v2(0, 0), v2(1, 1), 1, 0XFFFFFFFF, 0)
system.wait(0)
end
end, nil)

6
examples/rgba.lua Normal file
View File

@@ -0,0 +1,6 @@
-- 0-255, 0-255, 0-255, [0-1]
function rgb(r,g,b,a)
a = (a or 1) * 255
a = a + 0.5 - (a + 0.5) % 1
return ((r&0x0ff)<<0x00)|((g&0x0ff)<<0x08)|((b&0x0ff)<<0x10)|((a&0x0ff)<<0x18)
end

1
ts-lua/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

1
ts-lua/README Normal file
View File

@@ -0,0 +1 @@
wstring will not be added for now, and the only mention of it is in the discord where kektram mentions a bug that never got fixed so it's not worth it until i finish everything else (https://canary.discord.com/channels/701762303024169027/701762305012006921/846484799064899614)

368
ts-lua/dist/test.lua vendored Normal file
View File

@@ -0,0 +1,368 @@
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
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
scriptdraw.draw_rect(
v2(0, 0),
v2(1, 1),
4294967295
)
system.wait(0)
i = i + 1
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
end,
}
return require("test")

278
ts-lua/package-lock.json generated Normal file
View File

@@ -0,0 +1,278 @@
{
"name": "ts-lua",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"devDependencies": {
"lua-types": "^2.10.1",
"types-ts-2take1": "git+https://git@git.zomo.dev/zomo/types-ts-2take1",
"typescript-to-lua": "^0.40.1"
}
},
"node_modules/enhanced-resolve": {
"version": "5.8.2",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz",
"integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.2.4",
"tapable": "^2.2.0"
},
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"node_modules/graceful-fs": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==",
"dev": true
},
"node_modules/has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"dependencies": {
"function-bind": "^1.1.1"
},
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/is-core-module": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz",
"integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==",
"dev": true,
"dependencies": {
"has": "^1.0.3"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/lua-types": {
"version": "2.10.1",
"resolved": "https://registry.npmjs.org/lua-types/-/lua-types-2.10.1.tgz",
"integrity": "sha512-Ai7L25I5kHZYGN5C3LALUse7Eus0k/kM9tEO2zwReG2Xuker0c+0e2M4iyfiEvlGOmBc7cDouqJ5lFwyg8JqiQ==",
"dev": true,
"dependencies": {
"typescript-to-lua": "^0.39.0"
}
},
"node_modules/lua-types/node_modules/typescript-to-lua": {
"version": "0.39.6",
"resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-0.39.6.tgz",
"integrity": "sha512-Yq+XsmFKknMlz9jm1FvTw5B7R4H8lYUly4uwxlR44aT4OFyG9S7mOImrTIF07j414PdrJSQ5dAAhQOBVRqHbMw==",
"dev": true,
"dependencies": {
"resolve": "^1.15.1",
"source-map": "^0.7.3",
"typescript": "~4.3.2"
},
"bin": {
"tstl": "dist/tstl.js"
},
"engines": {
"node": ">=12.13.0"
}
},
"node_modules/path-parse": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"dev": true
},
"node_modules/resolve": {
"version": "1.20.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz",
"integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==",
"dev": true,
"dependencies": {
"is-core-module": "^2.2.0",
"path-parse": "^1.0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/source-map": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz",
"integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==",
"dev": true,
"engines": {
"node": ">= 8"
}
},
"node_modules/tapable": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.0.tgz",
"integrity": "sha512-FBk4IesMV1rBxX2tfiK8RAmogtWn53puLOQlvO8XuwlgxcYbP4mVPS9Ph4aeamSyyVjOl24aYWAuc8U5kCVwMw==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/types-ts-2take1": {
"version": "1.0.0",
"resolved": "git+https://git@git.zomo.dev/zomo/types-ts-2take1#dc5f38b2321b7c6d8adecf8c037c7a5650d48a1d",
"dev": true,
"license": "UNLICENSED"
},
"node_modules/typescript": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/typescript-to-lua": {
"version": "0.40.1",
"resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-0.40.1.tgz",
"integrity": "sha512-wbnXddF+kPWKDQMcuVZLRUeZsMde5Qni6FnYIc3SKOAhg2/ZAm9ctWQsyQLwH8piMUX+uZzFXaJ3pMe186crfw==",
"dev": true,
"dependencies": {
"enhanced-resolve": "^5.8.2",
"resolve": "^1.15.1",
"source-map": "^0.7.3",
"typescript": "~4.3.2"
},
"bin": {
"tstl": "dist/tstl.js"
},
"engines": {
"node": ">=12.13.0"
}
}
},
"dependencies": {
"enhanced-resolve": {
"version": "5.8.2",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz",
"integrity": "sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.4",
"tapable": "^2.2.0"
}
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"graceful-fs": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==",
"dev": true
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"requires": {
"function-bind": "^1.1.1"
}
},
"is-core-module": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz",
"integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==",
"dev": true,
"requires": {
"has": "^1.0.3"
}
},
"lua-types": {
"version": "2.10.1",
"resolved": "https://registry.npmjs.org/lua-types/-/lua-types-2.10.1.tgz",
"integrity": "sha512-Ai7L25I5kHZYGN5C3LALUse7Eus0k/kM9tEO2zwReG2Xuker0c+0e2M4iyfiEvlGOmBc7cDouqJ5lFwyg8JqiQ==",
"dev": true,
"requires": {
"typescript-to-lua": "^0.39.0"
},
"dependencies": {
"typescript-to-lua": {
"version": "0.39.6",
"resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-0.39.6.tgz",
"integrity": "sha512-Yq+XsmFKknMlz9jm1FvTw5B7R4H8lYUly4uwxlR44aT4OFyG9S7mOImrTIF07j414PdrJSQ5dAAhQOBVRqHbMw==",
"dev": true,
"requires": {
"resolve": "^1.15.1",
"source-map": "^0.7.3",
"typescript": "~4.3.2"
}
}
}
},
"path-parse": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"dev": true
},
"resolve": {
"version": "1.20.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz",
"integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==",
"dev": true,
"requires": {
"is-core-module": "^2.2.0",
"path-parse": "^1.0.6"
}
},
"source-map": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz",
"integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==",
"dev": true
},
"tapable": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.0.tgz",
"integrity": "sha512-FBk4IesMV1rBxX2tfiK8RAmogtWn53puLOQlvO8XuwlgxcYbP4mVPS9Ph4aeamSyyVjOl24aYWAuc8U5kCVwMw==",
"dev": true
},
"types-ts-2take1": {
"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"
},
"typescript": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
"dev": true
},
"typescript-to-lua": {
"version": "0.40.1",
"resolved": "https://registry.npmjs.org/typescript-to-lua/-/typescript-to-lua-0.40.1.tgz",
"integrity": "sha512-wbnXddF+kPWKDQMcuVZLRUeZsMde5Qni6FnYIc3SKOAhg2/ZAm9ctWQsyQLwH8piMUX+uZzFXaJ3pMe186crfw==",
"dev": true,
"requires": {
"enhanced-resolve": "^5.8.2",
"resolve": "^1.15.1",
"source-map": "^0.7.3",
"typescript": "~4.3.2"
}
}
}
}

13
ts-lua/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"private": true,
"scripts": {
"build": "tstl && $npm_package_scripts_postbuild",
"postbuild": "cp ./dist/test.lua ../",
"dev": "tstl --watch"
},
"devDependencies": {
"lua-types": "^2.10.1",
"types-ts-2take1": "git+https://git@git.zomo.dev/zomo/types-ts-2take1",
"typescript-to-lua": "^0.40.1"
}
}

View 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
View File

24
ts-lua/src/test.ts Normal file
View File

@@ -0,0 +1,24 @@
const fps = 60,
duration = 5 //seconds
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++) {
scriptdraw.draw_rect(v2(0, 0), v2(1, 1), 0xffffffff)
system.wait(0)
}
})
new FeatureAction('print parent data', testParent, f => {
if (f.parent)
print(`parent: ${f.parent.name}\nid: ${f.parent.id}`)
})

18
ts-lua/tsconfig.json Normal file
View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"target": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"types": ["lua-types/5.4", "types-ts-2take1"],
"strict": true,
"typeRoots": []
},
"tstl": {
"luaTarget": "universal",
"luaLibImport": "inline",
"luaBundle": "test.lua",
"luaBundleEntry": "./src/test.ts",
},
}