From 571a7c65c84bac1f2d29e20f2eeed59c4f082777 Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@gmail.com> Date: Thu, 18 Feb 2021 22:47:58 +0100 Subject: [PATCH] Improve code style and type checking --- js/003-data/gameVariableData.js | 4 ++-- src/futureSocieties/fsDecoration.js | 2 +- src/futureSocieties/fsPassage.js | 2 -- src/futureSocieties/futureSociety.js | 9 ++++++++- src/gui/Encyclopedia/encyclopediaEntries.js | 1 - src/gui/interactiveDetails.js | 2 +- src/gui/multipleInspect.js | 4 ++-- src/gui/options/options.js | 6 ------ src/gui/options/summaryOptions.js | 2 +- src/gui/quicklinks.js | 1 - src/gui/storyCaption.js | 5 +++-- 11 files changed, 18 insertions(+), 20 deletions(-) diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index 19b93893e47..40f9dbb513a 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -7,8 +7,8 @@ App.Data.defaultGameStateVariables = { storedLink: "", // Version - ver: 0, - pmodVer: 0, + ver: "", + pmodVer: "", releaseID: 0, // Slaves diff --git a/src/futureSocieties/fsDecoration.js b/src/futureSocieties/fsDecoration.js index b937b06c90c..789d1f662bb 100644 --- a/src/futureSocieties/fsDecoration.js +++ b/src/futureSocieties/fsDecoration.js @@ -10,7 +10,7 @@ App.UI.facilityRedecoration = function() { FutureSocieties.DecorationCleanup(); const applicableFS = FutureSocieties.activeFSes(arc).filter(name => (arc[name] > 20)); - const decorationNames = Array.from(applicableFS, FS => FutureSocieties.decorationName(FS)).filter(Boolean); + const decorationNames = Array.from(applicableFS, FS => FutureSocieties.decorationName(FS)).filter(Boolean); if (V.brothel > 0) { activeFacilities.set(V.brothelName, "brothelDecoration"); diff --git a/src/futureSocieties/fsPassage.js b/src/futureSocieties/fsPassage.js index 9a63c3ded19..47aa8eaa69d 100644 --- a/src/futureSocieties/fsPassage.js +++ b/src/futureSocieties/fsPassage.js @@ -886,7 +886,6 @@ App.UI.fsPassage = function() { App.Events.addNode(p, r, "div"); el.append(p); - /* Milking stands alone */ r = []; if (arc.FSPastoralist !== "unset") { @@ -911,7 +910,6 @@ App.UI.fsPassage = function() { } App.Events.addNode(el, r, "p"); - /* Physical Idealist vs Hedonist */ p = document.createElement("p"); r = []; diff --git a/src/futureSocieties/futureSociety.js b/src/futureSocieties/futureSociety.js index a59df4b695c..1be2fda9f85 100644 --- a/src/futureSocieties/futureSociety.js +++ b/src/futureSocieties/futureSociety.js @@ -51,9 +51,11 @@ globalThis.FutureSocieties = (function() { * @param {number} progress */ function applyBroadProgress(arcologyID, progress) { + /** @type {FC.ArcologyState} */ const arcology = V.arcologies[arcologyID]; for (const fs of activeFSes(arcology)) { if (fs !== "FSNull") { // does not progress this way + // @ts-ignore // Because of activeFSes() we know it cannot be "unset", the only valid non numeric value. arcology[fs] += progress; } } @@ -68,6 +70,7 @@ globalThis.FutureSocieties = (function() { for (const fs of activeFSes(arcology)) { if (fs !== "FSNull") { // no conventional progress if (arcology[fs] > V.FSLockinLevel) { + // @ts-ignore // Because of activeFSes() we know it cannot be "unset", the only valid non numeric value. arcology.influenceBonus += arcology[fs] - V.FSLockinLevel; arcology[fs] = V.FSLockinLevel; } @@ -232,6 +235,7 @@ globalThis.FutureSocieties = (function() { purged.push(fs); arc[fs] = "unset"; } else { + // @ts-ignore // Because of activeFSes() we know it cannot be "unset", the only valid non numeric value. arc[fs] -= 10; } } @@ -450,7 +454,10 @@ globalThis.FutureSocieties = (function() { const arc = V.arcologies[0]; if (FSProp && Number.isFinite(arc[FSProp])) { - arc[FSProp] = Math.clamp(arc[FSProp] + magnitude * V.FSSingleSlaveRep, 0, 100); + /** @type {number} */ + // @ts-ignore // We know this is true because of Number.isFinite() + const n = arc[FSProp]; + arc[FSProp] = Math.clamp(n + magnitude * V.FSSingleSlaveRep, 0, 100); } } diff --git a/src/gui/Encyclopedia/encyclopediaEntries.js b/src/gui/Encyclopedia/encyclopediaEntries.js index 1a96162a5bc..fd3cf50d6d7 100644 --- a/src/gui/Encyclopedia/encyclopediaEntries.js +++ b/src/gui/Encyclopedia/encyclopediaEntries.js @@ -72,7 +72,6 @@ App.Encyclopedia.Entries = (function() { App.UI.DOM.combineNodes(topic("Rest"), " is an assignment mostly used to improve ", encyLink("health", "Health"), ". It can be useful to order slaves you wish to intensively modify to rest, since most modifications damage health. It will synergize with curative treatments, providing bonus healing when both are simultaneously applied."); - entries.sexualServitude = () => App.UI.DOM.combineNodes(topic("Sexual servitude"), " is an assignment which pleases other slaves by forcing the slave to service them sexually. Useful for driving the targeted slave's ", diff --git a/src/gui/interactiveDetails.js b/src/gui/interactiveDetails.js index 113756d327e..647e970ea5e 100644 --- a/src/gui/interactiveDetails.js +++ b/src/gui/interactiveDetails.js @@ -7,7 +7,7 @@ App.UI.DOM.InteractiveDetails = class { * @param {function(): HTMLElement|DocumentFragment} [detailsGenerator] function which generates the contents of the details overlay (omit to disable details) * @param {string[]} [linkClasses=[]] list of extra CSS classes to apply to the link */ - constructor(linkText, detailsGenerator, linkClasses=[]) { + constructor(linkText, detailsGenerator, linkClasses = []) { this.span = App.UI.DOM.makeElement("span", "", "details-overlay"); this.span.style.visibility = "hidden"; this.link = detailsGenerator ? App.UI.DOM.link(linkText, () => this.toggle()) : App.UI.DOM.makeElement("span", linkText); diff --git a/src/gui/multipleInspect.js b/src/gui/multipleInspect.js index 93f5fb27a05..02d20945987 100644 --- a/src/gui/multipleInspect.js +++ b/src/gui/multipleInspect.js @@ -4,7 +4,7 @@ App.UI.MultipleInspect = (function() { * Intended for use from DOM passages. * @param {Array<App.Entity.SlaveState>} slaves * @param {boolean} showFamilyTree - * @param {string} [market] + * @param {FC.SlaveMarketName} [market] * @returns {DocumentFragment} */ function MultipleInspectDOM(slaves, showFamilyTree, market) { @@ -18,7 +18,7 @@ App.UI.MultipleInspect = (function() { if (slaves.length > 1 && showFamilyTree) { const button = App.UI.tabBar.tabButton(`familyTreeTab`, "Family Tree"); - button.addEventListener('click', event => { + button.addEventListener('click', () => { renderFamilyTree(slaves, slaves[0].ID); }); tabBar.append(button); diff --git a/src/gui/options/options.js b/src/gui/options/options.js index f91cfee161a..90faa04dd30 100644 --- a/src/gui/options/options.js +++ b/src/gui/options/options.js @@ -82,7 +82,6 @@ App.UI.optionsPassage = function() { ) ); - if (isNaN(V.rep)) { links.push( App.UI.DOM.link( @@ -296,7 +295,6 @@ App.UI.optionsPassage = function() { el.append(options.render()); - App.UI.DOM.appendNewElement("h2", el, "Images"); el.append(App.UI.artOptions()); @@ -483,7 +481,6 @@ App.UI.optionsPassage = function() { .addValueList([["Extremely fast", 2], ["Very fast", 1.5], ["Fast", 1.25], ["Normal", 1], ["Slow", 0.75], ["Very slow", 0.5]]); } - if (V.SecExp.settings.battle.enabled > 0) { options.addOption("Commanders gain a prestige rank every 10 victories", "allowSlavePrestige", V.SecExp.settings.battle) .addValue("Yes", 1).on().addValue("No", 0).off(); @@ -610,7 +607,6 @@ App.UI.optionsPassage = function() { tr.append(td); table.append(tr); - tr = document.createElement("tr"); td = document.createElement("td"); td.style.textAlign = "right"; @@ -828,7 +824,6 @@ App.UI.optionsPassage = function() { r.push(App.UI.DOM.makeElement("span", "Cheating will be flagged in your save", "note")); App.Events.addNode(el, r, "div", "scLink2"); - SectorCounts(); links = []; @@ -855,7 +850,6 @@ App.UI.optionsPassage = function() { ); App.UI.DOM.appendNewElement("div", el, App.UI.DOM.generateLinksStrip(links), "scLink2"); - links = []; links.push( App.UI.DOM.link( diff --git a/src/gui/options/summaryOptions.js b/src/gui/options/summaryOptions.js index 969394b0fa1..9f00e789743 100644 --- a/src/gui/options/summaryOptions.js +++ b/src/gui/options/summaryOptions.js @@ -40,7 +40,7 @@ App.UI.summaryOptions = function() { App.UI.DOM.appendNewElement("h2", el, "Individual panels"); App.UI.DOM.appendNewElement("div", el, "Sample summary:"); - el.append(App.UI.SlaveList.render([V.slaves.random().ID], new Array(), App.UI.SlaveList.SlaveInteract.stdInteract)); + el.append(App.UI.SlaveList.render([V.slaves.random().ID], [], App.UI.SlaveList.SlaveInteract.stdInteract)); options = (new App.UI.OptionsGroup()).enableDoubleColumn(); diff --git a/src/gui/quicklinks.js b/src/gui/quicklinks.js index f993e46a203..151ef419884 100644 --- a/src/gui/quicklinks.js +++ b/src/gui/quicklinks.js @@ -352,7 +352,6 @@ App.UI.quickMenu = (function() { addBackLink(links); div.append(...links); - // traverse from current passage up to uncollapse. if (currentPassage !== null) { while (!currentPassage.classList.contains("quick-links")) { diff --git a/src/gui/storyCaption.js b/src/gui/storyCaption.js index c5fe10d4fa5..57e9de9ff6e 100644 --- a/src/gui/storyCaption.js +++ b/src/gui/storyCaption.js @@ -244,9 +244,9 @@ App.UI.storyCaption = function() { App.UI.DOM.appendNewElement("span", div, name, "pink"); div.append(" | "); if (pops > cap) { - App.UI.DOM.appendNewElement("span", div, pops, "warning"); + App.UI.DOM.appendNewElement("span", div, String(pops), "warning"); } else { - div.append(pops); + div.append(String(pops)); } div.append(`/${cap}`); return div; @@ -467,6 +467,7 @@ App.UI.storyCaption = function() { } function startingGirls() { + // @ts-ignore // In starting girls we know that there is always an active slave let _slaveCost = startingSlaveCost(V.activeSlave); const p = document.createElement("p"); -- GitLab