From 588de2708d7a0dfeeff677af5988efbe0065a0c7 Mon Sep 17 00:00:00 2001 From: sD Date: Sun, 8 Mar 2020 16:33:45 +0100 Subject: it doesn't work but here it is --- webAO/client.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'webAO/client.js') diff --git a/webAO/client.js b/webAO/client.js index e55accd..63d656f 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -1293,13 +1293,19 @@ class Viewport { changeBackground(chatmsg.side); - if (this.chatmsg.name.toLowerCase().endsWith("_hd")) { - this.speakingSprite = this.chatmsg.sprite + ".png"; - this.silentSprite = this.chatmsg.sprite + ".png"; - } else { - this.speakingSprite = "(b)" + this.chatmsg.sprite + ".gif"; - this.silentSprite = "(a)" + this.chatmsg.sprite + ".gif"; - } + const { speakUrl } = await Promise.any([ + this.rejectOnError(fetch(AO_HOST + "characters/" + encodeURI(this.chatmsg.name.toLowerCase()) + "/(b)" + this.chatmsg.sprite + ".gif")), + this.rejectOnError(fetch(AO_HOST + "characters/" + encodeURI(this.chatmsg.name.toLowerCase()) + "/" + this.chatmsg.sprite + ".png")) + ]); + + this.speakingSprite = speakUrl; + + const { silentUrl } = await Promise.any([ + this.rejectOnError(fetch(AO_HOST + "characters/" + encodeURI(this.chatmsg.name.toLowerCase()) + "/(a)" + this.chatmsg.sprite + ".gif")), + this.rejectOnError(fetch(AO_HOST + "characters/" + encodeURI(this.chatmsg.name.toLowerCase()) + "/" + this.chatmsg.sprite + ".png")) + ]); + + this.silentSprite = silentUrl; // gets which shout shall played const shout = this.shouts[this.chatmsg.objection]; @@ -1399,6 +1405,15 @@ class Viewport { } } + rejectOnError(f) { + return new Promise((resolve, reject) => + f.then((res) => { + if (res.ok) resolve(f); + else reject(f); + }) + ); + } + /** * Adds up the frame delays to find out how long a GIF is * I totally didn't steal this @@ -1628,11 +1643,11 @@ class Viewport { } } - charSprite.src = AO_HOST + "characters/" + encodeURI(this.chatmsg.name.toLowerCase()) + "/" + encodeURI(this.speakingSprite); + charSprite.src = this.speakingSprite; charSprite.style.display = ""; if (this.textnow === this.chatmsg.content) { - charSprite.src = AO_HOST + "characters/" + encodeURI(this.chatmsg.name.toLowerCase()) + "/" + encodeURI(this.silentSprite); + charSprite.src = this.silentSprite; charSprite.style.display = ""; waitingBox.innerHTML = "▶"; this._animating = false; -- cgit