z_mirror/Krastorio2
git clone https://git.raiguard.me/z_mirror/Krastorio2
b9d041a3
trunk
1local util ={} 2 3--- @class FlyingTextOptions 4--- @field color Color? 5--- @field position MapPosition? 6--- @field sound LuaPlayer.play_sound_param? 7 8--- @param player LuaPlayer 9--- @param text LocalisedString 10--- @param options FlyingTextOptions? 11function util . flying_text_with_sound ( player , text , options ) 12options =options or {} 13options . sound =options . sound or { path ="utility/cannot_build" } 14player . create_local_flying_text ( { 15color =options . color , 16create_at_cursor =not options . position , 17position =options . position , 18text =text , 19} ) 20player . play_sound ( options . sound ) 21end 22 23--- @param entity LuaEntity 24--- @param text LocalisedString 25--- @param color Color? 26function util . entity_flying_text ( entity , text , color ) 27for _ , player in pairs ( game . players ) do 28if player . surface == entity . surface then 29player . create_local_flying_text ( { 30text =text , 31color =color , 32position =entity . position , 33} ) 34end 35end 36end 37 38--- @param entity LuaEntity 39--- @param text LocalisedString 40--- @param color Color 41function util . change_mode_fx ( entity , text , color ) 42-- Flying text 43util . entity_flying_text ( entity , text , color ) 44-- Welding sound 45game . play_sound ( { 46path ="kr-welding" , 47position =entity . position , 48volume_modifier =1.0 , 49} ) 50-- Welding particle 51entity . surface . create_particle ( { 52name ="kr-welding-particle" , 53position ={ entity . position . x , entity . position . y + 1 } , 54movement ={ 0.0 , - 0.05 } , 55height =1.0 , 56vertical_speed =0.015 , 57frame_speed =1 , 58} ) 59end 60 61--- @param commands_list table<string, function> 62function util . add_commands ( commands_list ) 63for name , func in pairs ( commands_list ) do 64commands . add_command ( name , { "command-help." .. name } , function ( e ) 65local player =game . get_player ( e . player_index ) --[[@as LuaPlayer]] 66if not player . admin then 67player . ( { "cant-run-command-not-admin" , name } ) 68return 69end 70 71func ( e ) 72end ) 73end 74end 75 76--- @param e EventData.on_player_setup_blueprint 77--- @return LuaItemStack? 78function util . get_blueprint ( e ) 79local player =game . get_player ( e . player_index ) 80if not player then 81return 82end 83 84local bp =player . blueprint_to_setup 85if bp and bp . valid_for_read then 86return bp 87end 88 89bp =player . cursor_stack 90if not bp or not bp . valid_for_read then 91return 92end 93 94if bp . type == "blueprint-book" then 95local item_inventory =bp . get_inventory ( defines . inventory . item_main ) 96if item_inventory then 97bp =item_inventory [ bp . active_index ] 98else 99return 100end 101end 102 103return bp 104end 105 106return util