z_mirror/EditorExtensions
git clone https://git.raiguard.me/z_mirror/EditorExtensions
e65a4b6
Quezler/patch-1
1--- @param pipe LuaEntity 2--- @param combinator LuaEntity 3local function copy_from_pipe_to_combinator ( pipe , combinator ) 4local filter =pipe . get_infinity_pipe_filter () 5if not filter then 6return 7end 8local cb =combinator . get_or_create_control_behavior () --[[@as LuaConstantCombinatorControlBehavior]] 9--- @type LuaLogisticSection? 10local section 11for _ , sec in pairs ( cb . sections ) do 12if sec . group == "" then 13section =sec 14break 15end 16end 17if not section then 18section =cb . add_section () 19end 20if not section then 21return -- When will this ever happen? 22end 23section . set_slot ( 1 , { 24value ={ 25comparator ="=" , 26type ="fluid" , 27name =filter . name --[[@as string]] , 28quality ="normal" , 29} , 30min =1 , 31} ) 32end 33 34--- @param combinator LuaEntity 35--- @param pipe LuaEntity 36local function copy_from_combinator_to_pipe ( combinator , pipe ) 37local cb =combinator . get_control_behavior () --[[@as LuaConstantCombinatorControlBehavior?]] 38if not cb then 39return 40end 41local cb =combinator . get_control_behavior () --[[@as LuaConstantCombinatorControlBehavior?]] 42if not cb then 43return 44end 45local section =cb . get_section ( 1 ) 46if not section then 47return 48end 49local filter =section . filters [ 1 ] 50if not filter then 51return 52end 53local value =filter . value 54-- XXX: `filter` will not always have a `type` field. 55if value and prototypes . fluid [ value . name ] then 56pipe . set_infinity_pipe_filter ( { type ="fluid" , name =value . name , percentage =1 } ) 57else 58pipe . set_infinity_pipe_filter ( nil ) 59end 60end 61 62--- @param e EventData.on_entity_settings_pasted 63local function on_entity_settings_pasted ( e ) 64local source , destination =e . source , e . destination 65if not source . valid or not destination . valid then 66return 67end 68local source_is_pipe , destination_is_pipe =source . type == "infinity-pipe" , destination . type == "infinity-pipe" 69if source_is_pipe and destination . name == "constant-combinator" then 70copy_from_pipe_to_combinator ( source , destination ) 71elseif source . name == "constant-combinator" and destination_is_pipe then 72copy_from_combinator_to_pipe ( source , destination ) 73end 74end 75 76local infinity_pipe ={} 77 78infinity_pipe . events ={ 79[ defines . events . on_entity_settings_pasted ] =on_entity_settings_pasted , 80} 81 82return infinity_pipe