test: cover combat feedback presentation contract
This commit is contained in:
@@ -3,12 +3,21 @@ extends Node2D
|
||||
|
||||
signal feedback_completed
|
||||
|
||||
const MOVEMENT_DURATION := 0.10
|
||||
const IMPACT_DURATION := 0.14
|
||||
const DEATH_DURATION := 0.18
|
||||
# Milliseconds are the presentation contract; durations are derived only where
|
||||
# Godot's Tween API requires seconds.
|
||||
const MOVEMENT_DURATION_MS := 100
|
||||
const IMPACT_DURATION_MS := 140
|
||||
const DEATH_DURATION_MS := 180
|
||||
const MOVEMENT_DURATION := float(MOVEMENT_DURATION_MS) / 1000.0
|
||||
const IMPACT_DURATION := float(IMPACT_DURATION_MS) / 1000.0
|
||||
const DEATH_DURATION := float(DEATH_DURATION_MS) / 1000.0
|
||||
const FLASH_COLOR := Color(1.0, 0.45, 0.45, 1.0)
|
||||
|
||||
var _test_mode := false
|
||||
var _movement_tween_configuration := {}
|
||||
var _impact_feedback_state := {}
|
||||
var _death_fade_configuration := {}
|
||||
var _active_impact_label: Label
|
||||
|
||||
func _enter_tree() -> void:
|
||||
_test_mode = "--test-mode" in OS.get_cmdline_user_args() and not Engine.is_editor_hint()
|
||||
@@ -16,6 +25,22 @@ func _enter_tree() -> void:
|
||||
func is_test_mode() -> bool:
|
||||
return _test_mode
|
||||
|
||||
# Public test seam: production mode remains determined from command-line args.
|
||||
func set_test_mode_for_testing(enabled: bool) -> void:
|
||||
_test_mode = enabled
|
||||
|
||||
func get_movement_tween_configuration() -> Dictionary:
|
||||
return _movement_tween_configuration.duplicate()
|
||||
|
||||
func get_impact_feedback_state() -> Dictionary:
|
||||
return _impact_feedback_state.duplicate()
|
||||
|
||||
func get_death_fade_configuration() -> Dictionary:
|
||||
return _death_fade_configuration.duplicate()
|
||||
|
||||
func get_active_impact_label() -> Label:
|
||||
return _active_impact_label
|
||||
|
||||
func begin(event: GameEvent, actor_lookup: Callable) -> void:
|
||||
if _test_mode:
|
||||
feedback_completed.emit()
|
||||
@@ -36,8 +61,15 @@ func _show_movement(event: GameEvent, actor_lookup: Callable) -> void:
|
||||
var actor_view := _find_actor_view(event.actor_id, actor_lookup)
|
||||
if actor_view == null:
|
||||
return
|
||||
var from_position := Vector2(event.payload.get("from_cell", event.cell)) * Vector2(ActorView.TILE_SIZE)
|
||||
var destination := Vector2(event.payload.get("to_cell", event.cell)) * Vector2(ActorView.TILE_SIZE)
|
||||
actor_view.position = Vector2(event.payload.get("from_cell", event.cell)) * Vector2(ActorView.TILE_SIZE)
|
||||
_movement_tween_configuration = {
|
||||
"property": &"position",
|
||||
"from": from_position,
|
||||
"to": destination,
|
||||
"duration_ms": MOVEMENT_DURATION_MS,
|
||||
}
|
||||
actor_view.position = from_position
|
||||
var tween := create_tween()
|
||||
tween.tween_property(actor_view, "position", destination, MOVEMENT_DURATION)
|
||||
await tween.finished
|
||||
@@ -51,6 +83,11 @@ func _show_impact(event: GameEvent, actor_lookup: Callable) -> void:
|
||||
actor_view.last_damage = int(event.payload.get("damage", 0))
|
||||
actor_view.modulate = FLASH_COLOR
|
||||
_show_damage_label(actor_view, actor_view.last_damage)
|
||||
_impact_feedback_state = {
|
||||
"flash_color": FLASH_COLOR,
|
||||
"label_text": _active_impact_label.text,
|
||||
"duration_ms": IMPACT_DURATION_MS,
|
||||
}
|
||||
var tween := create_tween()
|
||||
tween.tween_interval(IMPACT_DURATION)
|
||||
await tween.finished
|
||||
@@ -61,6 +98,12 @@ func _show_death(event: GameEvent, actor_lookup: Callable) -> void:
|
||||
var actor_view := _find_actor_view(event.actor_id, actor_lookup)
|
||||
if actor_view == null:
|
||||
return
|
||||
_death_fade_configuration = {
|
||||
"property": &"modulate:a",
|
||||
"from_alpha": actor_view.modulate.a,
|
||||
"to_alpha": 0.0,
|
||||
"duration_ms": DEATH_DURATION_MS,
|
||||
}
|
||||
var tween := create_tween()
|
||||
tween.tween_property(actor_view, "modulate:a", 0.0, DEATH_DURATION)
|
||||
await tween.finished
|
||||
@@ -71,6 +114,7 @@ func _show_damage_label(actor_view: ActorView, damage: int) -> void:
|
||||
label.position = actor_view.global_position + Vector2(6, -14)
|
||||
label.z_index = 10
|
||||
add_child(label)
|
||||
_active_impact_label = label
|
||||
var tween := create_tween()
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(label, "position:y", label.position.y - 16.0, IMPACT_DURATION)
|
||||
|
||||
Reference in New Issue
Block a user