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

Нет описания правки
Нет описания правки
 
(не показана 1 промежуточная версия этого же участника)
Строка 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


Строка 89: Строка 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


Строка 95: Строка 135:
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: Строка 182:
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
if targetState then
if getSpritePath(entry) == targetPath then
local byState = findByPathAndState(data, targetPath, targetState)
return entityId
if byState then
return byState
end
end
end
local byPath = findByPath(data, targetPath)
if byPath then
return byPath
end
end