mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: layers basic typization
This commit is contained in:
parent
7c2c624417
commit
1847772d74
15 changed files with 337 additions and 194 deletions
|
|
@ -1,3 +1,3 @@
|
|||
export function isCtrlClick(event: MouseEvent) {
|
||||
return event.ctrlKey || event.metaKey;
|
||||
export function isCtrlPressed(event?: MouseEvent) {
|
||||
return event && (event.ctrlKey || event.metaKey);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,29 @@ export function getNextId(core: string, index = 1) {
|
|||
}
|
||||
|
||||
export function getInputValue(id: string) {
|
||||
const $element = byId(id);
|
||||
if (!$element) throw new Error(`Element ${id} not found`);
|
||||
if (!("value" in $element)) throw new Error(`Element ${id} is not an input`);
|
||||
|
||||
return (byId(id) as HTMLInputElement)?.value;
|
||||
}
|
||||
|
||||
export function getInputNumber(id: string) {
|
||||
const $element = byId(id);
|
||||
if (!$element) throw new Error(`Element ${id} not found`);
|
||||
if (!("value" in $element)) throw new Error(`Element ${id} is not an input`);
|
||||
|
||||
return (byId(id) as HTMLInputElement)?.valueAsNumber;
|
||||
}
|
||||
|
||||
export function setInputValue(id: string, value: string | number | boolean) {
|
||||
const $element = byId(id);
|
||||
if (!$element) throw new Error(`Element ${id} not found`);
|
||||
if (!("value" in $element)) throw new Error(`Element ${id} is not an input`);
|
||||
|
||||
($element as HTMLInputElement).value = String(value);
|
||||
}
|
||||
|
||||
// apply drop-down menu option. If the value is not in options, add it
|
||||
export function applyDropdownOption($select: HTMLSelectElement, value: string, name = value) {
|
||||
const isExisting = Array.from($select.options).some(o => o.value === value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue