trusted
167
edits
(Sort recipes by GridIndex) |
(ipairs preserves order, use instead of pairs/sorting) |
||
Line 33: | Line 33: | ||
} | } | ||
local item = itemByName(name) | local item = itemByName(name) | ||
for _, recipe in | for _, recipe in ipairs(recipesMakingByID(item.ID)) do | ||
table.insert(rtable, recipeRow(recipe, frame)) | table.insert(rtable, recipeRow(recipe, frame)) | ||
end | end | ||
Line 40: | Line 40: | ||
table.insert(rtable, veinRow(item, vein, frame)) | table.insert(rtable, veinRow(item, vein, frame)) | ||
end | end | ||
for _, giant in | for _, giant in ipairs(deduplicateGiants(gasGiantsMakingByID(item.ID))) do | ||
table.insert(rtable, gasGiantRow(item, giant, frame)) | table.insert(rtable, gasGiantRow(item, giant, frame)) | ||
end | end | ||
Line 66: | Line 66: | ||
table.insert(output, '=== Components ===') | table.insert(output, '=== Components ===') | ||
table.insert(output, header) | table.insert(output, header) | ||
for _, recipe in | for _, recipe in ipairs(components) do | ||
table.insert(output, recipeRow(recipe, frame)) | table.insert(output, recipeRow(recipe, frame)) | ||
end | end | ||
Line 74: | Line 74: | ||
table.insert(output, '=== Buildings ===') | table.insert(output, '=== Buildings ===') | ||
table.insert(output, header) | table.insert(output, header) | ||
for _, recipe in | for _, recipe in ipairs(buildings) do | ||
table.insert(output, recipeRow(recipe, frame)) | table.insert(output, recipeRow(recipe, frame)) | ||
end | end | ||
Line 92: | Line 92: | ||
local item = itemByName(name) | local item = itemByName(name) | ||
local output = {} | local output = {} | ||
for _, r in | for _, r in ipairs(recipesMakingByID(item.ID)) do | ||
table.insert(output, itemRecipe(r, frame)) | table.insert(output, itemRecipe(r, frame)) | ||
end | end | ||
Line 99: | Line 99: | ||
table.insert(output, veinRecipe(item, vein, frame)) | table.insert(output, veinRecipe(item, vein, frame)) | ||
end | end | ||
for _, giant in | for _, giant in ipairs(deduplicateGiants(gasGiantsMakingByID(item.ID))) do | ||
table.insert(output, gasGiantRecipe(giant, frame)) | table.insert(output, gasGiantRecipe(giant, frame)) | ||
end | end | ||
Line 276: | Line 276: | ||
function itemByName(name) | function itemByName(name) | ||
local lame = string.lower(name) | local lame = string.lower(name) | ||
for _, item in | for _, item in ipairs(protosets.ItemProtoSet.dataArray) do | ||
if string.lower(item.Name) == lame then | if string.lower(item.Name) == lame then | ||
return item | return item | ||
Line 284: | Line 284: | ||
end | end | ||
function itemByID(id) | function itemByID(id) | ||
for _, item in | for _, item in ipairs(protosets.ItemProtoSet.dataArray) do | ||
if item.ID == id then | if item.ID == id then | ||
return item | return item | ||
Line 294: | Line 294: | ||
function recipesMakingByID(id) | function recipesMakingByID(id) | ||
local result = {} | local result = {} | ||
for _, recipe in | for _, recipe in ipairs(protosets.RecipeProtoSet.dataArray) do | ||
for _, itemid in | for _, itemid in ipairs(recipe.Results) do | ||
if itemid == id then | if itemid == id then | ||
table.insert(result, recipe) | table.insert(result, recipe) | ||
Line 307: | Line 307: | ||
local components = {} | local components = {} | ||
local buildings = {} | local buildings = {} | ||
for _, recipe in | for _, recipe in ipairs(protosets.RecipeProtoSet.dataArray) do | ||
for _, itemid in | for _, itemid in ipairs(recipe.Items) do | ||
if itemid == id then | if itemid == id then | ||
if recipe.GridIndex >= 2000 then | if recipe.GridIndex >= 2000 then | ||
Line 323: | Line 323: | ||
function technologyForRecipeID(id) | function technologyForRecipeID(id) | ||
for _, tech in | for _, tech in ipairs(protosets.TechProtoSet.dataArray) do | ||
for _, recipeid in | for _, recipeid in ipairs(tech.UnlockRecipes) do | ||
if recipeid == id then | if recipeid == id then | ||
return tech | return tech | ||
Line 334: | Line 334: | ||
function veinMakingByID(id) | function veinMakingByID(id) | ||
for _, vein in | for _, vein in ipairs(protosets.VeinProtoSet.dataArray) do | ||
if vein.MiningItem == id then | if vein.MiningItem == id then | ||
return vein | return vein | ||
Line 344: | Line 344: | ||
function gasGiantsMakingByID(id) | function gasGiantsMakingByID(id) | ||
local giants = {} | local giants = {} | ||
for _, planet in | for _, planet in ipairs(protosets.ThemeProtoSet.dataArray) do | ||
for _, item in | for _, item in ipairs(planet.GasItems) do | ||
if item == id then | if item == id then | ||
table.insert(giants, planet) | table.insert(giants, planet) | ||
Line 356: | Line 356: | ||
function isItemOcean(id) | function isItemOcean(id) | ||
for _, planet in | for _, planet in ipairs(protosets.ThemeProtoSet.dataArray) do | ||
if id == planet.WaterItemId then | if id == planet.WaterItemId then | ||
return true | return true | ||
Line 375: | Line 375: | ||
function deduplicateGiants(giants) | function deduplicateGiants(giants) | ||
local dedup = {} | local dedup = {} | ||
for _, planet in | for _, planet in ipairs(giants) do | ||
new = true | new = true | ||
for _, exist in | for _, exist in ipairs(dedup) do | ||
if string.lower(planet.DisplayName) == string.lower(exist.DisplayName) then | if string.lower(planet.DisplayName) == string.lower(exist.DisplayName) then | ||
new = false | new = false |