Модуль:Entity Sprite: различия между версиями

Нет описания правки
Нет описания правки
Строка 14: Строка 14:


return path
return path
end
-- Функция получения таблицы данных
local function getIdTable()
if type(spriteData) == "table" and type(spriteData.id) == "table" then
return spriteData.id
end
return nil
end
end


-- Функция для получения таблицы данных
-- Функция для получения таблицы данных
function p.getData()
function p.getData()
return spriteData
return getIdTable() or {}
end
end


Строка 29: Строка 37:
end
end


-- Проверка видимости слоя
-- Проверка visible
local function isLayerVisible(layer)
local function isLayerVisible(layer)
if not layer then
if not layer then
return false
return false
end
end
return layer.visible ~= false
return layer.visible ~= false
end
end
Строка 78: Строка 85:
end
end


-- image/state работают по entityId
local data = getIdTable()
if not data then
return "Ошибка: неверный формат JSON"
end
 
if mode == "image" or mode == "state" then
if mode == "image" or mode == "state" then
local entry = spriteData[id]
local entry = data[id]
if not entry then
if not entry then
return "Ошибка: ID не найден"
return "Ошибка: ID не найден"
Строка 88: Строка 99:
local sprite = getSpritePath(entry)
local sprite = getSpritePath(entry)
return sprite or "Ошибка: спрайт не найден"
return sprite or "Ошибка: спрайт не найден"
end
elseif mode == "state" then
 
if mode == "state" then
local states = getSpriteStates(entry)
local states = getSpriteStates(entry)
if not states then
if not states then
Строка 115: Строка 124:
end
end


-- path работает наоборот: ищет entityId по пути спрайта
if mode == "path" then
if mode == "path" then
local targetPath = normalizeSpritePath(id)
local targetPath = normalizeSpritePath(id)


for entityId, entry in pairs(spriteData) do
for entityId, entry in pairs(data) do
if getSpritePath(entry) == targetPath then
if getSpritePath(entry) == targetPath then
return entityId
return entityId