diff --git a/src/systems/draw.lua b/src/systems/draw.lua index c721ae9..9208f0a 100644 --- a/src/systems/draw.lua +++ b/src/systems/draw.lua @@ -4,44 +4,36 @@ drawRectanglesSystem = filteredSystem("drawRectangles", { position = T.XyPair, d gfx.fillRect(e.position.x, e.position.y, e.drawAsRectangle.size.x, e.drawAsRectangle.size.y) end) -drawSpriteSystem = filteredSystem("drawSprites", { position = T.XyPair, drawAsSprite = T.PdImage }, function(e, dt, system) +drawSpriteSystem = filteredSystem("drawSprites", { position = T.XyPair, drawAsSprite = T.pd_image }, function(e, dt, system) e.drawAsSprite:draw(e.position.x, e.position.y) end) -local textHeight = AshevilleSans14Bold:getHeight() local xMargin = 4 drawTextSystem = filteredSystem("drawText", - { position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.PdFont) } }, + { position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.pd_font) } }, function(e) - local textWidth = AshevilleSans14Bold:getTextWidth(e.drawAsText.text) + local font = e.drawAsText.font or AshevilleSans14Bold + local textHeight = font:getHeight() + local textWidth = font:getTextWidth(e.drawAsText.text) + + local bgLeftEdge = e.position.x - xMargin - textWidth / 2 + local bgTopEdge = e.position.y - 2 + local bgWidth, bgHeight = textWidth + (xMargin * 2), textHeight + 2 + if e.drawAsText.style == TextStyle.Inverted then - gfx.fillRect( - e.position.x - xMargin - textWidth / 2, - e.position.y - 2, - textWidth + (xMargin * 2), - textHeight + 2 - ) + gfx.fillRect(bgLeftEdge, bgTopEdge, textWidth + (xMargin * 2), textHeight + 2) gfx.setImageDrawMode(gfx.kDrawModeInverted) - end - if e.drawAsText.style == TextStyle.Bordered then + elseif e.drawAsText.style == TextStyle.Bordered then gfx.setColor(gfx.kColorWhite) - gfx.fillRect( - e.position.x - xMargin - textWidth / 2, - e.position.y - 2, - textWidth + (xMargin * 2), - textHeight + 2 - ) - gfx.setColor(gfx.kColorBlack) + gfx.fillRect(bgLeftEdge, bgTopEdge, bgWidth, bgHeight) + gfx.setImageDrawMode(gfx.kDrawModeCopy) - gfx.drawRect( - e.position.x - xMargin - textWidth / 2, - e.position.y - 2, - textWidth + (xMargin * 2), - textHeight + 2 - ) + gfx.setColor(gfx.kColorBlack) + gfx.drawRect(bgLeftEdge, bgTopEdge, bgWidth, bgHeight) end - AshevilleSans14Bold:drawTextAligned(e.drawAsText.text, e.position.x, e.position.y, kTextAlignment.center) + + font:drawTextAligned(e.drawAsText.text, e.position.x, e.position.y, kTextAlignment.center) if e.drawAsText.style == TextStyle.Inverted then gfx.setImageDrawMode(gfx.kDrawModeCopy) end diff --git a/src/systems/filter-types.lua b/src/systems/filter-types.lua index 24935f1..eb8d939 100644 --- a/src/systems/filter-types.lua +++ b/src/systems/filter-types.lua @@ -3,15 +3,15 @@ -- This file is composed of, essentially, "base types" +---@alias BitMask number +---@alias CanBeBounced { flat: XyPair, mult = XyPair } ---@alias CanSpawn { entity: Entity } ---@alias Collision { collisionBetween: Entity[] } ----@alias CanBeBounced { flat: XyPair, mult = XyPair } ----@alias XyPair { x: number, y: number } ----@alias BitMask number +---@alias Entity table ---@alias InRelations Entity[] ---@alias InputState { aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean } ----@alias Entity table ---@alias RoundStateAction "end" | "start" +---@alias XyPair { x: number, y: number } T = { @@ -29,26 +29,28 @@ T = { mult = XyPair, }, ---@type pd_image - PdImage = {}, + pd_image = {}, + ---@type pd_font + pd_font = {}, + ---@type BitMask + BitMask = 0, + ---@type CanBeBounced + CanBeBounced = {}, ---@type CanSpawn CanSpawn = {}, ---@type Collision Collision = {}, - ---@type CanBeBounced - CanBeBounced = {}, - ---@type XyPair - XyPair = {}, - ---@type BitMask - BitMask = 0, + ---@type Entity + Entity = {}, ---@type InRelations InRelations = {}, ---@type InputState InputState = {}, - ---@type Entity - Entity = {}, ---@type RoundStateAction RoundStateAction = "start", + ---@type XyPair + XyPair = {}, } ---@generic T diff --git a/src/systems/filter-types.lua2p b/src/systems/filter-types.lua2p index 1de6f7b..73ac011 100644 --- a/src/systems/filter-types.lua2p +++ b/src/systems/filter-types.lua2p @@ -21,7 +21,15 @@ end function tMany(tObj) local ret = "" + local keyValues = {} for k, v in pairs(tObj) do + keyValues[#keyValues + 1] = { key = k, value = v } + end + table.sort(keyValues, function(a, b) + return a.key < b.key + end) + for _, kv in ipairs(keyValues) do + local k, v = kv.key, kv.value if type(v) == "string" then ret = ret .. t(k, v) .. "\n" else @@ -53,7 +61,7 @@ end CanSpawn = "{ entity: Entity }", InRelations = "Entity[]", CanBeBounced = "{ flat: XyPair, mult = XyPair }", - InputState = "{ aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }" + InputState = "{ aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }", })) T = { @@ -71,7 +79,9 @@ T = { mult = XyPair, }, ---@type pd_image - PdImage = {}, + pd_image = {}, + ---@type pd_font + pd_font = {}, !!(dumpTypeObjects()) } diff --git a/src/systems/rounds.lua b/src/systems/rounds.lua index 200b1ac..2d66f2b 100644 --- a/src/systems/rounds.lua +++ b/src/systems/rounds.lua @@ -1,4 +1,4 @@ -collectedEntities = filteredSystem("collectedEntities", { collected = T.PdImage }) +collectedEntities = filteredSystem("collectedEntities", { collected = T.pd_image }) local onCollidingRemove = { "mass", "velocity", "canCollideWith" }