142 lines
4.3 KiB
GDScript
142 lines
4.3 KiB
GDScript
class_name DiagnosticDiveScreen
|
|
extends Control
|
|
|
|
signal menu_requested
|
|
|
|
const DiveUpdate = preload("res://game/domain/dive/dive_update.gd")
|
|
const DiveAlertLevel = preload("res://game/domain/dive/dive_alert_level.gd")
|
|
const DiveTerminalReason = preload("res://game/domain/dive/dive_terminal_reason.gd")
|
|
const ReturnEstimate = preload("res://game/domain/dive/return_estimate.gd")
|
|
|
|
@onready var _status_label: Label = %StatusLabel
|
|
@onready var _tick_label: Label = %TickLabel
|
|
@onready var _battery_label: Label = %BatteryLabel
|
|
@onready var _oxygen_label: Label = %OxygenLabel
|
|
@onready var _hull_label: Label = %HullLabel
|
|
@onready var _depth_label: Label = %DepthLabel
|
|
@onready var _return_label: Label = %ReturnLabel
|
|
@onready var _alert_label: Label = %AlertLabel
|
|
@onready var _event_label: Label = %EventLabel
|
|
@onready var _menu_button: Button = %MenuButton
|
|
|
|
|
|
func _ready() -> void:
|
|
_menu_button.pressed.connect(_on_menu_pressed)
|
|
|
|
|
|
func present(update: DiveUpdate) -> void:
|
|
if update == null or update.snapshot == null:
|
|
present_setup_error("Mise à jour de plongée absente")
|
|
return
|
|
if not update.accepted:
|
|
_status_label.text = "ÉTAT · PAS REFUSÉ · %s" % update.rejection_reason
|
|
else:
|
|
_status_label.text = "ÉTAT · SIMULATION DÉTERMINISTE · 60 HZ"
|
|
|
|
var snapshot = update.snapshot
|
|
_tick_label.text = "SESSION %s · TICK %d" % [snapshot.session_id, snapshot.tick_sequence]
|
|
_battery_label.text = (
|
|
"BATTERIE %.2f / %.2f kWh · %.0f %% · %.1f kW"
|
|
% [
|
|
snapshot.battery.remaining_kwh,
|
|
snapshot.battery.maximum_kwh,
|
|
snapshot.battery.ratio * 100.0,
|
|
snapshot.battery.current_power_kw,
|
|
]
|
|
)
|
|
_oxygen_label.text = (
|
|
"OXYGÈNE %.1f / %.1f L · %.0f %% · %.1f L/min · %.1f min"
|
|
% [
|
|
snapshot.oxygen.remaining_l,
|
|
snapshot.oxygen.maximum_l,
|
|
snapshot.oxygen.ratio * 100.0,
|
|
snapshot.oxygen.consumption_l_per_min,
|
|
snapshot.oxygen.endurance_minutes,
|
|
]
|
|
)
|
|
_hull_label.text = (
|
|
"COQUE %.1f / %.1f · %.0f %% · %.2f / %.2f bar recommandés"
|
|
% [
|
|
snapshot.hull.current_integrity,
|
|
snapshot.hull.maximum_integrity,
|
|
snapshot.hull.ratio * 100.0,
|
|
snapshot.hull.exterior_pressure_bar,
|
|
snapshot.hull.certified_pressure_bar,
|
|
]
|
|
)
|
|
_depth_label.text = (
|
|
"PROFONDEUR %.1f m · CERTIFIÉE %.1f m · CRITIQUE %.1f m"
|
|
% [
|
|
snapshot.depth.current_m,
|
|
snapshot.depth.certified_m,
|
|
snapshot.depth.critical_m,
|
|
]
|
|
)
|
|
_return_label.text = _format_return_estimate(snapshot.return_estimate)
|
|
_alert_label.text = "ALERTE MAXIMALE · %s" % _alert_level_text(snapshot.alerts.maximum)
|
|
_event_label.text = (
|
|
"TERMINAISON · %s · ÉVÉNEMENTS DU PAS · %d"
|
|
% [_terminal_reason_text(snapshot.terminal_reason), update.events.size()]
|
|
)
|
|
|
|
|
|
func present_setup_error(message: String) -> void:
|
|
_status_label.text = "ÉTAT · INITIALISATION IMPOSSIBLE"
|
|
_tick_label.text = message
|
|
|
|
|
|
func _on_menu_pressed() -> void:
|
|
menu_requested.emit()
|
|
|
|
|
|
func _format_return_estimate(estimate: ReturnEstimate) -> String:
|
|
match estimate.status:
|
|
ReturnEstimate.Status.UNKNOWN:
|
|
return "RETOUR · ESTIMATION INCONNUE"
|
|
ReturnEstimate.Status.SAFE:
|
|
return "RETOUR %.2f kWh requis · MARGE %.2f kWh · SÛR" % [
|
|
estimate.required_kwh,
|
|
estimate.margin_kwh,
|
|
]
|
|
ReturnEstimate.Status.TIGHT:
|
|
return "RETOUR %.2f kWh requis · MARGE %.2f kWh · SERRÉ" % [
|
|
estimate.required_kwh,
|
|
estimate.margin_kwh,
|
|
]
|
|
ReturnEstimate.Status.INSUFFICIENT:
|
|
return "RETOUR %.2f kWh requis · MANQUE %.2f kWh" % [
|
|
estimate.required_kwh,
|
|
absf(estimate.margin_kwh),
|
|
]
|
|
return "RETOUR · ÉTAT INCONNU"
|
|
|
|
|
|
func _alert_level_text(level: DiveAlertLevel.Value) -> String:
|
|
match level:
|
|
DiveAlertLevel.Value.NORMAL:
|
|
return tr("NORMAL")
|
|
DiveAlertLevel.Value.ATTENTION:
|
|
return tr("ATTENTION")
|
|
DiveAlertLevel.Value.RETURN:
|
|
return tr("RETOUR")
|
|
DiveAlertLevel.Value.CRITICAL:
|
|
return tr("CRITIQUE")
|
|
DiveAlertLevel.Value.FAILURE:
|
|
return tr("DÉFAILLANCE")
|
|
return tr("INCONNU")
|
|
|
|
|
|
func _terminal_reason_text(reason: DiveTerminalReason.Value) -> String:
|
|
match reason:
|
|
DiveTerminalReason.Value.NONE:
|
|
return tr("EN COURS")
|
|
DiveTerminalReason.Value.RETURNED:
|
|
return tr("RETOUR")
|
|
DiveTerminalReason.Value.VOLUNTARY_EJECTION:
|
|
return tr("ÉJECTION VOLONTAIRE")
|
|
DiveTerminalReason.Value.OXYGEN_DEPLETED:
|
|
return tr("OXYGÈNE ÉPUISÉ")
|
|
DiveTerminalReason.Value.HULL_DESTROYED:
|
|
return tr("COQUE DÉTRUITE")
|
|
return tr("INCONNU")
|