Working on fixing a bug with browser
This commit is contained in:
@@ -50,6 +50,9 @@ var projectiles: Dictionary = {} # id -> projectile node
|
||||
var aim_angle: float = 0.0
|
||||
var last_attack_time: float = -999.0 # Start far in the past so first attack always works
|
||||
var attack_cooldown: float = 0.5 # Default attack cooldown in seconds
|
||||
var _last_move_sent_time_ms: int = 0
|
||||
var _last_move_vec: Vector2 = Vector2.ZERO
|
||||
var _last_aim_sent: float = 0.0
|
||||
|
||||
func _ready():
|
||||
# Add to group for HUD to access
|
||||
@@ -220,14 +223,20 @@ func _build_tiles():
|
||||
func _input(event: InputEvent):
|
||||
# Handle touch screen taps for attacking
|
||||
if event is InputEventScreenTouch and event.pressed:
|
||||
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
|
||||
var ui_open = _is_ui_blocking_input()
|
||||
|
||||
# Don't attack if UI is open
|
||||
if ui_open:
|
||||
return
|
||||
|
||||
# Ignore touches on the joystick so movement doesn't trigger attacks
|
||||
if hud:
|
||||
var joystick = hud.get_node_or_null("TouchJoystick")
|
||||
if joystick and joystick is Control and joystick.get_global_rect().has_point(event.position):
|
||||
return
|
||||
|
||||
# Calculate attack direction from touch position to player
|
||||
var touch_world_pos = camera.get_global_mouse_position()
|
||||
var touch_world_pos = get_viewport().get_canvas_transform().affine_inverse() * event.position
|
||||
var player_pos = Vector2(GameState.self_player.get("x", 0), GameState.self_player.get("y", 0))
|
||||
var attack_angle = (touch_world_pos - player_pos).angle()
|
||||
|
||||
@@ -258,7 +267,7 @@ func _handle_input():
|
||||
return
|
||||
|
||||
# Don't process game input if inventory or chat is open
|
||||
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
|
||||
var ui_open = _is_ui_blocking_input()
|
||||
|
||||
# Calculate aim angle from mouse/touch position
|
||||
var mouse_pos = get_global_mouse_position()
|
||||
@@ -315,7 +324,7 @@ func _handle_input():
|
||||
|
||||
func _perform_attack(attack_angle: float):
|
||||
# Don't attack if UI is open
|
||||
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
|
||||
var ui_open = _is_ui_blocking_input()
|
||||
if ui_open:
|
||||
return
|
||||
|
||||
@@ -408,9 +417,11 @@ func _perform_attack(attack_angle: float):
|
||||
|
||||
func _send_movement():
|
||||
# Don't move if UI is open
|
||||
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible) or (crafting_panel and crafting_panel.visible) or (char_sheet_ui and char_sheet_ui.visible) or (loot_popup and loot_popup.visible)
|
||||
var ui_open = _is_ui_blocking_input()
|
||||
if ui_open:
|
||||
return
|
||||
if not Network or not Network.is_socket_connected():
|
||||
return
|
||||
|
||||
var dx = Input.get_axis("move_left", "move_right")
|
||||
var dy = Input.get_axis("move_up", "move_down")
|
||||
@@ -423,7 +434,18 @@ func _send_movement():
|
||||
if player_node and player_node.has_method("set_movement"):
|
||||
player_node.set_movement(move_vec)
|
||||
|
||||
GameState.send_move(move_vec.x, move_vec.y, aim_angle)
|
||||
# Throttle movement packets to avoid saturating the websocket
|
||||
var now_ms = Time.get_ticks_msec()
|
||||
var time_since_last = now_ms - _last_move_sent_time_ms
|
||||
var moved_changed = move_vec != _last_move_vec
|
||||
var aim_changed = abs(aim_angle - _last_aim_sent) > 0.05
|
||||
|
||||
# Always send when movement changes; otherwise, send at ~10Hz while moving
|
||||
if moved_changed or (move_vec.length() > 0.0 and time_since_last >= 100) or (aim_changed and move_vec.length() > 0.0):
|
||||
GameState.send_move(move_vec.x, move_vec.y, aim_angle)
|
||||
_last_move_sent_time_ms = now_ms
|
||||
_last_move_vec = move_vec
|
||||
_last_aim_sent = aim_angle
|
||||
|
||||
func _update_camera(delta):
|
||||
if not camera or not GameState:
|
||||
@@ -537,6 +559,21 @@ func _open_chat():
|
||||
if chat_panel.has_method("focus_input"):
|
||||
chat_panel.focus_input()
|
||||
|
||||
func _is_chat_typing() -> bool:
|
||||
if not chat_panel:
|
||||
return false
|
||||
if chat_panel.has_method("is_typing"):
|
||||
return chat_panel.is_typing()
|
||||
# Fallback if chat UI doesn't expose a helper
|
||||
var chat_input = chat_panel.get_node_or_null("Control/VBoxContainer/InputContainer/ChatInput")
|
||||
return chat_input != null and chat_input.has_focus()
|
||||
|
||||
func _is_ui_blocking_input() -> bool:
|
||||
return (inventory_panel and inventory_panel.visible) \
|
||||
or (crafting_panel and crafting_panel.visible) \
|
||||
or (char_sheet_ui and char_sheet_ui.visible) \
|
||||
or _is_chat_typing()
|
||||
|
||||
func _use_hotbar_slot(index: int):
|
||||
if not GameState:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user