Some vars for drawTextSystem consistency
Sort generated filter-types PdImage,PdFont -> pd_image,pd_font
This commit is contained in:
parent
67c2b81fc3
commit
110d02fe2c
|
@ -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)
|
gfx.fillRect(e.position.x, e.position.y, e.drawAsRectangle.size.x, e.drawAsRectangle.size.y)
|
||||||
end)
|
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)
|
e.drawAsSprite:draw(e.position.x, e.position.y)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local textHeight = AshevilleSans14Bold:getHeight()
|
|
||||||
local xMargin = 4
|
local xMargin = 4
|
||||||
|
|
||||||
drawTextSystem = filteredSystem("drawText",
|
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)
|
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
|
if e.drawAsText.style == TextStyle.Inverted then
|
||||||
gfx.fillRect(
|
gfx.fillRect(bgLeftEdge, bgTopEdge, textWidth + (xMargin * 2), textHeight + 2)
|
||||||
e.position.x - xMargin - textWidth / 2,
|
|
||||||
e.position.y - 2,
|
|
||||||
textWidth + (xMargin * 2),
|
|
||||||
textHeight + 2
|
|
||||||
)
|
|
||||||
gfx.setImageDrawMode(gfx.kDrawModeInverted)
|
gfx.setImageDrawMode(gfx.kDrawModeInverted)
|
||||||
end
|
elseif e.drawAsText.style == TextStyle.Bordered then
|
||||||
if e.drawAsText.style == TextStyle.Bordered then
|
|
||||||
gfx.setColor(gfx.kColorWhite)
|
gfx.setColor(gfx.kColorWhite)
|
||||||
gfx.fillRect(
|
gfx.fillRect(bgLeftEdge, bgTopEdge, bgWidth, bgHeight)
|
||||||
e.position.x - xMargin - textWidth / 2,
|
|
||||||
e.position.y - 2,
|
|
||||||
textWidth + (xMargin * 2),
|
|
||||||
textHeight + 2
|
|
||||||
)
|
|
||||||
gfx.setColor(gfx.kColorBlack)
|
|
||||||
gfx.setImageDrawMode(gfx.kDrawModeCopy)
|
gfx.setImageDrawMode(gfx.kDrawModeCopy)
|
||||||
gfx.drawRect(
|
gfx.setColor(gfx.kColorBlack)
|
||||||
e.position.x - xMargin - textWidth / 2,
|
gfx.drawRect(bgLeftEdge, bgTopEdge, bgWidth, bgHeight)
|
||||||
e.position.y - 2,
|
|
||||||
textWidth + (xMargin * 2),
|
|
||||||
textHeight + 2
|
|
||||||
)
|
|
||||||
end
|
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
|
if e.drawAsText.style == TextStyle.Inverted then
|
||||||
gfx.setImageDrawMode(gfx.kDrawModeCopy)
|
gfx.setImageDrawMode(gfx.kDrawModeCopy)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
|
|
||||||
-- This file is composed of, essentially, "base types"
|
-- This file is composed of, essentially, "base types"
|
||||||
|
|
||||||
|
---@alias BitMask number
|
||||||
|
---@alias CanBeBounced { flat: XyPair, mult = XyPair }
|
||||||
---@alias CanSpawn { entity: Entity }
|
---@alias CanSpawn { entity: Entity }
|
||||||
---@alias Collision { collisionBetween: Entity[] }
|
---@alias Collision { collisionBetween: Entity[] }
|
||||||
---@alias CanBeBounced { flat: XyPair, mult = XyPair }
|
---@alias Entity table
|
||||||
---@alias XyPair { x: number, y: number }
|
|
||||||
---@alias BitMask number
|
|
||||||
---@alias InRelations Entity[]
|
---@alias InRelations Entity[]
|
||||||
---@alias InputState { aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }
|
---@alias InputState { aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }
|
||||||
---@alias Entity table
|
|
||||||
---@alias RoundStateAction "end" | "start"
|
---@alias RoundStateAction "end" | "start"
|
||||||
|
---@alias XyPair { x: number, y: number }
|
||||||
|
|
||||||
|
|
||||||
T = {
|
T = {
|
||||||
|
@ -29,26 +29,28 @@ T = {
|
||||||
mult = XyPair,
|
mult = XyPair,
|
||||||
},
|
},
|
||||||
---@type pd_image
|
---@type pd_image
|
||||||
PdImage = {},
|
pd_image = {},
|
||||||
|
---@type pd_font
|
||||||
|
pd_font = {},
|
||||||
|
|
||||||
|
---@type BitMask
|
||||||
|
BitMask = 0,
|
||||||
|
---@type CanBeBounced
|
||||||
|
CanBeBounced = {},
|
||||||
---@type CanSpawn
|
---@type CanSpawn
|
||||||
CanSpawn = {},
|
CanSpawn = {},
|
||||||
---@type Collision
|
---@type Collision
|
||||||
Collision = {},
|
Collision = {},
|
||||||
---@type CanBeBounced
|
---@type Entity
|
||||||
CanBeBounced = {},
|
Entity = {},
|
||||||
---@type XyPair
|
|
||||||
XyPair = {},
|
|
||||||
---@type BitMask
|
|
||||||
BitMask = 0,
|
|
||||||
---@type InRelations
|
---@type InRelations
|
||||||
InRelations = {},
|
InRelations = {},
|
||||||
---@type InputState
|
---@type InputState
|
||||||
InputState = {},
|
InputState = {},
|
||||||
---@type Entity
|
|
||||||
Entity = {},
|
|
||||||
---@type RoundStateAction
|
---@type RoundStateAction
|
||||||
RoundStateAction = "start",
|
RoundStateAction = "start",
|
||||||
|
---@type XyPair
|
||||||
|
XyPair = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
---@generic T
|
---@generic T
|
||||||
|
|
|
@ -21,7 +21,15 @@ end
|
||||||
|
|
||||||
function tMany(tObj)
|
function tMany(tObj)
|
||||||
local ret = ""
|
local ret = ""
|
||||||
|
local keyValues = {}
|
||||||
for k, v in pairs(tObj) do
|
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
|
if type(v) == "string" then
|
||||||
ret = ret .. t(k, v) .. "\n"
|
ret = ret .. t(k, v) .. "\n"
|
||||||
else
|
else
|
||||||
|
@ -53,7 +61,7 @@ end
|
||||||
CanSpawn = "{ entity: Entity }",
|
CanSpawn = "{ entity: Entity }",
|
||||||
InRelations = "Entity[]",
|
InRelations = "Entity[]",
|
||||||
CanBeBounced = "{ flat: XyPair, mult = XyPair }",
|
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 = {
|
T = {
|
||||||
|
@ -71,7 +79,9 @@ T = {
|
||||||
mult = XyPair,
|
mult = XyPair,
|
||||||
},
|
},
|
||||||
---@type pd_image
|
---@type pd_image
|
||||||
PdImage = {},
|
pd_image = {},
|
||||||
|
---@type pd_font
|
||||||
|
pd_font = {},
|
||||||
!!(dumpTypeObjects())
|
!!(dumpTypeObjects())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
collectedEntities = filteredSystem("collectedEntities", { collected = T.PdImage })
|
collectedEntities = filteredSystem("collectedEntities", { collected = T.pd_image })
|
||||||
|
|
||||||
local onCollidingRemove = { "mass", "velocity", "canCollideWith" }
|
local onCollidingRemove = { "mass", "velocity", "canCollideWith" }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue