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

мНет описания правки
мНет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


local function loadData(filePath)
local spriteData = mw.loadData("Модуль:IanComradeBot/prototypes/entity sprite.json/data")
    local page = mw.title.new(filePath)
    local content = page and page:getContent()
    return content and mw.text.jsonDecode(content) or nil
end


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, data)
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 spriteField = getInsensitiveKey(entry, "Sprite")


     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]


    local data = loadData('User:IanComradeBot/prototypes/entity sprite.json')
     if not spriteData or type(spriteData) ~= "table" then
     if not data or type(data) ~= 'table' then
         return "Ошибка: Невозможно загрузить данные из JSON."
         return 'Ошибка: Невозможно загрузить данные из JSON.'
     end
     end


     if param == "repeat" then
     if param == "repeat" then
         return generateRepeatTemplate(data)
         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(data) do
         for _, entry in pairs(spriteData) do
             local template = generateTemplate(entry, param, data)
             local template = generateTemplate(entry, param)
             if template then
             if template then
                 table.insert(result, template)
                 table.insert(result, template)