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-06 14:49:46 -07:00
|
|
|
import { viewsheets, page } from "./viewsheets.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-06 14:49:46 -07:00
|
|
|
import { sheetsIcon } from "./icons.ts";
|
|
|
|
import { SheetType } from "./sheet.ts";
|
|
|
|
import { nonetab } from "./nonetab.ts";
|
2023-05-04 20:27:01 -07:00
|
|
|
|
2023-05-06 14:49:46 -07:00
|
|
|
type TabName = SheetType; // "code" | "sprite" | "map" | "sfx" | "music" | "sheet";
|
2023-05-05 16:39:51 -07:00
|
|
|
|
|
|
|
const buttons: Array<{update: () => void, draw: () => void}> = [];
|
2023-05-06 14:49:46 -07:00
|
|
|
const makeTabButton = (tabname: TabName | "sheet", x: number, y: number, icon: Array<number>) => {
|
2023-05-05 16:39:51 -07:00
|
|
|
buttons.push({
|
|
|
|
update() {
|
|
|
|
if (mouseClick()) {
|
|
|
|
const {x: mouseX, y: mouseY} = mousePos();
|
|
|
|
if (inRect(mouseX, mouseY, x, y, 8, 8)) {
|
2023-05-06 14:49:46 -07:00
|
|
|
page.tab = tabname;
|
2023-05-05 16:39:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
draw() {
|
2023-05-06 14:49:46 -07:00
|
|
|
drawIcon(x, y, icon, page.tab === tabname ? COLOR.YELLOW : COLOR.WHITE);
|
2023-05-05 16:39:51 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-06 14:49:46 -07:00
|
|
|
// makeTabButton("code", 88, 0, codeIcon);
|
|
|
|
// makeTabButton("sprite", 88+8, 0, spriteIcon);
|
|
|
|
makeTabButton("sheet", 120, 0, sheetsIcon);
|
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-06 14:49:46 -07:00
|
|
|
if (page.tab === "code") {
|
2023-05-05 14:59:52 -07:00
|
|
|
codetab.update();
|
2023-05-06 14:49:46 -07:00
|
|
|
} else if (page.tab === "spritesheet") {
|
2023-05-05 14:59:52 -07:00
|
|
|
spritetab.update();
|
2023-05-06 14:49:46 -07:00
|
|
|
} else if (page.tab === "sheet") {
|
|
|
|
viewsheets.update();
|
|
|
|
} else if (page.tab === "none") {
|
|
|
|
nonetab.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();
|
2023-05-06 14:49:46 -07:00
|
|
|
if (page.tab === "code") {
|
2023-05-05 14:59:52 -07:00
|
|
|
codetab.draw();
|
2023-05-06 14:49:46 -07:00
|
|
|
} else if (page.tab === "spritesheet") {
|
2023-05-05 14:59:52 -07:00
|
|
|
spritetab.draw();
|
2023-05-06 14:49:46 -07:00
|
|
|
} else if (page.tab === "sheet") {
|
|
|
|
viewsheets.draw();
|
|
|
|
} else if (page.tab === "none") {
|
|
|
|
nonetab.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,
|
|
|
|
}
|