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

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


return path
return path
end
local function normalizeState(state)
if state == nil then
return nil
end
state = mw.text.trim(tostring(state))
if state == "" then
return nil
end
return state
end
end


Строка 95: Строка 108:
local mode = frame.args[1]
local mode = frame.args[1]
local id = frame.args[2]
local id = frame.args[2]
local stateArg = frame.args[3]


if not mode or not id then
if not mode or not id then
Строка 141: Строка 155:
if mode == "path" then
if mode == "path" then
local targetPath = normalizeSpritePath(id)
local targetPath = normalizeSpritePath(id)
local targetState = normalizeState(stateArg)


for entityId, entry in pairs(data) do
for entityId, entry in pairs(data) do
if getSpritePath(entry) == targetPath then
if getSpritePath(entry) == targetPath then
return entityId
if not targetState then
return entityId
end
 
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
end
end


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