Reduce to one loadDialog function
This commit is contained in:
parent
0df054eacf
commit
c39db0afae
@ -8,8 +8,7 @@ import de.umarumg.models.TextSpeed;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
@ -34,9 +33,9 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length > 0) {
|
||||
loadDialog(args[0]);
|
||||
loadDialog(args[0], false);
|
||||
} else {
|
||||
loadDialogFromResources("dialog.json");
|
||||
loadDialog("dialog.json", true);
|
||||
}
|
||||
|
||||
System.out.println("How fast should the text scroll?: " + finalSpeeds);
|
||||
@ -61,20 +60,11 @@ public class Main {
|
||||
run(currentScene);
|
||||
}
|
||||
|
||||
public static void loadDialogFromResources(String fileName) {
|
||||
public static void loadDialog(String fileName, boolean defaultFile) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
story = mapper.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName), new TypeReference<>() {});
|
||||
} catch (Exception ex) {
|
||||
logger.severe("Error reading the internal dialog File. Exiting now!");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadDialog(String fileName) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
story = mapper.readValue(new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8), new TypeReference<>() {});
|
||||
InputStream inputStream = defaultFile ? Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName) : new FileInputStream(fileName);
|
||||
story = mapper.readValue(inputStream, new TypeReference<>() {});
|
||||
} catch (Exception ex) {
|
||||
logger.severe("Error reading the internal dialog File. Exiting now!");
|
||||
System.exit(1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user