From 9fbfecb76343c3e49da784f4dcc4c1e3ba5a18ef Mon Sep 17 00:00:00 2001 From: Niz Date: Mon, 9 Feb 2026 09:05:12 -0600 Subject: [PATCH 1/2] feat: Date support --- src/Date.cross.hx | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/Date.cross.hx diff --git a/src/Date.cross.hx b/src/Date.cross.hx new file mode 100644 index 0000000..0fcdd36 --- /dev/null +++ b/src/Date.cross.hx @@ -0,0 +1,101 @@ +package; + +class Date { + private var timestamp:Float; + + public function new(year:Int, month:Int, day:Int, hour:Int, minute:Int, second:Int) { + var dict = untyped __gdscript__("{ + 'year': {0}, + 'month': {1}, + 'day': {2}, + 'hour': {3}, + 'minute': {4}, + 'second': {5} + }", year, month + + 1, day, hour, minute, second); + timestamp = untyped __gdscript__("Time.get_unix_time_from_datetime_dict({0})", dict); + } + + public static function now():Date { + var d = new Date(1970, 0, 1, 0, 0, 0); + d.timestamp = untyped __gdscript__("Time.get_unix_time_from_system()"); + return d; + } + + public static function fromTime(t:Float):Date { + var d = new Date(1970, 0, 1, 0, 0, 0); + d.timestamp = t / 1000.0; + return d; + } + + public static function fromString(s:String):Date { + var parts = s.split(" "); + var dateParts = parts[0].split("-"); + var year = Std.parseInt(dateParts[0]); + var month = Std.parseInt(dateParts[1]) - 1; + var day = Std.parseInt(dateParts[2]); + + var hour = 0; + var minute = 0; + var second = 0; + + if (parts.length > 1) { + var timeParts = parts[1].split(":"); + hour = Std.parseInt(timeParts[0]); + minute = Std.parseInt(timeParts[1]); + if (timeParts.length > 2) { + second = Std.parseInt(timeParts[2]); + } + } + + return new Date(year, month, day, hour, minute, second); + } + + public function getTime():Float { + return timestamp * 1000.0; + } + + private function getDateDict():Dynamic { + return untyped __gdscript__("Time.get_datetime_dict_from_unix_time({0})", timestamp); + } + + public function getFullYear():Int { + return untyped getDateDict().year; + } + + public function getMonth():Int { + return untyped getDateDict().month - 1; + } + + public function getDate():Int { + return untyped getDateDict().day; + } + + public function getHours():Int { + return untyped getDateDict().hour; + } + + public function getMinutes():Int { + return untyped getDateDict().minute; + } + + public function getSeconds():Int { + return untyped getDateDict().second; + } + + public function getDay():Int { + return untyped getDateDict().weekday; + } + + public function toString():String { + var dict = getDateDict(); + var year = untyped dict.year; + var month = untyped dict.month; + var day = untyped dict.day; + var hour = untyped dict.hour; + var minute = untyped dict.minute; + var second = untyped dict.second; + + return untyped __gdscript__('"%04d-%02d-%02d %02d:%02d:%02d" % [{0}, {1}, {2}, {3}, {4}, {5}]', year, month, day, hour, minute, second); + } +} From c5543c22809607b1bdcf86dc41f83d801fc9be91 Mon Sep 17 00:00:00 2001 From: Niz Date: Mon, 9 Feb 2026 09:20:26 -0600 Subject: [PATCH 2/2] Feat: `Sys.args()` support --- src/Sys.cross.hx | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Sys.cross.hx b/src/Sys.cross.hx index ae6f9c7..f392528 100644 --- a/src/Sys.cross.hx +++ b/src/Sys.cross.hx @@ -2,47 +2,47 @@ package; @:require(sys) extern class Sys { - @:runtime public inline static function print(v: Dynamic): Void { + @:runtime public inline static function print(v:Dynamic):Void { untyped __gdscript__("print(str({0}))", v); } - @:runtime public inline static function println(v: Dynamic): Void { + @:runtime public inline static function println(v:Dynamic):Void { untyped __gdscript__("print(str({0}) + \"\n\")", v); } - @:runtime public inline static function args(): Array { - return []; + @:runtime public inline static function args():Array { + return untyped __gdscript__("OS.get_cmdline_args()"); // []; } - @:runtime public inline static function getEnv(s: String): String { + @:runtime public inline static function getEnv(s:String):String { return untyped __gdscript__("OS.get_environment({0})", s); } - @:runtime public inline static function putEnv(s: String, v: Null): Void { + @:runtime public inline static function putEnv(s:String, v:Null):Void { return untyped __gdscript__("OS.set_environment({0}, {1})", s, v == null ? "" : v); } - @:runtime public inline static function environment(): Map { + @:runtime public inline static function environment():Map { throw "Sys.environment not implemented for GDScript."; } - @:runtime public inline static function sleep(seconds: Float): Void { + @:runtime public inline static function sleep(seconds:Float):Void { untyped __gdscript__("OS.delay_msec({0} * 1000)", seconds); } - @:runtime public inline static function setTimeLocale(loc: String): Bool { + @:runtime public inline static function setTimeLocale(loc:String):Bool { return false; } - @:runtime public inline static function getCwd(): String { + @:runtime public inline static function getCwd():String { return programPath(); } - @:runtime public inline static function setCwd(s: String): Void { + @:runtime public inline static function setCwd(s:String):Void { throw "Sys.setCwd not implemented for GDScript."; } - @:runtime public inline static function systemName(): String { + @:runtime public inline static function systemName():String { return switch untyped __gdscript__("OS.get_name()") { case "macOS": "Mac"; case "FreeBSD" | "NetBSD" | "OpenBSD": "BSD"; @@ -50,45 +50,46 @@ extern class Sys { } } - @:runtime public inline static function command(cmd: String, ?args: Array): Int { - if(args == null) args = []; + @:runtime public inline static function command(cmd:String, ?args:Array):Int { + if (args == null) + args = []; return untyped __gdscript__("OS.execute({0}, PackedStringArray({1}))", cmd, args); } - @:runtime public inline static function exit(code: Int): Void { + @:runtime public inline static function exit(code:Int):Void { throw "Sys.exit not implemented for GDScript."; } - @:runtime public inline static function time(): Float { + @:runtime public inline static function time():Float { throw "Sys.time not implemented for GDScript."; } - @:runtime public inline static function cpuTime(): Float { + @:runtime public inline static function cpuTime():Float { return untyped __gdscript__("(Time.get_ticks_msec() * 1000)"); } @:deprecated("Use programPath instead") - @:runtime public inline static function executablePath(): String { + @:runtime public inline static function executablePath():String { return programPath(); } - @:runtime public inline static function programPath(): String { + @:runtime public inline static function programPath():String { return untyped __gdscript__("OS.get_executable_path()"); } - @:runtime public inline static function getChar(echo: Bool): Int { + @:runtime public inline static function getChar(echo:Bool):Int { throw "Sys.getChar not implemented for GDScript."; } - @:runtime public inline static function stdin(): haxe.io.Input { + @:runtime public inline static function stdin():haxe.io.Input { throw "Sys.stdin not implemented for GDScript."; } - @:runtime public inline static function stdout(): haxe.io.Output { + @:runtime public inline static function stdout():haxe.io.Output { throw "Sys.stdout not implemented for GDScript."; } - @:runtime public inline static function stderr(): haxe.io.Output { + @:runtime public inline static function stderr():haxe.io.Output { throw "Sys.stderr not implemented for GDScript."; } -} \ No newline at end of file +}