From e59e2a97773f93bdd25bd4680809c10699f0feb3 Mon Sep 17 00:00:00 2001 From: EVE Date: Tue, 14 Mar 2017 12:07:52 -0400 Subject: More help work. --- .../src/bjc/dicelang/util/ResourceLoader.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 dice-lang/src/bjc/dicelang/util/ResourceLoader.java (limited to 'dice-lang/src/bjc/dicelang/util/ResourceLoader.java') 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; + } +} -- cgit v1.2.3