Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | -- Загрузка данных | ||
local | local data = mw.loadData("Module:Entity Sprite/data") | ||
local p = {} | |||
local | |||
-- Получение таблицы данных | |||
function p.getData() | |||
return data | |||
return | |||
end | end | ||
| Строка 70: | Строка 25: | ||
end | end | ||
local function generateTemplate(entry, param, id, data) | |||
local function generateTemplate(entry, param, | |||
local spritePath = getSpritePath(entry) | local spritePath = getSpritePath(entry) | ||
if not entry.id or not spritePath then | if not entry.id or not spritePath then | ||
| Строка 113: | Строка 32: | ||
if param == "image" then | if param == "image" then | ||
if | if id then | ||
if tostring(entry.id) == tostring( | if tostring(entry.id) == tostring(id) then | ||
return spritePath | return spritePath | ||
end | end | ||
return nil | return nil | ||
else | else | ||
return | return "" | ||
end | end | ||
elseif param == "path" then | elseif param == "path" then | ||
if | if id then | ||
for _, e in pairs(data) do | for _, e in pairs(data) do | ||
if getSpritePath(e) == | if getSpritePath(e) == id then | ||
return e.id | return e.id | ||
end | end | ||
| Строка 130: | Строка 49: | ||
return nil | return nil | ||
end | end | ||
return | return "" | ||
end | end | ||
| Строка 136: | Строка 55: | ||
end | end | ||
-- | -- Получаем спрайт по ID | ||
function p.getSprite(frame) | |||
local id = | local id = frame.args[1] | ||
if not id then return "Ошибка: не указан ID" end | |||
if id | |||
for _, entry in ipairs(data) do | |||
if entry.id == id then | |||
if | return entry.Sprite and entry.Sprite.sprite or "Ошибка: спрайт не найден" | ||
return "" | |||
end | end | ||
end | end | ||
return | return "Ошибка: ID не найден" | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local param = frame.args[1] | local param = frame.args[1] | ||
local | local id = frame.args[2] | ||
if param == "image" or param == "path" then | |||
if | |||
local result = {} | local result = {} | ||
for _, entry in pairs(data) do | for _, entry in pairs(data) do | ||
local template = generateTemplate(entry, param, | local template = generateTemplate(entry, param, id, data) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||
| Строка 212: | Строка 86: | ||
end | end | ||
end | end | ||
return p | return p | ||