z_mirror/RecipeBook

git clone https://git.raiguard.me/z_mirror/RecipeBook

Caleb HeuerAdd alternate mode for grouping to only split out recipesa65a064

trunk
3.1 KiB102 linesraw
1local util = require("scripts.util")
2
3--- @alias GroupingMode "all"|"exclude-recipes"|"none"
4
5--- @class Grouped
6local grouped = {
7  --- @type table<SpritePath, LuaEntityPrototype>
8  entity = {},
9  --- @type table<SpritePath, LuaEquipmentPrototype>
10  equipment = {},
11  --- @type table<SpritePath, LuaFluidPrototype|LuaItemPrototype>
12  material = {},
13  --- @type table<SpritePath, LuaRecipePrototype>
14  recipe = {},
15  --- @type table<SpritePath, LuaTilePrototype>
16  tile = {},
17}
18
19--- @param recipe LuaRecipePrototype
20--- @return (LuaFluidPrototype|LuaItemPrototype)?
21local function get_simple_product(recipe)
22  local main_product = recipe.main_product
23  if main_product and main_product.name == recipe.name then
24    return prototypes[main_product.type][main_product.name]
25  end
26  local products = recipe.products
27  if #products ~= 1 then
28    return
29  end
30  local first_product = products[1]
31  if first_product.name ~= recipe.name or first_product.type == "research-progress" then
32    return
33  end
34  return prototypes[first_product.type][first_product.name]
35end
36
37--- @param prototype LuaEntityPrototype|LuaTilePrototype
38--- @return LuaItemPrototype?
39local function get_simple_item_to_place_this(prototype)
40  local items_to_place_this = prototype.items_to_place_this
41  if not items_to_place_this then
42    return
43  end
44  local first_item = items_to_place_this[1]
45  if not first_item then
46    return
47  end
48  if first_item.name ~= prototype.name then
49    return
50  end
51  return prototypes.item[first_item.name]
52end
53
54for entity_name, entity in pairs(prototypes.entity) do
55  local item = get_simple_item_to_place_this(entity)
56  if item and item.hidden_in_factoriopedia == entity.hidden_in_factoriopedia then
57    grouped.material[util.get_path(entity)] = item
58    grouped.entity[util.get_path(item)] = entity
59    goto continue
60  end
61  local mineable = entity.mineable_properties
62  if mineable then
63    local products = mineable.products
64    if products and #products == 1 then
65      local product = products[1]
66      if product.type == "item" and product.name == entity_name and product.amount then
67        grouped.material[util.get_path(entity)] = prototypes.item[product.name]
68        grouped.entity["item/" .. product.name] = entity
69      end
70    end
71  end
72  ::continue::
73end
74for _, recipe in pairs(prototypes.recipe) do
75  local material = get_simple_product(recipe)
76  if material and material.hidden_in_factoriopedia == recipe.hidden_in_factoriopedia then
77    grouped.material[util.get_path(recipe)] = material
78    grouped.recipe[util.get_path(material)] = recipe
79  end
80end
81for _, tile in pairs(prototypes.tile) do
82  local items_to_place_this = tile.items_to_place_this
83  if items_to_place_this then
84    for _, item in pairs(items_to_place_this) do
85      local item_prototype = prototypes.item[item.name]
86      if tile.hidden_in_factoriopedia == item_prototype.hidden_in_factoriopedia then
87        grouped.material[util.get_path(tile)] = item_prototype
88        grouped.tile[util.get_path(item_prototype)] = tile
89        break
90      end
91    end
92  end
93end
94-- TODO: Equipment
95-- Space location
96-- Asteroid chunk
97-- Ammo
98-- Space Connection
99-- Virtual signal
100-- Surface
101
102return grouped