Mostly correct menuing

Add tinyLogSystemChanges
This commit is contained in:
Sage Vaillancourt 2025-03-06 23:03:36 -05:00
parent 3149dd0131
commit 67c2b81fc3
6 changed files with 34 additions and 20 deletions

View File

@ -4,9 +4,10 @@ tinyTrackEntityAges = true
ENTITY_INIT_MS = { "ENTITY_INIT_MS" }
if tinyTrackEntityAges then
function tiny.getEntityAgeMs(entity)
function tinyGetEntityAgeMs(entity)
return entity[ENTITY_INIT_MS]
end
end
tinyLogSystemUpdateTime = false
tinyLogSystemChanges = false

View File

@ -495,6 +495,9 @@ end
--- Adds a System to the world. Returns the System.
function tiny.addSystem(world, system)
if tinyLogSystemChanges then
print("addSystem '" .. (system.name or "unnamed") .. "'")
end
if system.world ~= nil then
error("System " .. system.name .. " already belongs to a World.")
end
@ -532,6 +535,9 @@ tiny_removeEntity = tiny.removeEntity
--- Removes a System from the world. Returns the System.
function tiny.removeSystem(world, system)
if tinyLogSystemChanges then
print("removeSystem '" .. (system.name or "unnamed") .. "'")
end
if system.world ~= world then
error("System " .. system.name .. " does not belong to this World.")
end
@ -594,6 +600,9 @@ function tiny_manageSystems(world)
s2r[i] = nil
-- Clean up System
if tinyLogSystemChanges then
print("Cleaning up system '" .. (system.name or "unnamed") .. "'")
end
system.world = nil
system.entities = nil
system.indices = nil

View File

@ -3,15 +3,15 @@
-- This file is composed of, essentially, "base types"
---@alias Entity table
---@alias CanSpawn { entity: Entity }
---@alias Collision { collisionBetween: Entity[] }
---@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 InputState { aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }
---@alias Entity table
---@alias RoundStateAction "end" | "start"
T = {
@ -21,7 +21,7 @@ T = {
str = "",
marker = {},
---@type fun(self)
SelfFunction = function(self) end,
SelfFunction = function() end,
--- Actor
CanBounce = {
isSolid = true,
@ -31,24 +31,24 @@ T = {
---@type pd_image
PdImage = {},
---@type Entity
Entity = {},
---@type CanSpawn
CanSpawn = {},
---@type Collision
Collision = {},
---@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 = {},
---@type InputState
InputState = {},
---@type Entity
Entity = {},
---@type RoundStateAction
RoundStateAction = "start",
}
---@generic T

View File

@ -63,7 +63,7 @@ T = {
str = "",
marker = {},
---@type fun(self)
SelfFunction = function(self) end,
SelfFunction = function() end,
--- Actor
CanBounce = {
isSolid = true,

View File

@ -8,6 +8,10 @@ menuController = filteredSystem("menuController", { menuItems = MenuItems, input
if menuItem.highlighted then
if e.inputState.aJustPressed then
menuItem.onSelect(system.world)
for _, item in pairs(e.menuItems) do
system.world:removeEntity(item)
end
system.world:removeEntity(e)
end
if e.inputState.downJustPressed and menuItem.navigateDown then
menuItem.highlighted = false

View File

@ -42,6 +42,7 @@ filteredSystem("afterDelayAdd", { afterDelayAdd = { entity = T.Entity, delay = T
end)
roundSystem = filteredSystem("round", { roundAction = T.RoundStateAction, position = Maybe(T.XyPair) }, function(e, _, system)
system.world:removeEntity(e)
if e.roundAction == "start" then
for _, cart in pairs(cartSystem.entities) do
Cart.reset(cart)
@ -155,5 +156,4 @@ roundSystem = filteredSystem("round", { roundAction = T.RoundStateAction, positi
system.world:addEntity(menuEntity)
end
end
system.world:removeEntity(e)
end)