diff --git a/index.html b/index.html
index d477f9c..68f575a 100644
--- a/index.html
+++ b/index.html
@@ -10,7 +10,7 @@
TextHorror
-
+
Thanks for playing
diff --git a/text_horror/app.js b/text_horror/app.js
index 70a4f70..7387d74 100644
--- a/text_horror/app.js
+++ b/text_horror/app.js
@@ -1,12 +1,23 @@
var speed = 50;
-var dlgLines = ["Hello welcome to TextHorror", "This is the second line"];
+var typeindex = 0;
+var dlgFile = {};
+var dlgLines = [""];
var dlgPointer = 0;
-var i = 0;
+function load() {
+ fetch("text_horror/dialogue.json")
+ .then(Response => Response.json())
+ .then(data => {
+ dlgFile = data;
+ dlgLines = dlgFile[""];
+ typeWriter();
+ })
+}
+
function typeWriter() {
if (document.getElementById("bubble").innerHTML.length - 1 < dlgLines[dlgPointer].length) {
- document.getElementById("bubble").innerHTML += dlgLines[dlgPointer].charAt(i);
- i++;
+ document.getElementById("bubble").innerHTML += dlgLines[dlgPointer].charAt(typeindex);
+ typeindex++;
setTimeout(typeWriter, speed);//loops because of running "typeWriter" after waiting
}
}
@@ -15,7 +26,7 @@ function mouseClick() {
if (document.getElementById("bubble").innerHTML.length == dlgLines[dlgPointer].length) {
if (dlgPointer < dlgLines.length - 1) {
dlgPointer++;
- i = 0;
+ typeindex = 0;
document.getElementById("bubble").innerHTML = "";
typeWriter();
} else {
diff --git a/text_horror/dialogue.json b/text_horror/dialogue.json
new file mode 100644
index 0000000..1fc9053
--- /dev/null
+++ b/text_horror/dialogue.json
@@ -0,0 +1,7 @@
+{
+ "": [
+ "Hello welcome to TextHorror!",
+ "This is the second line",
+ "Aand a third line"
+ ]
+}
\ No newline at end of file