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

Нет описания правки
Нет описания правки
 
(не показана 1 промежуточная версия этого же участника)
Строка 154: Строка 154:
local parents = getParents(entry)
local parents = getParents(entry)


if whitelistSet then
if whitelistSet and not hasAnyParent(parents, whitelistSet) then
if not hasAnyParent(parents, whitelistSet) then
return false
return false
end
end
end


Строка 181: Строка 179:
end
end


local function getFirstSpriteAndState(entry)
local function buildFileLink(id, project)
local spritePath = getSpritePath(entry)
local prefix = getPrefix(id, project)
local states = getSpriteStates(entry)
return "[[:Файл:" .. prefix .. id .. ".png]]"
end


if not spritePath then
local function buildSpriteUrl(baseUrl, spritePath)
return nil, nil
return baseUrl .. spritePath
end
end


if states and #states > 0 and states[1].state then
local function buildSpritePathLink(baseUrl, spritePath)
return spritePath, states[1].state
local url = buildSpriteUrl(baseUrl, spritePath)
end
return "[" .. url .. " " .. spritePath .. "]"
 
if entry and entry.state then
return spritePath, tostring(entry.state)
end
 
return spritePath, nil
end
end


local function buildSpriteValue(entry)
local function buildStateLink(baseUrl, spritePath, state)
local spritePath, stateName = getFirstSpriteAndState(entry)
local url = buildSpriteUrl(baseUrl, spritePath) .. "/" .. state .. ".png"
 
return "[" .. url .. " " .. state .. "]"
if not spritePath then
return nil
end
 
if stateName and stateName ~= "" then
return spritePath .. " (" .. stateName .. ")"
end
 
return spritePath
end
end


local function getFirstSpriteAndState(entry)
local function buildSpriteStateLinks(baseUrl, states)
local spritePath = getSpritePath(entry)
if not states or #states == 0 then
local states = getSpriteStates(entry)
return ""
 
if not spritePath then
return nil, nil
end
end


if states and #states > 0 and states[1].state then
local links = {}
return spritePath, states[1].state
end


if entry and entry.state then
for _, item in ipairs(states) do
return spritePath, tostring(entry.state)
if item.sprite and item.state then
table.insert(links, buildStateLink(baseUrl, item.sprite, item.state))
end
end
end


return spritePath, nil
return table.concat(links, ", ")
end
end


local function buildLinkedSpriteValue(entry, baseUrl)
local function buildRepeatSpriteValue(baseUrl, entry)
local spritePath, stateName = getFirstSpriteAndState(entry)
local spritePath = getSpritePath(entry)
 
if not spritePath then
if not spritePath then
return nil
return ""
end
end


local pathLink = "[" .. baseUrl .. spritePath .. " " .. spritePath .. "]"
local pathLink = buildSpritePathLink(baseUrl, spritePath)
local states = getSpriteStates(entry)


if stateName and stateName ~= "" then
if states and #states > 0 and states[1].state and states[1].state ~= "" then
local stateLink = "[" .. baseUrl .. spritePath .. "/" .. stateName .. ".png " .. stateName .. "]"
return pathLink .. " (" .. buildStateLink(baseUrl, spritePath, states[1].state) .. ")"
return pathLink .. " (" .. stateLink .. ")"
end
end


Строка 267: Строка 247:


for _, obj in ipairs(group) do
for _, obj in ipairs(group) do
local id = obj.id
table.insert(idLinks, buildFileLink(obj.id, project))
local prefix = getPrefix(id, project)
 
table.insert(idLinks, "[[:Файл:" .. prefix .. id .. ".png]]")
end
end


Строка 276: Строка 253:
local firstEntry = group[1].entry
local firstEntry = group[1].entry
local prefix = getPrefix(firstId, project)
local prefix = getPrefix(firstId, project)
local spriteValue = buildLinkedSpriteValue(firstEntry, baseUrl) or ""
local spriteValue = buildRepeatSpriteValue(baseUrl, firstEntry)


table.insert(result, mw.getCurrentFrame():preprocess(
table.insert(result, mw.getCurrentFrame():preprocess(
"{{Entity Sprite/Repeat|спрайты=" .. table.concat(idLinks, " ") ..
"{{Entity Sprite/Repeat|файлы=" .. table.concat(idLinks, " ") ..
"|перенаправление=" .. prefix .. firstId ..
"|перенаправление=" .. prefix .. firstId ..
"|id=" .. firstId ..
"|id=" .. firstId ..
Строка 298: Строка 275:


local prefix = getPrefix(id, project)
local prefix = getPrefix(id, project)
local states = getSpriteStates(entry)
local states = getSpriteStates(entry)
local stateStr = ""
local stateStr = buildSpriteStateLinks(baseUrl, states)
 
if states then
local links = {}
for _, item in ipairs(states) do
if item.sprite and item.state then
local url = baseUrl .. item.sprite .. "/" .. item.state .. ".png"
table.insert(links, "[" .. url .. " " .. item.state .. "]")
end
end
stateStr = table.concat(links, ", ")
end


return mw.getCurrentFrame():preprocess(
return mw.getCurrentFrame():preprocess(
"{{Entity Sprite/Image|файл=" .. prefix .. id ..
"{{Entity Sprite/Image|файл=" .. prefix .. id ..
"|id=" .. id ..
"|id=" .. id ..
"|путь=" .. baseUrl .. spritePath ..
"|путь=" .. buildSpriteUrl(baseUrl, spritePath) ..
"|state=" .. stateStr ..
"|state=" .. stateStr ..
"}}"
"}}"
Строка 350: Строка 315:
if action == "repeat" then
if action == "repeat" then
return generateRepeatTemplate(filteredData, project, baseUrl)
return generateRepeatTemplate(filteredData, project, baseUrl)
elseif action == "image" then
elseif action == "image" then
local result = {}
local result = {}