z_mirror/BottleneckLite
git clone https://git.raiguard.me/z_mirror/BottleneckLite
ce25749
new-style
1local bounding_box =require ( "__flib__/bounding-box" ) 2 3local constants =require ( "__BottleneckLite__/constants" ) 4 5if not settings . startup [ "bnl-enable" ]. value then 6return 7end 8 9local enable_glow =settings . startup [ "bnl-glow" ]. value 10local size =constants . sizes [ settings . startup [ "bnl-indicator-size" ]. value ] 11local style =settings . startup [ "bnl-indicator-style" ]. value 12local animation 13if style == "default" then 14animation ={ 15filename ="__flib__/graphics/indicators.png" , 16flags ={ "icon" } , 17y =32 , 18size =32 , 19scale =size * 4 , 20line_length =1 , 21frame_count =1 , 22animation_speed =1 , 23direction_count =1 , 24} 25elseif style == "solid" then 26animation ={ 27filename ="__BottleneckLite__/graphics/solid.png" , 28flags ={ "icon" } , 29size =64 , 30scale =size , 31line_length =1 , 32frame_count =1 , 33animation_speed =1 , 34direction_count =1 , 35} 36end 37 38local status_colors ={} 39for name , spec in pairs ( settings . startup ) do 40local matched , _ , key =string . find ( name , "^bnl%-color%-(.-)$" ) 41if matched then 42status_colors [ key ] =constants . colors [ style ][ spec . value ] 43end 44end 45 46local function build_indicator ( prototype ) 47-- Calculate shift for the indicator 48local box =bounding_box . ensure_explicit ( prototype . selection_box or prototype . collision_box or prototype . drawing_box ) 49local positions ={ 50north_south ={} , 51east_west ={} , 52} 53for _ , tbl in pairs ( positions ) do 54tbl [ 1 ] =box . left_top . x + ( bounding_box . width ( box ) * constants . horizontal_position ) -- X 55tbl [ 2 ] =box . right_bottom . y - size - constants . additional_vertical_offset -- Y 56box =bounding_box . rotate ( box ) 57end 58 59return { 60always_draw =true , 61apply_tint ="status" , 62draw_as_light =enable_glow , 63draw_as_sprite =true , 64render_layer ="light-effect" , 65animation =animation , 66north_position =positions . north_south , 67east_position =positions . east_west , 68south_position =positions . north_south , 69west_position =positions . east_west , 70} 71end 72 73local function add_to_wv ( prototype , wv_root ) 74wv_root =wv_root or prototype 75 76-- Set status colors 77wv_root . status_colors =status_colors 78 79-- Get or create working visualisations table 80local wv =wv_root . working_visualisations 81if not wv then 82wv ={} 83wv_root . working_visualisations =wv 84end 85 86-- Add indicator to working visualisations 87wv [ # wv + 1 ] =build_indicator ( prototype ) 88end 89 90for _ , type in pairs ( { "assembling-machine" , "furnace" , "rocket-silo" } ) do 91for name , crafter in pairs ( data . raw [ type ]) do 92if not constants . ignored_entities [ name ] then 93if crafter . bottleneck_ignore then 94-- Remove the property to avoid pollution with some debugging features 95crafter . bottleneck_ignore =nil 96else 97add_to_wv ( crafter ) 98end 99end 100end 101end 102 103if settings . startup [ "bnl-include-mining-drills" ]. value then 104for name , drill in pairs ( data . raw [ "mining-drill" ]) do 105if not constants . ignored_entities [ name ] then 106if drill . bottleneck_ignore then 107-- Remove the property to avoid pollution with some debugging features 108drill . bottleneck_ignore =nil 109else 110drill . status_colors =status_colors 111 112-- Ensure the drill has a graphics set 113if not drill . graphics_set then 114drill . graphics_set ={ 115animation =drill . animations , 116} 117end 118 119add_to_wv ( drill , drill . graphics_set ) 120 121if drill . wet_mining_graphics_set then 122add_to_wv ( drill , drill . wet_mining_graphics_set ) 123end 124end 125end 126end 127end