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

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


-- Загрузка данных
-- Загрузка данных
local jsonData = nil
local function loadData(filePath)
local function loadData(filePath)
     local page = mw.title.new(filePath)
     if not jsonData then
    local content = page and page:getContent()
        local page = mw.title.new(filePath)
    return content and mw.text.jsonDecode(content) or nil
        local content = page and page:getContent()
        jsonData = content and mw.text.jsonDecode(content) or nil
    end
    return jsonData
end
end


Строка 101: Строка 106:
             end
             end
             local firstId = group[1].id
             local firstId = group[1].id
             table.insert(result, mw.getCurrentFrame():preprocess("{{Entity Sprite/Repeat|" .. table.concat(idLinks, " ") .. "|" .. firstId .. "}}"))
             table.insert(result, "{{Entity Sprite/Image|" .. entry.id .. "|" .. spritePath .. "}}")
         end
         end
     end
     end


     return table.concat(result, "\n")
     return mw.getCurrentFrame():preprocess(table.concat(result, "\n"))
end
end


-- Создаём индекс для путей
-- Создаём индекс для путей
local spritePathCache = nil
local function createSpritePathIndex(data)
local function createSpritePathIndex(data)
     local index = {}
     if not spritePathCache then
    for _, entry in ipairs(data) do
        spritePathCache = {}
        local spritePath = getSpritePath(entry)
        for _, entry in ipairs(data) do
        if spritePath then
            local spritePath = getSpritePath(entry)
            index[spritePath] = entry.id
            if spritePath then
                spritePathCache[spritePath] = entry.id
            end
         end
         end
     end
     end
     return index
     return spritePathCache
end
end