Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfixes; add link option to planet/moon #393

Merged
merged 7 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,4 +1238,9 @@ export function getWormAlbum(civShort: string): string {
return "EisHub Shaihuluda";
}
return '';
}

export function limitCreatureSize(input: HTMLInputElement) {
const firstLetter = input.value.substring(0, 1);
input.maxLength = firstLetter === '-' ? 4 : 3; // NoSonar negative numbers must have a limit of 4 to allow for `-0.1`. Else use 3 for `0.1`
}
6 changes: 6 additions & 0 deletions src/htmlSnippets/creatureInputs.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@
</div>
<div class="tableCell data" data-fauna="section${i}" data-section="fauna fauna${i}">
<input data-dest="faunaDiscoverer${i}" type="text" id="faunaDiscovererInput${i}">
</div>
<div class="tableCell text" data-fauna="section${i}" data-section="fauna fauna${i}">
<label for="faunaLinkCheckbox${i}">Link item:</label>
</div>
<div class="tableCell data" data-fauna="section${i}" data-section="fauna fauna${i}">
<input data-dest-noauto="faunaLink${i}" type="checkbox" id="faunaLinkCheckbox${i}" data-evt-id="creatureLink">
</div>
6 changes: 6 additions & 0 deletions src/htmlSnippets/floraInputs.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@
</div>
<div class="tableCell data" data-flora="section${i}" data-section="flora flora${i}">
<input data-dest="floraDiscoverer${i}" type="text" id="floraDiscovererInput${i}">
</div>
<div class="tableCell text" data-flora="section${i}" data-section="flora flora${i}">
<label for="floraLinkCheckbox${i}">Link item:</label>
</div>
<div class="tableCell data" data-flora="section${i}" data-section="flora flora${i}">
<input data-dest-noauto="floraLink${i}" type="checkbox" id="floraLinkCheckbox${i}" data-evt-id="floraLink">
</div>
6 changes: 6 additions & 0 deletions src/htmlSnippets/mineralInputs.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@
</div>
<div class="tableCell data" data-mineral="section${i}" data-section="mineral mineral${i}">
<input data-dest="mineralDiscoverer${i}" type="text" id="mineralDiscovererInput${i}">
</div>
<div class="tableCell text" data-mineral="section${i}" data-section="mineral mineral${i}">
<label for="mineralLinkCheckbox${i}">Link item:</label>
</div>
<div class="tableCell data" data-mineral="section${i}" data-section="mineral mineral${i}">
<input data-dest-noauto="mineralLink${i}" type="checkbox" id="mineralLinkCheckbox${i}" data-evt-id="mineralLink">
</div>
8 changes: 4 additions & 4 deletions src/miscLogic/celestialobjectslogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ export function docByExternal() {
* Add percentage sign to e-sell/buy property data for wikiCode output.
* @param {HTMLElement|null} element - the element to apply percentage formatting to.
*/
export function wikiCodePercentage(element: HTMLInputElement | null = null) {
export function wikiCodePercentage(element: HTMLInputElement | null = null, decimals: number = 0) {
if (!element) {
const inputs: NodeListOf<HTMLInputElement> = document.querySelectorAll('[data-percentage-input]');
for (const input of Array.from(inputs)) {
wikiCodePercentage(input);
wikiCodePercentage(input, decimals);
}
return;
}
const dest = element.dataset.destNoauto as string;
const propertyValue = pageData[dest] as string;
const propertyData = numberError(element, propertyValue);
const propertyValue = element.value;
const propertyData = numberError(element, propertyValue, decimals);
wikiCode(propertyData ? propertyData + '%' : '', dest);
}

Expand Down
40 changes: 35 additions & 5 deletions src/miscLogic/planetMoonLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoverview Provides functions that can be used by Planet and Moon pages.
*/

import { addDomAsElement, extractNumber, forceDatalist, getChildIndex, getWormAlbum, image, loadHTML, oddEven, removeSection, removeSpecificSection, sanitiseString, setDropdownOptions, sortObj, toggleSection, wikiCode } from '../common';
import { addDomAsElement, extractNumber, forceDatalist, getChildIndex, getWormAlbum, image, limitCreatureSize, loadHTML, oddEven, removeSection, removeSpecificSection, sanitiseString, setDropdownOptions, sortObj, toggleSection, wikiCode } from '../common';
import { globalElements, globalFunctions, links, pageData } from '../variables/objects';
import creatureInputs from '../htmlSnippets/creatureInputs.html?raw';
import floraInputs from '../htmlSnippets/floraInputs.html?raw';
Expand Down Expand Up @@ -210,7 +210,6 @@ export function sentinelSentence() {
/**
* Adds a new fauna section to the page and updates the output section accordingly.
*
* @async
* @param {Element} element - The button element that was clicked to add the fauna section.
* @returns {Promise} A promise that resolves when the fauna section is successfully added.
**/
Expand Down Expand Up @@ -247,12 +246,22 @@ export function addFauna(element: HTMLButtonElement) {
handler: 'change',
func: function () { addGenus(this as unknown as HTMLSelectElement) }
},
{
element: 'creaturePropInput',
handler: 'input',
func: function () { limitCreatureSize(this as unknown as HTMLInputElement) }
},
{
element: 'creatureLink',
handler: 'change',
func: function () { linkItem(this as unknown as HTMLInputElement) }
},
]

const inputDom = loadHTML(creatureInputs, { i }, evtListeners) as Document;

const outputHTML = `<div data-fauna="section${i}">|-</div>
<div data-fauna="section${i}">|[[File:<output id="faunaFile${i}"></output>|150px]] || <output id="faunaName${i}" name="faunaName${i}"></output> || <output id="faunaRarity${i}"></output> / <output id="faunaEcosystem${i}"></output> / <output id="faunaActivity${i}"> </output> <output id="faunaHemisphere${i}"></output> || <output id="faunaGenus${i}"></output> || <output id="faunaHeight${i}"></output>m || <output id="faunaWeight${i}"></output>kg || <output id="faunaDiscoverer${i}"></output></div>`;
<div data-fauna="section${i}">|[[File:<output id="faunaFile${i}"></output>|150px]] || <span style="display:none" name="faunaLink${i}">[[</span><output id="faunaName${i}" name="faunaName${i}"></output><span style="display:none" name="faunaLink${i}">]]</span> || <output id="faunaRarity${i}"></output> / <output id="faunaEcosystem${i}"></output> / <output id="faunaActivity${i}"> </output> <output id="faunaHemisphere${i}"></output> || <output id="faunaGenus${i}"></output> || <output id="faunaHeight${i}"></output>m || <output id="faunaWeight${i}"></output>kg || <output id="faunaDiscoverer${i}"></output></div>`;

addDomAsElement(inputDom, inputSection as HTMLElement, 'beforebegin');

Expand Down Expand Up @@ -296,12 +305,17 @@ export function addFlora(element: HTMLButtonElement) {
handler: 'input',
func: function () { floraMineralResourceLinks(this as unknown as HTMLInputElement) }
},
{
element: 'floraLink',
handler: 'change',
func: function () { linkItem(this as unknown as HTMLInputElement) }
},
]

const inputDom = loadHTML(floraInputs, { i }, evtListeners) as Document;

const outputHTML = `<div data-flora="section${i}">|-</div>
<div data-flora="section${i}">|[[File:<output id="floraFile${i}"></output>|150px]] || <output id="floraName${i}" name="floraName${i}"></output> || <output id="floraAge${i}"></output> || <output id="floraRoot${i}"></output> || <output id="floraNut${i}"></output> || <output id="floraNote${i}"></output> || <output id="floraElements${i}"></output> || <output id="floraDiscoverer${i}"></output></div>`;
<div data-flora="section${i}">|[[File:<output id="floraFile${i}"></output>|150px]] || <span style="display:none" name="floraLink${i}">[[</span><output id="floraName${i}" name="floraName${i}"></output><span style="display:none" name="floraLink${i}">]]</span> || <output id="floraAge${i}"></output> || <output id="floraRoot${i}"></output> || <output id="floraNut${i}"></output> || <output id="floraNote${i}"></output> || <output id="floraElements${i}"></output> || <output id="floraDiscoverer${i}"></output></div>`;

addDomAsElement(inputDom, inputSection as HTMLElement, 'beforebegin');

Expand Down Expand Up @@ -343,12 +357,17 @@ export function addMineral(element: HTMLButtonElement) {
handler: 'input',
func: function () { floraMineralResourceLinks(this as unknown as HTMLInputElement) }
},
{
element: 'mineralLink',
handler: 'change',
func: function () { linkItem(this as unknown as HTMLInputElement) }
},
]

const inputDom = loadHTML(mineralInputs, { i }, eventListeners) as Document;

const outputHTML = `<div data-mineral="section${i}">|-</div>
<div data-mineral="section${i}">|[[File:<output id="mineralFile${i}"></output>|150px]] || <output id="mineralName${i}" name="mineralName${i}"></output> || <output id="mineralMetal${i}"></output> || <output id="mineralFormation${i}"></output> || <output id="mineralNote${i}"></output> || <output id="mineralElements${i}"></output> || <output id="mineralDiscoverer${i}"></output></div>`;
<div data-mineral="section${i}">|[[File:<output id="mineralFile${i}"></output>|150px]] || <span style="display:none" name="mineralLink${i}">[[</span><output id="mineralName${i}" name="mineralName${i}"></output><span style="display:none" name="mineralLink${i}">]]</span> || <output id="mineralMetal${i}"></output> || <output id="mineralFormation${i}"></output> || <output id="mineralNote${i}"></output> || <output id="mineralElements${i}"></output> || <output id="mineralDiscoverer${i}"></output></div>`;

addDomAsElement(inputDom, inputSection as HTMLElement, 'beforebegin');

Expand Down Expand Up @@ -540,4 +559,15 @@ export function resetExternal() {

enableResourceAdd();
if (typeof globalFunctions.enableMoonAdd == 'function') globalFunctions.enableMoonAdd();
}

function linkItem(element: HTMLInputElement) {
const isChecked = element.checked;
const dest = element.dataset.destNoauto;
if (dest) {
const brackets: NodeListOf<HTMLSpanElement> = document.getElementsByName(dest);
for (const bracket of Array.from(brackets)) {
bracket.style.display = isChecked ? '' : 'none';
}
}
}
4 changes: 2 additions & 2 deletions src/pages/fauna/elementFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addInfoBullet, enableTextMarking, hideOrgName, numberError } from "../../common";
import { addInfoBullet, enableTextMarking, hideOrgName, limitCreatureSize, numberError } from "../../common";
import { planetMoonSentence } from "../../miscLogic/locationLogic";
import { toggleRedirect } from "../../modules/actions";
import { albumDiscoverer, albumName, albumOther } from "../../modules/albumactions";
Expand Down Expand Up @@ -52,7 +52,7 @@ const creatureElementFunctions: ElementFunctions = [
},
{
element: ['heightInput', 'height2Input'],
func: function () { genderProps("height", "height2"); albumOther(); numberError(this as unknown as HTMLInputElement) }
func: function () { genderProps("height", "height2"); albumOther(); numberError(this as unknown as HTMLInputElement); limitCreatureSize(this as unknown as HTMLInputElement) }
},
{
element: ['weightInput', 'weight2Input'],
Expand Down
4 changes: 2 additions & 2 deletions src/pages/fauna/fauna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export function genderProps(property1Name: string, property2Name: string) {
// adds .0
let property1Number, property2Number;
if (property1Name != 'gender') {
property1Number = parseFloat(property1Value) ? parseFloat(property1Value).toFixed(1) : '';
property2Number = parseFloat(property2Value) ? parseFloat(property2Value).toFixed(1) : '';
property1Number = isNaN(parseFloat(property1Value)) ? '' : parseFloat(property1Value).toFixed(1);
property2Number = isNaN(parseFloat(property2Value)) ? '' : parseFloat(property2Value).toFixed(1);
}

const property1Data = property1Number ?? property1Value;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/system/elementFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const systemElementFunctions: ElementFunctions = [
},
{
element: ['economybuyInput', 'economysellInput'],
func: function () { wikiCodePercentage(this as unknown as HTMLInputElement) }
func: function () { wikiCodePercentage(this as unknown as HTMLInputElement, 1) }
},
{
element: ['wealthInput', 'conflictInput'],
Expand Down
5 changes: 5 additions & 0 deletions src/pages/system/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ export function enableTradeableAdd() {
export function resetExternal() {
const sections: NodeListOf<HTMLDivElement> = document.querySelectorAll('[data-tradeable], [data-planet]');
removeSection(Array.from(sections));
const markedElements = document.querySelectorAll('.mark');
for (const element of Array.from(markedElements)) {
element.classList.remove('mark');
}
}

/**
Expand Down Expand Up @@ -825,6 +829,7 @@ export function civCatalog() {
export function generateGalleryArray() {
const array: Array<string> = [
'',
'Analysis Visor',
'System Exploration Guide',
'System Page',
'Default SS Multi-Tool',
Expand Down
Loading