From 86d8317e5acace9e43784fdea2849b03ee4d4c28 Mon Sep 17 00:00:00 2001 From: goldbuick Date: Sat, 21 Dec 2024 09:07:53 -0500 Subject: [PATCH] making universal NAME function --- zss/device.ts | 7 ++++--- zss/device/synth.ts | 3 ++- zss/firmware/audio.ts | 4 ++-- zss/firmware/cli.ts | 6 +++--- zss/firmware/gadget.ts | 6 +++--- zss/firmware/loader.ts | 3 ++- zss/firmware/loader/binaryloader.ts | 9 +++++---- zss/firmware/loader/parsefile.ts | 5 +++-- zss/gadget/components/panel/number.tsx | 3 ++- zss/gadget/components/panel/panelitem.tsx | 3 ++- zss/gadget/components/panel/text.tsx | 3 ++- zss/gadget/components/tape/elements/editorinput.tsx | 4 ++-- .../components/tape/elements/terminalinput.tsx | 3 ++- zss/gadget/components/tape/elements/terminalitem.tsx | 3 ++- zss/gadget/components/userinput.tsx | 5 +++-- zss/gadget/data/api.ts | 4 ++-- zss/lang/transformer.ts | 5 +++-- zss/memory/atomics.ts | 5 ++--- zss/memory/board.ts | 4 ++-- zss/memory/book.ts | 12 ++++++------ zss/memory/codepage.ts | 10 +++++----- zss/memory/index.ts | 10 +++++----- zss/words/category.ts | 4 ++-- zss/words/collision.ts | 6 +++--- zss/words/color.ts | 4 ++-- zss/words/dir.ts | 4 ++-- zss/words/expr.ts | 5 +++-- zss/words/stats.ts | 4 ++-- zss/words/types.ts | 4 ++++ 29 files changed, 82 insertions(+), 66 deletions(-) diff --git a/zss/device.ts b/zss/device.ts index 881e96ece..545cdfb92 100644 --- a/zss/device.ts +++ b/zss/device.ts @@ -1,6 +1,7 @@ import { MESSAGE } from './chip' import { hub } from './hub' import { createsid } from './mapping/guid' +import { NAME } from './words/types' export function createmessage( target: string, @@ -33,8 +34,8 @@ export function createdevice( onMessage: MESSAGE_FUNC, ) { const id = createsid() - const iname = name.toLowerCase() - const itopics = topics.map((tag) => tag.toLowerCase()) + const iname = NAME(name) + const itopics = topics.map(NAME) const device: DEVICE = { id() { @@ -54,7 +55,7 @@ export function createdevice( }, handle(message) { const { target, path } = parsetarget(message.target) - const itarget = target.toLowerCase() + const itarget = NAME(target) // we match by topics if (itopics.findIndex((tag) => tag === 'all' || tag === itarget) !== -1) { diff --git a/zss/device/synth.ts b/zss/device/synth.ts index 56c53aeb4..87c426430 100644 --- a/zss/device/synth.ts +++ b/zss/device/synth.ts @@ -28,6 +28,7 @@ import { SYNTH_NOTE_ON, } from 'zss/mapping/play' import { isarray, isnumber, ispresent, isstring } from 'zss/mapping/types' +import { NAME } from 'zss/words/types' import { api_error, tape_info } from './api' @@ -585,7 +586,7 @@ function validatesynthtype( maybepartials: string | number | number[], ) { if (isstring(value)) { - const maybetype = value.toLowerCase() + const maybetype = NAME(value) let type = maybetype // validate partials diff --git a/zss/firmware/audio.ts b/zss/firmware/audio.ts index f9c8fbe01..a9f7b63c9 100644 --- a/zss/firmware/audio.ts +++ b/zss/firmware/audio.ts @@ -3,7 +3,7 @@ import { synth_play, synth_voice, synth_voicefx } from 'zss/device/api' import { createfirmware } from 'zss/firmware' import { isnumber, isstring } from 'zss/mapping/types' import { ARG_TYPE, readargs } from 'zss/words/reader' -import { WORD } from 'zss/words/types' +import { NAME, WORD } from 'zss/words/types' const isfx = ['echo', 'reverb', 'chorus', 'phaser', 'distortion', 'vibrato'] @@ -20,7 +20,7 @@ function handlesynthvoice(idx: number, words: WORD[]) { const [voiceorfx] = readargs(words, 0, [ARG_TYPE.NUMBER_OR_STRING]) if (isnumber(voiceorfx)) { synth_voice('audio', idx, 'volume', voiceorfx) - } else if (isfx.includes(voiceorfx.toLowerCase())) { + } else if (isfx.includes(NAME(voiceorfx))) { const [maybeconfig, maybevalue] = readargs(words, 1, [ ARG_TYPE.NUMBER_OR_STRING, ARG_TYPE.MAYBE_NUMBER_OR_STRING, diff --git a/zss/firmware/cli.ts b/zss/firmware/cli.ts index 663d2dc34..6f920159b 100644 --- a/zss/firmware/cli.ts +++ b/zss/firmware/cli.ts @@ -30,7 +30,7 @@ import { CODE_PAGE, CODE_PAGE_TYPE } from 'zss/memory/types' import { ARG_TYPE, READ_CONTEXT, readargs } from 'zss/words/reader' import { stattypestring } from 'zss/words/stats' import { metakey } from 'zss/words/system' -import { STAT_TYPE } from 'zss/words/types' +import { NAME, STAT_TYPE } from 'zss/words/types' import { bg, fg, @@ -179,7 +179,7 @@ export const CLI_FIRMWARE = createfirmware({ const [maybetype, ...args] = words.map(maptostring) const maybename = args.join(' ') // attempt to check first word as codepage type to create - switch (maybetype.toLowerCase()) { + switch (NAME(maybetype)) { case stattypestring(STAT_TYPE.LOADER): codepage = memoryensuresoftwarecodepage( MEMORY_LABEL.CONTENT, @@ -190,7 +190,7 @@ export const CLI_FIRMWARE = createfirmware({ default: codepage = memoryensuresoftwarecodepage( MEMORY_LABEL.CONTENT, - `${maybetype} ${maybename}`, + [maybetype, ...args].join(' '), CODE_PAGE_TYPE.OBJECT, ) break diff --git a/zss/firmware/gadget.ts b/zss/firmware/gadget.ts index 727c7ba71..218e2ea03 100644 --- a/zss/firmware/gadget.ts +++ b/zss/firmware/gadget.ts @@ -16,7 +16,7 @@ import { bookelementdisplayread } from 'zss/memory/book' import { BOARD_ELEMENT } from 'zss/memory/types' import { ARG_TYPE, READ_CONTEXT, readargs } from 'zss/words/reader' import { statformat } from 'zss/words/stats' -import { COLOR, STAT_TYPE } from 'zss/words/types' +import { COLOR, NAME, STAT_TYPE } from 'zss/words/types' export const GADGET_FIRMWARE = createfirmware({ get() { @@ -75,7 +75,7 @@ export const GADGET_FIRMWARE = createfirmware({ } // the intent here is to gather a list of target chip ids - const ltarget = target.toLowerCase() + const ltarget = NAME(target) switch (ltarget) { case 'all': for (const id of Object.keys(READ_CONTEXT.board?.objects ?? {})) { @@ -140,7 +140,7 @@ export const GADGET_FIRMWARE = createfirmware({ // --- .command('gadget', (_, words) => { const [edge] = readargs(words, 0, [ARG_TYPE.STRING]) - const edgeConst = PANEL_TYPE_MAP[edge.toLowerCase()] + const edgeConst = PANEL_TYPE_MAP[NAME(edge)] if (edgeConst === PANEL_TYPE.SCROLL) { const [, name, size] = readargs(words, 0, [ ARG_TYPE.STRING, diff --git a/zss/firmware/loader.ts b/zss/firmware/loader.ts index 910f20775..9b461dfb8 100644 --- a/zss/firmware/loader.ts +++ b/zss/firmware/loader.ts @@ -9,6 +9,7 @@ import { memoryreadbinaryfile, } from 'zss/memory' import { ARG_TYPE, readargs } from 'zss/words/reader' +import { NAME } from 'zss/words/types' import { binaryloader } from './loader/binaryloader' @@ -18,7 +19,7 @@ export const LOADER_FIRMWARE = createfirmware({ const binaryfile = memoryreadbinaryfile(chip.id()) if (ispresent(binaryfile)) { - switch (name.toLowerCase()) { + switch (NAME(name)) { case 'filename': // name of binary file return [ispresent(binaryfile.filename), binaryfile.filename] diff --git a/zss/firmware/loader/binaryloader.ts b/zss/firmware/loader/binaryloader.ts index 4ca8de850..4e849df4b 100644 --- a/zss/firmware/loader/binaryloader.ts +++ b/zss/firmware/loader/binaryloader.ts @@ -1,15 +1,16 @@ import { FIRMWARE_COMMAND } from 'zss/firmware' -import { isnumber, ispresent, isstring, MAYBE_NUMBER } from 'zss/mapping/types' +import { isnumber, ispresent, isstring, MAYBE } from 'zss/mapping/types' import { memoryreadbinaryfile } from 'zss/memory' import { BINARY_READER } from 'zss/memory/types' import { ARG_TYPE, readargs } from 'zss/words/reader' +import { NAME } from 'zss/words/types' -function readbin(binaryfile: BINARY_READER, kind: string): MAYBE_NUMBER { +function readbin(binaryfile: BINARY_READER, kind: string): MAYBE { if (!ispresent(binaryfile)) { return undefined } - const lkind = kind.toLowerCase() + const lkind = NAME(kind) const le = lkind.endsWith('le') switch (lkind) { case 'float32': @@ -83,7 +84,7 @@ export const binaryloader: FIRMWARE_COMMAND = (chip, words) => { } const [kind] = readargs(words, 0, [ARG_TYPE.STRING]) - const lkind = kind.toLowerCase() + const lkind = NAME(kind) switch (lkind) { case 'seek': { const [cursor] = readargs(words, 1, [ARG_TYPE.NUMBER]) diff --git a/zss/firmware/loader/parsefile.ts b/zss/firmware/loader/parsefile.ts index 148c4ff59..73f0e1807 100644 --- a/zss/firmware/loader/parsefile.ts +++ b/zss/firmware/loader/parsefile.ts @@ -14,6 +14,7 @@ import { codepagereadtypetostring, createcodepage, } from 'zss/memory/codepage' +import { NAME } from 'zss/words/types' export function mimetypeofbytesread(filename: string, filebytes: Uint8Array) { const bytes = [...filebytes.slice(0, 4)] @@ -106,8 +107,8 @@ export async function parsebinaryfile( try { tape_info('parsebinaryfile', file.name) const arraybuffer = await file.arrayBuffer() - const ext = file.name.split('.').slice(-1)[0] - onbuffer((ext ?? '').toLowerCase(), new Uint8Array(arraybuffer)) + const ext = file.name.split('.').slice(-1)[0] ?? '' + onbuffer(NAME(ext), new Uint8Array(arraybuffer)) } catch (err: any) { api_error('memory', 'crash', err.message) } diff --git a/zss/gadget/components/panel/number.tsx b/zss/gadget/components/panel/number.tsx index 6fa8dce77..9fbc7bfa0 100644 --- a/zss/gadget/components/panel/number.tsx +++ b/zss/gadget/components/panel/number.tsx @@ -2,6 +2,7 @@ import { useCallback, useState } from 'react' import { modemwritevaluenumber, useWaitForValueNumber } from 'zss/device/modem' import { paneladdress } from 'zss/gadget/data/types' import { tokenizeandwritetextformat } from 'zss/words/textformat' +import { NAME } from 'zss/words/types' import { useBlink } from '../hooks' import { @@ -132,7 +133,7 @@ export function PanelItemNumber({ CANCEL_BUTTON={ok} OK_BUTTON={ok} keydown={(event) => { - switch (event.key.toLowerCase()) { + switch (NAME(event.key)) { case 'delete': if (strvalue.length > 0) { setstrValue((state) => strsplice(state, cursor, 1)) diff --git a/zss/gadget/components/panel/panelitem.tsx b/zss/gadget/components/panel/panelitem.tsx index 0ee92f403..c2215be19 100644 --- a/zss/gadget/components/panel/panelitem.tsx +++ b/zss/gadget/components/panel/panelitem.tsx @@ -3,6 +3,7 @@ import { useGadgetClientPlayer } from 'zss/gadget/data/state' import { PANEL_ITEM } from 'zss/gadget/data/types' import { isarray } from 'zss/mapping/types' import { writetextreset } from 'zss/words/textformat' +import { NAME } from 'zss/words/types' import { PanelItemContent } from './content' import { PanelItemHotkey } from './hotkey' @@ -45,7 +46,7 @@ export function PanelItem({ item, active }: PanelItemProps) { context, } - switch (input.toLowerCase()) { + switch (NAME(input)) { case 'hk': case 'hotkey': return diff --git a/zss/gadget/components/panel/text.tsx b/zss/gadget/components/panel/text.tsx index a47905540..235c389aa 100644 --- a/zss/gadget/components/panel/text.tsx +++ b/zss/gadget/components/panel/text.tsx @@ -9,6 +9,7 @@ import { applycolortoindexes, applystrtoindex, } from 'zss/words/textformat' +import { NAME } from 'zss/words/types' import { useBlink } from '../hooks' import { UserFocus, UserInput, UserInputMods } from '../userinput' @@ -126,7 +127,7 @@ export function PanelItemText({ } const { key } = event - const lkey = key.toLowerCase() + const lkey = NAME(key) const mods: UserInputMods = { alt: event.altKey, ctrl: ismac ? event.metaKey : event.ctrlKey, diff --git a/zss/gadget/components/tape/elements/editorinput.tsx b/zss/gadget/components/tape/elements/editorinput.tsx index 293d60e42..e7623e8d2 100644 --- a/zss/gadget/components/tape/elements/editorinput.tsx +++ b/zss/gadget/components/tape/elements/editorinput.tsx @@ -10,7 +10,7 @@ import { useTapeEditor } from 'zss/gadget/data/state' import { clamp } from 'zss/mapping/number' import { MAYBE, ispresent } from 'zss/mapping/types' import { applystrtoindex, textformatreadedges } from 'zss/words/textformat' -import { PT } from 'zss/words/types' +import { NAME, PT } from 'zss/words/types' import { useBlink, useWriteText } from '../../hooks' import { Scrollable } from '../../scrollable' @@ -165,7 +165,7 @@ export function EditorInput({ } const { key } = event - const lkey = key.toLowerCase() + const lkey = NAME(key) const mods = modsfromevent(event) switch (lkey) { diff --git a/zss/gadget/components/tape/elements/terminalinput.tsx b/zss/gadget/components/tape/elements/terminalinput.tsx index 7e8bb66f1..8ca250105 100644 --- a/zss/gadget/components/tape/elements/terminalinput.tsx +++ b/zss/gadget/components/tape/elements/terminalinput.tsx @@ -16,6 +16,7 @@ import { textformatreadedges, tokenizeandwritetextformat, } from 'zss/words/textformat' +import { NAME } from 'zss/words/types' import { useBlink, useWriteText } from '../../hooks' import { setuplogitem } from '../common' @@ -208,7 +209,7 @@ export function TerminalInput({ { const { key } = event - const lkey = key.toLowerCase() + const lkey = NAME(key) const mods = modsfromevent(event) switch (lkey) { case 'arrowleft': diff --git a/zss/gadget/components/tape/elements/terminalitem.tsx b/zss/gadget/components/tape/elements/terminalitem.tsx index 0d7f95482..1da273fab 100644 --- a/zss/gadget/components/tape/elements/terminalitem.tsx +++ b/zss/gadget/components/tape/elements/terminalitem.tsx @@ -5,6 +5,7 @@ import { tokenize, tokenizeandwritetextformat, } from 'zss/words/textformat' +import { NAME } from 'zss/words/types' import { TerminalItemInputProps, @@ -58,7 +59,7 @@ export function TerminalItem({ blink, active, text, y }: TerminalItemProps) { } // render hyperlink - switch (input.toLowerCase()) { + switch (NAME(input)) { case 'hk': case 'hotkey': return null diff --git a/zss/gadget/components/userinput.tsx b/zss/gadget/components/userinput.tsx index d3c300806..ab4afbc5a 100644 --- a/zss/gadget/components/userinput.tsx +++ b/zss/gadget/components/userinput.tsx @@ -13,6 +13,7 @@ import { vm_cli } from 'zss/device/api' import { getgadgetclientplayer } from 'zss/gadget/data/state' import { INPUT } from 'zss/gadget/data/types' import { ismac } from 'zss/words/system' +import { NAME } from 'zss/words/types' // user input @@ -92,7 +93,7 @@ function invoke(input: INPUT, mods: UserInputMods) { document.addEventListener( 'keydown', (event) => { - const key = event.key.toLowerCase() + const key = NAME(event.key) const mods = modsfromevent(event) // allowed shortcuts, all others we attempt to block @@ -195,7 +196,7 @@ document.addEventListener( document.addEventListener( 'keyup', (event) => { - const key = event.key.toLowerCase() + const key = NAME(event.key) const mods = modsfromevent(event) if (mods.alt) { diff --git a/zss/gadget/data/api.ts b/zss/gadget/data/api.ts index 9a1d11d72..68a1d4ba6 100644 --- a/zss/gadget/data/api.ts +++ b/zss/gadget/data/api.ts @@ -10,7 +10,7 @@ import { } from 'zss/device/modem' import { createsid } from 'zss/mapping/guid' import { ispresent, isnumber, isstring, MAYBE } from 'zss/mapping/types' -import { WORD } from 'zss/words/types' +import { NAME, WORD } from 'zss/words/types' import { GADGET_STATE, @@ -253,7 +253,7 @@ export function gadgethyperlink( } // package into a panel item - const linput = input.toLowerCase() + const linput = NAME(input) const hyperlink: WORD[] = [ chip.id(), diff --git a/zss/lang/transformer.ts b/zss/lang/transformer.ts index b75ce4239..1abfe48e8 100644 --- a/zss/lang/transformer.ts +++ b/zss/lang/transformer.ts @@ -1,6 +1,7 @@ import { CodeWithSourceMap, SourceNode } from 'source-map' import { deepcopy, ispresent, MAYBE } from 'zss/mapping/types' import { tokenize, MaybeFlag } from 'zss/words/textformat' +import { NAME } from 'zss/words/types' import { COMPARE, CodeNode, LITERAL, NODE, OPERATOR } from './visitor' @@ -281,7 +282,7 @@ function transformNode(ast: CodeNode): SourceNode { } return write(ast, ` // skipped ${ast.value}\n`) case NODE.LABEL: { - const llabel = ast.name.toLowerCase() + const llabel = NAME(ast.name) const ltype = ast.active ? 'label' : 'comment' if (!context.labels[llabel]) { context.labels[llabel] = [] @@ -289,7 +290,7 @@ function transformNode(ast: CodeNode): SourceNode { const lindex = (ast.active ? 1 : -1) * ast.lineindex context.labels[llabel].push(lindex) // document label - return write(ast, ` // ${lindex} ${ast.name} ${ltype}\n`) + return write(ast, ` // ${lindex} '${llabel}' ${ltype}\n`) } case NODE.HYPERLINK: return write(ast, [ diff --git a/zss/memory/atomics.ts b/zss/memory/atomics.ts index 620511613..a230a69a0 100644 --- a/zss/memory/atomics.ts +++ b/zss/memory/atomics.ts @@ -1,5 +1,4 @@ import { MAYBE, ispresent } from 'zss/mapping/types' -import { COLLISION } from 'zss/words/types' import { ispt } from 'zss/words/dir' import { readstrkindbg, @@ -7,7 +6,7 @@ import { readstrkindname, STR_KIND, } from 'zss/words/kind' -import { PT } from 'zss/words/types' +import { COLLISION, NAME, PT } from 'zss/words/types' import { boardelementbg, boardelementcolor, boardelementname } from './board' import { BOARD, BOARD_ELEMENT, BOARD_HEIGHT, BOARD_WIDTH } from './types' @@ -95,7 +94,7 @@ export function listelementsbyattr( return maybebyid } // check by name - const maybebyname = listnamedelements(board, idnameorpt.toLowerCase()) + const maybebyname = listnamedelements(board, NAME(idnameorpt)) if (maybebyname.length) { return maybebyname } diff --git a/zss/memory/board.ts b/zss/memory/board.ts index 2b571a5fc..a8753f4c3 100644 --- a/zss/memory/board.ts +++ b/zss/memory/board.ts @@ -10,7 +10,7 @@ import { ptapplydir, STR_DIR, } from 'zss/words/dir' -import { COLOR, DIR, PT } from 'zss/words/types' +import { COLOR, DIR, NAME, PT } from 'zss/words/types' import { listnamedelements, picknearestpt } from './atomics' import { exportboardelement, importboardelement } from './boardelement' @@ -113,7 +113,7 @@ export function boardelementread( } export function boardelementname(element: MAYBE) { - return (element?.name ?? element?.kinddata?.name ?? 'object').toLowerCase() + return NAME(element?.name ?? element?.kinddata?.name ?? 'object') } export function boardelementcolor(element: MAYBE) { diff --git a/zss/memory/book.ts b/zss/memory/book.ts index 4c651ffe8..9fa7cf635 100644 --- a/zss/memory/book.ts +++ b/zss/memory/book.ts @@ -3,7 +3,7 @@ import { createsid, createnameid } from 'zss/mapping/guid' import { TICK_FPS } from 'zss/mapping/tick' import { MAYBE, deepcopy, ispresent, isstring } from 'zss/mapping/types' import { STR_KIND } from 'zss/words/kind' -import { CATEGORY, COLLISION, COLOR, PT, WORD } from 'zss/words/types' +import { CATEGORY, COLLISION, COLOR, NAME, PT, WORD } from 'zss/words/types' import { checkcollision } from './atomics' import { @@ -84,7 +84,7 @@ export function bookreadcodepagebyaddress( return undefined } - const laddress = address.toLowerCase() + const laddress = NAME(address) const codepage = book.pages.find( (item) => item.id === address || laddress === codepagereadname(item), ) @@ -101,7 +101,7 @@ export function bookreadcodepagewithtype( return undefined } - const laddress = address.toLowerCase() + const laddress = NAME(address) const codepage = book.pages.find( (item) => codepagereadtype(item) === type && @@ -155,7 +155,7 @@ export function bookwritecodepage( export function bookclearcodepage(book: MAYBE, address: string) { const codepage = bookreadcodepagebyaddress(book, address) if (ispresent(book) && ispresent(codepage)) { - const laddress = address.toLowerCase() + const laddress = NAME(address) book.pages = book.pages.filter( (item) => item.id !== address && laddress !== codepagereadname(item), ) @@ -385,9 +385,9 @@ export function bookboardelementreadname( ) { const kind = bookelementkindread(book, element) if (ispresent(element?.id) && ispresent(element.x) && ispresent(element.y)) { - return (element.name ?? kind?.name ?? 'object').toLowerCase() + return NAME(element.name ?? kind?.name ?? 'object') } - return (element?.name ?? kind?.name ?? 'terrain').toLowerCase() + return NAME(element?.name ?? kind?.name ?? 'terrain') } export function bookboardnamedwrite( diff --git a/zss/memory/codepage.ts b/zss/memory/codepage.ts index fd34998b7..cda95d884 100644 --- a/zss/memory/codepage.ts +++ b/zss/memory/codepage.ts @@ -3,7 +3,7 @@ import { stat, tokenize } from 'zss/lang/lexer' import { createsid } from 'zss/mapping/guid' import { MAYBE, isnumber, ispresent, isstring } from 'zss/mapping/types' import { statformat, stattypestring } from 'zss/words/stats' -import { STAT_TYPE } from 'zss/words/types' +import { NAME, STAT_TYPE } from 'zss/words/types' import { createboard, exportboard, importboard } from './board' import { @@ -153,7 +153,7 @@ export function codepagereadstats(codepage: MAYBE): CODE_PAGE_STATS { const source = token.image.slice(1) const words = source.split(' ') const stat = statformat(words, isfirst) - const maybename = stat.values.join(' ').toLowerCase().trim() + const maybename = NAME(stat.values.join(' ')) isfirst = false switch (stat.type) { case STAT_TYPE.LOADER: @@ -183,7 +183,7 @@ export function codepagereadstats(codepage: MAYBE): CODE_PAGE_STATS { case STAT_TYPE.CONST: { const [maybename, maybevalue] = stat.values if (isstring(maybename)) { - const name = maybename.toLowerCase() + const name = NAME(maybename) if (isstring(maybevalue)) { // can we parse consts here ???? too ???? const numbervalue = parseFloat(maybevalue) @@ -205,7 +205,7 @@ export function codepagereadstats(codepage: MAYBE): CODE_PAGE_STATS { case STAT_TYPE.SCROLL: { const [maybename, ...args] = stat.values if (isstring(maybename)) { - const name = maybename.toLowerCase().trim() + const name = NAME(maybename) codepage.stats[name] = args } break @@ -254,7 +254,7 @@ export function codepagereadtypetostring(codepage: MAYBE) { export function codepagereadname(codepage: MAYBE) { const stats = codepagereadstats(codepage) - return (stats.name ?? '').toLowerCase() + return stats.name ?? '' } export function codepagereadstat(codepage: MAYBE, stat: string) { diff --git a/zss/memory/index.ts b/zss/memory/index.ts index 8f0a615e3..a76e2e0ca 100644 --- a/zss/memory/index.ts +++ b/zss/memory/index.ts @@ -27,7 +27,7 @@ import { tokenizeandmeasuretextformat, tokenizeandwritetextformat, } from 'zss/words/textformat' -import { COLOR, WORD } from 'zss/words/types' +import { COLOR, NAME, WORD } from 'zss/words/types' import { boarddeleteobject, @@ -116,10 +116,10 @@ export function memoryreadfirstbook(): MAYBE { } export function memoryreadbookbyaddress(address: string): MAYBE { - const laddress = address.toLowerCase() + const laddress = NAME(address) return ( MEMORY.books.get(address) ?? - memoryreadbooklist().find((item) => item.name.toLowerCase() === laddress) + memoryreadbooklist().find((item) => item.name === laddress) ) } @@ -234,7 +234,7 @@ export function memoryresetbooks(books: BOOK[], select: string) { books.forEach((book) => { MEMORY.books.set(book.id, book) // attempt default for main - if (book.name.toLowerCase() === 'main') { + if (book.name === 'main') { MEMORY.software.main = book.id } }) @@ -539,7 +539,7 @@ function memoryloader( ).filter((codepage) => { const stats = codepagereadstats(codepage) const matched = Object.keys(stats).filter((name) => - shouldmatch.includes(name.toLowerCase()), + shouldmatch.includes(NAME(name)), ) return matched.length === shouldmatch.length }) diff --git a/zss/words/category.ts b/zss/words/category.ts index 955527874..c6a8dfd88 100644 --- a/zss/words/category.ts +++ b/zss/words/category.ts @@ -2,7 +2,7 @@ import { isarray, ispresent, isstring, MAYBE } from 'zss/mapping/types' import { readexpr } from './expr' import { READ_CONTEXT } from './reader' -import { CATEGORY, WORD } from './types' +import { CATEGORY, NAME, WORD } from './types' export const categoryconsts = { isterrain: 'ISTERRAIN', @@ -24,7 +24,7 @@ function isstrcategoryconst(value: any): value is STR_CATEGORY_CONST { export function mapstrcategory(value: any): MAYBE { if (isstring(value)) { - return categoryconsts[value.toLowerCase() as STR_CATEGORY_KEYS] + return categoryconsts[NAME(value) as STR_CATEGORY_KEYS] } return undefined } diff --git a/zss/words/collision.ts b/zss/words/collision.ts index 8a3c431ca..48714f3cb 100644 --- a/zss/words/collision.ts +++ b/zss/words/collision.ts @@ -2,7 +2,7 @@ import { isarray, ispresent, isstring, MAYBE } from 'zss/mapping/types' import { readexpr } from './expr' import { READ_CONTEXT } from './reader' -import { COLLISION, WORD } from './types' +import { COLLISION, NAME, WORD } from './types' export const collisionconsts = { issolid: 'ISSOLID', @@ -34,7 +34,7 @@ export function isstrcollision(value: any): value is STR_COLLISION { } export function mapstrcollisiontoenum(value: STR_COLLISION): COLLISION { - return collisionenums[value[0].toLowerCase() as keyof typeof collisionenums] + return collisionenums[NAME(value[0]) as keyof typeof collisionenums] } function isstrcollisionconst(value: any): value is STR_COLLISION_CONST { @@ -43,7 +43,7 @@ function isstrcollisionconst(value: any): value is STR_COLLISION_CONST { export function mapstrcollision(value: any): MAYBE { if (isstring(value)) { - return collisionconsts[value.toLowerCase() as STR_COLLISION_KEYS] + return collisionconsts[NAME(value) as STR_COLLISION_KEYS] } return undefined } diff --git a/zss/words/color.ts b/zss/words/color.ts index 4e12f5f32..ee3717841 100644 --- a/zss/words/color.ts +++ b/zss/words/color.ts @@ -2,7 +2,7 @@ import { isarray, ispresent, isstring, MAYBE } from 'zss/mapping/types' import { readexpr } from './expr' import { READ_CONTEXT } from './reader' -import { COLOR, WORD } from './types' +import { COLOR, NAME, WORD } from './types' export function colortofg(color: MAYBE): MAYBE { return ispresent(color) && color < COLOR.ONBLACK ? color : undefined @@ -88,7 +88,7 @@ function isstrcolorconst(value: any): value is STR_COLOR_CONST { export function mapstrcolor(value: any): MAYBE { if (isstring(value)) { - return colorconsts[value.toLowerCase() as STR_COLOR_KEYS] + return colorconsts[NAME(value) as STR_COLOR_KEYS] } return undefined } diff --git a/zss/words/dir.ts b/zss/words/dir.ts index b2646ce58..c604e7629 100644 --- a/zss/words/dir.ts +++ b/zss/words/dir.ts @@ -2,7 +2,7 @@ import { isarray, ispresent, isstring, MAYBE } from 'zss/mapping/types' import { readexpr } from './expr' import { ARG_TYPE, READ_CONTEXT, readargs } from './reader' -import { DIR, PT, WORD } from './types' +import { DIR, NAME, PT, WORD } from './types' export function ispt(value: any): value is PT { return ispresent(value) && ispresent(value.x) && ispresent(value.y) @@ -109,7 +109,7 @@ export function mapstrdirtoconst(value: any): DIR { export function mapstrdir(value: any): MAYBE { if (isstring(value)) { - return dirconsts[value.toLowerCase() as STR_DIR_KEYS] + return dirconsts[NAME(value) as STR_DIR_KEYS] } return undefined } diff --git a/zss/words/expr.ts b/zss/words/expr.ts index 62a0dfe78..90b8e6073 100644 --- a/zss/words/expr.ts +++ b/zss/words/expr.ts @@ -7,6 +7,7 @@ import { isstrcollision, mapstrcollision, readcollision } from './collision' import { isstrcolor, mapstrcolor, readcolor } from './color' import { ispt, isstrdir, mapstrdir, readdir } from './dir' import { ARG_TYPE, READ_CONTEXT, readargs } from './reader' +import { NAME } from './types' export function readexpr(index: number, stringeval = true): [any, number] { const maybevalue = READ_CONTEXT.words[index] @@ -34,7 +35,7 @@ export function readexpr(index: number, stringeval = true): [any, number] { } // special case rnd expression - if (isstring(maybevalue) && maybevalue.toLowerCase() === 'rnd') { + if (isstring(maybevalue) && NAME(maybevalue) === 'rnd') { // RND - returns 0 or 1 // RND - return 0 to number // RND - return number to number @@ -70,7 +71,7 @@ export function readexpr(index: number, stringeval = true): [any, number] { // check for flags and expressions if (isstring(maybevalue)) { - const maybeexpr = maybevalue.toLowerCase() + const maybeexpr = NAME(maybevalue) // check for flag if (stringeval) { diff --git a/zss/words/stats.ts b/zss/words/stats.ts index a5b1ece5c..52dc2c2da 100644 --- a/zss/words/stats.ts +++ b/zss/words/stats.ts @@ -1,8 +1,8 @@ -import { STAT_TYPE } from './types' +import { NAME, STAT_TYPE } from './types' export function statformat(words: string[], first = true) { const [maybetype, ...values] = words - switch (maybetype.toLowerCase()) { + switch (NAME(maybetype)) { default: if (first) { return { diff --git a/zss/words/types.ts b/zss/words/types.ts index f63648435..b3310a1d3 100644 --- a/zss/words/types.ts +++ b/zss/words/types.ts @@ -98,3 +98,7 @@ export type STAT = { export type PT = { x: number; y: number } export type WORD = string | number | undefined | WORD[] export type WORD_RESULT = 0 | 1 + +export function NAME(name: string) { + return name.toLowerCase().trim() +}