Make tabs for code and sprite editors

This commit is contained in:
dylan
2023-05-05 16:39:51 -07:00
parent a3abb0d2d3
commit 9d2dc99a32
4 changed files with 63 additions and 11 deletions

View File

@ -2,11 +2,58 @@ import { clearScreen, fillRect } from "./window.ts";
import { codetab } from "./codetab.ts";
import { spritetab } from "./spritetab.ts";
import { COLOR } from "./colors.ts";
import { mouseClick, mousePos } from "./mouse.ts";
import { drawIcon } from "./builtins.ts";
import { inRect } from "./util.ts";
// deno-lint-ignore prefer-const
let tab: "code" | "sprite" | "map" | "sfx" | "music" = "sprite";
type TabName = "code" | "sprite" | "map" | "sfx" | "music";
let tab: TabName = "sprite";
const codeIcon = [
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 0, 1, 1, 0,
0, 1, 0, 0, 0, 0, 1, 0,
0, 1, 0, 0, 0, 0, 1, 0,
0, 1, 1, 0, 0, 1, 1, 0,
0, 0, 1, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
];
const spriteIcon = [
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 0,
0, 1, 1, 1, 1, 0, 0, 0,
0, 1, 1, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
];
const buttons: Array<{update: () => void, draw: () => void}> = [];
const makeTabButton = (tabname: TabName, x: number, y: number, icon: Array<number>) => {
buttons.push({
update() {
if (mouseClick()) {
const {x: mouseX, y: mouseY} = mousePos();
if (inRect(mouseX, mouseY, x, y, 8, 8)) {
tab = tabname;
}
}
},
draw() {
drawIcon(x, y, icon, tab === tabname ? COLOR.YELLOW : COLOR.WHITE);
}
})
}
makeTabButton("code", 88, 0, codeIcon);
makeTabButton("sprite", 88+8, 0, spriteIcon);
const update = () => {
buttons.forEach(button => button.update());
if (tab === "code") {
codetab.update();
} else if (tab === "sprite") {
@ -23,6 +70,7 @@ const draw = () => {
}
fillRect(0, 0, 128, 8, COLOR.RED);
fillRect(0, 120, 128, 8, COLOR.RED);
buttons.forEach(button => button.draw());
}
export const editmode = {