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