From c3ee593f863b85364d889235e44bcabe91311cd0 Mon Sep 17 00:00:00 2001 From: apemanzilla Date: Wed, 21 Mar 2018 23:16:51 -0400 Subject: [PATCH] Initial commit --- .gitignore | 2 + LICENSE.txt | 21 +++++++ README.md | 3 + extraParams.hxml | 0 haxelib.json | 13 +++++ src/cc/Colors.hx | 29 ++++++++++ src/cc/Commands.hx | 32 +++++++++++ src/cc/Disk.hx | 16 ++++++ src/cc/FileSystem.hx | 40 ++++++++++++++ src/cc/GPS.hx | 13 +++++ src/cc/Help.hx | 12 ++++ src/cc/Keys.hx | 127 +++++++++++++++++++++++++++++++++++++++++++ src/cc/Multishell.hx | 15 +++++ src/cc/OS.hx | 38 +++++++++++++ src/cc/PaintUtils.hx | 16 ++++++ src/cc/Parallel.hx | 10 ++++ src/cc/Peripheral.hx | 16 ++++++ src/cc/Rednet.hx | 35 ++++++++++++ src/cc/Redstone.hx | 19 +++++++ src/cc/Settings.hx | 16 ++++++ src/cc/Shell.hx | 24 ++++++++ src/cc/Term.hx | 54 ++++++++++++++++++ src/cc/TextUtils.hx | 17 ++++++ src/cc/Turtle.hx | 74 +++++++++++++++++++++++++ src/cc/Vector.hx | 16 ++++++ src/cc/Window.hx | 15 +++++ 26 files changed, 673 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 extraParams.hxml create mode 100644 haxelib.json create mode 100644 src/cc/Colors.hx create mode 100644 src/cc/Commands.hx create mode 100644 src/cc/Disk.hx create mode 100644 src/cc/FileSystem.hx create mode 100644 src/cc/GPS.hx create mode 100644 src/cc/Help.hx create mode 100644 src/cc/Keys.hx create mode 100644 src/cc/Multishell.hx create mode 100644 src/cc/OS.hx create mode 100644 src/cc/PaintUtils.hx create mode 100644 src/cc/Parallel.hx create mode 100644 src/cc/Peripheral.hx create mode 100644 src/cc/Rednet.hx create mode 100644 src/cc/Redstone.hx create mode 100644 src/cc/Settings.hx create mode 100644 src/cc/Shell.hx create mode 100644 src/cc/Term.hx create mode 100644 src/cc/TextUtils.hx create mode 100644 src/cc/Turtle.hx create mode 100644 src/cc/Vector.hx create mode 100644 src/cc/Window.hx diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..663505a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.zip +.vscode/* diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..29caeac --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Dominic "apemanzilla" Marcuse + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed91e79 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# computercraft-haxelib + +This is a minimal set of externs for the Lua APIs of ComputerCraft for the [haxe programming language](https://haxe.org). It's available through haxelib as `computercraft`. Only Lua is supported as a platform. \ No newline at end of file diff --git a/extraParams.hxml b/extraParams.hxml new file mode 100644 index 0000000..e69de29 diff --git a/haxelib.json b/haxelib.json new file mode 100644 index 0000000..0884b97 --- /dev/null +++ b/haxelib.json @@ -0,0 +1,13 @@ +{ + "name": "computercraft", + "url": "https://github.com/apemanzilla/computercraft-haxelib", + "license": "MIT", + "tags": ["computercraft", "cc", "minecraft", "lua"], + "description": "Bindings for the Lua APIs of the ComputerCraft mod for Minecraft", + "version": "1.0.0", + "classPath": "src", + "releasenote": "Initial release", + "contributors": [ + "apemanzilla" + ] +} \ No newline at end of file diff --git a/src/cc/Colors.hx b/src/cc/Colors.hx new file mode 100644 index 0000000..f5e81ad --- /dev/null +++ b/src/cc/Colors.hx @@ -0,0 +1,29 @@ +package cc; + +import haxe.extern.Rest; + +typedef Color = Int; + +@:native("colors") +extern class Colors { + public static function combine(colors: Rest): Color; + public static function subtract(from: Color, colors: Rest): Color; + public static function test(it: Color, check: Color): Bool; + + public static var white: Color; + public static var orange: Color; + public static var magenta: Color; + public static var lightBlue: Color; + public static var yellow: Color; + public static var lime: Color; + public static var pink: Color; + public static var gray: Color; + public static var lightGray: Color; + public static var cyan: Color; + public static var purple: Color; + public static var blue: Color; + public static var brown: Color; + public static var green: Color; + public static var red: Color; + public static var black: Color; +} diff --git a/src/cc/Commands.hx b/src/cc/Commands.hx new file mode 100644 index 0000000..dfd525c --- /dev/null +++ b/src/cc/Commands.hx @@ -0,0 +1,32 @@ +package cc; + +import lua.Table; + +@:multiReturn +extern class CommandExecutionResult { + var successful: Bool; + var output: Table; +} + +@:multiReturn +extern class BlockPosition { + var x: Int; + var y: Int; + var z: Int; +} + +extern class BlockInfo { + var name: String; + var metadata: Int; + var state: Dynamic; +} + +@:native("commands") +extern class Commands { + public static function exec(command: String): CommandExecutionResult; + public static function execAsync(command: String): Int; + public static function list(): Table; + public static function getBlockPosition(): BlockPosition; + public static function getBlockInfo(x: Int, y: Int, z: Int): BlockInfo; + public static function getBlockInfos(x1: Int, y1: Int, z1: Int, x2: Int, y2: Int, z2: Int): Table; +} \ No newline at end of file diff --git a/src/cc/Disk.hx b/src/cc/Disk.hx new file mode 100644 index 0000000..b634f70 --- /dev/null +++ b/src/cc/Disk.hx @@ -0,0 +1,16 @@ +package cc; + +@:native("disk") +extern class Disk { + public static function isPresent(side: String): Bool; + public static function hasData(side: String): Bool; + public static function getMountPath(side: String): String; + public static function setLabel(side: String, label: String): Void; + public static function getLabel(side: String): String; + public static function getID(side: String): Int; + public static function hasAudio(side: String): Bool; + public static function getAudioTitle(side: String): String; + public static function playAudio(side: String): Void; + public static function stopAudio(side: String): Void; + public static function eject(side: String): Void; +} \ No newline at end of file diff --git a/src/cc/FileSystem.hx b/src/cc/FileSystem.hx new file mode 100644 index 0000000..60e7b0b --- /dev/null +++ b/src/cc/FileSystem.hx @@ -0,0 +1,40 @@ +package cc; + +import lua.Table; + +@:enum +abstract OpenFileMode(String) { + var Read = "r"; + var Write = "w"; + var Append = "a"; +} + +@:luaDotMethod +extern class FileHandle { + public function close(): Void; + public function readLine(): String; + public function readAll(): String; + public function write(data: String): Void; + public function writeLine(data: String): Void; + public function flush(): Void; +} + +@:native("fs") +extern class FileSystem { + public static function list(path: String): Table; + public static function exists(path: String): Bool; + public static function isDir(path: String): Bool; + public static function isReadOnly(path: String): Bool; + public static function getDrive(path: String): String; + public static function getSize(path: String): Int; + public static function getFreeSpace(path: String): Int; + public static function makeDir(path: String): Void; + public static function move(from: String, to: String): Void; + public static function copy(from: String, to: String): Void; + public static function delete(path: String): Void; + public static function combine(base: String, part: String): String; + public static function open(path: String, mode: OpenFileMode): FileHandle; + public static function find(pattern: String): Table; + public static function getDir(path: String): String; + // todo: complete() +} \ No newline at end of file diff --git a/src/cc/GPS.hx b/src/cc/GPS.hx new file mode 100644 index 0000000..b96c7f2 --- /dev/null +++ b/src/cc/GPS.hx @@ -0,0 +1,13 @@ +package cc; + +@:multiReturn +extern class GPSLocation { + var x: Float; + var y: Float; + var z: Float; +} + +@:native("gps") +extern class GPS { + public static function locate(?timeout: Float, ?debug: Bool): GPSLocation; +} \ No newline at end of file diff --git a/src/cc/Help.hx b/src/cc/Help.hx new file mode 100644 index 0000000..999ff1a --- /dev/null +++ b/src/cc/Help.hx @@ -0,0 +1,12 @@ +package cc; + +import lua.Table; + +@:native("help") +extern class Help { + public static function path(): String; + public static function setPath(path: String): Void; + public static function lookup(topic: String): String; + public static function topics(): Table; + public static function completeTopic(prefix: String): Table; +} \ No newline at end of file diff --git a/src/cc/Keys.hx b/src/cc/Keys.hx new file mode 100644 index 0000000..2a28e55 --- /dev/null +++ b/src/cc/Keys.hx @@ -0,0 +1,127 @@ +package cc; + +@:native("keys") +extern class Keys { + public static function getName(code: Int): String; + public static inline function getCode(name: String): Int { + // i know this is bad please don't judge me + return (cast Keys)[cast name]; + } + + public static var a: Int; + public static var c: Int; + public static var b: Int; + public static var e: Int; + public static var pageUp: Int; + public static var g: Int; + public static var f: Int; + public static var i: Int; + public static var h: Int; + public static var k: Int; + public static var j: Int; + public static var space: Int; + public static var l: Int; + public static var o: Int; + public static var n: Int; + public static var q: Int; + public static var f1: Int; + public static var s: Int; + // public static var return: Int; + public static var f5: Int; + public static var seven: Int; + public static var w: Int; + public static var numPadEnter: Int; + public static var y: Int; + public static var x: Int; + public static var numPad6: Int; + public static var z: Int; + public static var backslash: Int; + public static var rightBracket: Int; + public static var f9: Int; + public static var yen: Int; + public static var left: Int; + public static var numPadSubtract: Int; + public static var noconvert: Int; + public static var leftCtrl: Int; + public static var rightCtrl: Int; + public static var numPad2: Int; + public static var insert: Int; + public static var delete: Int; + public static var f4: Int; + public static var grave: Int; + public static var leftAlt: Int; + public static var numPad8: Int; + public static var numLock: Int; + public static var four: Int; + public static var rightAlt: Int; + public static var pause: Int; + public static var numPad0: Int; + public static var numPadEquals: Int; + public static var enter: Int; + public static var down: Int; + public static var eight: Int; + public static var f11: Int; + public static var six: Int; + public static var r: Int; + public static var rightShift: Int; + public static var t: Int; + public static var u: Int; + public static var pageDown: Int; + public static var nine: Int; + public static var zero: Int; + public static var capsLock: Int; + public static var p: Int; + public static var leftBracket: Int; + public static var underscore: Int; + public static var scollLock: Int; + public static var minus: Int; + public static var f14: Int; + public static var m: Int; + public static var cimcumflex: Int; + public static var one: Int; + public static var up: Int; + public static var equals: Int; + public static var d: Int; + public static var f7: Int; + public static var apostrophe: Int; + public static var numPad9: Int; + public static var f15: Int; + public static var stop: Int; + public static var f10: Int; + public static var numPad7: Int; + public static var numPad3: Int; + public static var comma: Int; + public static var numPadAdd: Int; + public static var tab: Int; + public static var numPad4: Int; + public static var f3: Int; + public static var kana: Int; + public static var numPad1: Int; + public static var right: Int; + public static var numPadDecimal: Int; + public static var f2: Int; + public static var leftShift: Int; + public static var backspace: Int; + public static var convert: Int; + public static var end: Int; + public static var three: Int; + public static var kanji: Int; + public static var v: Int; + public static var colon: Int; + public static var semiColon: Int; + public static var two: Int; + public static var f13: Int; + public static var multiply: Int; + public static var period: Int; + public static var ax: Int; + public static var slash: Int; + public static var f6: Int; + public static var at: Int; + public static var numPadDivide: Int; + public static var numPad5: Int; + public static var f12: Int; + public static var f8: Int; + public static var home: Int; + public static var five: Int; + public static var numPadComma: Int; +} \ No newline at end of file diff --git a/src/cc/Multishell.hx b/src/cc/Multishell.hx new file mode 100644 index 0000000..2c396f3 --- /dev/null +++ b/src/cc/Multishell.hx @@ -0,0 +1,15 @@ +package cc; + +import lua.Table; +import haxe.extern.Rest; + +@:native("multishell") +extern class Multishell { + public static function getCurrent(): Int; + public static function getCount(): Int; + public static function launch(environment: Table, path: String, args: Rest): Int; + public static function setFocus(id: Int): Void; + public static function setTitle(id: Int, title: String): Void; + public static function getTitle(id: Int): String; + public static function getFocus(): Int; +} \ No newline at end of file diff --git a/src/cc/OS.hx b/src/cc/OS.hx new file mode 100644 index 0000000..59c4eff --- /dev/null +++ b/src/cc/OS.hx @@ -0,0 +1,38 @@ +package cc; + +import lua.Table; +import lua.TableTools; +import haxe.extern.Rest; + +@:native("os") +extern class OS { + public static function version(): String; + public static function getComputerID(): Int; + public static function getComputerLabel(): String; + public static function setComputerLabel(label: String): Void; + public static function run(environment: Table, path: String, args: Rest): Bool; + public static function loadAPI(path: String): Bool; + public static function unloadAPI(path: String): Void; + public static function queueEvent(type: String, data: Rest): Void; + public static function clock(): Float; + public static function startTimer(timeout: Int): Int; + public static function cancelTimer(id: Int): Void; + public static function time(): Float; + public static function sleep(timeout: Float): Void; + public static function day(): Int; + public static function setAlarm(time: Float): Int; + public static function cancelAlarm(id: Int): Void; + public static function shutdown(): Void; + public static function reboot(): Void; + + @:native("pullEvent") private static function _pullEvent(?type: String): Dynamic; + @:native("pullEventRaw") private static function _pullEventRaw(?type: String): Dynamic; + + public static inline function pullEvent(?type: String): ArrayAccess { + return cast TableTools.pack(_pullEvent(type)); + } + + public static inline function pullEventRaw(?type: String): ArrayAccess { + return cast TableTools.pack(_pullEventRaw(type)); + } +} \ No newline at end of file diff --git a/src/cc/PaintUtils.hx b/src/cc/PaintUtils.hx new file mode 100644 index 0000000..77d90fe --- /dev/null +++ b/src/cc/PaintUtils.hx @@ -0,0 +1,16 @@ +package cc; + +import lua.Table; +import cc.Colors; + +typedef Image = Table>; + +@:native("paintutils") +extern class PaintUtils { + public static function loadImage(path: String): Image; + public static function drawImage(image: Image, x: Int, y: Int): Void; + public static function drawPixel(x: Int, y: Int, ?color: Color): Void; + public static function drawLine(startX: Int, startY: Int, endX: Int, endY: Int, ?color: Color): Void; + public static function drawBox(startX: Int, startY: Int, endX: Int, endY: Int, ?color: Color): Void; + public static function drawFilledBox(startX: Int, startY: Int, endX: Int, endY: Int, ?color: Color): Void; +} \ No newline at end of file diff --git a/src/cc/Parallel.hx b/src/cc/Parallel.hx new file mode 100644 index 0000000..084c784 --- /dev/null +++ b/src/cc/Parallel.hx @@ -0,0 +1,10 @@ +package cc; + +import haxe.Constraints; +import haxe.extern.Rest; + +@:native("parallel") +extern class Parallel { + public static function waitForAny(f1: Function, funcs: Rest): Int; + public static function waitForAll(f1: Function, funcs: Rest): Int; +} \ No newline at end of file diff --git a/src/cc/Peripheral.hx b/src/cc/Peripheral.hx new file mode 100644 index 0000000..16d329f --- /dev/null +++ b/src/cc/Peripheral.hx @@ -0,0 +1,16 @@ +package cc; + +import lua.Table; +import haxe.Constraints; +import haxe.extern.Rest; + +@:native("peripheral") +extern class Peripheral { + public static function isPresent(name: String): Bool; + public static function getType(name: String): String; + public static function getMethods(name: String): Table; + public static function call(name: String, method: String, args: Rest): T; + public static function wrap(name: String): T; + public static function find(type: String, ?filter: (String, T) -> Bool): Table; + public static function getNames(): Table; +} \ No newline at end of file diff --git a/src/cc/Rednet.hx b/src/cc/Rednet.hx new file mode 100644 index 0000000..ff6a5b7 --- /dev/null +++ b/src/cc/Rednet.hx @@ -0,0 +1,35 @@ +package cc; + +import lua.Table; +import lua.TableTools; + +typedef MessageData = Dynamic; + +@:multiReturn +extern class ReceivedMessage { + public var senderID: Int; + public var message: T; + public var distance: Float; + public var protocol: String; +} + +@:native("rednet") +extern class Rednet { + public static function open(modem: String): Void; + public static function close(modem: String): Void; + public static function send(to: Int, data: MessageData, ?protocol: String): Void; + public static function broadcast(data: MessageData, ?protocol: String): Void; + public static function receive(?protocol: String, ?timeout: Int): ReceivedMessage; + public static function isOpen(modem: String): Bool; + public static function host(protocol: String, hostname: String): Void; + public static function unhost(protocol: String, hostname: String): Void; + + @:native("lookup") + private static function _lookup(protocol: String, ?hostname: String): Dynamic; + + public static inline function lookup(protocol: String, ?hostname: String): Table { + return TableTools.pack(_lookup(protocol, hostname)); + } + + public static function run(): Void; +} \ No newline at end of file diff --git a/src/cc/Redstone.hx b/src/cc/Redstone.hx new file mode 100644 index 0000000..e911452 --- /dev/null +++ b/src/cc/Redstone.hx @@ -0,0 +1,19 @@ +package cc; + +import lua.Table; +import cc.Colors; + +@:native("redstone") +extern class Redstone { + public static function getSides(): Table; + public static function getInput(side: String): Bool; + public static function setOutput(side: String, state: Bool): Void; + public static function getOutput(side: String): Bool; + public static function getAnalogInput(side: String): Int; + public static function setAnalogOutput(side: String, strength: Int): Void; + public static function getAnalogOutput(side: String): Int; + public static function getBundledInput(side: String): Color; + public static function setBundledOutput(side: String, state: Color): Void; + public static function getBundledOutput(side: String): Color; + public static function testBundledInput(side: String, value: Color): Bool; +} \ No newline at end of file diff --git a/src/cc/Settings.hx b/src/cc/Settings.hx new file mode 100644 index 0000000..9180b70 --- /dev/null +++ b/src/cc/Settings.hx @@ -0,0 +1,16 @@ +package cc; + +import lua.Table; + +typedef SettingData = Dynamic; + +@:native("settings") +extern class Settings { + public static function set(name: String, value: SettingData): Void; + public static function get(name: String, ?defaultValue: SettingData): SettingData; + public static function unset(name: String): Void; + public static function clear(): Void; + public static function getNames(): Table; + public static function load(path: String): Bool; + public static function save(path: String): Bool; +} \ No newline at end of file diff --git a/src/cc/Shell.hx b/src/cc/Shell.hx new file mode 100644 index 0000000..57173ea --- /dev/null +++ b/src/cc/Shell.hx @@ -0,0 +1,24 @@ +package cc; + +import lua.Table; +import haxe.extern.Rest; + +@:native("shell") +extern class Shell { + public static function exit(): Void; + public static function dir(): String; + public static function setDir(path: String): Void; + public static function path(): String; + public static function setPath(path: String): Void; + public static function resolve(localPath: String): String; + public static function resolveProgram(name: String): String; + public static function aliases(): Table; + public static function setAlias(alias: String, program: String): Void; + public static function clearAlias(alias: String): Void; + public static function programs(?showHidden: Bool): Table; + public static function getRunningProgram(): String; + public static function run(command: String, args: Rest): Bool; + public static function openTab(command: String, args: Rest): Int; + public static function switchTab(tabID: Int): Void; + // todo: completion functions +} diff --git a/src/cc/Term.hx b/src/cc/Term.hx new file mode 100644 index 0000000..54d08c5 --- /dev/null +++ b/src/cc/Term.hx @@ -0,0 +1,54 @@ +package cc; + +import cc.Colors; + +@:multiReturn +extern class TerminalPosition { + public var x: Int; + public var y: Int; +} + +@:multiReturn +extern class TerminalSize { + public var width: Int; + public var height: Int; +} + +extern class TerminalObject { + public function write(text: String): Void; + public function blit(text: String, colors: String, background: String): Void; + public function clear(): Void; + public function clearLine(): Void; + public function getCursorPos(): TerminalPosition; + public function setCursorPos(x: Int, y: Int): Void; + public function setCursorBlink(value: Bool): Void; + public function isColor(): Bool; + public function getSize(): TerminalSize; + public function scroll(lines: Int): Void; + public function setTextColor(color: Color): Void; + public function getTextColor(): Color; + public function setBackgroundColor(color: Color): Void; + public function getBackgroundColor(): Color; +} + +@:native("term") +extern class Term { + public static function write(text: String): Void; + public static function blit(text: String, colors: String, background: String): Void; + public static function clear(): Void; + public static function clearLine(): Void; + public static function getCursorPos(): TerminalPosition; + public static function setCursorPos(x: Int, y: Int): Void; + public static function setCursorBlink(value: Bool): Void; + public static function isColor(): Bool; + public static function getSize(): TerminalSize; + public static function scroll(lines: Int): Void; + public static function setTextColor(color: Color): Void; + public static function getTextColor(): Color; + public static function setBackgroundColor(color: Color): Void; + public static function getBackgroundColor(): Color; + + public static function redirect(target: TerminalObject): TerminalObject; + public static function current(): TerminalObject; + public static function native(): TerminalObject; +} \ No newline at end of file diff --git a/src/cc/TextUtils.hx b/src/cc/TextUtils.hx new file mode 100644 index 0000000..adb9cf6 --- /dev/null +++ b/src/cc/TextUtils.hx @@ -0,0 +1,17 @@ +package cc; + +typedef TextUtilsSerializable = Dynamic; + +@:native("textutils") +extern class TextUtils { + public static function slowWrite(text: String, ?rate: Float): Void; + public static function slowPrint(text: String, ?rate: Float): Void; + public static function formatTime(time: Float, ?twentyFourHour: Bool): String; + // todo: tabulate, paged tabulate + public static function pagedPrint(text: String, freeLines: Int): Int; + public static function serialize(data: TextUtilsSerializable): String; + public static function unserialize(from: String): T; + public static function serializeJSON(data: TextUtilsSerializable, ?unquoteKeys: Bool): String; + public static function urlEncode(data: String): String; + // todo: complete +} \ No newline at end of file diff --git a/src/cc/Turtle.hx b/src/cc/Turtle.hx new file mode 100644 index 0000000..28ad3ae --- /dev/null +++ b/src/cc/Turtle.hx @@ -0,0 +1,74 @@ +package cc; + +import haxe.extern.EitherType; + +@:multiReturn +extern class TurtleActionResult { + public var successful: Bool; + public var error: String; +} + +extern class TurtleItemDetail { + public var name: String; + public var damage: Int; + public var count: Int; +} + +extern class TurtleBlockDetail { + public var name: String; + public var metadata: Int; + public var state: Dynamic; +} + +@:multiReturn +extern class TurtleInspectResult { + public var successful: Bool; + public var result: EitherType; +} + +@:native("turtle") +extern class Turtle { + public static function craft(qty: Int): TurtleActionResult; + public static function forward(): TurtleActionResult; + public static function back(): TurtleActionResult; + public static function up(): TurtleActionResult; + public static function down(): TurtleActionResult; + public static function turnLeft(): TurtleActionResult; + public static function turnRight(): TurtleActionResult; + public static function select(slot: Int): Bool; + public static function getSelectedSlot(): Int; + public static function getItemCount(?slot: Int): Int; + public static function getItemSpace(?slot: Int): Int; + public static function getItemDetail(?slot: Int): TurtleItemDetail; + public static function equipLeft(): TurtleActionResult; + public static function equipRight(): TurtleActionResult; + public static function attack(): TurtleActionResult; + public static function attackUp(): TurtleActionResult; + public static function attackDown(): TurtleActionResult; + public static function dig(): TurtleActionResult; + public static function digUp(): TurtleActionResult; + public static function digDown(): TurtleActionResult; + public static function place(?signText: String): TurtleActionResult; + public static function placeUp(): TurtleActionResult; + public static function placeDown(): TurtleActionResult; + public static function detect(): Bool; + public static function detectUp(): Bool; + public static function detectDown(): Bool; + public static function inspect(): TurtleInspectResult; + public static function inspectUp(): TurtleInspectResult; + public static function inspectDown(): TurtleInspectResult; + public static function compare(): Bool; + public static function compareUp(): Bool; + public static function compareDown(): Bool; + public static function compareTo(slot: Int): Bool; + public static function drop(?count: Int): TurtleActionResult; + public static function dropUp(?count: Int): TurtleActionResult; + public static function dropDown(?count: Int): TurtleActionResult; + public static function suck(?amount: Int): TurtleActionResult; + public static function suckUp(?amount: Int): TurtleActionResult; + public static function suckDown(?amount: Int): TurtleActionResult; + public static function refuel(?qty: Int): TurtleActionResult; + public static function getFuelLevel(): Int; + public static function getFuelLimit(): Int; + public static function transferTo(to: Int, ?qty: Int): Bool; +} \ No newline at end of file diff --git a/src/cc/Vector.hx b/src/cc/Vector.hx new file mode 100644 index 0000000..42641aa --- /dev/null +++ b/src/cc/Vector.hx @@ -0,0 +1,16 @@ +package cc; + +@:native("vector") +extern class Vector { + @:native("new") public static function create(x: Int, y: Int, z: Int): Vector; + + public function add(other: Vector): Vector; + public function sub(other: Vector): Vector; + public function mul(n: Float): Vector; + public function dot(other: Vector): Float; + public function cross(other: Vector): Float; + public function length(): Float; + public function normalize(): Vector; + public function round(): Vector; + @:native("tostring") public function toString(): String; +} diff --git a/src/cc/Window.hx b/src/cc/Window.hx new file mode 100644 index 0000000..fa517c6 --- /dev/null +++ b/src/cc/Window.hx @@ -0,0 +1,15 @@ +package cc; + +import cc.Term; + +@:native("window") +@:luaDotMethod +extern class Window extends TerminalObject { + public static function create(parent: TerminalObject, x: Int, y: Int, width: Int, height: Int, ?visible: Bool): Window; + + public function setVisible(visible: Bool): Void; + public function redraw(): Void; + public function restoreCursor(): Void; + public function getPosition(): TerminalPosition; + public function reposition(x: Int, y: Int, ?width: Int, ?height: Int): Void; +} \ No newline at end of file