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" } ENTITY_INIT_MS = { "ENTITY_INIT_MS" }
if tinyTrackEntityAges then if tinyTrackEntityAges then
function tiny.getEntityAgeMs(entity) function tinyGetEntityAgeMs(entity)
return entity[ENTITY_INIT_MS] return entity[ENTITY_INIT_MS]
end end
end end
tinyLogSystemUpdateTime = false tinyLogSystemUpdateTime = false
tinyLogSystemChanges = false

View File

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

View File

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

View File

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

View File

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

View File

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