Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 75: | Строка 75: | ||
local spritePath = getSpritePath(entry) | local spritePath = getSpritePath(entry) | ||
local iconBlock = findFieldInsensitive(entry, "Icon") | local iconBlock = findFieldInsensitive(entry, "Icon") | ||
local spriteBlock = findFieldInsensitive(entry, "Sprite") | local spriteBlock = findFieldInsensitive(entry, "Sprite") | ||
| Строка 84: | Строка 85: | ||
for _, layer in ipairs(spriteBlock.layers) do | for _, layer in ipairs(spriteBlock.layers) do | ||
if layer.visible ~= false then | if layer.visible ~= false then | ||
local stateName = layer.state or (iconBlock and iconBlock.state) or "icon" | local stateName = layer.state or (iconBlock and iconBlock.state) or "icon" | ||
local s = layer.sprite or (iconBlock and iconBlock.sprite) or spritePath | local s = layer.sprite or (iconBlock and iconBlock.sprite) or spritePath | ||
addState(stateName, s) | addState(stateName, s) | ||
break | break | ||
| Строка 108: | Строка 109: | ||
if not alreadyAdded and layer.visible ~= false then | if not alreadyAdded and layer.visible ~= false then | ||
local stateName = layer.state or "icon" | local stateName = layer.state or "icon" | ||
local s = layer.sprite or (iconBlock and iconBlock.sprite) or spritePath | local s = layer.sprite or (iconBlock and iconBlock.sprite) or spritePath | ||
if s then | if s then | ||
| Строка 125: | Строка 126: | ||
end | end | ||
local function generateRepeatTemplate(data) | |||
local function generateRepeatTemplate(data | |||
local spriteGroups = {} | local spriteGroups = {} | ||
| Строка 149: | Строка 142: | ||
if not found then | if not found then | ||
table.insert(spriteGroups, { entry }) | table.insert(spriteGroups, {entry}) | ||
end | end | ||
end | end | ||
| Строка 158: | Строка 151: | ||
local idLinks = {} | local idLinks = {} | ||
for _, entry in pairs(group) do | for _, entry in pairs(group) do | ||
table.insert(idLinks, "[[:Файл:" .. entry.id .. ".png]]") | |||
table.insert(idLinks, "[[:Файл:" | |||
end | end | ||
table.insert(result, mw.getCurrentFrame():preprocess( | table.insert(result, mw.getCurrentFrame():preprocess( | ||
| Строка 170: | Строка 162: | ||
end | end | ||
local function generateTemplate(entry, | 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 | ||
| Строка 176: | Строка 168: | ||
end | end | ||
if param == "image" then | |||
local states = getSpriteStates(entry) | |||
local stateStr = "" | |||
if states then | |||
local baseUrl = "https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/" | |||
local links = {} | |||
for _, item in ipairs(states) do | |||
local spritePath = item.sprite | |||
local stateName = item.state | |||
local url = baseUrl .. spritePath .. "/" .. stateName .. ".png" | |||
table.insert(links, "[" .. url .. " " .. stateName .. "]") | |||
end | |||
stateStr = table.concat(links, ", ") | |||
end | end | ||
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 | ||
return | return nil | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local action = frame.args[1] | local action = frame.args[1] | ||
local mode = frame.args[2] | |||
local | |||
local dataPage = JsonPaths.get("prototype/sprite.json") | local dataPage = JsonPaths.get("prototype/sprite.json") | ||
local spriteData = mw.loadData(dataPage) | local spriteData = mw.loadData(dataPage) | ||
if not spriteData or type(spriteData) ~= "table" then | if not spriteData or type(spriteData) ~= "table" then | ||
return "Ошибка | return "Ошибка: Невозможно загрузить данные из JSON (" .. dataPage .. ")." | ||
end | end | ||
if action == "repeat" then | if action == "repeat" then | ||
return generateRepeatTemplate(spriteData | return generateRepeatTemplate(spriteData) | ||
elseif action == "image" then | elseif action == "image" then | ||
local result = {} | local result = {} | ||
for _, entry in pairs(spriteData) do | for _, entry in pairs(spriteData) do | ||
local | local template = generateTemplate(entry, action) | ||
if | if template then | ||
table.insert(result, | table.insert(result, template) | ||
end | end | ||
end | end | ||