aboutsummaryrefslogtreecommitdiff
path: root/webAO
diff options
context:
space:
mode:
Diffstat (limited to 'webAO')
-rw-r--r--webAO/client.js4
-rw-r--r--webAO/client/setEmote.js4
-rw-r--r--webAO/services/request.js2
-rw-r--r--webAO/utils/calculateApngLength.js26
-rw-r--r--webAO/utils/calculatorHandler.js2
-rw-r--r--webAO/utils/getAnimLength.js4
6 files changed, 35 insertions, 7 deletions
diff --git a/webAO/client.js b/webAO/client.js
index 835d8d2..41d7625 100644
--- a/webAO/client.js
+++ b/webAO/client.js
@@ -21,7 +21,7 @@ import chatbox_arr from './styles/chatbox/chatboxes.js';
import iniParse from './iniParse';
import getCookie from './utils/getCookie.js';
import setCookie from './utils/setCookie.js';
-import request from './services/request.js';
+import {request} from './services/request.js';
import { changeShoutVolume, changeSFXVolume } from './dom/changeVolume.js';
import setEmote from './client/setEmote.js';
import fileExists from './utils/fileExists.js';
@@ -2051,7 +2051,7 @@ class Viewport {
} else {
this.chatmsg.startspeaking = true;
}
-
+ console.log(gifLength);
this.chatmsg.preanimdelay = parseInt(gifLength);
this.changeBackground(chatmsg.side);
diff --git a/webAO/client/setEmote.js b/webAO/client/setEmote.js
index 16c95be..e6bf476 100644
--- a/webAO/client/setEmote.js
+++ b/webAO/client/setEmote.js
@@ -16,10 +16,10 @@ const setEmote = (AO_HOST, client, charactername, emotename, prefix, pair, side)
const apng_s = document.getElementById(`client_${position}${pairID}_apng`);
const webp_s = document.getElementById(`client_${position}${pairID}_webp`);
const extensionsMap = {
- '.gif': gif_s,
- '.png': png_s,
'.apng': apng_s,
'.webp': webp_s,
+ '.gif': gif_s,
+ '.png': png_s,
};
for (const [extension, htmlElement] of Object.entries(extensionsMap)) {
diff --git a/webAO/services/request.js b/webAO/services/request.js
index 5a060fd..88613e5 100644
--- a/webAO/services/request.js
+++ b/webAO/services/request.js
@@ -38,7 +38,7 @@ export async function requestBuffer(url) {
* @returns response data
* @throws {Error} if status code is not 2xx, or a network error occurs
*/
-const request = async (url) => new Promise((resolve, reject) => {
+export const request = async (url) => new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.responseType = 'text';
xhr.addEventListener('error', () => {
diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js
new file mode 100644
index 0000000..bc6b3fa
--- /dev/null
+++ b/webAO/utils/calculateApngLength.js
@@ -0,0 +1,26 @@
+ /**
+ * Adds up the chunk delays to find out how long a APNG is
+ * @param {data} apngFile the APNG data
+ */
+const calculateApngLength = (apngFile) => {
+ const d = new Uint8Array(apngFile);
+ // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk
+ let duration = 0;
+ for (var i = 0; i < d.length; i++) {
+ // Find fcTL header (66 63 54 4C)
+ if (d[i] === 0x66
+ && d[i + 1] === 0x63
+ && d[i + 2] === 0x54
+ && d[i + 3] === 0x4C) {
+ console.log("found apng header");
+ // numerator and denominator
+ let delay = ((d[i + 21] / d[i + 23]) * 1000)
+
+ // minimum is 100ms
+ duration += delay < 100 ? 100 : delay;
+ }
+ }
+ console.debug(duration);
+ return duration * 10;
+};
+export default calculateApngLength;
diff --git a/webAO/utils/calculatorHandler.js b/webAO/utils/calculatorHandler.js
index 7686573..9072195 100644
--- a/webAO/utils/calculatorHandler.js
+++ b/webAO/utils/calculatorHandler.js
@@ -1,7 +1,9 @@
import calculateGifLength from './calculateGifLength';
import calculateWebpLength from './calculateWebpLength';
+import calculateApngLength from './calculateApngLength';
export default {
'.gif': calculateGifLength,
'.webp': calculateWebpLength,
+ '.apng': calculateApngLength,
};
diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js
index 5b24e84..1441548 100644
--- a/webAO/utils/getAnimLength.js
+++ b/webAO/utils/getAnimLength.js
@@ -1,6 +1,6 @@
import calculatorHandler from './calculatorHandler';
import fileExists from './fileExists.js';
-import requestBuffer from '../services/request.js';
+import {requestBuffer} from '../services/request.js';
/**
* Gets animation length. If the animation cannot be found, it will
* silently fail and return 0 instead.
@@ -8,7 +8,7 @@ import requestBuffer from '../services/request.js';
*/
const getAnimLength = async (url) => {
- const extensions = ['.gif', '.webp'];
+ const extensions = ['.gif', '.webp', '.apng'];
for (const extension of extensions) {
const urlWithExtension = url + extension;
const exists = await fileExists(urlWithExtension);