Add sheet viewer page
This commit is contained in:
57
editmode.ts
57
editmode.ts
@ -1,72 +1,61 @@
|
||||
import { clearScreen, fillRect } from "./window.ts";
|
||||
import { codetab } from "./codetab.ts";
|
||||
import { spritetab } from "./spritetab.ts";
|
||||
import { viewsheets, page } from "./viewsheets.ts";
|
||||
import { COLOR } from "./colors.ts";
|
||||
import { mouseClick, mousePos } from "./mouse.ts";
|
||||
import { drawIcon } from "./builtins.ts";
|
||||
import { inRect } from "./util.ts";
|
||||
import { sheetsIcon } from "./icons.ts";
|
||||
import { SheetType } from "./sheet.ts";
|
||||
import { nonetab } from "./nonetab.ts";
|
||||
|
||||
type TabName = "code" | "sprite" | "map" | "sfx" | "music";
|
||||
|
||||
let tab: TabName = "code";
|
||||
|
||||
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,
|
||||
];
|
||||
type TabName = SheetType; // "code" | "sprite" | "map" | "sfx" | "music" | "sheet";
|
||||
|
||||
const buttons: Array<{update: () => void, draw: () => void}> = [];
|
||||
const makeTabButton = (tabname: TabName, x: number, y: number, icon: Array<number>) => {
|
||||
const makeTabButton = (tabname: TabName | "sheet", 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;
|
||||
page.tab = tabname;
|
||||
}
|
||||
}
|
||||
},
|
||||
draw() {
|
||||
drawIcon(x, y, icon, tab === tabname ? COLOR.YELLOW : COLOR.WHITE);
|
||||
drawIcon(x, y, icon, page.tab === tabname ? COLOR.YELLOW : COLOR.WHITE);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
makeTabButton("code", 88, 0, codeIcon);
|
||||
makeTabButton("sprite", 88+8, 0, spriteIcon);
|
||||
// makeTabButton("code", 88, 0, codeIcon);
|
||||
// makeTabButton("sprite", 88+8, 0, spriteIcon);
|
||||
makeTabButton("sheet", 120, 0, sheetsIcon);
|
||||
|
||||
const update = () => {
|
||||
buttons.forEach(button => button.update());
|
||||
if (tab === "code") {
|
||||
if (page.tab === "code") {
|
||||
codetab.update();
|
||||
} else if (tab === "sprite") {
|
||||
} else if (page.tab === "spritesheet") {
|
||||
spritetab.update();
|
||||
} else if (page.tab === "sheet") {
|
||||
viewsheets.update();
|
||||
} else if (page.tab === "none") {
|
||||
nonetab.update();
|
||||
}
|
||||
}
|
||||
|
||||
const draw = () => {
|
||||
clearScreen();
|
||||
if (tab === "code") {
|
||||
if (page.tab === "code") {
|
||||
codetab.draw();
|
||||
} else if (tab === "sprite") {
|
||||
} else if (page.tab === "spritesheet") {
|
||||
spritetab.draw();
|
||||
} else if (page.tab === "sheet") {
|
||||
viewsheets.draw();
|
||||
} else if (page.tab === "none") {
|
||||
nonetab.draw();
|
||||
}
|
||||
fillRect(0, 0, 128, 8, COLOR.RED);
|
||||
fillRect(0, 120, 128, 8, COLOR.RED);
|
||||
|
Reference in New Issue
Block a user