commit 7880ceeb4c5ccf47a2be690ac9e977d648f803a2 Author: ehko Date: Fri Jun 5 22:17:33 2026 -0400 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..311f53a --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# orbis-editor + +Orbis IDE built in OrbisScript + +## How it proves the point + +Purely this just proves that the runtime can transpile the OrbisScript files into Java code. It has Java reflection for stuff I forgot but it ultimately should be able to handle it all. Like I said, why build your own scripting lang if you can't make an IDE in it. + +## Deploy + +1. Drop `OrbisRuntime.jar` into your Hytale server's `mods/` +2. Copy `editor.hytale` to the server's `orbis-data/scripts/` +3. Run `/orbis run` in-game +4. Run `/orbis editor` diff --git a/editor.hytale b/editor.hytale new file mode 100644 index 0000000..2d59434 --- /dev/null +++ b/editor.hytale @@ -0,0 +1,167 @@ +// why build your own scripting lang if you can't make an IDE in it + +plugin = java_static("net.orbis.OrbisPlugin", "getInstance"); +dynUI = plugin.getDynamicUI; +dataDir = plugin.getDataDirectory; + + +function listScripts() { + path = java_static("java.nio.file.Paths", "get", java_call(dataDir, "toString"), "scripts"); + stream = java_static("java.nio.file.Files", "list", path); + return java_call(stream, "collect", java_static("java.util.stream.Collectors", "toList")); +} + +function readFile(relPath) { + path = java_static("java.nio.file.Paths", "get", java_call(dataDir, "toString"), "scripts", relPath); + return java_static("java.nio.file.Files", "readString", path); +} + +function writeFile(relPath, content) { + path = java_static("java.nio.file.Paths", "get", java_call(dataDir, "toString"), "scripts", relPath); + java_static("java.nio.file.Files", "writeString", path, content); +} + + +function uiComp(type, id) { java_call(dynUI, "createComponent", type, id); } +function uiSet(id, k, v) { java_call(dynUI, "setProperty", id, k, v); } +function uiAdd(p, c) { java_call(dynUI, "addChild", p, c); } +function uiOn(c, e, fn) { java_call(dynUI, "setCallback", c, e, fn); } +function uiRegister(id) { java_call(dynUI, "registerRoot", id); } +function uiClear(id) { java_call(dynUI, "clearChildren", id); } + +// ── Script reload via reflection chain ── + +function reloadAll() { + loader = plugin.getScriptLoader; + loader.reloadAll; + gameMgr = plugin.getGameManager; + gameMgr.clearEvents; + scripts = loader.loadAll; + i = 0; + while (i < len(scripts)) { + plugin.getInterpreter.execute(scripts[i]); + i = i + 1; + } +} + +// ── State ── + +editor_content = ""; +current_file = ""; +file_list_cache = []; +console_lines = []; + +// ── UI ── + +function buildEditor() { + uiClear("editor_win"); + + uiComp("SCROLL_PANEL", "file_tree"); + uiSet("file_tree", "Size", "200,400"); + uiSet("file_tree", "Position", "0,0"); + uiAdd("editor_win", "file_tree"); + + uiComp("TEXT_AREA", "code_area"); + uiSet("code_area", "Size", "600,400"); + uiSet("code_area", "Position", "210,0"); + uiAdd("editor_win", "code_area"); + + uiComp("TEXT_AREA", "console"); + uiSet("console", "Size", "810,80"); + uiSet("console", "Position", "0,410"); + uiAdd("editor_win", "console"); + + toolbar = [["btn_refresh","Refresh",0,"on_refresh"], + ["btn_save","Save",70,"on_save"], + ["btn_run","Run",140,"on_run"], + ["btn_new","+New",210,"on_new"]]; + for (i = 0; i < len(toolbar); i++) { + entry = toolbar[i]; + uiComp("TEXT_BUTTON", entry[0]); + uiSet(entry[0], "Text", entry[1]); + uiSet(entry[0], "Position", entry[2] + ",500"); + uiAdd("editor_win", entry[0]); + uiOn(entry[0], "click", entry[3]); + } +} + +// ── Events ── + +function on_refresh() { + files = listScripts(); + file_list_cache = files; + uiClear("file_tree"); + y = 0; + i = 0; + while (i < len(files)) { + id = "fe_" + i; + uiComp("TEXT_BUTTON", id); + uiSet(id, "Text", files[i]); + uiSet(id, "Position", "0," + y); + uiAdd("file_tree", id); + uiOn(id, "click", "on_file_click"); + y = y + 22; + i = i + 1; + } + log("Refreshed: " + len(files) + " files"); +} + +function on_file_click(index) { + i = floor(index); + if (i >= 0 && i < len(file_list_cache)) { + current_file = file_list_cache[i]; + editor_content = readFile(current_file); + uiSet("code_area", "Text", editor_content); + log("Opened: " + current_file); + } +} + +function on_save() { + if (current_file == "") { log("No file open"); return; } + writeFile(current_file, editor_content); + log("Saved: " + current_file); +} + +function on_run() { + if (current_file != "") { on_save(); } + reloadAll(); + log("Reloaded all scripts"); + on_refresh(); + uiSet("code_area", "Text", editor_content); +} + +function on_new() { + name = java_call(java_static("java.util.UUID", "randomUUID"), "toString") + ".hytale"; + name = java_call(name, "substring", 0, 8) + ".hytale"; + template = "// " + name + "\n\non_server_start {\n print(\"Hello!\");\n}\n"; + writeFile(name, template); + current_file = name; + editor_content = template; + uiSet("code_area", "Text", template); + log("Created: " + name); + on_refresh(); +} + +function log(msg) { + ts = java_static("java.time.LocalTime", "now"); + push(console_lines, "[" + ts + "] " + msg); + text = ""; + i = 0; + while (i < len(console_lines)) { + if (i > 0) text = text + "\n"; + text = text + console_lines[i]; + i = i + 1; + } + uiSet("console", "Text", text); +} + +// ── Register ── + +on_server_start { + uiComp("WINDOW", "editor_win"); + uiSet("editor_win", "Title", "Orbis Editor (Pure Reflection)"); + uiSet("editor_win", "Size", "830,540"); + buildEditor(); + uiRegister("editor_win"); + log("Editor ready. Use /orbis editor to open."); +}