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

Нет описания правки
Нет описания правки
 
(не показаны 3 промежуточные версии этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
-- Загрузка данных
local JsonPaths = require('Module:JsonPaths')
local JsonPaths = require('Module:JsonPaths')
local spriteData = mw.loadData(JsonPaths.get("prototype/sprite.json"))
local spriteData = mw.loadData(JsonPaths.get("component/Sprite.json"))


local p = {}
local p = {}
Строка 102: Строка 102:


return (#result > 0) and result or nil
return (#result > 0) and result or nil
end
local function findByPathAndState(data, targetPath, targetState)
for entityId, entry in pairs(data) do
if getSpritePath(entry) == targetPath then
local states = getSpriteStates(entry)
if states then
for _, item in ipairs(states) do
if normalizeState(item.state) == targetState then
return entityId
end
end
end
end
end
return nil
end
local function findByPath(data, targetPath)
for entityId, entry in pairs(data) do
if getSpritePath(entry) == targetPath then
return entityId
end
end
return nil
end
end


Строка 157: Строка 184:
local targetState = normalizeState(stateArg)
local targetState = normalizeState(stateArg)


for entityId, entry in pairs(data) do
if targetState then
if getSpritePath(entry) == targetPath then
local byState = findByPathAndState(data, targetPath, targetState)
if not targetState then
if byState then
return entityId
return JsonPaths.prefixFile(byState)
end
end
end


local states = getSpriteStates(entry)
local byPath = findByPath(data, targetPath)
if states then
if byPath then
for _, item in ipairs(states) do
return JsonPaths.prefixFile(byPath)
if normalizeState(item.state) == targetState then
return entityId
end
end
end
end
end
end


return "Ошибка: путь" .. (targetState and " или стейт" or "") .. " не найден"
return "Ошибка: путь не найден"
end
end