From 9b89185c2a83c2f0cf659e752391c9059e42b827 Mon Sep 17 00:00:00 2001 From: MCorange Date: Fri, 23 Aug 2024 13:03:14 +0300 Subject: [PATCH] :33333 uwu --- package-lock.json | 4 +++- package.json | 2 ++ rOSs.lua | 34 +++++++++++++++++++++++++++++++++- src/computercraft.ts | 15 +++++++++++++++ src/index.ts | 5 +++-- src/types/cct.d.ts | 2 +- tsconfig.json | 1 - 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/computercraft.ts diff --git a/package-lock.json b/package-lock.json index 4898aa6..4bea1ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "keypados", "version": "1.0.0", "license": "ISC", + "dependencies": { + "@typescript-to-lua/language-extensions": "^1.19.0" + }, "devDependencies": { "typescript": "^5.5.2", "typescript-to-lua": "^1.26.2" @@ -17,7 +20,6 @@ "version": "1.19.0", "resolved": "https://registry.npmjs.org/@typescript-to-lua/language-extensions/-/language-extensions-1.19.0.tgz", "integrity": "sha512-Os5wOKwviTD4LeqI29N0btYOjokSJ97iCf45EOjIABlb5IwNQy7AE/AqZJobRw3ywHH8+KzJUMkEirWPzh2tUA==", - "dev": true, "license": "MIT" }, "node_modules/enhanced-resolve": { diff --git a/package.json b/package.json index 6449a9a..017c0f3 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,7 @@ "devDependencies": { "typescript": "^5.5.2", "typescript-to-lua": "^1.26.2" + }, + "dependencies": { } } diff --git a/rOSs.lua b/rOSs.lua index 41b1f60..e2ddb59 100644 --- a/rOSs.lua +++ b/rOSs.lua @@ -22,13 +22,45 @@ local function require(file, ...) end end ____modules = { +["lualib_bundle"] = function(...) +local function __TS__Class(self) + local c = {prototype = {}} + c.prototype.__index = c.prototype + c.prototype.constructor = c + return c +end + +return { + __TS__Class = __TS__Class +} + end, +["src.computercraft"] = function(...) +local ____lualib = require("lualib_bundle") +local __TS__Class = ____lualib.__TS__Class +local ____exports = {} +____exports.Peripheral = __TS__Class() +local Peripheral = ____exports.Peripheral +Peripheral.name = "Peripheral" +function Peripheral.prototype.____constructor(self) +end +function Peripheral.find(self, ty, filter) + return peripheral.find(ty, filter) +end +function Peripheral.findOne(self, ty, filter) + local p, _a, _b, _c = table.unpack(____exports.Peripheral:find(ty, filter)) + return p +end +return ____exports + end, ["src.index"] = function(...) --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] local ____exports = {} local ____basalt = require("src.basalt") local basalt = ____basalt.default +local ____computercraft = require("src.computercraft") +local Peripheral = ____computercraft.Peripheral local function main(self) - local d = peripheral.find("monitor")[1] + local d = table.unpack(Peripheral:findOne("monitor")) local main = basalt.addMonitor() main:setMonitor(d) main:addLabel():setText("uwu") diff --git a/src/computercraft.ts b/src/computercraft.ts new file mode 100644 index 0000000..79b9137 --- /dev/null +++ b/src/computercraft.ts @@ -0,0 +1,15 @@ + +export class Peripheral { + static find(ty: string, + filter?: (name: string, wrapped: Peripheral) => boolean + ): [T, T|null, T|null, T|null] { + return peripheral.find(ty, filter); + } + static findOne(ty: string, + filter?: (name: string, wrapped: Peripheral) => boolean + ): T { + const [p, _a, _b, _c] = Peripheral.find(ty, filter); + return p as T; + } + +} diff --git a/src/index.ts b/src/index.ts index 0b1f53c..21815ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,10 @@ import basalt from "basalt"; - +import {Peripheral } from "./computercraft"; function main() { - const d: Monitor = peripheral.find("monitor")[0] as Monitor; + const [d]: [Monitor] = Peripheral.findOne("monitor"); + const main = basalt.addMonitor(); main.setMonitor(d); diff --git a/src/types/cct.d.ts b/src/types/cct.d.ts index f4024c0..f91d14f 100644 --- a/src/types/cct.d.ts +++ b/src/types/cct.d.ts @@ -125,7 +125,7 @@ declare namespace peripheral { function call(name: string, method: string, ...arguments: unknown[]): unknown; function wrap(name: string): T | null; - + /** @tupleReturn */ function find(ty: string, filter?: (name: string, wrapped: Peripheral) => boolean ): [T, T|null, T|null, T|null]; diff --git a/tsconfig.json b/tsconfig.json index 212827a..e133edc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,6 @@ "lib": ["ESNext"], "moduleResolution": "NodeNext", "module": "NodeNext", - "types": [], "typeRoots": [ "./src/types" ],