diff --git a/Source/main.lua b/Source/main.lua index 3943317..bd7cae4 100644 --- a/Source/main.lua +++ b/Source/main.lua @@ -2829,30 +2829,6 @@ Engine.secondaryColor = playdate.graphics.kColorWhite Engine.ticks = 0 Engine.shouldCountTicks = true ____exports.Engine = Engine -return ____exports - end, -["engine.input"] = function(...) ---[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] -local ____exports = {} -local keyMap = { - up = playdate.kButtonUp, - down = playdate.kButtonDown, - left = playdate.kButtonLeft, - right = playdate.kButtonRight, - a = playdate.kButtonA, - b = playdate.kButtonB -} -class("Input").extends(Object) -Input.init = function(self) - Input.super.init(self) -end -function Input.getKey(self, key) - return playdate.buttonIsPressed(keyMap[key]) -end -function Input.getKeyDown(self, key) - return playdate.buttonJustPressed(keyMap[key]) -end -____exports.Input = Input return ____exports end, ["engine.textures"] = function(...) @@ -2928,6 +2904,49 @@ function Textures.load(self, name) return {normal = normal, inverted = inverted} end ____exports.Textures = Textures +return ____exports + end, +["engine.frame"] = function(...) +--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] +local ____exports = {} +import("CoreLibs/nineslice") +local function drawFrame(self, x, y, w, h, clippingRegion) + local patchSize = 9 + local slice = playdate.graphics.nineSlice.new( + "images/frame", + patchSize, + patchSize, + patchSize, + patchSize + ) + slice:drawInRect(x, y, w, h) + clippingRegion(nil) +end +____exports.drawFrame = drawFrame +return ____exports + end, +["engine.input"] = function(...) +--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]] +local ____exports = {} +local keyMap = { + up = playdate.kButtonUp, + down = playdate.kButtonDown, + left = playdate.kButtonLeft, + right = playdate.kButtonRight, + a = playdate.kButtonA, + b = playdate.kButtonB +} +class("Input").extends(Object) +Input.init = function(self) + Input.super.init(self) +end +function Input.getKey(self, key) + return playdate.buttonIsPressed(keyMap[key]) +end +function Input.getKeyDown(self, key) + return playdate.buttonJustPressed(keyMap[key]) +end +____exports.Input = Input return ____exports end, ["main-menu-stage"] = function(...) @@ -2935,6 +2954,8 @@ return ____exports local ____exports = {} local ____engine = require("engine.engine") local Engine = ____engine.Engine +local ____frame = require("engine.frame") +local drawFrame = ____frame.drawFrame local ____input = require("engine.input") local Input = ____input.Input local ____stage = require("engine.stage") @@ -2976,6 +2997,17 @@ function MainMenuStage.render(self) local h = 82 local x = (Engine.width - w) / 2 local y = 90 + drawFrame( + nil, + x, + y, + w, + h, + function() + local mx = x + 16 + 2 + Textures.listPointerRightTexture.normal:draw(x, y + 2 + 30 * self.cursor) + end + ) end function MainMenuStage.onDestroy(self) end diff --git a/src-web/engine/frame.ts b/src-web/engine/frame.ts deleted file mode 100644 index d8c0ed7..0000000 --- a/src-web/engine/frame.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { Textures } from 'src/engine/textures'; - -export function drawFrame(x: number, y: number, w: number, h: number, ctx: CanvasRenderingContext2D, clippingRegion: () => void): void { - const patchSize = 9; - - // top-left corner - ctx.drawImage( - Textures.frameTexture.normal, - 0, - 0, - patchSize, - patchSize, - x - patchSize, - y - patchSize, - patchSize, - patchSize, - ); - - // top-right corner - ctx.drawImage( - Textures.frameTexture.normal, - patchSize * 2, - 0, - patchSize, - patchSize, - x + w, - y - patchSize, - patchSize, - patchSize, - ); - - // bottom-left corner - ctx.drawImage( - Textures.frameTexture.normal, - 0, - patchSize * 2, - patchSize, - patchSize, - x - patchSize, - y + h, - patchSize, - patchSize, - ); - - // bottom-right corner - ctx.drawImage( - Textures.frameTexture.normal, - patchSize * 2, - patchSize * 2, - patchSize, - patchSize, - x + w, - y + h, - patchSize, - patchSize, - ); - - // top border - ctx.drawImage( - Textures.frameTexture.normal, - patchSize, - 0, - patchSize, - patchSize, - x, - y - patchSize, - w, - patchSize, - ); - - // bottom border - ctx.drawImage( - Textures.frameTexture.normal, - patchSize, - patchSize * 2, - patchSize, - patchSize, - x, - y + h, - w, - patchSize, - ); - - // left border - ctx.drawImage( - Textures.frameTexture.normal, - 0, - patchSize, - patchSize, - patchSize, - x - patchSize, - y, - patchSize, - h, - ); - - // right border - ctx.drawImage( - Textures.frameTexture.normal, - patchSize * 2, - patchSize, - patchSize, - patchSize, - x + w, - y, - patchSize, - h, - ); - - // middle - ctx.drawImage( - Textures.frameTexture.normal, - patchSize, - patchSize, - patchSize, - patchSize, - x, - y, - w, - h, - ); - - // Clipping content inside - ctx.save(); - ctx.beginPath(); - ctx.rect(x, y, w, h); - ctx.clip(); - clippingRegion(); - ctx.restore(); -} diff --git a/src/engine/frame.ts b/src/engine/frame.ts new file mode 100644 index 0000000..214ac09 --- /dev/null +++ b/src/engine/frame.ts @@ -0,0 +1,20 @@ +require('CoreLibs/nineslice'); + +import { Textures } from 'src/engine/textures'; + +function drawFrame(x: number, y: number, w: number, h: number, clippingRegion: () => void): void { + const patchSize = 9; + + const slice = playdate.graphics.nineSlice.new('images/frame', patchSize, patchSize, patchSize, patchSize); + slice.drawInRect(x, y, w, h); + + // Clipping content inside + // ctx.save(); + // ctx.beginPath(); + // ctx.rect(x, y, w, h); + // ctx.clip(); + clippingRegion(); + // ctx.restore(); +} + +export { drawFrame }; diff --git a/src/main-menu-stage.ts b/src/main-menu-stage.ts index af21605..dc3b286 100644 --- a/src/main-menu-stage.ts +++ b/src/main-menu-stage.ts @@ -2,7 +2,7 @@ require('CoreLibs/object'); import { Engine } from 'src/engine/engine'; // import { Font } from 'src/engine/font'; -// import { drawFrame } from 'src/engine/frame'; +import { drawFrame } from 'src/engine/frame'; import { Input } from 'src/engine/input'; // import { playSound, Sound } from 'src/engine/sounds'; import { Stage } from 'src/engine/stage'; @@ -56,20 +56,20 @@ class MainMenuStage extends Stage { const x = (Engine.width - w) / 2; const y = 90; - // drawFrame(x, y, w, h, ctx, () => { - // const mx = x + 16 + 2; + drawFrame(x, y, w, h, () => { + const mx = x + 16 + 2; - // ctx.drawImage(Textures.listPointerRightTexture.normal, x, y + 2 + (30 * this.cursor)); + Textures.listPointerRightTexture.normal.draw(x, y + 2 + (30 * this.cursor)); - // Font.draw('New game', mx, y, ctx); + // Font.draw('New game', mx, y, ctx); - // if (this.hasSaveData) { - // Font.draw('Continue', mx, y + 30, ctx); - // Font.draw('How to play', mx, y + 30 * 2, ctx); - // } else { - // Font.draw('How to play', mx, y + 30, ctx); - // } - // }); + // if (this.hasSaveData) { + // Font.draw('Continue', mx, y + 30, ctx); + // Font.draw('How to play', mx, y + 30 * 2, ctx); + // } else { + // Font.draw('How to play', mx, y + 30, ctx); + // } + }); } onDestroy(): void {