From e372941e997587fea872ea6f8d5c38abecc3c11b Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:18:41 +0200 Subject: [PATCH] refactor: generalize Reading class --- src/me/topchetoeu/jscript/Main.java | 8 ++++---- src/me/topchetoeu/jscript/Reading.java | 4 ++-- src/me/topchetoeu/jscript/engine/debug/DebugServer.java | 6 +++--- src/me/topchetoeu/jscript/lib/Internals.java | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/me/topchetoeu/jscript/Main.java b/src/me/topchetoeu/jscript/Main.java index abcc2a8..a1aa22b 100644 --- a/src/me/topchetoeu/jscript/Main.java +++ b/src/me/topchetoeu/jscript/Main.java @@ -60,7 +60,7 @@ public class Main { } for (var i = 0; ; i++) { try { - var raw = Reading.read(); + var raw = Reading.readline(); if (raw == null) break; var res = engine.pushMsg( @@ -136,16 +136,16 @@ public class Main { engine.pushMsg( false, tsEnv, new Filename("jscript", "ts.js"), - Reading.resourceToString("js/ts.js"), null + Reading.resourceToString("assets/js/ts.js"), null ).await(); System.out.println("Loaded typescript!"); var typescript = tsEnv.global.get(new Context(engine, bsEnv), "ts"); - var libs = new ArrayValue(null, Reading.resourceToString("js/lib.d.ts")); + var libs = new ArrayValue(null, Reading.resourceToString("assets/js/lib.d.ts")); engine.pushMsg( false, bsEnv, - new Filename("jscript", "bootstrap.js"), Reading.resourceToString("js/bootstrap.js"), null, + new Filename("jscript", "bootstrap.js"), Reading.resourceToString("assets/js/bootstrap.js"), null, typescript, new EnvironmentLib(environment), libs ).await(); } diff --git a/src/me/topchetoeu/jscript/Reading.java b/src/me/topchetoeu/jscript/Reading.java index c076f53..7665ffb 100644 --- a/src/me/topchetoeu/jscript/Reading.java +++ b/src/me/topchetoeu/jscript/Reading.java @@ -10,7 +10,7 @@ import me.topchetoeu.jscript.exceptions.UncheckedException; public class Reading { private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - public static synchronized String read() throws IOException { + public static synchronized String readline() throws IOException { return reader.readLine(); } @@ -19,7 +19,7 @@ public class Reading { catch (Throwable e) { throw new UncheckedException(e); } } public static InputStream resourceToStream(String name) { - return Reading.class.getResourceAsStream("/assets/" + name); + return Reading.class.getResourceAsStream("/" + name); } public static String resourceToString(String name) { return streamToString(resourceToStream(name)); diff --git a/src/me/topchetoeu/jscript/engine/debug/DebugServer.java b/src/me/topchetoeu/jscript/engine/debug/DebugServer.java index 18f9899..65247c7 100644 --- a/src/me/topchetoeu/jscript/engine/debug/DebugServer.java +++ b/src/me/topchetoeu/jscript/engine/debug/DebugServer.java @@ -231,9 +231,9 @@ public class DebugServer { public DebugServer() { try { - this.favicon = Reading.resourceToStream("debugger/favicon.png").readAllBytes(); - this.protocol = Reading.resourceToStream("debugger/protocol.json").readAllBytes(); - this.index = Reading.resourceToString("debugger/index.html") + this.favicon = Reading.resourceToStream("assets/debugger/favicon.png").readAllBytes(); + this.protocol = Reading.resourceToStream("assets/debugger/protocol.json").readAllBytes(); + this.index = Reading.resourceToString("assets/debugger/index.html") .replace("${NAME}", Metadata.name()) .replace("${VERSION}", Metadata.version()) .replace("${AUTHOR}", Metadata.author()) diff --git a/src/me/topchetoeu/jscript/lib/Internals.java b/src/me/topchetoeu/jscript/lib/Internals.java index 4ad447e..03116e8 100644 --- a/src/me/topchetoeu/jscript/lib/Internals.java +++ b/src/me/topchetoeu/jscript/lib/Internals.java @@ -40,7 +40,7 @@ public class Internals { } @Native public static String readline(Context ctx) { try { - return Reading.read(); + return Reading.readline(); } catch (IOException e) { e.printStackTrace();