diff --git a/lib/tiny-debug.lua b/lib/tiny-debug.lua index ce1f4d5..0e2dce4 100644 --- a/lib/tiny-debug.lua +++ b/lib/tiny-debug.lua @@ -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 \ No newline at end of file +tinyLogSystemUpdateTime = false +tinyLogSystemChanges = false \ No newline at end of file diff --git a/lib/tiny.lua b/lib/tiny.lua index ef29000..243e1ba 100644 --- a/lib/tiny.lua +++ b/lib/tiny.lua @@ -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 diff --git a/src/systems/filter-types.lua b/src/systems/filter-types.lua index 80aca94..24935f1 100644 --- a/src/systems/filter-types.lua +++ b/src/systems/filter-types.lua @@ -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 diff --git a/src/systems/filter-types.lua2p b/src/systems/filter-types.lua2p index 2a4a687..1de6f7b 100644 --- a/src/systems/filter-types.lua2p +++ b/src/systems/filter-types.lua2p @@ -63,7 +63,7 @@ T = { str = "", marker = {}, ---@type fun(self) - SelfFunction = function(self) end, + SelfFunction = function() end, --- Actor CanBounce = { isSolid = true, diff --git a/src/systems/menu.lua b/src/systems/menu.lua index f39228d..7b526cf 100644 --- a/src/systems/menu.lua +++ b/src/systems/menu.lua @@ -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 diff --git a/src/systems/rounds.lua b/src/systems/rounds.lua index b7c4137..200b1ac 100644 --- a/src/systems/rounds.lua +++ b/src/systems/rounds.lua @@ -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)