Use alphabetic characters, so button symbols can be used as identifiers

This commit is contained in:
dylan 2023-05-09 08:19:20 -07:00
parent 2ac5f3dff7
commit 1211891f53
3 changed files with 35 additions and 24 deletions

View File

@ -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;

35
font.ts
View File

@ -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<number>},
@ -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,
],

View File

@ -1,4 +1,4 @@
import { font } from "./font.ts";
import { font, CHAR } from "./font.ts";
const keyboard = new Map<number, {first: boolean, repeat: boolean, held: boolean}>();
@ -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) => {