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

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


local function batchFileExists(names)
local function fileExists(name)
local result = {}
if fileExistsCache[name] ~= nil then
local batch = {}
return fileExistsCache[name]
local seen = {}
 
local function flush()
if #batch == 0 then
return
end
 
local titles = mw.title.newBatch(batch, 6):lookupExistence():getTitles()
for i, title in ipairs(titles) do
local name = batch[i]
fileExistsCache[name] = title and title.exists or false
end
 
batch = {}
seen = {}
end
end


for _, name in ipairs(names) do
local title = mw.title.new(name, "File")
if fileExistsCache[name] == nil and not seen[name] then
local exists = title and title.exists or false
seen[name] = true
fileExistsCache[name] = exists
table.insert(batch, name)
return exists
 
if #batch == 25 then
flush()
end
end
end
 
flush()
 
for _, name in ipairs(names) do
result[name] = fileExistsCache[name] or false
end
 
return result
end
end


Строка 101: Строка 72:


local result = {}
local result = {}
local frame = mw.getCurrentFrame()


for _, group in pairs(spriteGroups) do
for _, group in pairs(spriteGroups) do
Строка 109: Строка 81:
local id = obj.id
local id = obj.id
local prefix = getPrefix(id, project)
local prefix = getPrefix(id, project)
table.insert(idLinks, "[[:Файл:" .. prefix .. id .. ".png]]")
table.insert(idLinks, "[[:Файл:" .. prefix .. id .. ".png]]")
end
end


table.insert(result, mw.getCurrentFrame():preprocess(
table.insert(result, frame:preprocess(
"{{Entity Sprite/Repeat|" ..
"{{Entity Sprite/Repeat|" ..
table.concat(idLinks, " ") ..
table.concat(idLinks, " ") ..
Строка 158: Строка 129:
local json = frame.args.json or "sprite_entity.json"
local json = frame.args.json or "sprite_entity.json"
local checkFile = frame.args.checkFile or ""
local checkFile = frame.args.checkFile or ""
if checkFile == "" then checkFile = false end
if checkFile == "" then
checkFile = false
end


local project = JsonPaths.project()
local project = JsonPaths.project()
Строка 173: Строка 146:


elseif action == "image" then
elseif action == "image" then
local items = {}
local result = {}
local fileNames = {}


for id, entry in pairs(spriteData) do
for id, entry in pairs(spriteData) do
local prefix = getPrefix(id, project)
local prefix = getPrefix(id, project)
local fileName = prefix .. id .. ".png"
table.insert(items, {
id = id,
entry = entry,
fileName = fileName
})


local skip = false
if checkFile then
if checkFile then
table.insert(fileNames, fileName)
local fileName = prefix .. id .. ".png"
end
if fileExists(fileName) then
end
skip = true
 
end
local existsMap = nil
if checkFile then
existsMap = batchFileExists(fileNames)
end
 
local result = {}
 
for _, item in ipairs(items) do
local skip = false
 
if checkFile and existsMap[item.fileName] then
skip = true
end
end


if not skip then
if not skip then
local t = generateTemplate(item.id, item.entry, baseUrl, project)
local t = generateTemplate(id, entry, baseUrl, project)
if t then
if t then
table.insert(result, t)
table.insert(result, t)