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:
|
all:
|
||||||
pdc --skip-unknown src Luncher.pdx
|
pdc --skip-unknown src Luncher.pdx
|
||||||
|
|
||||||
assets:
|
preprocess:
|
||||||
lua lib/preprocess-cl.lua src/assets.lua2p
|
find ./src -name '*.lua2p' | xargs -L1 -I %% lua lib/preprocess-cl.lua %%
|
||||||
|
|
||||||
check: assets
|
check: preprocess
|
||||||
stylua -c --indent-type Spaces src/
|
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
|
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:
|
lint:
|
||||||
stylua --indent-type Spaces src/
|
stylua --indent-type Spaces src/
|
||||||
|
|
|
@ -3,4 +3,10 @@ getCurrentTimeMilliseconds = playdate.getCurrentTimeMilliseconds
|
||||||
tinyTrackEntityAges = true
|
tinyTrackEntityAges = true
|
||||||
ENTITY_INIT_MS = { "ENTITY_INIT_MS" }
|
ENTITY_INIT_MS = { "ENTITY_INIT_MS" }
|
||||||
|
|
||||||
|
if tinyTrackEntityAges then
|
||||||
|
function tiny.getEntityAgeMs(entity)
|
||||||
|
return entity[ENTITY_INIT_MS]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
tinyLogSystemUpdateTime = false
|
tinyLogSystemUpdateTime = false
|
|
@ -2,12 +2,12 @@ collidingEntities = filteredSystem("collidingEntitites", {
|
||||||
velocity = T.XyPair,
|
velocity = T.XyPair,
|
||||||
position = T.XyPair,
|
position = T.XyPair,
|
||||||
size = T.XyPair,
|
size = T.XyPair,
|
||||||
canCollideWith = T.bitMask,
|
canCollideWith = T.BitMask,
|
||||||
isSolid = Maybe(T.bool),
|
isSolid = Maybe(T.bool),
|
||||||
})
|
})
|
||||||
|
|
||||||
collisionDetection = filteredSystem("collisionDetection",
|
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*
|
-- Here, the entity, e, refers to some entity that a moving object may be colliding *into*
|
||||||
function(e, _, system)
|
function(e, _, system)
|
||||||
for _, collider in pairs(collidingEntities.entities) do
|
for _, collider in pairs(collidingEntities.entities) do
|
||||||
|
|
|
@ -12,8 +12,8 @@ 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) } },
|
{ position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.PdFont) } },
|
||||||
function(e, dt)
|
function(e)
|
||||||
local textWidth = AshevilleSans14Bold:getTextWidth(e.drawAsText.text)
|
local textWidth = AshevilleSans14Bold:getTextWidth(e.drawAsText.text)
|
||||||
if e.drawAsText.style == TextStyle.Inverted then
|
if e.drawAsText.style == TextStyle.Inverted then
|
||||||
gfx.fillRect(
|
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 Entity table
|
||||||
|
---@alias CanBeBounced { flat: XyPair, mult = XyPair }
|
||||||
---@alias Collision { collisionBetween: Entity[] }
|
---@alias XyPair { x: number, y: number }
|
||||||
|
|
||||||
---@type Entity
|
|
||||||
local Entity = {}
|
|
||||||
|
|
||||||
---@type XyPair
|
|
||||||
local XyPair = { x = 1, y = 1 }
|
|
||||||
|
|
||||||
---@alias BitMask number
|
|
||||||
|
|
||||||
---@alias CanBeBounced { flat: XyPair, mult: XyPair }
|
|
||||||
|
|
||||||
---@alias RoundStateAction "end" | "start"
|
---@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 CanSpawn { entity: Entity }
|
||||||
|
|
||||||
---@alias InRelations Entity[]
|
|
||||||
|
|
||||||
T = {
|
T = {
|
||||||
XyPair = XyPair,
|
|
||||||
bool = true,
|
bool = true,
|
||||||
number = 0,
|
number = 0,
|
||||||
---@type BitMask
|
|
||||||
bitMask = 0,
|
|
||||||
numberArray = { 1, 2, 3 },
|
numberArray = { 1, 2, 3 },
|
||||||
str = "",
|
str = "",
|
||||||
marker = {},
|
marker = {},
|
||||||
|
@ -37,26 +28,27 @@ T = {
|
||||||
flat = XyPair,
|
flat = XyPair,
|
||||||
mult = XyPair,
|
mult = XyPair,
|
||||||
},
|
},
|
||||||
--- Receiver
|
|
||||||
---@type CanBeBounced
|
|
||||||
CanBeBounced = {
|
|
||||||
flat = XyPair,
|
|
||||||
mult = XyPair,
|
|
||||||
},
|
|
||||||
---@type Collision
|
|
||||||
Collision = { Entity, Entity },
|
|
||||||
---@type pd_image
|
---@type pd_image
|
||||||
PdImage = {},
|
PdImage = {},
|
||||||
---@type RoundStateAction
|
|
||||||
RoundStateAction = "start",
|
|
||||||
---@type CanSpawn
|
|
||||||
CanSpawn = {},
|
|
||||||
---@type InRelations
|
|
||||||
InRelations = {},
|
|
||||||
---@type InputState
|
|
||||||
InputState = {},
|
|
||||||
---@type Entity
|
---@type Entity
|
||||||
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
|
---@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