Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 2: | Строка 2: | ||
local cachedData = nil | local cachedData = nil | ||
local loadCount = 0 | |||
local function loadData(filePath) | local function loadData(filePath) | ||
| Строка 7: | Строка 8: | ||
return cachedData | return cachedData | ||
end | end | ||
loadCount = loadCount + 1 | |||
local page = mw.title.new(filePath) | local page = mw.title.new(filePath) | ||
local content = page and page:getContent() | local content = page and page:getContent() | ||
cachedData = content and mw.text.jsonDecode(content) or nil | cachedData = content and mw.text.jsonDecode(content) or nil | ||
return cachedData | return cachedData | ||
end | end | ||
| Строка 33: | Строка 19: | ||
local secondaryParam = frame.args[2] | local secondaryParam = frame.args[2] | ||
local data = loadData('User:IanComradeBot/prototypes/entity sprite.json') | |||
if not data then | |||
return 'Ошибка: Невозможно загрузить данные из JSON.' | |||
end | end | ||
if | if param == "debug" then | ||
return | return "Количество загрузок JSON: " .. loadCount | ||
end | end | ||
if param == "image" and secondaryParam then | if param == "image" and secondaryParam then | ||
for _, entry in ipairs(data) do | |||
if entry.id == secondaryParam then | |||
return entry.Sprite and entry.Sprite.sprite or (entry.Icon and entry.Icon.sprite) or "Ошибка: Спрайт не найден." | |||
end | |||
end | |||
return "Ошибка: ID не найден." | |||
end | end | ||
end | end | ||
return p | return p | ||