Модуль:Песочница/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 getTextureBaseUrl(project)
local function generateRepeatTemplate(data)
    if project == "Goob" then
        return "https://github.com/space-syndicate/Goob-Station/blob/master/Resources/Textures/"
    end
 
    return "https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/"
end
 
local function generateRepeatTemplate(data, project)
     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
                local prefix = (project ~= "" and JsonPaths.has(entry.id)) and (project .. ":") or ""
                 table.insert(idLinks, "[[:Файл:" .. entry.id .. ".png]]")
                 table.insert(idLinks, "[[:Файл:" .. prefix .. entry.id .. ".png]]")
             end
             end
             table.insert(result, mw.getCurrentFrame():preprocess(
             table.insert(result, mw.getCurrentFrame():preprocess(
Строка 170: Строка 162:
end
end


local function generateTemplate(entry, baseUrl, project)
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


     local prefix = (project ~= "" and JsonPaths.has(entry.id)) and (project .. ":") or ""
     if param == "image" then
 
        local states = getSpriteStates(entry)
    local states = getSpriteStates(entry)
        local stateStr = ""
    local stateStr = ""
        if states then
 
            local baseUrl = "https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/"
    if states then
            local links = {}
        local links = {}
            for _, item in ipairs(states) do
        for _, item in ipairs(states) do
                local spritePath = item.sprite
            local url = baseUrl .. item.sprite .. "/" .. item.state .. ".png"
                local stateName = item.state
            table.insert(links, "[" .. url .. " " .. item.state .. "]")
                local url = baseUrl .. spritePath .. "/" .. stateName .. ".png"
                table.insert(links, "[" .. url .. " " .. stateName .. "]")
            end
            stateStr = table.concat(links, ", ")
         end
         end
         stateStr = table.concat(links, ", ")
         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 mw.getCurrentFrame():preprocess(
     return nil
        "{{Entity Sprite/Image|" .. prefix .. entry.id ..
        "|" .. baseUrl .. spritePath ..
        "|" .. stateStr .. "}}"
    )
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 project = JsonPaths.project()
    local baseUrl = getTextureBaseUrl(project)


     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 "Ошибка загрузки JSON: " .. dataPage
         return "Ошибка: Невозможно загрузить данные из JSON (" .. dataPage .. ")."
     end
     end


     if action == "repeat" then
     if action == "repeat" then
         return generateRepeatTemplate(spriteData, project)
         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 t = generateTemplate(entry, baseUrl, project)
             local template = generateTemplate(entry, action)
             if t then
             if template then
                 table.insert(result, t)
                 table.insert(result, template)
             end
             end
         end
         end