Модуль:Entity Sprite/all: различия между версиями
Pok (обсуждение | вклад) Новая страница: «local p = {} -- Загрузка данных local function loadData(filePath) local page = mw.title.new(filePath) local content = page and page:getContent() return content and mw.text.jsonDecode(content) or nil end -- Проверка равенства двух таблиц local function deepEqual(t1, t2) if t1 == t2 then return true end if type(t1) ~= "table" or type(t2) ~= "table" then return false end -- Если это ма...» |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 105: | Строка 105: | ||
end | end | ||
-- | -- Функция генерации шаблона по записи | ||
local function generateTemplate(entry, param | local function generateTemplate(entry, param, data) | ||
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: | Строка 113: | ||
if param == "image" then | if param == "image" then | ||
return mw.getCurrentFrame():preprocess("{{Entity Sprite/Image|" .. entry.id .. "|" .. spritePath .. "}}") | |||
elseif param == "path" then | elseif param == "path" then | ||
return mw.getCurrentFrame():preprocess("{{Entity Sprite/Path|" .. entry.id .. "|" .. spritePath .. "}}") | return mw.getCurrentFrame():preprocess("{{Entity Sprite/Path|" .. entry.id .. "|" .. spritePath .. "}}") | ||
end | end | ||
return nil | return nil | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local param = frame.args[1] | local param = frame.args[1] | ||
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | ||
| Строка 191: | Строка 131: | ||
if param == "repeat" then | if param == "repeat" then | ||
return generateRepeatTemplate(data) | return generateRepeatTemplate(data) | ||
elseif param == "image" or param == "path" then | elseif param == "image" or param == "path" then | ||
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, data) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||
| Строка 209: | Строка 141: | ||
return table.concat(result, "\n") | return table.concat(result, "\n") | ||
else | else | ||
return | return nil | ||
end | end | ||
end | end | ||
return p | return p | ||