Модуль:Entity Sprite/all: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local | local spriteData = mw.loadData("Модуль:IanComradeBot/prototypes/entity sprite.json/data") | ||
local function deepEqual(t1, t2) | local function deepEqual(t1, t2) | ||
| Строка 122: | Строка 118: | ||
table.insert(idLinks, "[[:Файл:" .. entry.id .. ".png]]") | table.insert(idLinks, "[[:Файл:" .. entry.id .. ".png]]") | ||
end | end | ||
table.insert(result, mw.getCurrentFrame():preprocess("{{Entity Sprite/Repeat|" .. table.concat(idLinks, " ") .. "|" .. group[1].id .. "}}")) | table.insert(result, mw.getCurrentFrame():preprocess( | ||
"{{Entity Sprite/Repeat|" .. table.concat(idLinks, " ") .. "|" .. group[1].id .. "}}" | |||
)) | |||
end | end | ||
end | end | ||
| Строка 129: | Строка 127: | ||
end | end | ||
local function generateTemplate(entry, param | 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 | ||
return nil | return nil | ||
end | end | ||
local state = getSpriteState(entry) | local state = getSpriteState(entry) | ||
| Строка 144: | Строка 140: | ||
stateStr = " (state: " .. state .. ")" | stateStr = " (state: " .. state .. ")" | ||
end | end | ||
return mw.getCurrentFrame():preprocess("{{Entity Sprite/Image|" .. entry.id .. "|https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/" .. spritePath .. stateStr .. "}}") | return mw.getCurrentFrame():preprocess( | ||
"{{Entity Sprite/Image|" .. entry.id .. | |||
"|https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/" .. | |||
spritePath .. stateStr .. "}}" | |||
) | |||
end | end | ||
| Строка 153: | Строка 153: | ||
local param = frame.args[1] | local param = frame.args[1] | ||
if not spriteData or type(spriteData) ~= "table" then | |||
if not | return "Ошибка: Невозможно загрузить данные из JSON." | ||
return | |||
end | end | ||
if param == "repeat" then | if param == "repeat" then | ||
return generateRepeatTemplate( | return generateRepeatTemplate(spriteData) | ||
elseif param == "image" or param == "path" then | elseif param == "image" or param == "path" then | ||
local result = {} | local result = {} | ||
for _, entry in pairs( | for _, entry in pairs(spriteData) do | ||
local template = generateTemplate(entry, param | local template = generateTemplate(entry, param) | ||
if template then | if template then | ||
table.insert(result, template) | table.insert(result, template) | ||