Модуль:Сущность/data: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: отменено |
Pok (обсуждение | вклад) Отмена версии 213664, сделанной Pok (обсуждение) Метки: отмена отменено |
||
| Строка 14: | Строка 14: | ||
if not s then return s end | if not s then return s end | ||
return (s:gsub("^%s*(.-)%s*$", "%1")) | return (s:gsub("^%s*(.-)%s*$", "%1")) | ||
end | end | ||
| Строка 349: | Строка 337: | ||
local isWhitelisted = cardFilter and matches_card_list(cardFilter.whitelist, callKey, compositeKey) or | local isWhitelisted = cardFilter and matches_card_list(cardFilter.whitelist, callKey, compositeKey) or | ||
false | |||
local isBlacklisted = cardFilter and matches_card_list(cardFilter.blacklist, callKey, compositeKey) or | local isBlacklisted = cardFilter and matches_card_list(cardFilter.blacklist, callKey, compositeKey) or | ||
false | |||
if isWhitelisted and content ~= "" then | if isWhitelisted and content ~= "" then | ||
rawContentParts[#rawContentParts + 1] = content | rawContentParts[#rawContentParts + 1] = content | ||
| Строка 395: | Строка 383: | ||
end | end | ||
end | end | ||
local out = {} | local out = {} | ||
| Строка 595: | Строка 576: | ||
end | end | ||
return not (filter.blacklist[sw] and filter.blacklist[sw][key]) | return not (filter.blacklist[sw] and filter.blacklist[sw][key]) | ||
end | |||
local function each_csv_value(str, fn) | |||
if not str or str == "" then | |||
return | |||
end | |||
for item in string.gmatch(str, "[^,]+") do | |||
local value = trim(item) | |||
if value ~= "" then | |||
fn(value) | |||
end | |||
end | |||
end | end | ||
| Строка 686: | Строка 679: | ||
flattenExtraCache[cacheKey] = extra | flattenExtraCache[cacheKey] = extra | ||
return extra | return extra | ||
end | end | ||
| Строка 740: | Строка 711: | ||
end | end | ||
local function | local function build_missing_template_error(kind, name, isStore, tplPath) | ||
local | local baseType = (kind and (kind:sub(1, 1):upper() .. kind:sub(2)) or "") | ||
local componentBlacklist = | local classType = baseType | ||
local prototypeWhitelist = | if isStore then | ||
local prototypeBlacklist = | classType = classType .. "Store" | ||
end | |||
local className = name .. baseType | |||
local tplLabel = "Template:" .. tplPath | |||
return "{{сущность/infobox/base|тип=" .. classType .. "|название=" .. className .. "|ссылка=" .. tplLabel .. "}}" | |||
end | |||
local function renderBlocks(frame, state, renderOptions, entityId, showSource) | |||
local outLocal = {} | |||
local noHeaders = renderOptions and renderOptions.noHeaders | |||
local cardFilter = renderOptions and renderOptions.cardFilter | |||
for _, sw in ipairs(switchModeOrder) do | |||
local mode = switchModeRegistry[sw] or {} | |||
if mode.full then | |||
local outStr = "" | |||
if type(mode.render_full) == "function" then | |||
outStr = mode.render_full(frame, state.keyOrder[sw], state.keyToTemplates[sw], state.keySources[sw], | |||
entityId, noHeaders, showSource, cardFilter) | |||
end | |||
if outStr and outStr ~= "" then table.insert(outLocal, outStr) end | |||
else | |||
for _, key in ipairs(state.keyOrder[sw] or {}) do | |||
local entries = state.keyToTemplates[sw][key] or {} | |||
if type(mode.render_key) == "function" then | |||
local outStr = mode.render_key(frame, key, entries, noHeaders, showSource) | |||
if outStr and outStr ~= "" then table.insert(outLocal, outStr) end | |||
end | |||
end | |||
end | |||
end | |||
return outLocal | |||
end | |||
function p.get(frame) | |||
local args = getArgs(frame, { removeBlanks = false }) | |||
local id = args[1] or "" | |||
if id == "" then return "" end | |||
local showSource = trim(args.showSource or "") == "" | |||
local filter = build_key_filter(args) | |||
local renderOptions = build_render_options(filter) | |||
local componentWhitelist = args.componentWhitelist or args.componentwhitelist or "" | |||
local componentBlacklist = args.componentBlacklist or args.componentblacklist or "" | |||
local prototypeWhitelist = args.prototypeWhitelist or args.prototypewhitelist or "" | |||
local prototypeBlacklist = args.prototypeBlacklist or args.prototypeblacklist or "" | |||
local componentDefs = load_module_data("component.json") | local componentDefs = load_module_data("component.json") | ||
local prototypeStoreDefs = load_module_data("prototype_store.json") | local prototypeStoreDefs = load_module_data("prototype_store.json") | ||
if not componentDefs or not prototypeStoreDefs then | if not componentDefs or not prototypeStoreDefs then return "" end | ||
local foundComponents, foundPrototypes = collect_entity_sets(id, componentDefs, prototypeStoreDefs, | local foundComponents, foundPrototypes = collect_entity_sets(id, componentDefs, prototypeStoreDefs, | ||
componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist) | componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist) | ||
local state = new_switch_state() | |||
local ok, dp = pcall(require, "Module:GetField") | local ok, dp = pcall(require, "Module:GetField") | ||
local errors = {} | |||
local function processEntity(kind, name, isStore) | local function processEntity(kind, name, isStore) | ||
| Строка 766: | Строка 783: | ||
local content = load_template_content(tplPath) | local content = load_template_content(tplPath) | ||
if not content then | if not content then | ||
if | if filter.hasWhitelist then | ||
return | |||
end | end | ||
errors[#errors + 1] = build_missing_template_error(kind, name, isStore, tplPath) | |||
return | return | ||
end | end | ||
| Строка 784: | Строка 802: | ||
end | end | ||
add_entries_from_meta(state, parsed, { | |||
tplPath = tplPath, | tplPath = tplPath, | ||
id = id, | id = id, | ||
| Строка 790: | Строка 808: | ||
source = make_source(kind, name, pathName, tplPath), | source = make_source(kind, name, pathName, tplPath), | ||
priority = resolve_priority(parsed) | priority = resolve_priority(parsed) | ||
}) | }, filter, false) | ||
end | end | ||
| Строка 818: | Строка 836: | ||
end | end | ||
end | end | ||
local out = {} | local out = {} | ||