Модуль:Entity Sprite: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 8: | Строка 8: | ||
if type(t1) ~= "table" or type(t2) ~= "table" then return false end | if type(t1) ~= "table" or type(t2) ~= "table" then return false end | ||
local function isArray(t) | local function isArray(t) | ||
local i = 0 | local i = 0 | ||
| Строка 35: | Строка 34: | ||
end | end | ||
for k, v in pairs(t1) do | for k, v in pairs(t1) do | ||
if t2[k] == nil or not deepEqual(v, t2[k]) then | if t2[k] == nil or not deepEqual(v, t2[k]) then | ||
| Строка 101: | Строка 99: | ||
return table.concat(result, "\n") | return table.concat(result, "\n") | ||
end | end | ||
-- Обновляем основную функцию шаблонизации | -- Обновляем основную функцию шаблонизации | ||
local function generateTemplate(entry, param, secondaryParam | local function generateTemplate(entry, param, secondaryParam) | ||
local spritePath = getSpritePath(entry) | local spritePath = getSpritePath(entry) | ||
if not entry.id or not spritePath then | if not entry.id or not spritePath then | ||
| Строка 130: | Строка 116: | ||
else | else | ||
return mw.getCurrentFrame():preprocess("{{Entity Sprite/Image|" .. entry.id .. "|" .. spritePath .. "}}") | return mw.getCurrentFrame():preprocess("{{Entity Sprite/Image|" .. entry.id .. "|" .. spritePath .. "}}") | ||
end | end | ||
end | end | ||
| Строка 158: | Строка 133: | ||
local path = params.Path | local path = params.Path | ||
local entry = nil | local entry = nil | ||
if id and id ~= "" then | if id and id ~= "" then | ||
| Строка 169: | Строка 143: | ||
end | end | ||
if entry then | if entry then | ||
spritePath = getSpritePath(entry) | spritePath = getSpritePath(entry) | ||
| Строка 177: | Строка 150: | ||
end | end | ||
if not path or path == "" then | if not path or path == "" then | ||
path = "Resources/Textures/" .. (spritePath or "") | path = "Resources/Textures/" .. (spritePath or "") | ||
end | end | ||
return mw.getCurrentFrame():preprocess( | return mw.getCurrentFrame():preprocess( | ||
"{{Файл\n" .. | "{{Файл\n" .. | ||
| Строка 202: | Строка 173: | ||
return 'Ошибка: Невозможно загрузить данные из JSON.' | return 'Ошибка: Невозможно загрузить данные из JSON.' | ||
end | end | ||
if param == "repeat" then | if param == "repeat" then | ||
return generateRepeatTemplate(data) | return generateRepeatTemplate(data) | ||
elseif param == "image" then | |||
elseif param == "image | |||
local result = {} | local result = {} | ||
for _, entry in ipairs(data) do | for _, entry in ipairs(data) do | ||
local template = generateTemplate(entry, param, secondaryParam | local template = generateTemplate(entry, param, secondaryParam) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||
| Строка 226: | Строка 186: | ||
return table.concat(result, "\n") | return table.concat(result, "\n") | ||
else | else | ||
return generateDefaultTemplate(data, frame.args) | return generateDefaultTemplate(data, frame.args) | ||
end | end | ||