Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 19: | Строка 19: | ||
end | end | ||
-- Функция получения пути спрайта | -- Функция получения пути спрайта: сначала пытаем Icon.sprite, затем Sprite.sprite, затем первый layer.sprite | ||
local function getSpritePath(entry) | local function getSpritePath(entry) | ||
local | local iconBlock = findFieldInsensitive(entry, "Icon") | ||
if type(iconBlock) == "table" and iconBlock.sprite then | |||
return iconBlock.sprite | |||
end | |||
local spriteBlock = findFieldInsensitive(entry, "Sprite") | |||
if not spriteBlock then return nil end | if not spriteBlock then return nil end | ||
| Строка 71: | Строка 75: | ||
if iconBlock and iconBlock.state and isLayerVisibleAndShaded(iconBlock) then | if iconBlock and iconBlock.state and isLayerVisibleAndShaded(iconBlock) then | ||
addState(iconBlock.state, | local s = (type(iconBlock) == "table" and iconBlock.sprite) or spritePath | ||
addState(iconBlock.state, s) | |||
else | else | ||
local spriteBlock = findFieldInsensitive(entry, "Sprite") | local spriteBlock = findFieldInsensitive(entry, "Sprite") | ||
| Строка 138: | Строка 143: | ||
local spritePath = item.sprite | local spritePath = item.sprite | ||
local stateName = item.state | local stateName = item.state | ||
local url = baseUrl .. spritePath .. "/" .. stateName .. ".png" | if spritePath then | ||
local url = baseUrl .. spritePath .. "/" .. stateName .. ".png" | |||
table.insert(links, "[" .. url .. " " .. stateName .. "]") | |||
else | |||
table.insert(links, stateName .. " Error: sprite not found") | |||
end | |||
end | end | ||
return "(state: " .. table.concat(links, ", ") .. ")" | return "(state: " .. table.concat(links, ", ") .. ")" | ||