Compare commits

..

No commits in common. "9e7a787d831f93d036162cc54538263b549d9ea2" and "80ae1e0a68579afcb7be8c7195b3c489487d7c56" have entirely different histories.

View File

@ -1,6 +1,8 @@
local utils = require "lib.utils.utils" local utils = require "lib.utils.utils"
local pQueue = require "lib.utils.priority_queue"
--- @class CharacterGrid : Grid --- @class CharacterGrid : Grid
--- @field __grid {string: Id|nil} --- @field __grid {string: Id|nil}
--- @field yOrderQueue PriorityQueue<Character> очередь отрисовки сверху вниз
local grid = setmetatable({}, require "lib.level.grid.base") local grid = setmetatable({}, require "lib.level.grid.base")
grid.__index = grid grid.__index = grid
@ -27,13 +29,22 @@ function grid:add(id)
end end
end end
--- @param a Character
--- @param b Character
local function drawCmp(a, b)
--- @TODO: это захардкожено, надо разделить поведения
return a:has(Tree.behaviors.positioned).position.y < b:has(Tree.behaviors.positioned).position.y
end
--- fills the grid with the actual data --- fills the grid with the actual data
--- ---
--- should be called as early as possible during every tick --- should be called as early as possible during every tick
function grid:reload() function grid:reload()
self:reset() self:reset()
self.yOrderQueue = pQueue.new(drawCmp)
utils.each(Tree.level.characters, function(c) utils.each(Tree.level.characters, function(c)
self:add(c.id) self:add(c.id)
self.yOrderQueue:insert(c)
end) end)
end end