cache my beloved
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
This commit is contained in:
parent
e700045c47
commit
7d4c856832
@ -10,6 +10,8 @@ local utils = require "lib.utils.utils"
|
||||
local level = {}
|
||||
level.__index = level
|
||||
|
||||
local path = nil
|
||||
|
||||
--- @param type "procedural"|"handmaded"
|
||||
--- @param template Procedural|Handmaded
|
||||
local function new(type, template)
|
||||
@ -25,11 +27,25 @@ local function new(type, template)
|
||||
}, level)
|
||||
end
|
||||
|
||||
local mposCache = nil
|
||||
|
||||
function level:update(dt)
|
||||
self.characterGrid:reset()
|
||||
utils.each(self.characters, function(el)
|
||||
el:update(dt)
|
||||
end)
|
||||
if self.characters[self.selector.id] then
|
||||
local charPos = self.characters[self.selector.id].logic.mapLogic.position:floor()
|
||||
--- @type Vec3
|
||||
local mpos = self.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
|
||||
|
||||
-- ДУШИ здесь больше нет, приводите рыжих обратно
|
||||
if not path or tostring(mpos) ~= mposCache then
|
||||
path = require "lib.pathfinder" (charPos, mpos) -- ?????
|
||||
end
|
||||
mposCache = tostring(mpos)
|
||||
-- path = (require "lib.pathfinder")(charPos, mpos)
|
||||
end
|
||||
self.camera:update(dt)
|
||||
self.selector:update(dt)
|
||||
end
|
||||
@ -38,12 +54,7 @@ function level:draw()
|
||||
self.map:draw()
|
||||
|
||||
--- Это отрисовка пути персонажа к мышке
|
||||
if self.selector.id then
|
||||
local charPos = self.characters[self.selector.id].logic.mapLogic.position:floor()
|
||||
--- @type Vec3
|
||||
local mpos = self.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
|
||||
local path = (require "lib.pathfinder")(charPos, mpos)
|
||||
|
||||
if self.selector.id and path then
|
||||
love.graphics.setColor(0.6, 0.75, 0.5)
|
||||
for p in path:values() do
|
||||
love.graphics.circle("fill", p.x + 0.45, p.y + 0.45, 0.1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user