Some renames to be a little less generic
I.e. `entity` is unclear, and hard to search for.
This commit is contained in:
parent
e90e06d15c
commit
60461aa14f
|
@ -1,3 +1,6 @@
|
|||
if not playdate.isSimulator then
|
||||
return
|
||||
end
|
||||
getCurrentTimeMilliseconds = playdate.getCurrentTimeMilliseconds
|
||||
|
||||
tinyTrackEntityAges = true
|
||||
|
@ -10,4 +13,33 @@ if tinyTrackEntityAges then
|
|||
end
|
||||
|
||||
tinyLogSystemUpdateTime = false
|
||||
tinyLogSystemChanges = false
|
||||
tinyLogSystemChanges = false
|
||||
|
||||
tinyWarnWhenNonDataOnEntities = false
|
||||
|
||||
if tinyWarnWhenNonDataOnEntities then
|
||||
function checkForNonData(e, nested, tableCache)
|
||||
nested = nested or false
|
||||
tableCache = tableCache or {}
|
||||
|
||||
local valType = type(e)
|
||||
if valType == "table" then
|
||||
if tableCache[e] then
|
||||
return
|
||||
end
|
||||
tableCache[e] = true
|
||||
for k, v in pairs(e) do
|
||||
local keyWarning = checkForNonData(k, true, tableCache)
|
||||
if keyWarning then
|
||||
return keyWarning
|
||||
end
|
||||
local valueWarning = checkForNonData(v, true, tableCache)
|
||||
if valueWarning then
|
||||
return valueWarning
|
||||
end
|
||||
end
|
||||
elseif valType == "function" or valType == "thread" or valType == "userdata" then
|
||||
return valType
|
||||
end
|
||||
end
|
||||
end
|
14
lib/tiny.lua
14
lib/tiny.lua
|
@ -489,6 +489,20 @@ if tinyTrackEntityAges then
|
|||
function tiny.addEntity(world, entity)
|
||||
local added = wrapped(world, entity)
|
||||
added[ENTITY_INIT_MS] = getCurrentTimeMilliseconds()
|
||||
return added
|
||||
end
|
||||
tiny_addEntity = tiny.addEntity
|
||||
end
|
||||
|
||||
if tinyWarnWhenNonDataOnEntities then
|
||||
local wrapped = tiny.addEntity
|
||||
function tiny.addEntity(world, entity)
|
||||
local added = wrapped(world, entity)
|
||||
local nonDataType = checkForNonData(added)
|
||||
if nonDataType then
|
||||
print("Detected non-data type '" .. nonDataType .. "' on entity")
|
||||
end
|
||||
return added
|
||||
end
|
||||
tiny_addEntity = tiny.addEntity
|
||||
end
|
||||
|
|
|
@ -27,6 +27,7 @@ function Cart.reset(o)
|
|||
|
||||
---@param world World
|
||||
function o:spawnEntitiesWhenStopped(world)
|
||||
-- it'd be funny if the cart fully just exploded instead
|
||||
self.velocity = { x = 300, y = 0 }
|
||||
self.canCollideWith = 4
|
||||
world:addEntity({
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
---@alias BitMask number
|
||||
---@alias CanBeBounced { flat: XyPair, mult = XyPair }
|
||||
---@alias CanSpawn { entity: Entity }
|
||||
---@alias CanSpawn { entityToSpawn: Entity }
|
||||
---@alias Collision { collisionBetween: Entity[] }
|
||||
---@alias Entity table
|
||||
---@alias InRelations Entity[]
|
||||
|
|
|
@ -58,7 +58,7 @@ end
|
|||
BitMask = "number",
|
||||
CanBeBounced = "{ flat: XyPair, mult: XyPair }",
|
||||
RoundStateAction = { '"end" | "start"', '"start"' },
|
||||
CanSpawn = "{ entity: Entity }",
|
||||
CanSpawn = "{ entityToSpawn: Entity }",
|
||||
InRelations = "Entity[]",
|
||||
CanBeBounced = "{ flat: XyPair, mult = XyPair }",
|
||||
InputState = "{ receivedInputThisFrame: boolean, aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }",
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
local MenuItems = {}
|
||||
|
||||
menuController = filteredSystem("menuController", { menuItems = MenuItems, inputState = T.InputState }, function(e, _, system)
|
||||
if not e.inputState.receivedInputThisFrame then
|
||||
return
|
||||
end
|
||||
|
||||
for _, menuItem in pairs(e.menuItems) do
|
||||
if menuItem.highlighted then
|
||||
if e.inputState.aJustPressed then
|
||||
|
|
|
@ -32,12 +32,12 @@ end)
|
|||
|
||||
removeAtRoundStart = filteredSystem("removeAtRoundStart", { removeAtRoundStart = T.bool })
|
||||
|
||||
filteredSystem("afterDelayAdd", { afterDelayAdd = { entity = T.Entity, delay = T.number } }, function(e, dt, system)
|
||||
filteredSystem("afterDelayAdd", { afterDelayAdd = { entityToAdd = T.Entity, delay = T.number } }, function(e, dt, system)
|
||||
e.afterDelayAdd.delay = e.afterDelayAdd.delay - dt
|
||||
if e.afterDelayAdd.delay > 0 then
|
||||
return
|
||||
end
|
||||
system.world:addEntity(e.afterDelayAdd.entity)
|
||||
system.world:addEntity(e.afterDelayAdd.entityToAdd)
|
||||
system.world:removeEntity(e)
|
||||
end)
|
||||
|
||||
|
@ -150,7 +150,7 @@ roundSystem = filteredSystem("round", { roundAction = T.RoundStateAction, positi
|
|||
system.world:addEntity({
|
||||
afterDelayAdd = {
|
||||
delay = delay,
|
||||
entity = upgradeEntity
|
||||
entityToAdd = upgradeEntity
|
||||
},
|
||||
})
|
||||
system.world:addEntity(menuEntity)
|
||||
|
|
|
@ -35,7 +35,7 @@ function spawnerSystem:preProcess()
|
|||
return tiny.SKIP_PROCESS
|
||||
end
|
||||
|
||||
local spawnEveryX = 30
|
||||
local spawnEveryX = 35
|
||||
|
||||
-- Currently spawns AT MOST one new ingredient per frame, which is probably not enough at high speeds!
|
||||
function spawnerSystem:postProcess()
|
||||
|
@ -43,7 +43,7 @@ function spawnerSystem:postProcess()
|
|||
local newlySpawned = Ingredients.nextInCache()
|
||||
|
||||
-- TODO: If performance becomes an issue, maybe just swap out __index
|
||||
for k, v in pairs(selectedSpawner.canSpawn.entity) do
|
||||
for k, v in pairs(selectedSpawner.canSpawn.entityToSpawn) do
|
||||
newlySpawned[k] = v
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ function addAllSpawners(world)
|
|||
odds = spawnerOdds,
|
||||
canSpawn = {
|
||||
yRange = yRange,
|
||||
entity = {
|
||||
entityToSpawn = {
|
||||
score = score,
|
||||
canBeCollidedBy = 1,
|
||||
expireAfterCollision = true,
|
||||
|
@ -111,13 +111,13 @@ function getAvailableSpawnerUpgrades()
|
|||
-- upgrades[#upgrades + 1] = { hasUpgradeSpeed = spawner.hasUpgradeSpeed }
|
||||
end
|
||||
|
||||
if spawner.canSpawn.entity.score then
|
||||
if spawner.canSpawn.entityToSpawn.score then
|
||||
local name = "Double " .. spawner.name .. " value"
|
||||
upgrades[#upgrades + 1] = {
|
||||
name = name,
|
||||
apply = function(world)
|
||||
print("Applying " .. name)
|
||||
spawner.canSpawn.entity.score = spawner.canSpawn.entity.score * 2
|
||||
spawner.canSpawn.entityToSpawn.score = spawner.canSpawn.entityToSpawn.score * 2
|
||||
world:addEntity({ roundAction = "start" })
|
||||
end,
|
||||
}
|
||||
|
@ -133,15 +133,6 @@ function getAvailableSpawnerUpgrades()
|
|||
world:addEntity({ roundAction = "start" })
|
||||
end,
|
||||
}
|
||||
|
||||
-- if not spawner.canSpawn.entity.velocity then
|
||||
-- upgrades[#upgrades + 1] = {
|
||||
-- name = spawner.name .. " Movement",
|
||||
-- upgrade = function()
|
||||
-- spawner.canSpawn.entity.velocity = { x = -10, y = 0 }
|
||||
-- end,
|
||||
-- }
|
||||
-- end
|
||||
end
|
||||
return upgrades
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue