diff --git a/birb.js b/birb.js index 807b82f..83979dd 100644 --- a/birb.js +++ b/birb.js @@ -48,6 +48,7 @@ const DEFAULT_SETTINGS = { * @typedef {typeof DEFAULT_SETTINGS} Settings */ +/** @type {Partial} */ let userSettings = {}; const STYLESHEET = `___STYLESHEET___`; @@ -65,6 +66,7 @@ class Layer { class Frame { + /** @type {{ [tag: string]: string[][] }} */ #pixelsByTag = {}; /** @@ -191,6 +193,7 @@ const HEART_BORDER = "heart-border"; const HEART_SHINE = "heart-shine"; const FEATHER_SPINE = "feather-spine"; +/** @type {Record} */ const SPRITE_SHEET_COLOR_MAP = { "transparent": TRANSPARENT, "#ffffff": BORDER, @@ -234,11 +237,13 @@ class BirdType { [HOOD]: colors.face, [NOSE]: colors.face, }; + /** @type {Record} */ this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face }; this.tags = tags; } } +/** @type {Record} */ const species = { bluebird: new BirdType("Eastern Bluebird", "Native to North American and very social, though can be timid around people.", { @@ -681,6 +686,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI /** @type {HTMLElement|null} */ let focusedElement = null; let lastActionTimestamp = Date.now(); + /** @type {number[]} */ let petStack = []; let currentSpecies = DEFAULT_BIRD; let unlockedSpecies = [DEFAULT_BIRD]; @@ -702,6 +708,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI } function load() { + /** @type {Record} */ let saveData = {}; if (isUserScript()) { log("Loading save data from UserScript storage"); @@ -733,6 +740,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI } function save() { + /** @type {Record} */ let saveData = { unlockedSpecies: unlockedSpecies, currentSpecies: currentSpecies, @@ -840,11 +848,14 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI const textarea = noteElement.querySelector(".birb-sticky-note-input"); if (textarea && textarea instanceof HTMLTextAreaElement) { + /** @type {NodeJS.Timeout | undefined} */ let saveTimeout; // Save after debounce textarea.addEventListener("input", () => { stickyNote.content = textarea.value; - clearTimeout(saveTimeout); + if (saveTimeout) { + clearTimeout(saveTimeout); + } saveTimeout = setTimeout(() => { save(); }, 250); @@ -888,15 +899,13 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI /** @type {Record} */ const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => { const [key, value] = param.split("="); - params[key] = value; - return params; + return {...params, [key]: value}; }, {}); /** @type {Record} */ const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => { const [key, value] = param.split("="); - params[key] = value; - return params; + return {...params, [key]: value}; }, {}); debug("Comparing params: ", stickyNoteParams, currentParams); diff --git a/dist/birb.js b/dist/birb.js index 62ee598..8429396 100644 --- a/dist/birb.js +++ b/dist/birb.js @@ -48,6 +48,7 @@ const DEFAULT_SETTINGS = { * @typedef {typeof DEFAULT_SETTINGS} Settings */ +/** @type {Partial} */ let userSettings = {}; const STYLESHEET = `:root { @@ -397,6 +398,7 @@ class Layer { class Frame { + /** @type {{ [tag: string]: string[][] }} */ #pixelsByTag = {}; /** @@ -523,6 +525,7 @@ const HEART_BORDER = "heart-border"; const HEART_SHINE = "heart-shine"; const FEATHER_SPINE = "feather-spine"; +/** @type {Record} */ const SPRITE_SHEET_COLOR_MAP = { "transparent": TRANSPARENT, "#ffffff": BORDER, @@ -566,11 +569,13 @@ class BirdType { [HOOD]: colors.face, [NOSE]: colors.face, }; + /** @type {Record} */ this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face }; this.tags = tags; } } +/** @type {Record} */ const species = { bluebird: new BirdType("Eastern Bluebird", "Native to North American and very social, though can be timid around people.", { @@ -1013,6 +1018,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI /** @type {HTMLElement|null} */ let focusedElement = null; let lastActionTimestamp = Date.now(); + /** @type {number[]} */ let petStack = []; let currentSpecies = DEFAULT_BIRD; let unlockedSpecies = [DEFAULT_BIRD]; @@ -1034,6 +1040,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI } function load() { + /** @type {Record} */ let saveData = {}; if (isUserScript()) { log("Loading save data from UserScript storage"); @@ -1065,6 +1072,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI } function save() { + /** @type {Record} */ let saveData = { unlockedSpecies: unlockedSpecies, currentSpecies: currentSpecies, @@ -1172,11 +1180,14 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI const textarea = noteElement.querySelector(".birb-sticky-note-input"); if (textarea && textarea instanceof HTMLTextAreaElement) { + /** @type {NodeJS.Timeout | undefined} */ let saveTimeout; // Save after debounce textarea.addEventListener("input", () => { stickyNote.content = textarea.value; - clearTimeout(saveTimeout); + if (saveTimeout) { + clearTimeout(saveTimeout); + } saveTimeout = setTimeout(() => { save(); }, 250); @@ -1220,15 +1231,13 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI /** @type {Record} */ const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => { const [key, value] = param.split("="); - params[key] = value; - return params; + return {...params, [key]: value}; }, {}); /** @type {Record} */ const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => { const [key, value] = param.split("="); - params[key] = value; - return params; + return {...params, [key]: value}; }, {}); debug("Comparing params: ", stickyNoteParams, currentParams); diff --git a/dist/birb.user.js b/dist/birb.user.js index 5ddb0d1..beb0d00 100644 --- a/dist/birb.user.js +++ b/dist/birb.user.js @@ -62,6 +62,7 @@ const DEFAULT_SETTINGS = { * @typedef {typeof DEFAULT_SETTINGS} Settings */ +/** @type {Partial} */ let userSettings = {}; const STYLESHEET = `:root { @@ -411,6 +412,7 @@ class Layer { class Frame { + /** @type {{ [tag: string]: string[][] }} */ #pixelsByTag = {}; /** @@ -537,6 +539,7 @@ const HEART_BORDER = "heart-border"; const HEART_SHINE = "heart-shine"; const FEATHER_SPINE = "feather-spine"; +/** @type {Record} */ const SPRITE_SHEET_COLOR_MAP = { "transparent": TRANSPARENT, "#ffffff": BORDER, @@ -580,11 +583,13 @@ class BirdType { [HOOD]: colors.face, [NOSE]: colors.face, }; + /** @type {Record} */ this.colors = { ...defaultColors, ...colors, [THEME_HIGHLIGHT]: colors[THEME_HIGHLIGHT] ?? colors.hood ?? colors.face }; this.tags = tags; } } +/** @type {Record} */ const species = { bluebird: new BirdType("Eastern Bluebird", "Native to North American and very social, though can be timid around people.", { @@ -1027,6 +1032,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI /** @type {HTMLElement|null} */ let focusedElement = null; let lastActionTimestamp = Date.now(); + /** @type {number[]} */ let petStack = []; let currentSpecies = DEFAULT_BIRD; let unlockedSpecies = [DEFAULT_BIRD]; @@ -1048,6 +1054,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI } function load() { + /** @type {Record} */ let saveData = {}; if (isUserScript()) { log("Loading save data from UserScript storage"); @@ -1079,6 +1086,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI } function save() { + /** @type {Record} */ let saveData = { unlockedSpecies: unlockedSpecies, currentSpecies: currentSpecies, @@ -1186,11 +1194,14 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI const textarea = noteElement.querySelector(".birb-sticky-note-input"); if (textarea && textarea instanceof HTMLTextAreaElement) { + /** @type {NodeJS.Timeout | undefined} */ let saveTimeout; // Save after debounce textarea.addEventListener("input", () => { stickyNote.content = textarea.value; - clearTimeout(saveTimeout); + if (saveTimeout) { + clearTimeout(saveTimeout); + } saveTimeout = setTimeout(() => { save(); }, 250); @@ -1234,15 +1245,13 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI /** @type {Record} */ const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => { const [key, value] = param.split("="); - params[key] = value; - return params; + return {...params, [key]: value}; }, {}); /** @type {Record} */ const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => { const [key, value] = param.split("="); - params[key] = value; - return params; + return {...params, [key]: value}; }, {}); debug("Comparing params: ", stickyNoteParams, currentParams);