Модуль:Entity Sprite/all: различия между версиями

мНет описания правки
мНет описания правки
Строка 39: Строка 39:
end
end


local function getInsensitiveKey(t, target)
local function getInsensitiveKey(tbl, fieldName)
    target = target:lower()
     for key, value in pairs(tbl) do
     for k, v in pairs(t) do
         if type(key) == "string" and mw.ustring.lower(key) == mw.ustring.lower(fieldName) then
         if type(k) == "string" and k:lower() == target then
             return value
             return v
         end
         end
     end
     end
Строка 68: Строка 67:


local function getSpriteStates(entry)
local function getSpriteStates(entry)
    local result = {}
     local spriteBlock = getInsensitiveKey(entry, "Sprite")
     local spriteBlock = getInsensitiveKey(entry, "Sprite")
     if spriteBlock and spriteBlock.layers then
     if spriteBlock and spriteBlock.layers then
        local states = {}
         for _, layer in ipairs(spriteBlock.layers) do
         for _, layer in ipairs(spriteBlock.layers) do
             if layer.visible == false then
             if layer.visible == false then
            elseif layer.state and layer.sprite then
                table.insert(result, { state = layer.state, sprite = layer.sprite })
             elseif layer.state then
             elseif layer.state then
                 table.insert(states, layer.state)
                 table.insert(result, { state = layer.state, sprite = getSpritePath(entry) })
             end
             end
         end
         end
        if #states > 0 then
            return states
        end
     end
     end
    if #result > 0 then
        return result
    end
     local iconBlock = getInsensitiveKey(entry, "Icon")
     local iconBlock = getInsensitiveKey(entry, "Icon")
     if iconBlock and iconBlock.state then
     if iconBlock and iconBlock.state then
         return { iconBlock.state }
         return { { state = iconBlock.state, sprite = getSpritePath(entry) } }
     end
     end
     if spriteBlock and spriteBlock.state then
     if spriteBlock and spriteBlock.state then
         return { spriteBlock.state }
         return { { state = spriteBlock.state, sprite = getSpritePath(entry) } }
     end
     end
     return nil
     return nil
end
end
Строка 137: Строка 141:
         local stateStr = ""
         local stateStr = ""
         if states then
         if states then
             local joined = table.concat(states, ", ")
             local baseUrl = "https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/"
            local base = "https://github.com/space-syndicate/space-station-14/blob/master/Resources/Textures/" .. spritePath .. "/"
            local links = {}
            joined = mw.ustring.gsub(joined, "([%w_%-]+)", "[" .. base .. "%1.png %1]")
            for _, item in ipairs(states) do
             stateStr = "" .. joined
                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
         return mw.getCurrentFrame():preprocess(
         return mw.getCurrentFrame():preprocess(