local GridEdgeCell = class("GridEdgeCell", BaseCell)
local DEFAULT_X = 10000

function GridEdgeCell:refresh(entity)
    local uiMap = self:getUIMap()
    local mask = uiMap["grid_edge_cell.ani_node.mask"]

    self.entity = entity
    local icon = self.entity:getIcon()
    if self.lastIcon ~= icon then
        self.lastIcon = icon
        uiMap["grid_edge_cell.ani_node.icon"]:setSprite(GConst.ATLAS_PATH.BATTLE, icon)
        mask:setSprite(GConst.ATLAS_PATH.BATTLE, icon)
    end
    self:resetPosition()
    mask:setVisible(self.showMaskTag == true)

end

function GridEdgeCell:resetPosition()
    if not self.entity or self.entity:getIsIdle() then
        self:getBaseObject():setAnchoredPositionX(DEFAULT_X)
        self:getBaseObject():setVisible(false)
        return
    end
    self:getBaseObject():setVisible(true)

    local pos = self.entity:getPos()
    self:getBaseObject():setAnchoredPosition(pos.x, pos.y)
    local eulerAngles = self.entity:getEulerAngles()
    self:getBaseObject():setLocalEulerAngles(eulerAngles.x, eulerAngles.y, eulerAngles.z)
end

function GridEdgeCell:showMask(show)
    if self.showMaskTag == show then
        return
    end
    self.showMaskTag = show
    local uiMap = self:getUIMap()
    local mask = uiMap["grid_edge_cell.ani_node.mask"]
    mask:setVisible(show)
end

return GridEdgeCell