From 59028dd4046ad0715d80be8d1ed0031f20f05b7a Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 20 Sep 2023 12:57:45 +0200 Subject: mostly whitespaces, please don't break --- webAO/utils/aoml.ts | 4 +- webAO/utils/calculatorHandler.js | 6 +-- webAO/utils/fileExists.js | 28 ++++++------ webAO/utils/getAnimLength.js | 20 ++++----- webAO/utils/getCookie.ts | 36 +++++++-------- webAO/utils/getResources.js | 72 +++++++++++++++--------------- webAO/utils/queryParser.ts | 31 +++++++------ webAO/utils/setCookie.ts | 8 ++-- webAO/viewport/constants/colors.ts | 2 +- webAO/viewport/constants/defaultChatMsg.ts | 2 +- webAO/viewport/interfaces/ChatMsg.ts | 2 +- webAO/viewport/interfaces/Viewport.ts | 1 + webAO/viewport/utils/createMusic.ts | 2 +- webAO/viewport/utils/handleICSpeaking.ts | 14 +++--- webAO/viewport/viewport.ts | 2 + 15 files changed, 119 insertions(+), 111 deletions(-) (limited to 'webAO') diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index 5b5da5f..1f2f482 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -10,7 +10,7 @@ interface Aoml { color: string; } const aomlParser = (text: string) => { - let parsed: {[key: string]: Aoml}= {} + const parsed: {[key: string]: Aoml}= {} let currentHeader = '' for (const line of text.split(/\r?\n/)) { if (line === '') { @@ -35,7 +35,7 @@ const aomlParser = (text: string) => { const mlConfig = (AO_HOST: string) => { const defaultUrl = `${AO_HOST}themes/default/chat_config.ini` - let aomlParsed: Promise<{ [key: string]: Aoml }> = request(defaultUrl).then((data) => aomlParser(data)); + const aomlParsed: Promise<{ [key: string]: Aoml }> = request(defaultUrl).then((data) => aomlParser(data)); diff --git a/webAO/utils/calculatorHandler.js b/webAO/utils/calculatorHandler.js index 9072195..890b53c 100644 --- a/webAO/utils/calculatorHandler.js +++ b/webAO/utils/calculatorHandler.js @@ -3,7 +3,7 @@ import calculateWebpLength from './calculateWebpLength'; import calculateApngLength from './calculateApngLength'; export default { - '.gif': calculateGifLength, - '.webp': calculateWebpLength, - '.apng': calculateApngLength, + '.gif': calculateGifLength, + '.webp': calculateWebpLength, + '.apng': calculateApngLength, }; diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index a4b3b80..5b60976 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -1,18 +1,18 @@ const fileExists = async (url) => new Promise((resolve) => { - const xhr = new XMLHttpRequest(); - xhr.open('HEAD', url); - xhr.onload = function checkLoad() { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - resolve(true); - } else { + const xhr = new XMLHttpRequest(); + xhr.open('HEAD', url); + xhr.onload = function checkLoad() { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + resolve(true); + } else { + resolve(false); + } + } + }; + xhr.onerror = function checkError() { resolve(false); - } - } - }; - xhr.onerror = function checkError() { - resolve(false); - }; - xhr.send(null); + }; + xhr.send(null); }); export default fileExists; diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js index b33757a..2d83844 100644 --- a/webAO/utils/getAnimLength.js +++ b/webAO/utils/getAnimLength.js @@ -12,16 +12,16 @@ import { requestBuffer } from '../services/request'; */ const getAnimLength = async (url) => { - const extensions = ['.gif', '.webp', '.apng']; - for (const extension of extensions) { - const urlWithExtension = url + extension; - const exists = await fileExists(urlWithExtension); - if (exists) { - const fileBuffer = await requestBuffer(urlWithExtension); - const length = calculatorHandler[extension](fileBuffer); - return length; + const extensions = ['.gif', '.webp', '.apng']; + for (const extension of extensions) { + const urlWithExtension = url + extension; + const exists = await fileExists(urlWithExtension); + if (exists) { + const fileBuffer = await requestBuffer(urlWithExtension); + const length = calculatorHandler[extension](fileBuffer); + return length; + } } - } - return 0; + return 0; }; export default getAnimLength; diff --git a/webAO/utils/getCookie.ts b/webAO/utils/getCookie.ts index f5b9679..638dcb7 100644 --- a/webAO/utils/getCookie.ts +++ b/webAO/utils/getCookie.ts @@ -2,25 +2,25 @@ * read a cookie from storage * got this from w3schools * https://www.w3schools.com/js/js_cookies.asp - * @param {String} cname The name of the cookie to return + * @param {string} cname The name of the cookie to return */ -const getCookie = (cname: String) => { - try { - const name = `${cname}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const ca = decodedCookie.split(';'); - for (let i = 0; i < ca.length; i++) { - let c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1); - } - if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length); - } +const getCookie = (cname: string) => { + try { + const name = `${cname}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) === ' ') { + c = c.substring(1); + } + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length); + } + } + return ''; + } catch (error) { + return ''; } - return ''; - } catch (error) { - return ''; - } }; export default getCookie; diff --git a/webAO/utils/getResources.js b/webAO/utils/getResources.js index 859e63b..a711452 100644 --- a/webAO/utils/getResources.js +++ b/webAO/utils/getResources.js @@ -1,39 +1,39 @@ const getResources = (AO_HOST, THEME) => ({ - holdit: { - src: `${AO_HOST}misc/default/holdit_bubble.png`, - duration: 720, - }, - objection: { - src: `${AO_HOST}misc/default/objection_bubble.png`, - duration: 720, - }, - takethat: { - src: `${AO_HOST}misc/default/takethat_bubble.png`, - duration: 840, - }, - custom: { - src: '', - duration: 840, - }, - witnesstestimony: { - 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_bubble.gif`, - duration: 1600, - sfx: `${AO_HOST}sounds/general/sfx-testimony2.opus`, - }, - guilty: { - 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_bubble.gif`, - duration: 2440, - sfx: `${AO_HOST}sounds/general/sfx-notguilty.opus`, - }, + holdit: { + src: `${AO_HOST}misc/default/holdit_bubble.png`, + duration: 720, + }, + objection: { + src: `${AO_HOST}misc/default/objection_bubble.png`, + duration: 720, + }, + takethat: { + src: `${AO_HOST}misc/default/takethat_bubble.png`, + duration: 840, + }, + custom: { + src: '', + duration: 840, + }, + witnesstestimony: { + 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_bubble.gif`, + duration: 1600, + sfx: `${AO_HOST}sounds/general/sfx-testimony2.opus`, + }, + guilty: { + 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_bubble.gif`, + duration: 2440, + sfx: `${AO_HOST}sounds/general/sfx-notguilty.opus`, + }, }); export default getResources; diff --git a/webAO/utils/queryParser.ts b/webAO/utils/queryParser.ts index 3110c14..20863ca 100644 --- a/webAO/utils/queryParser.ts +++ b/webAO/utils/queryParser.ts @@ -1,22 +1,25 @@ +/* eslint @typescript-eslint/no-explicit-any: "warn" */ + interface QueryParams { - ip: string; - serverIP: string; - mode: string; - asset: string; - theme: string; + ip: string; + serverIP: string; + mode: string; + asset: string; + theme: string; } + interface StringMap { - [key: string]: any; + [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; + 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.ts b/webAO/utils/setCookie.ts index f9ac5d2..a4e554e 100644 --- a/webAO/utils/setCookie.ts +++ b/webAO/utils/setCookie.ts @@ -1,10 +1,12 @@ +/* eslint @typescript-eslint/no-explicit-any: "off" */ + /** * set a cookie * the version from w3schools expects these to expire - * @param {String} cname The name of the cookie to return + * @param {string} cname The name of the cookie to return * @param {any} value The value of that cookie option */ -const setCookie = (cname: String, value: any) => { - document.cookie = `${cname}=${value};SameSite=Strict`; +const setCookie = (cname: string, value: any) => { + document.cookie = `${cname}=${value};SameSite=Strict`; }; export default setCookie; diff --git a/webAO/viewport/constants/colors.ts b/webAO/viewport/constants/colors.ts index 4858081..7d1a9a8 100644 --- a/webAO/viewport/constants/colors.ts +++ b/webAO/viewport/constants/colors.ts @@ -9,4 +9,4 @@ export const COLORS = [ "cyan", "grey", "rainbow", - ]; \ No newline at end of file +]; diff --git a/webAO/viewport/constants/defaultChatMsg.ts b/webAO/viewport/constants/defaultChatMsg.ts index 8a5db6b..d25426e 100644 --- a/webAO/viewport/constants/defaultChatMsg.ts +++ b/webAO/viewport/constants/defaultChatMsg.ts @@ -12,4 +12,4 @@ export const defaultChatMsg = { snddelay: 0, preanimdelay: 0, speed: UPDATE_INTERVAL, - } as ChatMsg; \ No newline at end of file +} as ChatMsg; diff --git a/webAO/viewport/interfaces/ChatMsg.ts b/webAO/viewport/interfaces/ChatMsg.ts index 6b96c6e..352674b 100644 --- a/webAO/viewport/interfaces/ChatMsg.ts +++ b/webAO/viewport/interfaces/ChatMsg.ts @@ -4,7 +4,7 @@ export interface ChatMsg { sound: string; startpreanim?: boolean; startspeaking?: boolean; - side: any; + side: string; color: number; snddelay: number; preanimdelay?: number; diff --git a/webAO/viewport/interfaces/Viewport.ts b/webAO/viewport/interfaces/Viewport.ts index 5b428c1..5492b0b 100644 --- a/webAO/viewport/interfaces/Viewport.ts +++ b/webAO/viewport/interfaces/Viewport.ts @@ -1,3 +1,4 @@ +/* eslint @typescript-eslint/ban-types: "off" */ import { ChatMsg } from "./ChatMsg"; export interface Viewport { diff --git a/webAO/viewport/utils/createMusic.ts b/webAO/viewport/utils/createMusic.ts index 9bf5240..e660173 100644 --- a/webAO/viewport/utils/createMusic.ts +++ b/webAO/viewport/utils/createMusic.ts @@ -4,7 +4,7 @@ export const createMusic = () => { const audioChannels = document.getElementsByClassName( "audioChannel" ) as HTMLCollectionOf; - let music = [...audioChannels]; + const music = [...audioChannels]; music.forEach((channel: HTMLAudioElement) => (channel.volume = 0.5)); music.forEach( (channel: HTMLAudioElement) => (channel.onerror = opusCheck(channel)) diff --git a/webAO/viewport/utils/handleICSpeaking.ts b/webAO/viewport/utils/handleICSpeaking.ts index 020ad24..220dd58 100644 --- a/webAO/viewport/utils/handleICSpeaking.ts +++ b/webAO/viewport/utils/handleICSpeaking.ts @@ -244,9 +244,9 @@ export const handle_ic_speaking = async (playerChatMsg: ChatMsg) => { client.viewport.blipChannels.forEach( (channel: HTMLAudioElement) => - (channel.src = `${AO_HOST}sounds/blips/${encodeURI( - client.viewport.getChatmsg().blips.toLowerCase() - )}.opus`) + (channel.src = `${AO_HOST}sounds/blips/${encodeURI( + client.viewport.getChatmsg().blips.toLowerCase() + )}.opus`) ); // process markup @@ -312,10 +312,10 @@ export const handle_ic_speaking = async (playerChatMsg: ChatMsg) => { console.warn("markdown failed"); let output: HTMLSpanElement[] = [] for (const letter of client.viewport.getChatmsg().content) { - let currentSelector = document.createElement('span') - currentSelector.innerHTML = letter - currentSelector.className = `text_${COLORS[client.viewport.getChatmsg().color]}` - output.push(currentSelector) + let currentSelector = document.createElement('span'); + currentSelector.innerHTML = letter; + currentSelector.className = `text_${COLORS[client.viewport.getChatmsg().color]}`; + output.push(currentSelector); } client.viewport.getChatmsg().parsed = output; } diff --git a/webAO/viewport/viewport.ts b/webAO/viewport/viewport.ts index de95030..3410f46 100644 --- a/webAO/viewport/viewport.ts +++ b/webAO/viewport/viewport.ts @@ -1,3 +1,5 @@ +/* eslint indent: ["error", 2, { "SwitchCase": 1 }] */ + import { client, delay } from "../client"; import { UPDATE_INTERVAL } from "../client"; import setEmote from "../client/setEmote"; -- cgit