Рефакторинг.

This commit is contained in:
sasha80
2025-10-01 11:57:21 +03:00
parent 293ca59936
commit 39bb436407
7 changed files with 36 additions and 35 deletions

View File

@@ -45,13 +45,13 @@ signal threats_resized(th: Dictionary)
func _ready() -> void:
var threats = {} ## Список целей. Индекс - <номер цели>
var unit_caps = network.get_unit_instance('уарэп-капсрпб')
var unit_5p28 = network.get_unit_instance('уарэп-5п28')
var timer_check_lost: = Timer.new()
var timer_aoa_update: = Timer.new()
add_child(timer_check_lost)
add_child(timer_aoa_update)
var threats = {} ## Список целей. Индекс - <номер цели>
unit_caps.connect('data_received', Callable(self, 'on_data_capsrpb_received').bind(threats))
unit_5p28.connect('get_threats', Callable(self, 'on_get_threats').bind(unit_5p28, threats))
timer_check_lost.connect('timeout', Callable(self, 'on_timer_check_lost').bind(settings.ThreatParams.time_lost, threats))
@@ -69,7 +69,7 @@ func _ready() -> void:
## Периодически удаляет устаревшие цели.
func on_timer_check_lost(time_lost: int, threats: Dictionary):
var tick = Time.get_ticks_msec()
var tick: = Time.get_ticks_msec()
var sz: = threats.size()
for th in threats.values():
if (tick - th.tick_rx) >= time_lost:
@@ -115,7 +115,7 @@ func on_interfer_init(interfer_name, fs_arr, power, threats):
sel_threats.append(threat)
if threat.auto_selected:
sel_threats.append(threat)
if len(sel_threats) or (len(fs_arr)):
if len(sel_threats) or len(fs_arr):
signaller.emit_signal('interfer_create', interfer_name, sel_threats, fs_arr, power)
@@ -128,20 +128,22 @@ func on_data_capsrpb_received(unit: capsrpb.CapsRpb, threats: Dictionary):
var mis = unit.json_dic['mis']
var sz: = threats.size()
for dic_th in mis:
if dic_th is Dictionary:
if dic_th.has('id'):
var id = int(dic_th['id'])
if threats.has(id):
var th = threats[id]
th.clear_fflags()
th.set_from_dic(dic_th)
th.tick_rx = unit.tick
call_deferred('emit_signal', 'threat_update', th)
else:
var th = Threat.new()
th.set_from_dic(dic_th)
threats[id] = th
th.tick_rx = unit.tick
call_deferred('emit_signal', 'threat_new', th)
if dic_th is not Dictionary:
continue
if not dic_th.has('id'):
continue
var id = int(dic_th['id'])
if threats.has(id):
var th = threats[id]
th.clear_fflags()
th.set_from_dic(dic_th)
th.tick_rx = unit.tick
call_deferred('emit_signal', 'threat_update', th)
else:
var th: = Threat.new()
th.set_from_dic(dic_th)
threats[id] = th
th.tick_rx = unit.tick
call_deferred('emit_signal', 'threat_new', th)
if sz != threats.size():
call_deferred('emit_signal', 'threats_resized', threats)