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