now uses json files for dialogue
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
<title>TextHorror</title>
|
<title>TextHorror</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onpageshow="typeWriter()" onclick="mouseClick()">
|
<body onpageshow="load()" onclick="mouseClick()">
|
||||||
<div id="bubble"></div>
|
<div id="bubble"></div>
|
||||||
<img id="triangle" src="text_horror/assets/triangle.png">
|
<img id="triangle" src="text_horror/assets/triangle.png">
|
||||||
<p class="thx-for-playing">Thanks for playing</p>
|
<p class="thx-for-playing">Thanks for playing</p>
|
||||||
|
@@ -1,12 +1,23 @@
|
|||||||
var speed = 50;
|
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 dlgPointer = 0;
|
||||||
|
|
||||||
var i = 0;
|
function load() {
|
||||||
|
fetch("text_horror/dialogue.json")
|
||||||
|
.then(Response => Response.json())
|
||||||
|
.then(data => {
|
||||||
|
dlgFile = data;
|
||||||
|
dlgLines = dlgFile["<start>"];
|
||||||
|
typeWriter();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function typeWriter() {
|
function typeWriter() {
|
||||||
if (document.getElementById("bubble").innerHTML.length - 1 < dlgLines[dlgPointer].length) {
|
if (document.getElementById("bubble").innerHTML.length - 1 < dlgLines[dlgPointer].length) {
|
||||||
document.getElementById("bubble").innerHTML += dlgLines[dlgPointer].charAt(i);
|
document.getElementById("bubble").innerHTML += dlgLines[dlgPointer].charAt(typeindex);
|
||||||
i++;
|
typeindex++;
|
||||||
setTimeout(typeWriter, speed);//loops because of running "typeWriter" after waiting
|
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 (document.getElementById("bubble").innerHTML.length == dlgLines[dlgPointer].length) {
|
||||||
if (dlgPointer < dlgLines.length - 1) {
|
if (dlgPointer < dlgLines.length - 1) {
|
||||||
dlgPointer++;
|
dlgPointer++;
|
||||||
i = 0;
|
typeindex = 0;
|
||||||
document.getElementById("bubble").innerHTML = "";
|
document.getElementById("bubble").innerHTML = "";
|
||||||
typeWriter();
|
typeWriter();
|
||||||
} else {
|
} else {
|
||||||
|
7
text_horror/dialogue.json
Normal file
7
text_horror/dialogue.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"<start>": [
|
||||||
|
"Hello welcome to TextHorror!",
|
||||||
|
"This is the second line",
|
||||||
|
"Aand a third line"
|
||||||
|
]
|
||||||
|
}
|
Reference in New Issue
Block a user