2023-05-05 11:52:08 -07:00
|
|
|
import { clearScreen, fillRect } from "./window.ts";
|
2023-05-05 14:59:52 -07:00
|
|
|
import { codetab } from "./codetab.ts";
|
|
|
|
import { spritetab } from "./spritetab.ts";
|
2023-05-05 11:52:08 -07:00
|
|
|
import { COLOR } from "./colors.ts";
|
2023-05-05 16:39:51 -07:00
|
|
|
import { mouseClick, mousePos } from "./mouse.ts";
|
|
|
|
import { drawIcon } from "./builtins.ts";
|
|
|
|
import { inRect } from "./util.ts";
|
2023-05-04 20:27:01 -07:00
|
|
|
|
2023-05-05 16:39:51 -07:00
|
|
|
type TabName = "code" | "sprite" | "map" | "sfx" | "music";
|
|
|
|
|
2023-05-05 16:42:03 -07:00
|
|
|
let tab: TabName = "code";
|
2023-05-05 16:39:51 -07:00
|
|
|
|
|
|
|
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);
|
2023-05-05 11:52:08 -07:00
|
|
|
|
|
|
|
const update = () => {
|
2023-05-05 16:39:51 -07:00
|
|
|
buttons.forEach(button => button.update());
|
2023-05-05 11:52:08 -07:00
|
|
|
if (tab === "code") {
|
2023-05-05 14:59:52 -07:00
|
|
|
codetab.update();
|
|
|
|
} else if (tab === "sprite") {
|
|
|
|
spritetab.update();
|
2023-05-05 11:52:08 -07:00
|
|
|
}
|
2023-05-04 20:27:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const draw = () => {
|
2023-05-05 11:52:08 -07:00
|
|
|
clearScreen();
|
|
|
|
if (tab === "code") {
|
2023-05-05 14:59:52 -07:00
|
|
|
codetab.draw();
|
|
|
|
} else if (tab === "sprite") {
|
|
|
|
spritetab.draw();
|
2023-05-05 11:52:08 -07:00
|
|
|
}
|
2023-05-05 14:59:52 -07:00
|
|
|
fillRect(0, 0, 128, 8, COLOR.RED);
|
|
|
|
fillRect(0, 120, 128, 8, COLOR.RED);
|
2023-05-05 16:39:51 -07:00
|
|
|
buttons.forEach(button => button.draw());
|
2023-05-04 20:27:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export const editmode = {
|
|
|
|
update,
|
|
|
|
draw,
|
|
|
|
}
|