z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
083a3ed
trunk
1local flib_table =require ( "__flib__.table" ) 2 3local util ={} 4 5--- Create a local flying text with an error sound. 6--- @param player LuaPlayer 7--- @param text LocalisedString 8function util . error_text ( player , text ) 9player . create_local_flying_text ( { create_at_cursor =true , text =text } ) 10player . play_sound ( { path ="utility/cannot_build" } ) 11end 12 13--- Get the force for the player, accounting for Editor Extensions. 14--- @param player LuaPlayer 15--- @return LuaForce 16function util . get_force ( player ) 17local interface =remote . interfaces [ "EditorExtensions" ] 18if interface and interface . get_player_proper_force then 19return remote . call ( "EditorExtensions" , "get_player_proper_force" , player ) 20end 21local force =player . force --[[@as LuaForce]] 22if string . find ( force . name , "bpsb%-" ) then 23local proper_name =string . match ( force . name , "bpsb%-sb%-f%-(.*)" ) 24if proper_name then 25force =game . forces [ proper_name ] 26end 27end 28return force 29end 30 31--- @class GuiIdent 32--- @field name string 33--- @field id string|number 34 35--- Safely retrieve the GUI for the given player. 36--- @param player_index number 37--- @param gui_name string 38--- @return EditTaskGui|TasksGui? 39function util . get_gui ( player_index , gui_name ) 40local player_table =storage . players [ player_index ] 41if player_table then 42local Gui =player_table . guis [ gui_name ] 43if Gui and Gui . refs . window . valid then 44return Gui 45end 46end 47end 48 49--- Update completed visibility for all subtasks 50--- @param flow LuaGuiElement 51--- @param to_state boolean 52function util . recursive_show_completed ( flow , to_state ) 53for _ , row in pairs ( flow . incompleted . children ) do --- @diagnostic disable-line 54util . recursive_show_completed ( row . details_flow . subtasks_flow , to_state ) 55end 56 57local completed_flow =flow . completed --[[@as LuaGuiElement]] 58if to_state and # completed_flow . children > 0 then 59completed_flow . visible =true 60 61for _ , row in pairs ( completed_flow . children ) do 62util . recursive_show_completed ( row . details_flow . subtasks_flow , to_state ) 63end 64else 65completed_flow . visible =false 66end 67end 68 69function util . remove_task ( source , task_id ) 70table . remove ( source , flib_table . find ( source , task_id )) 71end 72 73return util