Text typing works with html
Fix some text with no parameters being skipped. Fix quickly going through text breaking lerp loop.
This commit is contained in:
parent
a192a0eb0e
commit
bf5108bfe6
@ -249,6 +249,8 @@ class Player {
|
||||
//Loop through the lerp targets, modify the needed objects. If a object is at its 1 time state remove it from the list.
|
||||
let toRemove = [];
|
||||
for(let i = 0; i < this.lerpTargets.length; ++i) {
|
||||
try
|
||||
{
|
||||
let l = this.lerpTargets[i];
|
||||
l.curTime += deltaTime;
|
||||
if(l.curTime < 0) { continue; }
|
||||
@ -274,6 +276,10 @@ class Player {
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
} catch(error) {
|
||||
//If we got an exception during this it probably means the object doesnt exist anymore so just remove it.
|
||||
toRemove.push(i);
|
||||
}
|
||||
}
|
||||
for(let i = toRemove.length - 1; i > -1; --i) {
|
||||
this.lerpTargets.splice(toRemove[i], 1);
|
||||
@ -505,7 +511,7 @@ class Player {
|
||||
this.text.dialogText(true, commonFunctions.convertUtageTextTags(text));
|
||||
} else {
|
||||
let charName = "";
|
||||
let found = true;
|
||||
let found = false;
|
||||
//Look for the character that is saying the text to get their name
|
||||
//future note: This might be better to just look for the character in character info if this start failing.
|
||||
for(let c of Object.keys(this.currentCharacters)) {
|
||||
|
@ -8,7 +8,7 @@ class TextFunctions {
|
||||
this.dialogBox = undefined;
|
||||
this.character = undefined;
|
||||
this.dialog = undefined;
|
||||
this.dialogToDisplay = {timeout: undefined, fullText: "", text: "", subsection: "", subindex: -1};
|
||||
this.dialogToDisplay = {timeout: undefined, fullText: "", text: "", curPos: 0};
|
||||
this.textScrollSpeedMs = 40;
|
||||
this.scrollingText = false;
|
||||
this.lineHeight = -1;
|
||||
@ -61,8 +61,10 @@ class TextFunctions {
|
||||
} else {
|
||||
this.dialogToDisplay.text = text;
|
||||
this.dialogToDisplay.fullText = text;
|
||||
this.dialogInner.innerHTML = this.dialogToDisplay.text[0];
|
||||
this.dialogToDisplay.text = this.dialogToDisplay.text.slice(1);
|
||||
this.dialogToDisplay.curPos = 0;
|
||||
this.dialogInner.innerHTML = "";
|
||||
//this.dialogInner.innerHTML = this.dialogToDisplay.text[0];
|
||||
//this.dialogToDisplay.text = this.dialogToDisplay.text.slice(1);
|
||||
this.scrollingText = true;
|
||||
this.dialogToDisplay.timeout = setTimeout(putText.bind(this), this.textScrollSpeedMs);
|
||||
}
|
||||
@ -70,14 +72,24 @@ class TextFunctions {
|
||||
this.mainUi.style = show ? "opacity: 1;" : "opacity: 0;";
|
||||
this.dialogBox.style = show ? "opacity: 1;" : "opacity: 0;";
|
||||
|
||||
//This is based off https://github.com/mattboldt/typed.js/
|
||||
function putText() {
|
||||
let t = this.getNextTextToPut();
|
||||
if(!t) { return; }
|
||||
this.dialogInner.innerHTML += t;
|
||||
// skip over any HTML chars
|
||||
this.dialogToDisplay.curPos = this.typeHtmlChars(this.dialogToDisplay.text, this.dialogToDisplay.curPos);
|
||||
let substr = this.dialogToDisplay.text.substr(this.dialogToDisplay.curPos);
|
||||
if (this.dialogToDisplay.curPos === this.dialogToDisplay.text.length) {
|
||||
this.scrollingText = false;
|
||||
return;
|
||||
} else {
|
||||
this.dialogToDisplay.curPos += 1;
|
||||
const nextString = this.dialogToDisplay.text.substr(0, this.dialogToDisplay.curPos);
|
||||
this.dialogInner.innerHTML = nextString;
|
||||
let lHeight = this.lineHeight * 2
|
||||
if(this.dialogInner.offsetHeight > lHeight) {
|
||||
this.dialog.scrollTop = this.dialogInner.offsetHeight - lHeight;
|
||||
}
|
||||
}
|
||||
|
||||
this.dialogToDisplay.timeout = setTimeout(putText.bind(this), this.textScrollSpeedMs);
|
||||
}
|
||||
}
|
||||
@ -95,37 +107,30 @@ class TextFunctions {
|
||||
this.scrollingText = false;
|
||||
}
|
||||
|
||||
typeHtmlChars(curString, curStrPos) {
|
||||
const curChar = curString.substr(curStrPos).charAt(0);
|
||||
if (curChar === '<' || curChar === '&') {
|
||||
let endTag = '';
|
||||
if (curChar === '<') {
|
||||
endTag = '>';
|
||||
} else {
|
||||
endTag = ';';
|
||||
}
|
||||
while (curString.substr(curStrPos + 1).charAt(0) !== endTag) {
|
||||
curStrPos++;
|
||||
if (curStrPos + 1 > curString.length) { break; }
|
||||
}
|
||||
curStrPos++;
|
||||
}
|
||||
return curStrPos;
|
||||
}
|
||||
|
||||
hideUi(show) {
|
||||
this.mainUi.style = show ? "opacity: 1;" : "opacity: 0;";
|
||||
this.dialogBox.style = show ? "opacity: 1;" : "opacity: 0;";
|
||||
this.character.style = show ? "opacity: 1;" : "opacity: 0;";
|
||||
}
|
||||
|
||||
getNextTextToPut() {
|
||||
if(!this.dialogToDisplay.text || this.dialogToDisplay.text.length === 0) {
|
||||
this.scrollingText = false;
|
||||
return "";
|
||||
}
|
||||
let toSlice = 1;
|
||||
let text = this.dialogToDisplay.text[0];
|
||||
if(text === '<') {
|
||||
let match = this.dialogToDisplay.text.match(/<.+>/);
|
||||
if(match && match[0]); {
|
||||
debugger;
|
||||
text = match[0];
|
||||
toSlice = match[0].length;
|
||||
if(!text.includes("/")) {
|
||||
let s = text.split('');
|
||||
s.splice(1, 0, '/');
|
||||
text += s.join('');
|
||||
}
|
||||
}
|
||||
}
|
||||
this.dialogToDisplay.text = this.dialogToDisplay.text.slice(toSlice);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
resetAll() {
|
||||
this.title.innerHTML = '';
|
||||
this.diva.innerHTML = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user