z_mirror/EditorExtensions
git clone https://git.raiguard.me/z_mirror/EditorExtensions
596431c
trunk
1local aggregate_chest_names ={ 2[ "ee-aggregate-chest" ] ="ee-aggregate-chest" , 3[ "ee-aggregate-chest-passive-provider" ] ="ee-aggregate-chest-passive-provider" , 4} 5 6--- @type table<string, InfinityInventoryFilter[]> 7local filters ={} 8do 9local include_hidden =settings . global [ "ee-aggregate-include-hidden" ]. value --[[@as boolean]] 10local i =0 11for quality_name in pairs ( prototypes . quality ) do 12local this_filters ={} 13for item_name , prototype in pairs ( prototypes . item ) do 14if string . find ( item_name , "^parameter%-" ) then 15goto continue 16end 17if prototype . hidden and not include_hidden then 18goto continue 19end 20i =i + 1 21this_filters [ i ] ={ 22name =item_name , 23quality =quality_name , 24count =prototype . stack_size , 25mode ="exactly" , 26index =i , 27} 28:: continue :: 29end 30filters [ quality_name ] =this_filters 31end 32end 33--- Set the filters for the given aggregate chest and removes the bar if there is one 34--- @param entity LuaEntity 35local function set_filters ( entity ) 36entity . remove_unfiltered_items =true 37entity . infinity_container_filters =filters [ entity . quality . name ] 38entity . get_inventory ( defines . inventory . chest ). set_bar () 39end 40 41-- Update the filters of all existing aggregate chests 42local function update_all_filters () 43for _ , surface in pairs ( game . surfaces ) do 44for _ , entity in pairs ( surface . find_entities_filtered ( { name =aggregate_chest_names } )) do 45set_filters ( entity ) 46end 47end 48end 49 50--- @param e BuiltEvent 51local function on_entity_built ( e ) 52local entity =e . entity or e . destination 53if not entity or not entity . valid or not aggregate_chest_names [ entity . name ] then 54return 55end 56set_filters ( entity ) 57end 58 59--- @param e EventData.on_player_setup_blueprint 60local function on_player_setup_blueprint ( e ) 61local blueprint =e . stack or e . record 62if not blueprint then 63return 64end 65 66local entities =blueprint . get_blueprint_entities () 67if not entities then 68return 69end 70local set =false 71for _ , entity in pairs ( entities ) do 72if aggregate_chest_names [ entity . name ] then 73set =true 74entity . infinity_settings . filters =nil --- @diagnostic disable-line 75end 76end 77if set then 78blueprint . set_blueprint_entities ( entities ) 79end 80end 81 82local aggregate_chest ={} 83 84aggregate_chest . on_configuration_changed =function ( _ ) 85update_all_filters () 86end 87 88aggregate_chest . events ={ 89[ defines . events . on_built_entity ] =on_entity_built , 90[ defines . events . on_entity_cloned ] =on_entity_built , 91[ defines . events . on_player_setup_blueprint ] =on_player_setup_blueprint , 92[ defines . events . on_robot_built_entity ] =on_entity_built , 93[ defines . events . on_space_platform_built_entity ] =on_entity_built , 94[ defines . events . script_raised_built ] =on_entity_built , 95[ defines . events . script_raised_revive ] =on_entity_built , 96} 97 98return aggregate_chest