From dda92bd41f4bee11e2cc5de265ce4fbf5221f1ff Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 20 Sep 2023 13:10:36 +0200 Subject: autoformat with eslint --- webAO/client/__tests__/setEmote.test.js | 132 ++++++++++++++++---------------- webAO/client/aoHost.ts | 2 +- webAO/client/saveChatLogHandle.ts | 6 +- webAO/client/sender/sendIC.ts | 2 +- webAO/client/sender/sendServer.ts | 2 +- webAO/client/setEmote.ts | 76 +++++++++--------- 6 files changed, 110 insertions(+), 110 deletions(-) (limited to 'webAO/client') diff --git a/webAO/client/__tests__/setEmote.test.js b/webAO/client/__tests__/setEmote.test.js index 829c94d..a0091c0 100644 --- a/webAO/client/__tests__/setEmote.test.js +++ b/webAO/client/__tests__/setEmote.test.js @@ -9,104 +9,104 @@ jest.mock('../../viewport/utils/createSfxAudio'); jest.mock('../../viewport/utils/createShoutAudio'); jest.mock('../../viewport/utils/createTestimonyAudio'); describe('setEmote', () => { - const AO_HOST = ''; + const AO_HOST = ''; - const client = new Client('127.0.0.1'); - const firstExtension = '.gif'; + const client = new Client('127.0.0.1'); + const firstExtension = '.gif'; - test('Should have a client_def_char_img with a valid source', async () => { - fileExists.mockReturnValue(true); - document.body.innerHTML = ` + test('Should have a client_def_char_img with a valid source', async () => { + fileExists.mockReturnValue(true); + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'def'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_def_char_img').src).toEqual(expected); - }); - test('Should have a client_pro_char_img to have a valid src', async () => { - document.body.innerHTML = ` + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'def'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + expect(document.getElementById('client_def_char_img').src).toEqual(expected); + }); + test('Should have a client_pro_char_img to have a valid src', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'pro'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_pro_char_img').src).toEqual(expected); - }); - test('Should have a client_wit_char_img', async () => { - document.body.innerHTML = ` + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'pro'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + expect(document.getElementById('client_pro_char_img').src).toEqual(expected); + }); + test('Should have a client_wit_char_img', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'wit'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'wit'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_wit_char_img').src).toEqual(expected); - }); - test('Should have a client_def_pair_img', async () => { - document.body.innerHTML = ` + expect(document.getElementById('client_wit_char_img').src).toEqual(expected); + }); + test('Should have a client_def_pair_img', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'def'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'def'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_def_pair_img').src).toEqual(expected); - }); - test('Should have a client_pro_pair_img', async () => { - document.body.innerHTML = ` + expect(document.getElementById('client_def_pair_img').src).toEqual(expected); + }); + test('Should have a client_pro_pair_img', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'pro'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'pro'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_pro_pair_img').src).toEqual(expected); - }); - test('Should have a client_wit_pair_img', async () => { - document.body.innerHTML = ` + expect(document.getElementById('client_pro_pair_img').src).toEqual(expected); + }); + test('Should have a client_wit_pair_img', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'wit'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'wit'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_wit_pair_img').src).toEqual(expected); - }); - test('Should have a client_char_img', async () => { - document.body.innerHTML = ` + expect(document.getElementById('client_wit_pair_img').src).toEqual(expected); + }); + test('Should have a client_char_img', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'notvalid'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'notvalid'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_char_img').src).toEqual(expected); - }); - test('Should have a client_pair_img', async () => { - document.body.innerHTML = ` + expect(document.getElementById('client_char_img').src).toEqual(expected); + }); + test('Should have a client_pair_img', async () => { + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'notvalid'); - const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + await setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'notvalid'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; - expect(document.getElementById('client_pair_img').src).toEqual(expected); - }); - test('Should handle .png urls differently', async () => { - fileExists.mockReturnValueOnce(false); - document.body.innerHTML = ` + expect(document.getElementById('client_pair_img').src).toEqual(expected); + }); + test('Should handle .png urls differently', async () => { + fileExists.mockReturnValueOnce(false); + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid'); - const expected = 'http://localhost/characters/salanto/coding.png'; + await setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid'); + const expected = 'http://localhost/characters/salanto/coding.png'; - expect(document.getElementById('client_pair_img').src).toEqual(expected); - }); - test('Should replace character if new character responds', async () => { - fileExists.mockReturnValue(false); - document.body.innerHTML = ` + expect(document.getElementById('client_pair_img').src).toEqual(expected); + }); + test('Should replace character if new character responds', async () => { + fileExists.mockReturnValue(false); + document.body.innerHTML = ` `; - await setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid'); - const expected = transparentPng; - expect(document.getElementById('client_pair_img').src).toEqual(expected); - }); + await setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid'); + const expected = transparentPng; + expect(document.getElementById('client_pair_img').src).toEqual(expected); + }); }); diff --git a/webAO/client/aoHost.ts b/webAO/client/aoHost.ts index 9b0a768..fa13e79 100644 --- a/webAO/client/aoHost.ts +++ b/webAO/client/aoHost.ts @@ -1,5 +1,5 @@ import queryParser from '../utils/queryParser' -let { asset } = queryParser(); +const { asset } = queryParser(); const DEFAULT_HOST = 'http://attorneyoffline.de/base/'; export let AO_HOST = asset || DEFAULT_HOST export const setAOhost = (val: string) => { diff --git a/webAO/client/saveChatLogHandle.ts b/webAO/client/saveChatLogHandle.ts index bcc1075..497dd50 100644 --- a/webAO/client/saveChatLogHandle.ts +++ b/webAO/client/saveChatLogHandle.ts @@ -14,9 +14,9 @@ export const saveChatlogHandle = async () => { messages.push(message); } const d = new Date(); - let ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d); - let mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d); - let da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d); + const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d); + const mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d); + const da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d); const filename = `chatlog-${da}-${mo}-${ye}`.toLowerCase(); downloadFile(messages.join("\n"), filename); diff --git a/webAO/client/sender/sendIC.ts b/webAO/client/sender/sendIC.ts index 9064115..ca8984f 100644 --- a/webAO/client/sender/sendIC.ts +++ b/webAO/client/sender/sendIC.ts @@ -2,7 +2,7 @@ import { extrafeatures } from "../../client"; import { escapeChat } from "../../encoding"; import {client} from '../../client' import queryParser from "../../utils/queryParser"; -let {mode} = queryParser() +const {mode} = queryParser() /** * Sends an in-character chat message. diff --git a/webAO/client/sender/sendServer.ts b/webAO/client/sender/sendServer.ts index 7678381..ae95480 100644 --- a/webAO/client/sender/sendServer.ts +++ b/webAO/client/sender/sendServer.ts @@ -1,6 +1,6 @@ import { client } from "../../client"; import queryParser from "../../utils/queryParser"; -let { mode } = queryParser() +const { mode } = queryParser() /** * Hook for sending messages to the server * @param {string} message the message to send diff --git a/webAO/client/setEmote.ts b/webAO/client/setEmote.ts index f4fbdbb..2b5a614 100644 --- a/webAO/client/setEmote.ts +++ b/webAO/client/setEmote.ts @@ -8,48 +8,48 @@ import fileExists from "../utils/fileExists"; */ const setEmote = async ( - AO_HOST: string, - client: Client, - charactername: string, - emotename: string, - prefix: string, - pair: boolean, - side: string + AO_HOST: string, + client: Client, + charactername: string, + emotename: string, + prefix: string, + pair: boolean, + side: string ) => { - const pairID = pair ? "pair" : "char"; - const characterFolder = `${AO_HOST}characters/`; - const acceptedPositions = ["def", "pro", "wit"]; - const position = acceptedPositions.includes(side) ? `${side}_` : ""; - const emoteSelector = document.getElementById( - `client_${position}${pairID}_img` - ) as HTMLImageElement; - const extensionsMap = [".gif", ".png", ".apng", ".webp", ".webp.static"]; + const pairID = pair ? "pair" : "char"; + const characterFolder = `${AO_HOST}characters/`; + const acceptedPositions = ["def", "pro", "wit"]; + const position = acceptedPositions.includes(side) ? `${side}_` : ""; + const emoteSelector = document.getElementById( + `client_${position}${pairID}_img` + ) as HTMLImageElement; + const extensionsMap = [".gif", ".png", ".apng", ".webp", ".webp.static"]; - for (const extension of extensionsMap) { + for (const extension of extensionsMap) { // Hides all sprites before creating a new sprite - if (client.viewport.getLastCharacter() !== client.viewport.getChatmsg().name) { - emoteSelector.src = transparentPng; + if (client.viewport.getLastCharacter() !== client.viewport.getChatmsg().name) { + emoteSelector.src = transparentPng; + } + let url; + if (extension === ".png") { + url = `${characterFolder}${encodeURI(charactername)}/${encodeURI( + emotename + )}${extension}`; + } else if (extension === ".webp.static") { + url = `${characterFolder}${encodeURI(charactername)}/${encodeURI( + emotename + )}.webp`; + } else { + url = `${characterFolder}${encodeURI(charactername)}/${encodeURI( + prefix + )}${encodeURI(emotename)}${extension}`; + } + const exists = await fileExists(url); + if (exists) { + emoteSelector.src = url; + break; + } } - let url; - if (extension === ".png") { - url = `${characterFolder}${encodeURI(charactername)}/${encodeURI( - emotename - )}${extension}`; - } else if (extension === ".webp.static") { - url = `${characterFolder}${encodeURI(charactername)}/${encodeURI( - emotename - )}.webp`; - } else { - url = `${characterFolder}${encodeURI(charactername)}/${encodeURI( - prefix - )}${encodeURI(emotename)}${extension}`; - } - const exists = await fileExists(url); - if (exists) { - emoteSelector.src = url; - break; - } - } }; export default setEmote; -- cgit