feat: add nearby social interactions
This commit is contained in:
@@ -25,8 +25,11 @@ const DIRECTION_ROWS: Dictionary = {
|
||||
var lastDirection: String = "down"
|
||||
var _nameLabel: Label
|
||||
var _movementLocked: bool = false
|
||||
var has_scene_position_override: bool = false
|
||||
var _discoveryElapsed: float = 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("whaletown_local_player")
|
||||
_reset_movement_input_state()
|
||||
_apply_current_appearance()
|
||||
_subscribe_to_appearance_events()
|
||||
@@ -71,28 +74,40 @@ func _release_movement_actions() -> void:
|
||||
|
||||
func _check_spawn_position() -> void:
|
||||
var spawnPos: Variant = SceneManager.get_next_scene_position()
|
||||
if spawnPos != null:
|
||||
if spawnPos is Vector2:
|
||||
global_position = spawnPos
|
||||
_update_world_sort_z()
|
||||
has_scene_position_override = true
|
||||
_update_world_sort_z()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_handle_movement(delta)
|
||||
_update_world_sort_z()
|
||||
_handle_interaction()
|
||||
_report_nearby_discoveries(delta)
|
||||
|
||||
func _handle_interaction() -> void:
|
||||
if _is_text_input_focused():
|
||||
# 统一交互由 /root/InteractionManager 收集附近候选并处理 E 键。
|
||||
return
|
||||
|
||||
func _report_nearby_discoveries(delta: float) -> void:
|
||||
_discoveryElapsed += delta
|
||||
if _discoveryElapsed < 0.35:
|
||||
return
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
EventSystem.emit_event(EventNames.INTERACT_PRESSED, {
|
||||
"player": self,
|
||||
"position": global_position,
|
||||
"direction": lastDirection
|
||||
})
|
||||
if ray_cast.is_colliding():
|
||||
var collider := ray_cast.get_collider()
|
||||
if collider and collider.has_method("interact"):
|
||||
collider.interact()
|
||||
_discoveryElapsed = 0.0
|
||||
var scene := get_tree().current_scene
|
||||
if scene == null:
|
||||
return
|
||||
var map_id: String = str({
|
||||
"Square": "whale_port",
|
||||
"WorkZone": "work_zone",
|
||||
"CafeInterior": "whale_cafe",
|
||||
"PersonalSpace": "personal_space",
|
||||
}.get(str(scene.name), ""))
|
||||
if map_id.is_empty():
|
||||
return
|
||||
var social_manager := get_node_or_null("/root/SocialManager")
|
||||
if social_manager != null and social_manager.has_method("discover_nearby_destinations"):
|
||||
social_manager.call("discover_nearby_destinations", map_id, global_position)
|
||||
|
||||
func _handle_movement(_delta: float) -> void:
|
||||
if _movementLocked:
|
||||
@@ -111,10 +126,7 @@ func _handle_movement(_delta: float) -> void:
|
||||
return
|
||||
|
||||
# 获取移动向量 (参考 docs/02-开发规范/输入映射配置.md)
|
||||
var direction := Input.get_vector(
|
||||
"move_left", "move_right",
|
||||
"move_up", "move_down"
|
||||
)
|
||||
var direction := _movement_direction()
|
||||
|
||||
# 应用移动
|
||||
if direction != Vector2.ZERO:
|
||||
@@ -133,6 +145,16 @@ func _handle_movement(_delta: float) -> void:
|
||||
"position": global_position
|
||||
})
|
||||
|
||||
func _movement_direction() -> Vector2:
|
||||
var interactionManager := get_node_or_null("/root/InteractionManager")
|
||||
if interactionManager != null and interactionManager.has_method("is_selection_active") and bool(interactionManager.call("is_selection_active")):
|
||||
# 有交互候选时方向键用于选择,保留 WASD 移动。
|
||||
return Vector2(
|
||||
(-1.0 if Input.is_key_pressed(KEY_A) else 0.0) + (1.0 if Input.is_key_pressed(KEY_D) else 0.0),
|
||||
(-1.0 if Input.is_key_pressed(KEY_W) else 0.0) + (1.0 if Input.is_key_pressed(KEY_S) else 0.0)
|
||||
).normalized()
|
||||
return Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
func _update_animation_state(direction: Vector2) -> void:
|
||||
if not animation_player:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user