Модуль:Entity Sprite/all: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: отменено |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показано 9 промежуточных версий этого же участника) | |||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local JsonPaths = require('Module:JsonPaths') | local JsonPaths = require('Module:JsonPaths') | ||
local function normalizeSpritePath(path) | local function normalizeSpritePath(path) | ||
| Строка 139: | Строка 138: | ||
end | end | ||
local function getParents( | local function getParents(parentData, id) | ||
if not | if not parentData or type(parentData) ~= "table" or not id then | ||
return nil | return nil | ||
end | end | ||
if type( | local parents = parentData[id] | ||
return | if type(parents) ~= "table" then | ||
return nil | |||
end | end | ||
return parents | |||
end | end | ||
| Строка 169: | Строка 165: | ||
end | end | ||
local function shouldIncludeEntry( | local function shouldIncludeEntry(id, whitelistSet, blacklistSet, parentData) | ||
local parents = getParents( | local parents = getParents(parentData, id) | ||
if whitelistSet and not hasAnyParent(parents, whitelistSet) then | if whitelistSet and not hasAnyParent(parents, whitelistSet) then | ||
| Строка 183: | Строка 179: | ||
end | end | ||
local function filterSpriteData(spriteData, | local function filterSpriteData(spriteData, parentData, whitelistSet, blacklistSet, project) | ||
local result = {} | local result = {} | ||
for id, entry in pairs(spriteData) do | for id, entry in pairs(spriteData) do | ||
if shouldIncludeEntry(id, whitelistSet, blacklistSet, parentData) then | |||
if shouldIncludeEntry( | |||
if project == "" or JsonPaths.has(id, project) then | if project == "" or JsonPaths.has(id, project) then | ||
result[id] = entry | result[id] = entry | ||
| Строка 199: | Строка 193: | ||
end | end | ||
local function | local function buildFileLink(id, project) | ||
return "[[:Файл:" .. JsonPaths.prefixFile(id) .. ".png]]" | |||
return | |||
end | end | ||
| Строка 277: | Строка 260: | ||
for _, obj in ipairs(group) do | for _, obj in ipairs(group) do | ||
table.insert(idLinks, buildFileLink(obj.id)) | table.insert(idLinks, buildFileLink(obj.id, project)) | ||
end | end | ||
| Строка 286: | Строка 269: | ||
table.insert(result, mw.getCurrentFrame():preprocess( | table.insert(result, mw.getCurrentFrame():preprocess( | ||
"{{Entity Sprite/Repeat|файлы=" .. table.concat(idLinks, " ") .. | "{{Entity Sprite/Repeat|файлы=" .. table.concat(idLinks, " ") .. | ||
"|перенаправление=" .. | "|перенаправление=" .. JsonPaths.prefixFile(firstId) .. | ||
"|id=" .. firstId .. | "|id=" .. firstId .. | ||
"|спрайт=" .. spriteValue .. | "|спрайт=" .. spriteValue .. | ||
| Строка 307: | Строка 290: | ||
return mw.getCurrentFrame():preprocess( | return mw.getCurrentFrame():preprocess( | ||
"{{Entity Sprite/Image|файл=" .. | "{{Entity Sprite/Image|файл=" .. JsonPaths.prefixFile(id) .. | ||
"|id=" .. id .. | "|id=" .. id .. | ||
"|путь=" .. buildSpriteUrl(baseUrl, spritePath) .. | "|путь=" .. buildSpriteUrl(baseUrl, spritePath) .. | ||
| Строка 317: | Строка 300: | ||
function p.main(frame) | function p.main(frame) | ||
local action = frame.args[1] | local action = frame.args[1] | ||
local json = frame.args.json or " | local json = frame.args.json or "component/Sprite.json" | ||
local project = JsonPaths.project() | local project = JsonPaths.project() | ||
| Строка 323: | Строка 306: | ||
local dataPage = JsonPaths.get(json) | local dataPage = JsonPaths.get(json) | ||
local | local parentPage = JsonPaths.get("entity parent.json") | ||
local spriteDataRaw = mw.loadData(dataPage) | local spriteDataRaw = mw.loadData(dataPage) | ||
local | local parentDataRaw = mw.loadData(parentPage) | ||
local spriteData = normalizeData(spriteDataRaw) | local spriteData = normalizeData(spriteDataRaw) | ||
local | local parentData = normalizeData(parentDataRaw) | ||
if not spriteData or type(spriteData) ~= "table" then | if not spriteData or type(spriteData) ~= "table" then | ||
| Строка 335: | Строка 318: | ||
end | end | ||
if not | if not parentData or type(parentData) ~= "table" then | ||
return "Ошибка загрузки JSON: " .. | return "Ошибка загрузки JSON: " .. parentPage | ||
end | end | ||
local whitelistSet = buildSet(frame.args.whitelistParent) | local whitelistSet = buildSet(frame.args.whitelistParent) | ||
local blacklistSet = buildSet(frame.args.blacklistParent) | local blacklistSet = buildSet(frame.args.blacklistParent) | ||
local filteredData = filterSpriteData(spriteData, | local filteredData = filterSpriteData(spriteData, parentData, whitelistSet, blacklistSet, project) | ||
if action == "repeat" then | if action == "repeat" then | ||