diff options
| author | sD <stoned@derpymail.org> | 2020-03-08 16:33:45 +0100 |
|---|---|---|
| committer | sD <stoned@derpymail.org> | 2020-03-08 16:33:45 +0100 |
| commit | 588de2708d7a0dfeeff677af5988efbe0065a0c7 (patch) | |
| tree | e123127c99f86ffbfbefc8150a04f3442fb32dcf /webAO/client.js | |
| parent | 2228b820af936ca27bb18fb0f52c013e29a4ce27 (diff) | |
it doesn't work but here it is
Diffstat (limited to 'webAO/client.js')
| -rw-r--r-- | webAO/client.js | 33 |
1 files changed, 24 insertions, 9 deletions
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; |
