cleaner code, disabled text and image dragging

This commit is contained in:
Yannik
2023-05-27 14:45:54 +02:00
parent 08d795402d
commit 4aa35684ab
4 changed files with 25 additions and 16 deletions

View File

@@ -11,11 +11,14 @@
</head> </head>
<body onpageshow="load()"> <body onpageshow="load()">
<div id="bubble"> <div id="bubble" onclick="nextDlg()">
<p id="title"></p> <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"> <div id="answer-box">
<p>Test</p>
</div>
<img draggable="false" hidden="true" 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>
</body> </body>

View File

@@ -1,7 +1,7 @@
var speed = 50; var speed = 50;
var typeindex = 0; var typeindex = 0;
var dlgFile = {}; var dlgFile = {};
let dlgLines; let dlgLines = [];
var dlgPointer = 0; var dlgPointer = 0;
function load() { function load() {
@@ -22,22 +22,20 @@ function typeWriter() {
} }
} }
document.addEventListener('click', nextDlg, false)
function nextDlg() { function nextDlg() {
document.getElementById("triangle").hidden = true; document.getElementById("triangle").hidden = true;
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 - 2) { //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++;
if (typeof dlgLines[dlgPointer] === 'number')
speed = 50 / dlgLines[dlgPointer];
else if (typeof dlgLines[dlgPointer] === 'object') { }
else if (typeof dlgLines[dlgPointer] === 'string' && String(dlgLines[dlgPointer]).startsWith("_")) {
if (dlgLines[dlgPointer].split(":")[0] === "_title")
document.getElementById("title").innerHTML = dlgLines[dlgPointer].split(':')[1];
}
} }
while (typeof dlgLines[dlgPointer] !== 'string' || String(dlgLines[dlgPointer]).startsWith("_")) //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;
@@ -45,6 +43,7 @@ function nextDlg() {
typeWriter(); typeWriter();
} else { } else {
document.getElementById("bubble").hidden = true; document.getElementById("bubble").hidden = true;
document.getElementById("answer-box").hidden = true;
} }
} }
} }

View File

@@ -2,9 +2,15 @@
"start": [ "start": [
"Hello welcome to TextHorror!", "Hello welcome to TextHorror!",
"_title:NPC Name", "_title:NPC Name",
1,
"This is the second line", "This is the second line",
2, "Aand a third line",
"Aand a third line" 0.3,
"This text is slow",
1,
"And again normal text",
{
"Yes": "CoooooooolllSADVwqavedWSDV",
"Also Yes": "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMGGHWhudujwd"
}
] ]
} }

View File

@@ -8,6 +8,7 @@ body {
background-color: black; background-color: black;
color: white; color: white;
font-family: pixel-font; font-family: pixel-font;
user-select: none;
} }
.thx-for-playing { .thx-for-playing {