From e242ab8b30090b98db4d6a8f9fd4e4627dd2abba Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 19 Mar 2025 15:47:11 -0400 Subject: [PATCH] More explicit collision type. Skip over globals defined in generated/assets during luacheck --- Makefile | 2 +- generated/filter-types.lua | 2 +- generated/filter-types.lua2p | 2 +- systems/collision-detection.lua | 2 +- systems/collision-resolution.lua | 1 - systems/velocity.lua | 4 ++-- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d7860d8..173265b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ preprocess: check: preprocess stylua -c --indent-type Spaces ./ - luacheck -d --globals tiny T Arr Maybe TextStyle --codes ./ --exclude-files ./test/ ./generated/ ./lib/ ./tiny-* + luacheck -d --no-self --globals bit tiny T Arr Maybe TextStyle $$(grep "^[A-Z]" generated/assets.lua | awk '{print $$1}' | tr '\n' ' ') --codes ./ --exclude-files ./test/ ./generated/ ./lib/ ./tiny-* test: check find ./test -name '*.lua' | xargs -L1 -I %% lua %% -v diff --git a/generated/filter-types.lua b/generated/filter-types.lua index 314ed91..82b5138 100644 --- a/generated/filter-types.lua +++ b/generated/filter-types.lua @@ -7,7 +7,7 @@ local SOME_TABLE = {} ---@alias AnyComponent any ---@alias BitMask number ----@alias Collision { collisionBetween: Entity[] } +---@alias Collision { collidedInto: Entity, collider: Entity } ---@alias Entity table ---@alias FontData love.FontData ---@alias KeyState table diff --git a/generated/filter-types.lua2p b/generated/filter-types.lua2p index a4071f4..078b475 100644 --- a/generated/filter-types.lua2p +++ b/generated/filter-types.lua2p @@ -57,7 +57,7 @@ local SOME_TABLE = {} AnyComponent = "any", Entity = "table", XyPair = "{ x: number, y: number }", - Collision = "{ collisionBetween: Entity[] }", + Collision = "{ collidedInto: Entity, collider: Entity }", BitMask = "number", FontData = "love.FontData", KeyState = "table", diff --git a/systems/collision-detection.lua b/systems/collision-detection.lua index 971f5c9..a0442fe 100644 --- a/systems/collision-detection.lua +++ b/systems/collision-detection.lua @@ -34,7 +34,7 @@ world:filteredSystem( and bit.band(collider.canCollideWith, e.canBeCollidedBy) ~= 0 then if intersects(e, collider) then - system.world:addEntity({ collisionBetween = { e, collider } }) + system.world:addEntity({ collisionBetween = { collider = collider, collidedInto = e } }) end end end diff --git a/systems/collision-resolution.lua b/systems/collision-resolution.lua index aee3f58..9c8144f 100644 --- a/systems/collision-resolution.lua +++ b/systems/collision-resolution.lua @@ -1,6 +1,5 @@ local world = require("world") world:filteredSystem("collisionResolution", { collisionBetween = T.Collision }, function(e, _, system) - local collidedInto, collider = e.collisionBetween[1], e.collisionBetween[2] system.world:removeEntity(e) end) diff --git a/systems/velocity.lua b/systems/velocity.lua index 9b4207f..bac463b 100644 --- a/systems/velocity.lua +++ b/systems/velocity.lua @@ -1,7 +1,7 @@ local world = require("world") local sqrt = math.sqrt -world:filteredSystem("velocity", { position = T.XyPair, velocity = T.XyPair }, function(e, dt, system) +world:filteredSystem("velocity", { position = T.XyPair, velocity = T.XyPair }, function(e, dt, _) if sqrt((e.velocity.x * e.velocity.x) + (e.velocity.y * e.velocity.y)) < 2 then -- velocity = nil else @@ -10,7 +10,7 @@ world:filteredSystem("velocity", { position = T.XyPair, velocity = T.XyPair }, f end end) -world:filteredSystem("drag", { velocity = T.XyPair, drag = T.number }, function(e, dt, system) +world:filteredSystem("drag", { velocity = T.XyPair, drag = T.number }, function(e, dt, _) local currentDrag = e.drag * dt e.velocity.x = e.velocity.x - (e.velocity.x * currentDrag * dt) e.velocity.y = e.velocity.y - (e.velocity.y * currentDrag * dt)