From 3162071cb27510954dde918af629ed5d75deb583 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 08:39:19 +0200 Subject: get list of extensions to try from host --- webAO/client.ts | 4 ++++ webAO/client/fetchLists.ts | 14 +++++++++++--- webAO/client/handleCharacterInfo.ts | 6 +++--- webAO/client/setEmote.ts | 3 +-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/webAO/client.ts b/webAO/client.ts index 4d8390a..28679c0 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -151,6 +151,8 @@ class Client extends EventEmitter { connect: () => void; loadResources: () => void; isLowMemory: () => void; + charicon_extensions: string[]; + emote_extensions: string[]; constructor(connectionString: string) { super(); @@ -209,6 +211,8 @@ class Client extends EventEmitter { this.temp_packet = ""; loadResources; isLowMemory; + this.charicon_extensions = [".png", ".webp"]; + this.emote_extensions = [".gif", ".png", ".apng", ".webp", ".webp.static"]; } /** diff --git a/webAO/client/fetchLists.ts b/webAO/client/fetchLists.ts index 2489c97..2aff60a 100644 --- a/webAO/client/fetchLists.ts +++ b/webAO/client/fetchLists.ts @@ -50,8 +50,6 @@ export const fetchEvidenceList = async () => { try { const evidata = await request(`${AO_HOST}evidence.json`); const evi_array = JSON.parse(evidata); - // the try catch will fail before here when there is no file - evi_array.forEach((evi: string) => { evi_select.add(new Option(evi)); }); @@ -64,8 +62,18 @@ export const fetchManifest = async () => { try { const manifestdata = await request(`${AO_HOST}manifest.txt`); client.manifest = manifestdata.split(/\r\n|\n\r|\n|\r/); - // the try catch will fail before here when there is no file } catch (err) { console.warn("there was no manifest.txt file"); } }; + +export const fetchExtensions = async () => { + try { + const extensiondata = await request(`${AO_HOST}extensions.json`); + const allextensions = JSON.parse(extensiondata); + client.charicon_extensions = allextensions.charicon_extensions|| [".png", ".webp"]; + client.emote_extensions = allextensions.emote_extensions || [".gif", ".png", ".apng", ".webp", ".webp.static"]; + } catch (err) { + console.warn("there was no extensions.json file"); + } +}; diff --git a/webAO/client/handleCharacterInfo.ts b/webAO/client/handleCharacterInfo.ts index 3f81e57..a364b5e 100644 --- a/webAO/client/handleCharacterInfo.ts +++ b/webAO/client/handleCharacterInfo.ts @@ -6,13 +6,13 @@ import fileExists from "../utils/fileExists"; import { AO_HOST } from "./aoHost"; export const getCharIcon = async (img: HTMLImageElement, charname: string) => { - const extensions = [".png", ".webp"]; + const charicon_extensions = [".png", ".webp"]; img.alt = charname; const charIconBaseUrl = `${AO_HOST}characters/${encodeURI( charname.toLowerCase(), )}/char_icon`; - for (let i = 0; i < extensions.length; i++) { - const fileUrl = charIconBaseUrl + extensions[i]; + for (let i = 0; i < charicon_extensions.length; i++) { + const fileUrl = charIconBaseUrl + charicon_extensions[i]; const exists = await fileExists(fileUrl); if (exists) { img.alt = charname; diff --git a/webAO/client/setEmote.ts b/webAO/client/setEmote.ts index 70f23ac..4c05afc 100644 --- a/webAO/client/setEmote.ts +++ b/webAO/client/setEmote.ts @@ -23,9 +23,8 @@ const setEmote = async ( 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 client.emote_extensions) { // Hides all sprites before creating a new sprite if ( -- cgit From c2ce0abe8af72603ad35761cb798fdd1aff01c85 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 09:20:22 +0200 Subject: fetch em --- webAO/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webAO/client.ts b/webAO/client.ts index 28679c0..46f4ba9 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -19,6 +19,7 @@ import { fetchBackgroundList, fetchEvidenceList, fetchCharacterList, + fetchExtensions, } from "./client/fetchLists"; import getCookie from "./utils/getCookie"; import setCookie from "./utils/setCookie"; @@ -408,7 +409,7 @@ class Client extends EventEmitter { resetAreaList() { this.areas = []; document.getElementById("areas").innerHTML = ""; - + fetchExtensions(); fetchBackgroundList(); fetchEvidenceList(); fetchCharacterList(); -- cgit From 14b569e05ab43baf76fd6404ca50a2b05a843134 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 10:13:13 +0200 Subject: logging --- webAO/client/fetchLists.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webAO/client/fetchLists.ts b/webAO/client/fetchLists.ts index 2aff60a..68b1a43 100644 --- a/webAO/client/fetchLists.ts +++ b/webAO/client/fetchLists.ts @@ -71,8 +71,10 @@ export const fetchExtensions = async () => { try { const extensiondata = await request(`${AO_HOST}extensions.json`); const allextensions = JSON.parse(extensiondata); - client.charicon_extensions = allextensions.charicon_extensions|| [".png", ".webp"]; + client.charicon_extensions = allextensions.charicon_extensions || [".png", ".webp"]; client.emote_extensions = allextensions.emote_extensions || [".gif", ".png", ".apng", ".webp", ".webp.static"]; + console.log("charicons "+client.charicon_extensions) + console.log("emotes "+client.emote_extensions) } catch (err) { console.warn("there was no extensions.json file"); } -- cgit From e58dcb7186bb3c80ba87279a6643fcb4b8b3b2be Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 10:27:49 +0200 Subject: emotions --- webAO/client.ts | 2 ++ webAO/client/fetchLists.ts | 2 ++ webAO/packets/handlers/handlePV.ts | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/webAO/client.ts b/webAO/client.ts index 46f4ba9..27861de 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -154,6 +154,7 @@ class Client extends EventEmitter { isLowMemory: () => void; charicon_extensions: string[]; emote_extensions: string[]; + emotions_extensions: string[]; constructor(connectionString: string) { super(); @@ -214,6 +215,7 @@ class Client extends EventEmitter { isLowMemory; this.charicon_extensions = [".png", ".webp"]; this.emote_extensions = [".gif", ".png", ".apng", ".webp", ".webp.static"]; + this.emotions_extensions = [".png", ".webp"]; } /** diff --git a/webAO/client/fetchLists.ts b/webAO/client/fetchLists.ts index 68b1a43..7940eea 100644 --- a/webAO/client/fetchLists.ts +++ b/webAO/client/fetchLists.ts @@ -73,8 +73,10 @@ export const fetchExtensions = async () => { const allextensions = JSON.parse(extensiondata); client.charicon_extensions = allextensions.charicon_extensions || [".png", ".webp"]; client.emote_extensions = allextensions.emote_extensions || [".gif", ".png", ".apng", ".webp", ".webp.static"]; + client.emotions_extensions = allextensions.emotions_extensions || [".png", ".webp"]; console.log("charicons "+client.charicon_extensions) console.log("emotes "+client.emote_extensions) + console.log("emotions "+client.emotions_extensions) } catch (err) { console.warn("there was no extensions.json file"); } diff --git a/webAO/packets/handlers/handlePV.ts b/webAO/packets/handlers/handlePV.ts index 900ea89..4ac747f 100644 --- a/webAO/packets/handlers/handlePV.ts +++ b/webAO/packets/handlers/handlePV.ts @@ -58,9 +58,8 @@ export const handlePV = async (args: string[]) => { } // Make sure the asset server is case insensitive, or that everything on it is lowercase - const extensionsMap = [".png", ".webp"]; let url; - for (const extension of extensionsMap) { + for (const extension of client.emotions_extensions) { url = `${AO_HOST}characters/${encodeURI( me.name.toLowerCase(), )}/emotions/button${i}_off${extension}`; -- cgit From 1ba59be463abe60448b0eb7da157251c393c0590 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 10:29:13 +0200 Subject: bgurls --- webAO/__tests__/tryBackgroundUrls.test.ts | 28 ++++++++++++++++++++++++++++ webAO/__tests__/tryUrls.test.ts | 28 ---------------------------- webAO/dom/updateBackgroundPreview.ts | 4 ++-- webAO/packets/handlers/handleBN.ts | 22 +++++++++++----------- webAO/utils/tryBackgroundUrls.ts | 15 +++++++++++++++ webAO/utils/tryUrls.ts | 15 --------------- webAO/viewport/utils/setSide.ts | 4 ++-- 7 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 webAO/__tests__/tryBackgroundUrls.test.ts delete mode 100644 webAO/__tests__/tryUrls.test.ts create mode 100644 webAO/utils/tryBackgroundUrls.ts delete mode 100644 webAO/utils/tryUrls.ts diff --git a/webAO/__tests__/tryBackgroundUrls.test.ts b/webAO/__tests__/tryBackgroundUrls.test.ts new file mode 100644 index 0000000..cfbf3f9 --- /dev/null +++ b/webAO/__tests__/tryBackgroundUrls.test.ts @@ -0,0 +1,28 @@ +import fileExists from "../utils/fileExists"; +import tryBackgroundUrls from "../utils/tryBackgroundUrls"; +import transparentPng from "../constants/transparentPng"; +jest.mock("../utils/fileExists"); + +const mockFileExists = fileExists as jest.MockedFunction; + +describe("tryBackgroundUrls", () => { + it("Should try multiple file extensions", async () => { + const url = "localhost/stoneddiscord/assets"; + mockFileExists + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(true)); + const actual = await tryBackgroundUrls(url); + const expected = "localhost/stoneddiscord/assets.apng"; + expect(actual).toBe(expected); + }); + + it("Should return a transparent png if it cant find any assets", async () => { + const url = "localhost/stoneddiscord/assets"; + mockFileExists.mockReturnValue(Promise.resolve(false)); + const actual = await tryBackgroundUrls(url); + const expected = transparentPng; + expect(actual).toBe(expected); + }); +}); diff --git a/webAO/__tests__/tryUrls.test.ts b/webAO/__tests__/tryUrls.test.ts deleted file mode 100644 index 4a32f32..0000000 --- a/webAO/__tests__/tryUrls.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import fileExists from "../utils/fileExists"; -import tryUrls from "../utils/tryUrls"; -import transparentPng from "../constants/transparentPng"; -jest.mock("../utils/fileExists"); - -const mockFileExists = fileExists as jest.MockedFunction; - -describe("tryUrls", () => { - it("Should try multiple file extensions", async () => { - const url = "localhost/stoneddiscord/assets"; - mockFileExists - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(true)); - const actual = await tryUrls(url); - const expected = "localhost/stoneddiscord/assets.apng"; - expect(actual).toBe(expected); - }); - - it("Should return a transparent png if it cant find any assets", async () => { - const url = "localhost/stoneddiscord/assets"; - mockFileExists.mockReturnValue(Promise.resolve(false)); - const actual = await tryUrls(url); - const expected = transparentPng; - expect(actual).toBe(expected); - }); -}); diff --git a/webAO/dom/updateBackgroundPreview.ts b/webAO/dom/updateBackgroundPreview.ts index 61eec58..61186e0 100644 --- a/webAO/dom/updateBackgroundPreview.ts +++ b/webAO/dom/updateBackgroundPreview.ts @@ -1,5 +1,5 @@ import { AO_HOST } from "../client/aoHost"; -import tryUrls from "../utils/tryUrls"; +import tryBackgroundUrls from "../utils/tryBackgroundUrls"; /** * Update background preview. @@ -20,7 +20,7 @@ export function updateBackgroundPreview() { } else { background_filename.style.display = "none"; } - tryUrls( + tryBackgroundUrls( `${AO_HOST}background/${encodeURI( background_select.value.toLowerCase(), )}/defenseempty`, diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index aeea03b..5e9e8f8 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -5,7 +5,7 @@ import { updateBackgroundPreview } from "../../dom/updateBackgroundPreview"; import { getIndexFromSelect } from "../../dom/getIndexFromSelect"; import { switchPanTilt } from "../../dom/switchPanTilt"; import transparentPng from "../../constants/transparentPng"; -import tryUrls from "../../utils/tryUrls"; +import tryBackgroundUrls from "../../utils/tryBackgroundUrls"; /** * Handles a background change. @@ -28,21 +28,21 @@ export const handleBN = (args: string[]) => { client.viewport.getBackgroundName(); } - tryUrls( + tryBackgroundUrls( `${AO_HOST}background/${encodeURI(args[1].toLowerCase())}/defenseempty`, ).then((resp) => { (document.getElementById("bg_preview")).src = resp; }); - tryUrls(`${bgfolder}defensedesk`).then((resp) => { + tryBackgroundUrls(`${bgfolder}defensedesk`).then((resp) => { (document.getElementById("client_def_bench")).src = resp; }); - tryUrls(`${bgfolder}stand`).then((resp) => { + tryBackgroundUrls(`${bgfolder}stand`).then((resp) => { (document.getElementById("client_wit_bench")).src = resp; }); - tryUrls(`${bgfolder}prosecutiondesk`).then((resp) => { + tryBackgroundUrls(`${bgfolder}prosecutiondesk`).then((resp) => { (document.getElementById("client_pro_bench")).src = resp; }); - tryUrls(`${bgfolder}court`).then((resp) => { + tryBackgroundUrls(`${bgfolder}court`).then((resp) => { (document.getElementById("client_court")).src = resp; if (resp !== transparentPng) { (document.getElementById("client_pantilt")).checked = @@ -50,19 +50,19 @@ export const handleBN = (args: string[]) => { switchPanTilt(); } }); - tryUrls(`${bgfolder}defenseempty`).then((resp) => { + tryBackgroundUrls(`${bgfolder}defenseempty`).then((resp) => { (document.getElementById("client_court_def")).src = resp; }); - tryUrls(`${bgfolder}transition_def`).then((resp) => { + tryBackgroundUrls(`${bgfolder}transition_def`).then((resp) => { (document.getElementById("client_court_deft")).src = resp; }); - tryUrls(`${bgfolder}witnessempty`).then((resp) => { + tryBackgroundUrls(`${bgfolder}witnessempty`).then((resp) => { (document.getElementById("client_court_wit")).src = resp; }); - tryUrls(`${bgfolder}transition_pro`).then((resp) => { + tryBackgroundUrls(`${bgfolder}transition_pro`).then((resp) => { (document.getElementById("client_court_prot")).src = resp; }); - tryUrls(`${bgfolder}prosecutorempty`).then((resp) => { + tryBackgroundUrls(`${bgfolder}prosecutorempty`).then((resp) => { (document.getElementById("client_court_pro")).src = resp; }); diff --git a/webAO/utils/tryBackgroundUrls.ts b/webAO/utils/tryBackgroundUrls.ts new file mode 100644 index 0000000..154978b --- /dev/null +++ b/webAO/utils/tryBackgroundUrls.ts @@ -0,0 +1,15 @@ +import fileExists from "./fileExists"; +import transparentPng from "../constants/transparentPng"; +const urlExtensionsToTry = [".png", ".gif", ".webp", ".apng"]; +const tryBackgroundUrls = async (url: string) => { + for (let i = 0; i < urlExtensionsToTry.length; i++) { + const extension = urlExtensionsToTry[i]; + const fullFileUrl = url + extension; + const exists = await fileExists(fullFileUrl); + if (exists) { + return fullFileUrl; + } + } + return transparentPng; +}; +export default tryBackgroundUrls; diff --git a/webAO/utils/tryUrls.ts b/webAO/utils/tryUrls.ts deleted file mode 100644 index 127bc5b..0000000 --- a/webAO/utils/tryUrls.ts +++ /dev/null @@ -1,15 +0,0 @@ -import fileExists from "./fileExists"; -import transparentPng from "../constants/transparentPng"; -const urlExtensionsToTry = [".png", ".gif", ".webp", ".apng"]; -const tryUrls = async (url: string) => { - for (let i = 0; i < urlExtensionsToTry.length; i++) { - const extension = urlExtensionsToTry[i]; - const fullFileUrl = url + extension; - const exists = await fileExists(fullFileUrl); - if (exists) { - return fullFileUrl; - } - } - return transparentPng; -}; -export default tryUrls; diff --git a/webAO/viewport/utils/setSide.ts b/webAO/viewport/utils/setSide.ts index fd229e1..5966a52 100644 --- a/webAO/viewport/utils/setSide.ts +++ b/webAO/viewport/utils/setSide.ts @@ -1,7 +1,7 @@ import { positions } from "../constants/positions"; import { AO_HOST } from "../../client/aoHost"; import { client } from "../../client"; -import tryUrls from "../../utils/tryUrls"; +import tryBackgroundUrls from "../../utils/tryBackgroundUrls"; import findImgSrc from "../../utils/findImgSrc"; /** @@ -55,7 +55,7 @@ export const set_side = async ({ if (showSpeedLines === true) { court.src = `${AO_HOST}themes/default/${encodeURI(speedLines)}`; } else { - court.src = await tryUrls(client.viewport.getBackgroundFolder() + bg); + court.src = await tryBackgroundUrls(client.viewport.getBackgroundFolder() + bg); } if (showDesk === true && desk) { -- cgit From d8d2fbc8b7bf91dbedc7042daa1081ebd0d1330f Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 11:04:17 +0200 Subject: also get backgrounds --- webAO/client.ts | 10 ++++++---- webAO/client/fetchLists.ts | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/webAO/client.ts b/webAO/client.ts index 27861de..4cceb98 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -102,6 +102,7 @@ fpPromise client.hdid = hdid; isLowMemory(); loadResources(); + fetchExtensions(); }); export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)); @@ -155,6 +156,7 @@ class Client extends EventEmitter { charicon_extensions: string[]; emote_extensions: string[]; emotions_extensions: string[]; + background_extensions: string[]; constructor(connectionString: string) { super(); @@ -213,9 +215,10 @@ class Client extends EventEmitter { this.temp_packet = ""; loadResources; isLowMemory; - this.charicon_extensions = [".png", ".webp"]; - this.emote_extensions = [".gif", ".png", ".apng", ".webp", ".webp.static"]; - this.emotions_extensions = [".png", ".webp"]; + this.charicon_extensions = []; + this.emote_extensions = []; + this.emotions_extensions = []; + this.background_extensions = []; } /** @@ -411,7 +414,6 @@ class Client extends EventEmitter { resetAreaList() { this.areas = []; document.getElementById("areas").innerHTML = ""; - fetchExtensions(); fetchBackgroundList(); fetchEvidenceList(); fetchCharacterList(); diff --git a/webAO/client/fetchLists.ts b/webAO/client/fetchLists.ts index 7940eea..3d590b9 100644 --- a/webAO/client/fetchLists.ts +++ b/webAO/client/fetchLists.ts @@ -74,6 +74,7 @@ export const fetchExtensions = async () => { client.charicon_extensions = allextensions.charicon_extensions || [".png", ".webp"]; client.emote_extensions = allextensions.emote_extensions || [".gif", ".png", ".apng", ".webp", ".webp.static"]; client.emotions_extensions = allextensions.emotions_extensions || [".png", ".webp"]; + client.background_extensions = allextensions.background_extensions || [".png", ".gif", ".webp", ".apng"]; console.log("charicons "+client.charicon_extensions) console.log("emotes "+client.emote_extensions) console.log("emotions "+client.emotions_extensions) -- cgit From 183fd0fdddbcf194eec08f8e79e6a1709e18d3a9 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 12:20:42 +0200 Subject: also do bgs --- webAO/__tests__/tryBackgroundUrls.test.ts | 28 ------------ webAO/client/fetchLists.ts | 1 + webAO/dom/updateBackgroundPreview.ts | 17 ++++++- webAO/packets/handlers/handleBN.ts | 76 ++++++++++++++++--------------- webAO/utils/tryBackgroundUrls.ts | 15 ------ webAO/viewport/utils/setSide.ts | 3 +- 6 files changed, 58 insertions(+), 82 deletions(-) delete mode 100644 webAO/__tests__/tryBackgroundUrls.test.ts delete mode 100644 webAO/utils/tryBackgroundUrls.ts diff --git a/webAO/__tests__/tryBackgroundUrls.test.ts b/webAO/__tests__/tryBackgroundUrls.test.ts deleted file mode 100644 index cfbf3f9..0000000 --- a/webAO/__tests__/tryBackgroundUrls.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import fileExists from "../utils/fileExists"; -import tryBackgroundUrls from "../utils/tryBackgroundUrls"; -import transparentPng from "../constants/transparentPng"; -jest.mock("../utils/fileExists"); - -const mockFileExists = fileExists as jest.MockedFunction; - -describe("tryBackgroundUrls", () => { - it("Should try multiple file extensions", async () => { - const url = "localhost/stoneddiscord/assets"; - mockFileExists - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(true)); - const actual = await tryBackgroundUrls(url); - const expected = "localhost/stoneddiscord/assets.apng"; - expect(actual).toBe(expected); - }); - - it("Should return a transparent png if it cant find any assets", async () => { - const url = "localhost/stoneddiscord/assets"; - mockFileExists.mockReturnValue(Promise.resolve(false)); - const actual = await tryBackgroundUrls(url); - const expected = transparentPng; - expect(actual).toBe(expected); - }); -}); diff --git a/webAO/client/fetchLists.ts b/webAO/client/fetchLists.ts index 3d590b9..d391fac 100644 --- a/webAO/client/fetchLists.ts +++ b/webAO/client/fetchLists.ts @@ -78,6 +78,7 @@ export const fetchExtensions = async () => { console.log("charicons "+client.charicon_extensions) console.log("emotes "+client.emote_extensions) console.log("emotions "+client.emotions_extensions) + console.log("backgrounds "+client.background_extensions) } catch (err) { console.warn("there was no extensions.json file"); } diff --git a/webAO/dom/updateBackgroundPreview.ts b/webAO/dom/updateBackgroundPreview.ts index 61186e0..2b8a18b 100644 --- a/webAO/dom/updateBackgroundPreview.ts +++ b/webAO/dom/updateBackgroundPreview.ts @@ -1,5 +1,20 @@ import { AO_HOST } from "../client/aoHost"; -import tryBackgroundUrls from "../utils/tryBackgroundUrls"; +import fileExists from "../utils/fileExists"; +import transparentPng from "../constants/transparentPng"; + +const urlExtensionsToTry = [".png", ".gif", ".webp", ".apng"]; +const tryBackgroundUrls = async (url: string) => { + for (let i = 0; i < urlExtensionsToTry.length; i++) { + const extension = urlExtensionsToTry[i]; + const fullFileUrl = url + extension; + const exists = await fileExists(fullFileUrl); + if (exists) { + return fullFileUrl; + } + } + return transparentPng; +}; +export default tryBackgroundUrls; /** * Update background preview. diff --git a/webAO/packets/handlers/handleBN.ts b/webAO/packets/handlers/handleBN.ts index 5e9e8f8..769a0dc 100644 --- a/webAO/packets/handlers/handleBN.ts +++ b/webAO/packets/handlers/handleBN.ts @@ -5,7 +5,29 @@ import { updateBackgroundPreview } from "../../dom/updateBackgroundPreview"; import { getIndexFromSelect } from "../../dom/getIndexFromSelect"; import { switchPanTilt } from "../../dom/switchPanTilt"; import transparentPng from "../../constants/transparentPng"; -import tryBackgroundUrls from "../../utils/tryBackgroundUrls"; +import fileExists from "../../utils/fileExists"; + +function setBackgroundImage(elementid: string, bgname: string, bgpart: string): boolean { + + let url; + let success = false; + for (const extension of client.background_extensions) { + url = `${AO_HOST}background/${encodeURI(bgname.toLowerCase())}/${bgpart}${extension}`; + + const exists = fileExists(url); + + if (exists) { + success = true; + break; + } + } + if (success) + (document.getElementById(elementid)).src = url; + else + (document.getElementById(elementid)).src = transparentPng; + return success; +} + /** * Handles a background change. @@ -28,43 +50,25 @@ export const handleBN = (args: string[]) => { client.viewport.getBackgroundName(); } - tryBackgroundUrls( - `${AO_HOST}background/${encodeURI(args[1].toLowerCase())}/defenseempty`, - ).then((resp) => { - (document.getElementById("bg_preview")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}defensedesk`).then((resp) => { - (document.getElementById("client_def_bench")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}stand`).then((resp) => { - (document.getElementById("client_wit_bench")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}prosecutiondesk`).then((resp) => { - (document.getElementById("client_pro_bench")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}court`).then((resp) => { - (document.getElementById("client_court")).src = resp; - if (resp !== transparentPng) { - (document.getElementById("client_pantilt")).checked = + + setBackgroundImage("bg_preview",args[1],"defenseempty") + + setBackgroundImage("client_def_bench",args[1],"defensedesk") + setBackgroundImage("client_wit_bench",args[1],"stand") + setBackgroundImage("client_pro_bench",args[1],"prosecutiondesk") + + setBackgroundImage("client_court_def",args[1],"defenseempty") + setBackgroundImage("client_court_wit",args[1],"witnessempty") + setBackgroundImage("client_court_pro",args[1],"prosecutorempty") + + setBackgroundImage("client_court_deft",args[1],"transition_def") + setBackgroundImage("client_court_prot",args[1],"transition_pro") + + if(setBackgroundImage("client_court",args[1],"court")) { + (document.getElementById("client_pantilt")).checked = true; switchPanTilt(); - } - }); - tryBackgroundUrls(`${bgfolder}defenseempty`).then((resp) => { - (document.getElementById("client_court_def")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}transition_def`).then((resp) => { - (document.getElementById("client_court_deft")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}witnessempty`).then((resp) => { - (document.getElementById("client_court_wit")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}transition_pro`).then((resp) => { - (document.getElementById("client_court_prot")).src = resp; - }); - tryBackgroundUrls(`${bgfolder}prosecutorempty`).then((resp) => { - (document.getElementById("client_court_pro")).src = resp; - }); + } if (client.charID === -1) { client.viewport.set_side({ diff --git a/webAO/utils/tryBackgroundUrls.ts b/webAO/utils/tryBackgroundUrls.ts deleted file mode 100644 index 154978b..0000000 --- a/webAO/utils/tryBackgroundUrls.ts +++ /dev/null @@ -1,15 +0,0 @@ -import fileExists from "./fileExists"; -import transparentPng from "../constants/transparentPng"; -const urlExtensionsToTry = [".png", ".gif", ".webp", ".apng"]; -const tryBackgroundUrls = async (url: string) => { - for (let i = 0; i < urlExtensionsToTry.length; i++) { - const extension = urlExtensionsToTry[i]; - const fullFileUrl = url + extension; - const exists = await fileExists(fullFileUrl); - if (exists) { - return fullFileUrl; - } - } - return transparentPng; -}; -export default tryBackgroundUrls; diff --git a/webAO/viewport/utils/setSide.ts b/webAO/viewport/utils/setSide.ts index 5966a52..c9948e2 100644 --- a/webAO/viewport/utils/setSide.ts +++ b/webAO/viewport/utils/setSide.ts @@ -1,7 +1,6 @@ import { positions } from "../constants/positions"; import { AO_HOST } from "../../client/aoHost"; import { client } from "../../client"; -import tryBackgroundUrls from "../../utils/tryBackgroundUrls"; import findImgSrc from "../../utils/findImgSrc"; /** @@ -55,7 +54,7 @@ export const set_side = async ({ if (showSpeedLines === true) { court.src = `${AO_HOST}themes/default/${encodeURI(speedLines)}`; } else { - court.src = await tryBackgroundUrls(client.viewport.getBackgroundFolder() + bg); + //court.src = await tryBackgroundUrls(client.viewport.getBackgroundFolder() + bg); } if (showDesk === true && desk) { -- cgit From a2ac0577dc5bb9ef345f3ef04e0eb842020db404 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 14:10:20 +0200 Subject: move up --- webAO/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webAO/client.ts b/webAO/client.ts index 4cceb98..177d9a3 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -98,11 +98,11 @@ fpPromise } client = new Client(connectionString); + fetchExtensions(); client.connect(); client.hdid = hdid; isLowMemory(); loadResources(); - fetchExtensions(); }); export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)); -- cgit From c9dd3b460d81923b89795bf4e220dd7095584c04 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 14:18:23 +0200 Subject: defaults needed to pass test --- webAO/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webAO/client.ts b/webAO/client.ts index 177d9a3..8c842f8 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -215,10 +215,10 @@ class Client extends EventEmitter { this.temp_packet = ""; loadResources; isLowMemory; - this.charicon_extensions = []; - this.emote_extensions = []; - this.emotions_extensions = []; - this.background_extensions = []; + this.charicon_extensions = [".png", ".webp"]; + this.emote_extensions = [".gif", ".png", ".apng", ".webp", ".webp.static"]; + this.emotions_extensions = [".png", ".webp"]; + this.background_extensions = [".png", ".gif"];; } /** -- cgit From 035951baf3819f56093f7156b345689aa5093f28 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 3 Sep 2025 14:20:28 +0200 Subject: remove failed manifesto --- public/index.html | 1 - webAO/client.ts | 2 -- webAO/client/fetchLists.ts | 9 --------- 3 files changed, 12 deletions(-) diff --git a/public/index.html b/public/index.html index 89e7740..5078682 100644 --- a/public/index.html +++ b/public/index.html @@ -77,7 +77,6 @@ -