From 1211891f53f571263139f053dc2682c2a17effad Mon Sep 17 00:00:00 2001 From: dylan <> Date: Tue, 9 May 2023 08:19:20 -0700 Subject: [PATCH] Use alphabetic characters, so button symbols can be used as identifiers --- codetab.ts | 14 +++++++++----- font.ts | 35 +++++++++++++++++++++-------------- keyboard.ts | 10 +++++----- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/codetab.ts b/codetab.ts index daaaf7c..c7d3b23 100644 --- a/codetab.ts +++ b/codetab.ts @@ -1,5 +1,5 @@ import { clearScreen, fillRect } from "./window.ts"; -import { font } from "./font.ts"; +import { CHAR, font } from "./font.ts"; import { drawText, measureText } from "./builtins.ts"; import { COLOR } from "./colors.ts"; import { getCodeSheet, setSheet } from "./sheet.ts"; @@ -159,15 +159,19 @@ const tokenColors = { } const transformForCopy = (text: string) => { - text = text.replaceAll("➡", "➡️"); - text = text.replaceAll("⬅", "⬅️"); - text = text.replaceAll("⬇", "⬇️"); - text = text.replaceAll("⬆", "⬆️"); + text = text.replaceAll(CHAR.UP, "⬆️"); + text = text.replaceAll(CHAR.LEFT, "⬅️"); + text = text.replaceAll(CHAR.DOWN, "⬇️"); + text = text.replaceAll(CHAR.RIGHT, "➡️"); return text; } const transformForPaste = (text: string) => { let newstr = ""; + text = text.replaceAll("⬆️", CHAR.UP); + text = text.replaceAll("⬅️", CHAR.LEFT); + text = text.replaceAll("⬇️", CHAR.DOWN); + text = text.replaceAll("➡️", CHAR.RIGHT); for (const char of text) { if (char in font.chars) { newstr += char; diff --git a/font.ts b/font.ts index 0742203..b55e115 100644 --- a/font.ts +++ b/font.ts @@ -17,6 +17,13 @@ // export const fontWidth = 4; // export const fontHeight = 6; +export const CHAR = { + UP: "À", + LEFT: "Á", + DOWN: "Â", + RIGHT: "Ã", +} + export type Font = { height: 6, chars: {[key: string]: Array}, @@ -467,12 +474,12 @@ export const font: Font = { 0, 0, 0, ], "\t": [ - 0, 0, 0, - 0, 0, 0, - 0, 0, 0, - 0, 0, 0, - 0, 0, 0, - 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, ], "\n": [ 0, 0, 0, @@ -802,15 +809,15 @@ export const font: Font = { 0, 0, 0, 0, 0, 0, ], - "➡": [ + [CHAR.UP]: [ 0, 1, 1, 1, 1, 1, 0, - 1, 1, 0, 0, 1, 1, 1, + 1, 1, 1, 0, 1, 1, 1, + 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, - 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, ], - "⬅": [ + [CHAR.LEFT]: [ 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, @@ -818,7 +825,7 @@ export const font: Font = { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, ], - "⬇": [ + [CHAR.DOWN]: [ 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, @@ -826,11 +833,11 @@ export const font: Font = { 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, ], - "⬆": [ + [CHAR.RIGHT]: [ 0, 1, 1, 1, 1, 1, 0, - 1, 1, 1, 0, 1, 1, 1, - 1, 1, 0, 0, 0, 1, 1, + 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, + 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, ], diff --git a/keyboard.ts b/keyboard.ts index c46fe8c..684b176 100644 --- a/keyboard.ts +++ b/keyboard.ts @@ -1,4 +1,4 @@ -import { font } from "./font.ts"; +import { font, CHAR } from "./font.ts"; const keyboard = new Map(); @@ -63,10 +63,10 @@ export const shiftMap = { } export const altMap = { - "w": "⬆", - "a": "⬅", - "s": "⬇", - "d": "➡", + "w": CHAR.UP, + "a": CHAR.LEFT, + "s": CHAR.DOWN, + "d": CHAR.RIGHT, } addEventListener("keydown", (evt) => {