diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-10-12 18:25:14 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2022-10-12 18:25:14 +0200 |
| commit | 8a7942c0565298c29edbf0b271d5d7c7f9e56fd8 (patch) | |
| tree | 67b788f40b7a4713904836de05f0e5876c32bd79 /webAO/utils | |
| parent | a83c8962b68f2cc0a0e22d988b8ff030057454e5 (diff) | |
| parent | 82983e0c38383ec2602b4f41327342d1c8d0a8fd (diff) | |
Merge branch 'master' into 2fa
Diffstat (limited to 'webAO/utils')
| -rw-r--r-- | webAO/utils/__tests__/paths.test.ts | 13 | ||||
| -rw-r--r-- | webAO/utils/calculateApngLength.js | 13 | ||||
| -rw-r--r-- | webAO/utils/getCookie.ts (renamed from webAO/utils/getCookie.js) | 2 | ||||
| -rw-r--r-- | webAO/utils/getResources.js | 8 | ||||
| -rw-r--r-- | webAO/utils/paths.ts | 1 | ||||
| -rw-r--r-- | webAO/utils/queryParser.js | 9 | ||||
| -rw-r--r-- | webAO/utils/queryParser.ts | 22 | ||||
| -rw-r--r-- | webAO/utils/setCookie.ts (renamed from webAO/utils/setCookie.js) | 4 |
8 files changed, 52 insertions, 20 deletions
diff --git a/webAO/utils/__tests__/paths.test.ts b/webAO/utils/__tests__/paths.test.ts new file mode 100644 index 0000000..4f41d09 --- /dev/null +++ b/webAO/utils/__tests__/paths.test.ts @@ -0,0 +1,13 @@ +import {getFilenameFromPath} from '../paths' +jest.mock('../fileExists') + +describe('getFilenameFromPath', () => { + const EXAMPLE_PATH = "localhost/stoneddiscord/assets.png" + it('Should get the last value from a path', async () => { + const actual = getFilenameFromPath(EXAMPLE_PATH); + const expected = 'assets.png'; + expect(actual).toBe(expected); + }); +}) + + diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js index 932f581..d6a40b6 100644 --- a/webAO/utils/calculateApngLength.js +++ b/webAO/utils/calculateApngLength.js @@ -13,13 +13,18 @@ const calculateApngLength = (apngFile) => { && d[i + 2] === 0x54 && d[i + 3] === 0x4C) { // numerator and denominator - const delay = ((d[i + 21] / d[i + 23]) * 1000); - + const delay_num = Number(d[i + 23]); + const delay_den = Number(d[i + 25]); + let delay; // minimum is 100ms - duration += delay < 100 ? 100 : delay; + if (delay_den == 0) + delay = delay_num / 100; + else + delay = delay_num / delay_den; + + duration = duration + delay; } } - console.debug(duration); return duration * 10; }; export default calculateApngLength; diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.ts index 3be0733..f5b9679 100644 --- a/webAO/utils/getCookie.js +++ b/webAO/utils/getCookie.ts @@ -4,7 +4,7 @@ * https://www.w3schools.com/js/js_cookies.asp * @param {String} cname The name of the cookie to return */ -const getCookie = (cname) => { +const getCookie = (cname: String) => { try { const name = `${cname}=`; const decodedCookie = decodeURIComponent(document.cookie); diff --git a/webAO/utils/getResources.js b/webAO/utils/getResources.js index a0c513e..859e63b 100644 --- a/webAO/utils/getResources.js +++ b/webAO/utils/getResources.js @@ -16,22 +16,22 @@ const getResources = (AO_HOST, THEME) => ({ duration: 840, }, witnesstestimony: { - src: `${AO_HOST}themes/${THEME}/witnesstestimony.gif`, + src: `${AO_HOST}themes/${THEME}/witnesstestimony_bubble.gif`, duration: 1560, sfx: `${AO_HOST}sounds/general/sfx-testimony.opus`, }, crossexamination: { - src: `${AO_HOST}themes/${THEME}/crossexamination.gif`, + src: `${AO_HOST}themes/${THEME}/crossexamination_bubble.gif`, duration: 1600, sfx: `${AO_HOST}sounds/general/sfx-testimony2.opus`, }, guilty: { - src: `${AO_HOST}themes/${THEME}/guilty.gif`, + src: `${AO_HOST}themes/${THEME}/guilty_bubble.gif`, duration: 2870, sfx: `${AO_HOST}sounds/general/sfx-guilty.opus`, }, notguilty: { - src: `${AO_HOST}themes/${THEME}/notguilty.gif`, + src: `${AO_HOST}themes/${THEME}/notguilty_bubble.gif`, duration: 2440, sfx: `${AO_HOST}sounds/general/sfx-notguilty.opus`, }, diff --git a/webAO/utils/paths.ts b/webAO/utils/paths.ts new file mode 100644 index 0000000..f4284b6 --- /dev/null +++ b/webAO/utils/paths.ts @@ -0,0 +1 @@ +export const getFilenameFromPath = (path: string) => path.substring(path.lastIndexOf('/') + 1) diff --git a/webAO/utils/queryParser.js b/webAO/utils/queryParser.js deleted file mode 100644 index 1c2b83a..0000000 --- a/webAO/utils/queryParser.js +++ /dev/null @@ -1,9 +0,0 @@ -// Get the arguments from the URL bar -const queryParser = () => { - const queryDict = {}; - location.search.substr(1).split('&').forEach((item) => { - queryDict[item.split('=')[0]] = item.split('=')[1]; - }); - return queryDict; -}; -export default queryParser; diff --git a/webAO/utils/queryParser.ts b/webAO/utils/queryParser.ts new file mode 100644 index 0000000..3110c14 --- /dev/null +++ b/webAO/utils/queryParser.ts @@ -0,0 +1,22 @@ +interface QueryParams { + ip: string; + serverIP: string; + mode: string; + asset: string; + theme: string; +} +interface StringMap { + [key: string]: any; +} + +const queryParser = (): QueryParams => { + const queryDict: StringMap = {}; + location.search + .substr(1) + .split("&") + .forEach((item) => { + queryDict[item.split("=")[0]] = item.split("=")[1]; + }); + return queryDict as QueryParams; +}; +export default queryParser; diff --git a/webAO/utils/setCookie.js b/webAO/utils/setCookie.ts index 9734eae..084fa20 100644 --- a/webAO/utils/setCookie.js +++ b/webAO/utils/setCookie.ts @@ -2,9 +2,9 @@ * set a cookie * the version from w3schools expects these to expire * @param {String} cname The name of the cookie to return - * @param {String} value The value of that cookie option + * @param {any} value The value of that cookie option */ -const setCookie = (cname, value) => { +const setCookie = (cname: String, value: any) => { document.cookie = `${cname}=${value}`; }; export default setCookie; |
