Giving NPC names now possible

This commit is contained in:
Yannik
2023-05-27 13:40:11 +02:00
parent 6753c437d1
commit 08d795402d
4 changed files with 35 additions and 12 deletions

View File

@@ -12,6 +12,7 @@
<body onpageshow="load()"> <body onpageshow="load()">
<div id="bubble"> <div id="bubble">
<p id="title"></p>
<p id="dlg-text"></p> <p id="dlg-text"></p>
</div> </div>
<img hidden="true" id="triangle" src="text_horror/assets/triangle.png"> <img hidden="true" id="triangle" src="text_horror/assets/triangle.png">

View File

@@ -9,8 +9,7 @@ function load() {
.then(Response => Response.json()) .then(Response => Response.json())
.then(data => { .then(data => {
dlgFile = data; dlgFile = data;
dlgLines = dlgFile; changeDlg("start");
typeWriter();
}) })
} }
@@ -30,9 +29,17 @@ function nextDlg() {
if (document.getElementById("dlg-text").innerHTML.length == dlgLines[dlgPointer].length) { //check if text is typed out if (document.getElementById("dlg-text").innerHTML.length == dlgLines[dlgPointer].length) { //check if text is typed out
document.getElementById("triangle").hidden = true; document.getElementById("triangle").hidden = true;
if (dlgPointer < dlgLines.length - 1) { //check if dlgPointer is not at the array end if (dlgPointer < dlgLines.length - 1) { //check if dlgPointer is not at the array end
do do {
if (String(dlgLines[dlgPointer]).startsWith("_")) {
switch (dlgLines[dlgPointer].split(":")[0]) {
case "_title":
document.getElementById("title").innerHTML = dlgLines[dlgPointer].split(':')[1];
break;
}
}
dlgPointer++; dlgPointer++;
while (!(typeof dlgLines[dlgPointer] === 'string')) //again if it's not string }
while (typeof dlgLines[dlgPointer] !== 'string' || String(dlgLines[dlgPointer]).startsWith("_")) //again if it's not string
typeindex = 0; typeindex = 0;
document.getElementById("dlg-text").innerHTML = ""; document.getElementById("dlg-text").innerHTML = "";
typeWriter(); typeWriter();
@@ -41,3 +48,9 @@ function nextDlg() {
} }
} }
} }
function changeDlg(dlgKey = "") {
var dlgPointer = 0;
dlgLines = dlgFile[dlgKey];
typeWriter();
}

View File

@@ -1,7 +1,10 @@
[ {
"start": [
"Hello welcome to TextHorror!", "Hello welcome to TextHorror!",
"This is the second line", "_title:NPC Name",
1, 1,
"This is the second line",
2, 2,
"Aand a third line" "Aand a third line"
] ]
}

View File

@@ -7,7 +7,6 @@ body {
color-scheme: dark; color-scheme: dark;
background-color: black; background-color: black;
color: white; color: white;
text-align: center;
font-family: pixel-font; font-family: pixel-font;
} }
@@ -20,6 +19,13 @@ body {
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
#title {
font-size: 30px;
text-decoration: underline;
margin: 0;
position: absolute;
}
#dlg-text { #dlg-text {
text-align: left; text-align: left;
font-size: 40px; font-size: 40px;