Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показаны 3 промежуточные версии этого же участника) | |||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | -- Загрузка данных | ||
local JsonPaths = require('Module:JsonPaths') | local JsonPaths = require('Module:JsonPaths') | ||
local spriteData = mw.loadData(JsonPaths.get(" | 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) | ||
if targetState then | |||
if | local byState = findByPathAndState(data, targetPath, targetState) | ||
if byState then | |||
return JsonPaths.prefixFile(byState) | |||
end | |||
end | |||
local byPath = findByPath(data, targetPath) | |||
if byPath then | |||
return JsonPaths.prefixFile(byPath) | |||
end | end | ||
return "Ошибка: путь | return "Ошибка: путь не найден" | ||
end | end | ||