Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly fix crash loop when positioncomponent is nil #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/game/villagersystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,18 @@ function VillagerSystem:_fidget(entity)
local villager = entity:get("VillagerComponent")

local dirConv = require("src.game.worksystem").DIR_CONV[villager:getCardinalDirection()] -- XXX
if entity:get("PositionComponent") == nil then
print(entity, "PositionComponent is nil.")
local min, max = VillagerSystem.TIMERS.IDLE_FIDGET_MIN, VillagerSystem.TIMERS.IDLE_FIDGET_MAX
local delay = love.math.random() * (max - min) + min
villager:setDelay(delay)
-- XXX: Dummy timer component to avoid doing anything until the delay is up...
entity:add(TimerComponent(delay, { entity }, function(data)
data[1]:remove("TimerComponent")
end))

return
end
local grid = entity:get("PositionComponent"):getGrid()

if self.map:isGridReserved(entity:get("PositionComponent"):getGrid()) then
Expand Down
4 changes: 4 additions & 0 deletions src/game/walkingsystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ end
function WalkingSystem:_createPath(entity)
local walking = entity:get("WalkingComponent")

if entity:get("PositionComponent") == nil then
return nil
end

local start = entity:get("PositionComponent"):getGrid()
local path, targetEntity, targetRotation, nextStop
local instruction = walking:getInstructions()
Expand Down