diff --git a/test.lua b/test.lua index 2cbab27..df4d60f 100644 --- a/test.lua +++ b/test.lua @@ -1,7 +1,22 @@ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] +fps = 60 +duration = 5 menu.add_feature( "test", "action", 0, - function() return ui.notify_above_map("Hello from TypeScript", "", 140) end + 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 ) diff --git a/ts-lua/dist/test.lua b/ts-lua/dist/test.lua index 2cbab27..df4d60f 100644 --- a/ts-lua/dist/test.lua +++ b/ts-lua/dist/test.lua @@ -1,7 +1,22 @@ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] +fps = 60 +duration = 5 menu.add_feature( "test", "action", 0, - function() return ui.notify_above_map("Hello from TypeScript", "", 140) end + 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 ) diff --git a/ts-lua/package.json b/ts-lua/package.json index 67276c3..c31305f 100644 --- a/ts-lua/package.json +++ b/ts-lua/package.json @@ -1,12 +1,12 @@ { - "private": true, - "scripts": { - "build": "tstl && npm run post-build", - "post-build": "cp dist/test.lua ../test.lua", - "dev": "tstl --watch" - }, - "devDependencies": { - "lua-types": "^2.10.1", - "typescript-to-lua": "^0.40.1" - } + "private": true, + "scripts": { + "build": "tstl && $npm_package_scripts_postbuild", + "postbuild": "cp dist/test.lua ../test.lua", + "dev": "tstl --watch" + }, + "devDependencies": { + "lua-types": "^2.10.1", + "typescript-to-lua": "^0.40.1" + } } diff --git a/ts-lua/src/test.ts b/ts-lua/src/test.ts index 2e9d943..a1388c6 100644 --- a/ts-lua/src/test.ts +++ b/ts-lua/src/test.ts @@ -1,2 +1,13 @@ -menu.add_feature('test', 'action', 0, () => - ui.notify_above_map('Hello from TypeScript', '', 140)) +const fps = 60, + duration = 5 //seconds + +menu.add_feature('test', 'action', 0, () => { + + for (let i = 0; i < fps * duration; i++) { + + scriptdraw.draw_rect(v2(0, 0), v2(1, 1), 0xffffffff) + system.wait(0) + + } + +}) diff --git a/ts-lua/types/D3D.d.ts b/ts-lua/types/D3D.d.ts index bbd1561..976dd9a 100644 --- a/ts-lua/types/D3D.d.ts +++ b/ts-lua/types/D3D.d.ts @@ -1,10 +1,22 @@ /** * D3D Functions + * + * These functions should only be used from renderers: feature, which can be set through the renderer property + * + * Renderer callbacks are executed from the d3d thread + * @example + * menu.add_feature("d3d renderer", "toggle", 0, nil).renderer = d3d_draw * @public * @noSelf */ declare namespace d3d { - + function draw_text(text: string, pos: v2, size: v2, scale: float, color: int, flags: int): void; + function register_sprite(path: string): int; + function draw_sprite(id: int, pos: v2, scale: float, rot: float, color: int): void; + function get_sprite_origin(id: int): v2; + function get_sprite_size(id: int): v2; + function draw_line(start: v2, end: v2, size: int, color: int): void; + function draw_rect(pos: v2, size: v2, color: int): void; } \ No newline at end of file diff --git a/ts-lua/types/Events.d.ts b/ts-lua/types/Events.d.ts new file mode 100644 index 0000000..0030975 --- /dev/null +++ b/ts-lua/types/Events.d.ts @@ -0,0 +1,16 @@ +/** + * Hook Functions + * @public + * @noSelf + */ +declare namespace hook { + + function add_event_listener(eventName: "exit", callback: (code: integer) => void|never): int; + function add_event_listener(eventName: "chat", callback: (player: integer, body: string) => void|never): int; + function add_event_listener(eventName: "player_join", callback: (player: integer) => void|never): int; + function add_event_listener(eventName: "player_leave", callback: (player: integer) => void|never): int; + function add_event_listener(eventName: "script", callback: (id: integer, params: vector) => void|never): int; + + function remove_event_listener(eventName: string, id: int): boolean; + +} \ No newline at end of file diff --git a/ts-lua/types/Hooks.d.ts b/ts-lua/types/Hooks.d.ts index fdb4e73..0624f6d 100644 --- a/ts-lua/types/Hooks.d.ts +++ b/ts-lua/types/Hooks.d.ts @@ -5,6 +5,12 @@ */ declare namespace hook { - + type script_event_hook = (source: Player, target: Player, params: int[], count: int) => false|null; + type net_event_hook = (source: Player, target: Player, eventId: int) => false|null; + + function register_script_event_hook(callback: script_event_hook): int + function remove_script_event_hook(id: int): boolean + function register_net_event_hook(callback: net_event_hook): int + function remove_net_event_hook(id: int): boolean } \ No newline at end of file diff --git a/ts-lua/types/Input.d.ts b/ts-lua/types/Input.d.ts index 7d468da..ba8eb54 100644 --- a/ts-lua/types/Input.d.ts +++ b/ts-lua/types/Input.d.ts @@ -5,6 +5,22 @@ */ declare namespace input { - + enum resonse { + SUCCESS = 0, + PENDING, + FAILED + } + + enum types { + ASCII = 0, + ALPHA, + ALPHA_NUM, + NUM, + NUM_DOT, + FLOAT + + } + + function get(title: string, default_value: string, len: int, type: int): [int, string]; } \ No newline at end of file diff --git a/ts-lua/types/Menu.d.ts b/ts-lua/types/Menu.d.ts index 75955af..8c418bf 100644 --- a/ts-lua/types/Menu.d.ts +++ b/ts-lua/types/Menu.d.ts @@ -9,27 +9,18 @@ declare namespace menu { type featureTypes = "parent"|"toggle"|"action"|"value_i"|"action_value_i"|"autoaction_value_i"; - export function add_feature(name: string, type: featureTypes, parent: Feature, script_handler: (feat: Feat) => void): Feat; - - export function delete_feature(id: int): boolean; - - export function set_menu_can_navigate(): void; - - export function get_version(): void; - - export function add_player_feature(name: string, type: string, parent: integer, script_handler: (feat: Feat) => void): PlayerFeat - - export function get_player_feature(i: uint32_t): PlayerFeat - - export function is_threading_mode(mode: int): boolean - + function add_feature(name: string, type: featureTypes, parent: Feature, script_handler: (feat: Feat) => void|never): Feat; + function delete_feature(id: int): boolean; + function set_menu_can_navigate(): void; + function get_version(): void; + function add_player_feature(name: string, type: string, parent: integer, script_handler: (feat: Feat) => void|never): PlayerFeat + function get_player_feature(i: uint32_t): PlayerFeat + function is_threading_mode(mode: int): boolean /** * @privateRemarks callback declaration may be wrong */ - export function create_thread(callback: () => void, context: any): Thread - - export function has_thread_finished(id: Thread): boolean - - export function delete_thread(id: Thread): boolean + function create_thread(callback: (() => void|never), context: any): Thread + function has_thread_finished(id: Thread): boolean + function delete_thread(id: Thread): boolean } \ No newline at end of file diff --git a/ts-lua/types/structs/v2.d.ts b/ts-lua/types/structs/v2.d.ts index 2221456..cde1fea 100644 --- a/ts-lua/types/structs/v2.d.ts +++ b/ts-lua/types/structs/v2.d.ts @@ -1,66 +1,33 @@ /** * a 2x1 matrix * @public + * @noSelf */ declare class v2 { + + readonly x: float; + readonly y: float; /** - * - * @remarks float + * **instanciating this class with `new` will break the lua** + * @deprecated */ - readonly x: number; - - /** - * - * @remarks float - */ - readonly y: number; - - /** - * - * @param x float - * @param y float - */ - constructor(x?: number, y?: number); - - /** - * - * @param val float - */ - public __add(val: v2|v3|number): v2; - - /** - * - * @param val float - */ - public __sub(val: v2|v3|number): v2; - - /** - * - * @param val float - */ - public __mul(val: v2|v3|number): v2; - - /** - * - * @param val float - */ - public __div(val: v2|v3|number): v2; + constructor(x: float, y: float); + public __add(val: v2|v3|float): v2; + public __sub(val: v2|v3|float): v2; + public __mul(val: v2|v3|float): v2; + public __div(val: v2|v3|float): v2; public __eq(val: v2): boolean; - public __lt(val: v2): boolean; - public __le(val: v2): boolean; - public __tostring(): string - /** - * - * @returns float - */ - public magnitude(val: v2|null): number; + public magnitude(val: v2|null): float; } -declare function v2(x?: number, y?: number): v2 \ No newline at end of file +/** + * @noSelf + */ +declare function v2(x: float, y: float): v2 \ No newline at end of file diff --git a/ts-lua/types/structs/v3.d.ts b/ts-lua/types/structs/v3.d.ts index 37a3885..c0b2425 100644 --- a/ts-lua/types/structs/v3.d.ts +++ b/ts-lua/types/structs/v3.d.ts @@ -18,86 +18,37 @@ * pos += dir * * @public + * @noSelf */ declare class v3 { - /** - * - * @remarks float - */ - readonly x: number; + readonly x: float; + readonly y: float; + readonly z: float; /** - * - * @remarks float + * **instanciating this class with `new` will break the lua** + * @deprecated */ - readonly y: number; - - /** - * - * @remarks float - */ - readonly z: number; - - /** - * - * @param x float - * @param y float - * @param z float - */ - constructor(x?: number, y?: number, z?: number); - - /** - * - * @param val float - */ - public __add(val: v2|v3|number): v3; - - /** - * - * @param val float - */ - public __sub(val: v2|v3|number): v3; - - /** - * - * @param val float - */ - public __mul(val: v2|v3|number): v3; - - /** - * - * @param val float - */ - public __div(val: v2|v3|number): v3; + constructor(x: float, y: float, z: float); + public __add(val: v2|v3|float): v3; + public __sub(val: v2|v3|float): v3; + public __mul(val: v2|v3|float): v3; + public __div(val: v2|v3|float): v3; public __eq(val: v2): boolean; - public __lt(val: v2): boolean; - public __le(val: v2): boolean; - public __tostring(): string - /** - * - * @returns float - */ - public magnitude(val: v3|null): number; - - /** - * - * @privateRemarks - * - * I don't understand this methough function enough to even try to test this in typescript - * - */ + public magnitude(val: v3|null): float; public transformRotToDir(): void; - public radToDeg(): void; - public degToRad(): void; } -declare function v3(x?: number, y?: number, z?: number): v3 +/** + * @noSelf + */ +declare function v3(x: float, y: float, z: float): v3