summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/util/ResourceLoader.java
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-14 12:07:52 -0400
committerEVE <EVE@EVE-PC>2017-03-14 12:07:52 -0400
commite59e2a97773f93bdd25bd4680809c10699f0feb3 (patch)
tree30eec8de5c4304a332e05c8a16f164aa5e6b5e83 /dice-lang/src/bjc/dicelang/util/ResourceLoader.java
parent9b4ee8edf4f93b167be5ae3025d1fd4a433d183f (diff)
More help work.
Diffstat (limited to 'dice-lang/src/bjc/dicelang/util/ResourceLoader.java')
-rw-r--r--dice-lang/src/bjc/dicelang/util/ResourceLoader.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/dice-lang/src/bjc/dicelang/util/ResourceLoader.java b/dice-lang/src/bjc/dicelang/util/ResourceLoader.java
new file mode 100644
index 0000000..1cb29b0
--- /dev/null
+++ b/dice-lang/src/bjc/dicelang/util/ResourceLoader.java
@@ -0,0 +1,40 @@
+package bjc.dicelang.util;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import bjc.dicelang.Errors;
+
+import static bjc.dicelang.Errors.ErrorKey.*;
+
+/**
+ * Load resources bundled with DiceLang
+ *
+ * @author EVE
+ *
+ */
+public class ResourceLoader {
+ /**
+ * Loads a .help file from the data/help directory.
+ *
+ * @param name The name of the help file to load.
+ *
+ * @return The contents of the help file, or null if it could not be opened
+ */
+ public String[] loadHelpFile(String name) {
+ URL fle = this.getClass().getResource("/data/help/" + name + ".help");
+
+ try {
+ return Files.lines(Paths.get(fle.toURI())).toArray(sze -> new String[sze]);
+ } catch (IOException ioex) {
+ Errors.inst.printError(EK_MISC_IOEX, fle.toString());
+ } catch (URISyntaxException usex) {
+ Errors.inst.printError(EK_MISC_IOEX, fle.toString());
+ }
+
+ return null;
+ }
+}