Модуль:Местонахождение: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) м Замена текста — «IanComradeBot/prototypes/сargo.json/data» на «IanComradeBot/prototypes/cargo.json/data» |
||
| (не показано 7 промежуточных версий этого же участника) | |||
| Строка 13: | Строка 13: | ||
local loadoutGroupData = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | local loadoutGroupData = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | ||
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/ | local itemBorgData = mw.loadData("Модуль:IanComradeBot/prototypes/ItemBorgModule.json/data") | ||
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data") | |||
local latheData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data") | local latheData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe.json/data") | ||
local recipeData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data") | local recipeData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipes.json/data") | ||
local recipePackData = mw.loadData("Модуль:IanComradeBot/prototypes/lathe/recipe pack.json/data") | |||
local researchData = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data") | local researchData = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data") | ||
local materialData = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data") | local materialData = mw.loadData("Модуль:IanComradeBot/prototypes/materials.json/data") | ||
| Строка 71: | Строка 74: | ||
-- Формирование ссылки для роли/джоба (reverseEquipment) | -- Формирование ссылки для роли/джоба (reverseEquipment) | ||
local function createJobLink(jobId) | local function createJobLink(jobId) | ||
local translation = "{{#invoke:Ftl|main|translation|" .. jobId .. "}}" | local translation = "{{#invoke:Ftl|main|translation|Job" .. jobId .. "}}" | ||
return "[[" .. translation .. "|{{ucfirst:" .. translation .. "}}]]" | return "[[" .. translation .. "|{{ucfirst:" .. translation .. "}}]]" | ||
end | end | ||
| Строка 174: | Строка 177: | ||
end | end | ||
return | return table.concat(links, ", ") | ||
end | end | ||
| Строка 184: | Строка 187: | ||
end | end | ||
local | local resultsMap = {} | ||
-- Обработка startingGear (gearData) | -- Обработка startingGear (gearData) | ||
for _, gear in pairs(gearData) do | for _, gear in pairs(gearData) do | ||
if gear.equipment then | if gear.equipment then | ||
for slot, equipId in pairs(gear.equipment) do | for slot, equipId in pairs(gear.equipment) do | ||
if equipId == targetId and (not slotFilter or slot == slotFilter) then | if equipId == targetId and (not slotFilter or slot == slotFilter) then | ||
local | local gearId = gear.id | ||
for | if gearId then | ||
for _, job in ipairs(jobData) do | |||
if job.startingGear == gearId then | |||
resultsMap[job.id] = true | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
| Строка 206: | Строка 206: | ||
end | end | ||
end | end | ||
-- loadout + loadoutGroup + roleLoadout | |||
-- | |||
for _, loadout in pairs(loadoutData) do | for _, loadout in pairs(loadoutData) do | ||
if loadout.equipment then | if loadout.equipment then | ||
for slot, equipId in pairs(loadout.equipment) do | for slot, equipId in pairs(loadout.equipment) do | ||
if equipId == targetId and (not slotFilter or slot == slotFilter) then | if equipId == targetId and (not slotFilter or slot == slotFilter) then | ||
for _, group in pairs(loadoutGroupData) do | for _, group in pairs(loadoutGroupData) do | ||
if group.loadouts and type(group.loadouts) == "table" then | if group.loadouts and type(group.loadouts) == "table" then | ||
for _, lId in ipairs(group.loadouts) do | for _, lId in ipairs(group.loadouts) do | ||
if lId == loadout.id then | if lId == loadout.id then | ||
for _, role in pairs(gearRoleLoadout) do | |||
if role.groups and type(role.groups) == "table" then | |||
for _, g in ipairs(role.groups) do | |||
if g == group.id then | |||
local moduleKey = role.id:gsub("^Job", "") | |||
resultsMap[moduleKey] = true | |||
end | |||
end | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
end | |||
-- Собираем результаты, убираем дубликаты | |||
local results = {} | |||
for jobId in pairs(resultsMap) do | |||
table.insert(results, createJobLink(jobId)) | |||
end | end | ||
| Строка 250: | Строка 245: | ||
end | end | ||
return | return table.concat(results, ", ") | ||
end | end | ||
| Строка 269: | Строка 264: | ||
if #directCargo > 0 then | if #directCargo > 0 then | ||
local links = {} | |||
for _, storage in ipairs(directCargo) do | |||
table.insert(links, createCargoLink(storage)) | |||
end | |||
return table.concat(links, ", ") | |||
end | end | ||
| Строка 296: | Строка 291: | ||
table.insert(links, createCargoLink(storage)) | table.insert(links, createCargoLink(storage)) | ||
end | end | ||
return | return table.concat(links, ", ") | ||
end | end | ||
| Строка 309: | Строка 304: | ||
function p.reverseLathe(frame) | function p.reverseLathe(frame) | ||
local | local targetRecipe = frame.args[2] | ||
if not | if not targetRecipe or targetRecipe == "" then | ||
return "Ошибка: не указан результат рецепта для обратного поиска." | return "Ошибка: не указан результат рецепта для обратного поиска." | ||
end | end | ||
local | local matchingPacks = {} | ||
local function | for _, pack in ipairs(recipePackData) do | ||
for _, | if pack.recipes then | ||
for _, recipe in ipairs(pack.recipes) do | |||
if recipe == targetRecipe then | |||
table.insert(matchingPacks, pack.id) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
if #matchingPacks == 0 then | |||
return "" | |||
end | |||
local function containsAny(array, targets) | |||
for _, v in ipairs(array or {}) do | |||
for _, t in ipairs(targets) do | |||
if v == t then | |||
return true | |||
end | |||
end | end | ||
end | end | ||
| Строка 325: | Строка 336: | ||
end | end | ||
local matchingLathes = {} | |||
for _, lathe in ipairs(latheData) do | for _, lathe in ipairs(latheData) do | ||
local found = false | local found = false | ||
if lathe.Lathe then | if lathe.Lathe then | ||
if | if containsAny(lathe.Lathe.staticPacks, matchingPacks) or containsAny(lathe.Lathe.dynamicPacks, matchingPacks) then | ||
found = true | found = true | ||
end | end | ||
end | end | ||
if not found and lathe.EmagLatheRecipes then | if not found and lathe.EmagLatheRecipes then | ||
if | if containsAny(lathe.EmagLatheRecipes.emagStaticRecipes, matchingPacks) or containsAny(lathe.EmagLatheRecipes.emagDynamicPacks, matchingPacks) then | ||
found = true | found = true | ||
end | end | ||
| Строка 351: | Строка 363: | ||
end | end | ||
return | return table.concat(links, ", ") | ||
end | end | ||
| Строка 418: | Строка 430: | ||
end | end | ||
return table.concat(links, ", ") | |||
local | end | ||
function p.reverseBorg(frame) | |||
local targetItem = frame.args[2] | |||
if not targetItem or targetItem == "" then | |||
return "Ошибка: не указан искомый элемент для поиска в ItemBorgModule." | |||
return | end | ||
local results = {} | |||
-- Проходим по всем записям из itemBorgData | |||
for _, entry in pairs(itemBorgData) do | |||
if type(entry) == "table" and entry.ItemBorgModule and type(entry.ItemBorgModule) == "table" then | |||
local items = entry.ItemBorgModule.items | |||
if type(items) == "table" then | |||
for _, item in ipairs(items) do | |||
if item == targetItem then | |||
table.insert(results, createEntityLink(entry.id)) | |||
break | |||
end | |||
end | |||
end | |||
end | |||
end | |||
if #results == 0 then | |||
return "" | |||
end | |||
return table.concat(results, ", ") | |||
end | end | ||
| Строка 443: | Строка 477: | ||
reverseLathe = p.reverseLathe, | reverseLathe = p.reverseLathe, | ||
reverseVending = p.reverseVending, | reverseVending = p.reverseVending, | ||
reverseBorg = p.reverseBorg, | |||
} | } | ||