From 9f67a590331247c8cbf9b6432b77c20f556a05b5 Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sat, 6 May 2023 15:01:01 -0700 Subject: [PATCH] Add trash button to delete sheet --- editmode.ts | 22 ++++++++++++++++++++-- icons.ts | 11 +++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/editmode.ts b/editmode.ts index 44f9355..51547b0 100644 --- a/editmode.ts +++ b/editmode.ts @@ -6,8 +6,8 @@ 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 { sheetsIcon, trashIcon } from "./icons.ts"; +import { SheetType, setSheet } from "./sheet.ts"; import { nonetab } from "./nonetab.ts"; type TabName = SheetType; // "code" | "sprite" | "map" | "sfx" | "music" | "sheet"; @@ -29,9 +29,27 @@ const makeTabButton = (tabname: TabName | "sheet", x: number, y: number, icon: A }) } +const makeTrashButton = (x: number, y: number, icon: Array) => { + buttons.push({ + update() { + if (mouseClick()) { + const {x: mouseX, y: mouseY} = mousePos(); + if (inRect(mouseX, mouseY, x, y, 8, 8)) { + setSheet(page.activeSheet, "none", null); + page.tab = "sheet"; + } + } + }, + draw() { + drawIcon(x, y, icon, COLOR.BLACK); + } + }) +} + // makeTabButton("code", 88, 0, codeIcon); // makeTabButton("sprite", 88+8, 0, spriteIcon); makeTabButton("sheet", 120, 0, sheetsIcon); +makeTrashButton(0, 0, trashIcon); const update = () => { buttons.forEach(button => button.update()); diff --git a/icons.ts b/icons.ts index 0b91aea..9b3e7d4 100644 --- a/icons.ts +++ b/icons.ts @@ -30,3 +30,14 @@ export const sheetsIcon = [ 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; + +export const trashIcon = [ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, +];