Toy with a generated filter-types.lua
This commit is contained in:
parent
a278e30c74
commit
3149dd0131
10
Makefile
10
Makefile
|
@ -1,15 +1,15 @@
|
|||
all:
|
||||
pdc --skip-unknown src Luncher.pdx
|
||||
|
||||
assets:
|
||||
lua lib/preprocess-cl.lua src/assets.lua2p
|
||||
preprocess:
|
||||
find ./src -name '*.lua2p' | xargs -L1 -I %% lua lib/preprocess-cl.lua %%
|
||||
|
||||
check: assets
|
||||
check: preprocess
|
||||
stylua -c --indent-type Spaces src/
|
||||
luacheck -g -d --codes src/ --exclude-files src/test/
|
||||
luacheck -d --codes src/ --exclude-files src/test/
|
||||
|
||||
test: check
|
||||
(cd src; find ./test -name '*lua' | xargs -L1 -I %% lua %% -v)
|
||||
(cd src; find ./test -name '*.lua' | xargs -L1 -I %% lua %% -v)
|
||||
|
||||
lint:
|
||||
stylua --indent-type Spaces src/
|
||||
|
|
|
@ -3,4 +3,10 @@ getCurrentTimeMilliseconds = playdate.getCurrentTimeMilliseconds
|
|||
tinyTrackEntityAges = true
|
||||
ENTITY_INIT_MS = { "ENTITY_INIT_MS" }
|
||||
|
||||
if tinyTrackEntityAges then
|
||||
function tiny.getEntityAgeMs(entity)
|
||||
return entity[ENTITY_INIT_MS]
|
||||
end
|
||||
end
|
||||
|
||||
tinyLogSystemUpdateTime = false
|
|
@ -2,12 +2,12 @@ collidingEntities = filteredSystem("collidingEntitites", {
|
|||
velocity = T.XyPair,
|
||||
position = T.XyPair,
|
||||
size = T.XyPair,
|
||||
canCollideWith = T.bitMask,
|
||||
canCollideWith = T.BitMask,
|
||||
isSolid = Maybe(T.bool),
|
||||
})
|
||||
|
||||
collisionDetection = filteredSystem("collisionDetection",
|
||||
{ position = T.XyPair, size = T.XyPair, canBeCollidedBy = T.bitMask, isSolid = Maybe(T.bool) },
|
||||
{ position = T.XyPair, size = T.XyPair, canBeCollidedBy = T.BitMask, isSolid = Maybe(T.bool) },
|
||||
-- Here, the entity, e, refers to some entity that a moving object may be colliding *into*
|
||||
function(e, _, system)
|
||||
for _, collider in pairs(collidingEntities.entities) do
|
||||
|
|
|
@ -12,8 +12,8 @@ local textHeight = AshevilleSans14Bold:getHeight()
|
|||
local xMargin = 4
|
||||
|
||||
drawTextSystem = filteredSystem("drawText",
|
||||
{ position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str) } },
|
||||
function(e, dt)
|
||||
{ position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.PdFont) } },
|
||||
function(e)
|
||||
local textWidth = AshevilleSans14Bold:getTextWidth(e.drawAsText.text)
|
||||
if e.drawAsText.style == TextStyle.Inverted then
|
||||
gfx.fillRect(
|
||||
|
|
|
@ -1,31 +1,22 @@
|
|||
---@alias XyPair { x: number, y: number }
|
||||
-- GENERATED FILE - DO NOT EDIT
|
||||
-- Instead, edit the source file directly: filter-types.lua2p
|
||||
|
||||
-- This file is composed of, essentially, "base types"
|
||||
|
||||
---@alias Entity table
|
||||
|
||||
---@alias Collision { collisionBetween: Entity[] }
|
||||
|
||||
---@type Entity
|
||||
local Entity = {}
|
||||
|
||||
---@type XyPair
|
||||
local XyPair = { x = 1, y = 1 }
|
||||
|
||||
---@alias BitMask number
|
||||
|
||||
---@alias CanBeBounced { flat: XyPair, mult: XyPair }
|
||||
|
||||
---@alias CanBeBounced { flat: XyPair, mult = XyPair }
|
||||
---@alias XyPair { x: number, y: number }
|
||||
---@alias RoundStateAction "end" | "start"
|
||||
|
||||
---@alias BitMask number
|
||||
---@alias InputState { aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }
|
||||
---@alias InRelations Entity[]
|
||||
---@alias Collision { collisionBetween: Entity[] }
|
||||
---@alias CanSpawn { entity: Entity }
|
||||
|
||||
---@alias InRelations Entity[]
|
||||
|
||||
T = {
|
||||
XyPair = XyPair,
|
||||
bool = true,
|
||||
number = 0,
|
||||
---@type BitMask
|
||||
bitMask = 0,
|
||||
numberArray = { 1, 2, 3 },
|
||||
str = "",
|
||||
marker = {},
|
||||
|
@ -37,26 +28,27 @@ T = {
|
|||
flat = XyPair,
|
||||
mult = XyPair,
|
||||
},
|
||||
--- Receiver
|
||||
---@type CanBeBounced
|
||||
CanBeBounced = {
|
||||
flat = XyPair,
|
||||
mult = XyPair,
|
||||
},
|
||||
---@type Collision
|
||||
Collision = { Entity, Entity },
|
||||
---@type pd_image
|
||||
PdImage = {},
|
||||
---@type RoundStateAction
|
||||
RoundStateAction = "start",
|
||||
---@type CanSpawn
|
||||
CanSpawn = {},
|
||||
---@type InRelations
|
||||
InRelations = {},
|
||||
---@type InputState
|
||||
InputState = {},
|
||||
|
||||
---@type Entity
|
||||
Entity = {},
|
||||
---@type CanBeBounced
|
||||
CanBeBounced = {},
|
||||
---@type XyPair
|
||||
XyPair = {},
|
||||
---@type RoundStateAction
|
||||
RoundStateAction = "start",
|
||||
---@type BitMask
|
||||
BitMask = 0,
|
||||
---@type InputState
|
||||
InputState = {},
|
||||
---@type InRelations
|
||||
InRelations = {},
|
||||
---@type Collision
|
||||
Collision = {},
|
||||
---@type CanSpawn
|
||||
CanSpawn = {},
|
||||
}
|
||||
|
||||
---@generic T
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
!(
|
||||
local types = {}
|
||||
function generatedFileWarning()
|
||||
-- Only in a function to make clear that THIS .lua2p is not the generated file!
|
||||
return "-- GENERATED FILE - DO NOT EDIT\n-- Instead, edit the source file directly: filter-types.lua2p"
|
||||
end
|
||||
|
||||
function t(name, type, value)
|
||||
if not value then
|
||||
if type == "number" then
|
||||
value = 0
|
||||
elseif type == "string" then
|
||||
value = ""
|
||||
else
|
||||
value = "{}"
|
||||
end
|
||||
end
|
||||
types[#types + 1] = { name = name, type = type, value = value }
|
||||
return "---@alias " .. name .. " " .. type
|
||||
end
|
||||
|
||||
function tMany(tObj)
|
||||
local ret = ""
|
||||
for k, v in pairs(tObj) do
|
||||
if type(v) == "string" then
|
||||
ret = ret .. t(k, v) .. "\n"
|
||||
else
|
||||
ret = ret .. t(k, v[1], v[2]) .. "\n"
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function dumpTypeObjects()
|
||||
local ret = ""
|
||||
for _, v in ipairs(types) do
|
||||
local line = "\n ---@type " .. v.name .. "\n " .. v.name .. " = " .. v.value .. ","
|
||||
ret = ret .. line
|
||||
end
|
||||
return ret
|
||||
end
|
||||
)!!(generatedFileWarning())
|
||||
|
||||
-- This file is composed of, essentially, "base types"
|
||||
|
||||
!!(tMany({
|
||||
Entity = "table",
|
||||
XyPair = "{ x: number, y: number }",
|
||||
Collision = "{ collisionBetween: Entity[] }",
|
||||
BitMask = "number",
|
||||
CanBeBounced = "{ flat: XyPair, mult: XyPair }",
|
||||
RoundStateAction = { '"end" | "start"', '"start"' },
|
||||
CanSpawn = "{ entity: Entity }",
|
||||
InRelations = "Entity[]",
|
||||
CanBeBounced = "{ flat: XyPair, mult = XyPair }",
|
||||
InputState = "{ aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }"
|
||||
}))
|
||||
|
||||
T = {
|
||||
bool = true,
|
||||
number = 0,
|
||||
numberArray = { 1, 2, 3 },
|
||||
str = "",
|
||||
marker = {},
|
||||
---@type fun(self)
|
||||
SelfFunction = function(self) end,
|
||||
--- Actor
|
||||
CanBounce = {
|
||||
isSolid = true,
|
||||
flat = XyPair,
|
||||
mult = XyPair,
|
||||
},
|
||||
---@type pd_image
|
||||
PdImage = {},
|
||||
!!(dumpTypeObjects())
|
||||
}
|
||||
|
||||
---@generic T
|
||||
---@param t T
|
||||
---@return nil | T
|
||||
function Maybe(t)
|
||||
return { maybe = t }
|
||||
end
|
||||
|
||||
TextStyle = {
|
||||
Inverted = "INVERTED",
|
||||
Bordered = "BORDERED",
|
||||
None = "None",
|
||||
}
|
Loading…
Reference in New Issue