z_mirror/MouseOverConstruction
git clone https://git.raiguard.me/z_mirror/MouseOverConstruction
7c145b8
insertion
1--- @param player_index PlayerIndex 2local function cancel ( player_index ) 3storage . repairing [ player_index ] =nil 4end 5 6--- @param player LuaPlayer 7--- @param entity LuaEntity 8--- @return boolean 9local function start ( player , entity ) 10if not entity . valid then 11return false 12end 13 14if not player . mod_settings [ "moc-enable-repairing" ]. value then 15return false 16end 17 18if not entity . health or entity . health == entity . prototype . get_max_health ( entity . quality ) then 19return false 20end 21 22storage . repairing [ player . index ] =entity . position 23return true 24end 25 26local function on_tick () 27if not storage . repairing then 28return 29end 30 31for player_index , position in pairs ( storage . repairing ) do 32local player =game . get_player ( player_index ) 33if not player then 34cancel ( player_index ) 35goto continue 36end 37local entity =player . selected 38if entity and entity . health and entity . health < entity . prototype . get_max_health ( entity . quality ) then 39player . repair_state ={ repairing =true , position =position } 40else 41cancel ( player_index ) 42end 43:: continue :: 44end 45end 46 47local function init () 48--- @type table<PlayerIndex, MapPosition> 49storage . repairing ={} 50end 51 52--- @class repair_handler : event_handler 53local repair_handler ={} 54 55repair_handler . on_init =init 56repair_handler . on_configuration_changed =init 57 58repair_handler . events ={ 59[ defines . events . on_tick ] =on_tick , 60} 61 62repair_handler . cancel =cancel 63repair_handler . start =start 64 65return repair_handler