From e97816759d6631819f9f0b35bbb2728d0051f5c0 Mon Sep 17 00:00:00 2001
From: Yannik <80621863+vaporvee@users.noreply.github.com>
Date: Fri, 26 May 2023 17:19:55 +0200
Subject: [PATCH] now uses json files for dialogue
---
index.html | 2 +-
text_horror/app.js | 21 ++++++++++++++++-----
text_horror/dialogue.json | 7 +++++++
3 files changed, 24 insertions(+), 6 deletions(-)
create mode 100644 text_horror/dialogue.json
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