diff --git a/client/Main.gd b/client/Main.gd index eb07e79..9d42843 100644 --- a/client/Main.gd +++ b/client/Main.gd @@ -3,16 +3,14 @@ extends Node @export var ui: UI func _ready(): - connect_events() pause(true) + connect_events() + start() - var args := OS.get_cmdline_args() - var offline := args.has("--offline") - - if offline: - start_offline() - else: - start_online() +func _input(event: InputEvent): + if event.is_action_pressed("toggle_fullscreen"): + WindowManager.toggle_fullscreen(get_window()) + get_viewport().set_input_as_handled() func connect_events(): %Login.success.connect(on_login) @@ -26,7 +24,16 @@ func connect_events(): %Client.upload_changed.connect(ui.network.set_upload) %Chat.message_received.connect(ui.chat.add_message) - ui.chat.message_submitted.connect(%Chat.send_message) + ui.chat.message_submitted.connect( %Chat.send_message) + +func start(): + var args := OS.get_cmdline_args() + var offline := args.has("--offline") + + if offline: + start_offline() + else: + start_online() func start_offline(): Global.account.id = "test" @@ -38,44 +45,19 @@ func start_offline(): func start_online(): %Login.send_login() -func _input(event): - if event.is_action_pressed("toggle_fullscreen"): - toggle_fullscreen() - get_viewport().set_input_as_handled() +func pause(enabled: bool): + get_tree().paused = enabled + Audio.mute(enabled) func on_login(): - %Client.log("Login succeeded.") - %Client.log("ID: %s" % Global.account.id) - %Client.log("Auth token: %s" % Global.account.auth_token) + Log.info("Login succeeded.") + Log.info("ID: %s" % Global.account.id) + Log.info("Auth token: %s" % Global.account.auth_token) - DisplayServer.window_set_title("%s - %s" % [Global.account.name, Global.account.id]) - DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540)) + #DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540)) + get_window().title = "%s - %s" % [Global.account.name, Global.account.id] pause(false) func on_logout(): - %Client.log("[%s] Logout." % Global.account.name) - pause(true) - -func pause(enabled: bool): - get_tree().paused = enabled - mute_audio(enabled) - -func mute_audio(enabled: bool): - var master_sound = AudioServer.get_bus_index("Master") - AudioServer.set_bus_mute(master_sound, enabled) - -func toggle_fullscreen(): - var mode = DisplayServer.window_get_mode() - - match mode: - DisplayServer.WINDOW_MODE_FULLSCREEN: - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) - center_window() - _: - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) - -func center_window(): - var screen_center := DisplayServer.screen_get_position() + DisplayServer.screen_get_size() / 2 - var window := get_window() - var window_size = window.get_size_with_decorations() - window.set_position(screen_center - window_size / 2) + Log.info("[%s] Logout." % Global.account.name) + pause(true) \ No newline at end of file diff --git a/client/Start.gd b/client/Start.gd index f576de2..1c444e6 100644 --- a/client/Start.gd +++ b/client/Start.gd @@ -14,7 +14,7 @@ func _ready(): if OS.has_feature("editor"): fade_duration /= 2 -func _process(_delta): +func _process(_delta: float): var status := ResourceLoader.load_threaded_get_status(scene_path, progress) progress_bar.value = progress[0] * 100 diff --git a/client/camera/Camera.gd b/client/camera/Camera.gd index 06bf8ac..e6692b0 100644 --- a/client/camera/Camera.gd +++ b/client/camera/Camera.gd @@ -37,7 +37,7 @@ func _ready(): Global.camera = self update_look_offset() -func _unhandled_input(event): +func _unhandled_input(event: InputEvent): if !event.is_action("look"): return @@ -47,7 +47,7 @@ func _unhandled_input(event): false: end_look() -func _input(event): +func _input(event: InputEvent): if event.is_action_pressed("zoom_in", true): target_distance -= zoom_speed on_distance_changed() @@ -72,7 +72,7 @@ func _input(event): update_look_offset() -func _process(delta): +func _process(delta: float): if !Global.player: return diff --git a/client/camera/CameraShake.gd b/client/camera/CameraShake.gd index 34cfde0..81f093e 100644 --- a/client/camera/CameraShake.gd +++ b/client/camera/CameraShake.gd @@ -7,7 +7,7 @@ extends Node3D var trauma := 0.0 var trauma_time := 0.0 -func _process(delta): +func _process(delta: float): if trauma: trauma = max(trauma - shake_decay * delta, 0) trauma_time += 4096 * delta diff --git a/client/enemy/EnemyController.gd b/client/enemy/EnemyController.gd index d445623..2c79a4c 100644 --- a/client/enemy/EnemyController.gd +++ b/client/enemy/EnemyController.gd @@ -9,7 +9,7 @@ func _init(): func _ready(): enemy = owner -func _process(_delta): +func _process(_delta: float): if !Global.player: return diff --git a/client/item/soul/Soul.gd b/client/item/soul/Soul.gd index edc5973..acd40d5 100644 --- a/client/item/soul/Soul.gd +++ b/client/item/soul/Soul.gd @@ -20,7 +20,7 @@ func _ready(): attractor = %Attractor sound = %Sound -func _process(delta): +func _process(delta: float): if !collected_by: return diff --git a/client/network/Chat.gd b/client/network/Chat.gd index 7ef2f6b..31af478 100644 --- a/client/network/Chat.gd +++ b/client/network/Chat.gd @@ -16,7 +16,7 @@ func handle_packet(data: PackedByteArray): var player := Global.players.get_player(player_id) var message := buffer.get_utf8_string() - %Client.log("%s: %s" % [player.name, message]) + Log.info("%s: %s" % [player.name, message]) message_received.emit("[color=#e0e0e0]%s:[/color] %s" % [player.name, escape_bbcode(message)]) func escape_bbcode(text: String) -> String: diff --git a/client/network/Client.gd b/client/network/Client.gd index 04fdebc..4157c3f 100644 --- a/client/network/Client.gd +++ b/client/network/Client.gd @@ -20,7 +20,7 @@ func _ready(): var ip := IP.resolve_hostname(host) socket.connect_to_host(ip, port) -func _process(_delta): +func _process(_delta: float): while socket.get_available_packet_count() > 0: var packet := socket.get_packet() handle_packet(packet) @@ -33,7 +33,4 @@ func update_statistics(): func send(data: PackedByteArray): socket.put_packet(data) - upload += data.size() - -func log(message: String): - print_rich("[color=#808080][%s][/color] %s" % [Global.account.name, message]) + upload += data.size() \ No newline at end of file diff --git a/client/network/Login.gd b/client/network/Login.gd index eb8235c..6a970db 100644 --- a/client/network/Login.gd +++ b/client/network/Login.gd @@ -9,7 +9,7 @@ func handle_packet(data: PackedByteArray): var error := buffer.get_8() if error != 0: - %Client.log("[%s] Login failed." % Global.account.name) + Log.info("[%s] Login failed." % Global.account.name) failure.emit() return @@ -27,7 +27,7 @@ func send_login(): buffer.put_u8(Packet.LOGIN) buffer.put_data(JSON.stringify([Global.account.name, password]).to_utf8_buffer()) %Client.send(buffer.data_array) - %Client.log("Connecting...") + Log.info("Connecting...") func is_logged_in() -> bool: return Global.account.auth_token != "" diff --git a/client/network/PlayerAdd.gd b/client/network/PlayerAdd.gd index b711ef2..f7f63e5 100644 --- a/client/network/PlayerAdd.gd +++ b/client/network/PlayerAdd.gd @@ -19,7 +19,7 @@ func handle_packet(data: PackedByteArray): server_position.y = buffer.get_float() server_position.z = buffer.get_float() - %Client.log("Add player: %s %s @ %v" % [player_id, player_name, server_position]) + Log.info("Add player: %s %s @ %v" % [player_id, player_name, server_position]) spawn_player(player_id, player_name, server_position) diff --git a/client/network/PlayerMove.gd b/client/network/PlayerMove.gd index ba71462..b43885f 100644 --- a/client/network/PlayerMove.gd +++ b/client/network/PlayerMove.gd @@ -36,7 +36,7 @@ func handle_packet(data: PackedByteArray): controller.server_position.z = z controller.direction_changed.emit(Vector3(direction_x, 0, direction_z)) -func _process(_delta): +func _process(_delta: float): if !Global.player: return diff --git a/client/network/PlayerRemove.gd b/client/network/PlayerRemove.gd index 04ddf3f..76f1ba5 100644 --- a/client/network/PlayerRemove.gd +++ b/client/network/PlayerRemove.gd @@ -2,5 +2,5 @@ extends PacketHandler func handle_packet(data: PackedByteArray): var player_id := data.get_string_from_ascii() - %Client.log("Remove player: %s" % player_id) + Log.info("Remove player: %s" % player_id) Global.players.remove(player_id) \ No newline at end of file diff --git a/client/player/Player.gd b/client/player/Player.gd index 7563d10..1413fbe 100644 --- a/client/player/Player.gd +++ b/client/player/Player.gd @@ -23,4 +23,4 @@ signal name_changed(new_name: String) func set_player_name(new_name: String): name = new_name - name_changed.emit(new_name) \ No newline at end of file + name_changed.emit(new_name) diff --git a/client/player/animation/AnimationComponent.gd b/client/player/animation/AnimationComponent.gd index 4d70874..fb3abac 100644 --- a/client/player/animation/AnimationComponent.gd +++ b/client/player/animation/AnimationComponent.gd @@ -13,7 +13,7 @@ func _ready(): state.transitioned.connect(on_transition) animations = %AnimationPlayer -func _process(delta): +func _process(delta: float): accumulated_delta += delta if skipped_frames >= skip_frames: diff --git a/client/player/controller/BotController.gd b/client/player/controller/BotController.gd index c059441..18c850d 100644 --- a/client/player/controller/BotController.gd +++ b/client/player/controller/BotController.gd @@ -4,7 +4,7 @@ extends Controller var turn: float var turn_speed: float = 2.0 -func _process(delta): +func _process(delta: float): if (Time.get_ticks_msec() / 1000) % 2 == 0: direction_changed.emit(Vector3.ZERO) else: diff --git a/client/player/footsteps/FootstepsComponent.gd b/client/player/footsteps/FootstepsComponent.gd index 26fb7ec..f98fb33 100644 --- a/client/player/footsteps/FootstepsComponent.gd +++ b/client/player/footsteps/FootstepsComponent.gd @@ -30,6 +30,7 @@ func _ready(): foot.attachment.bone_name = foot_name foot.attachment.bone_idx = foot.bone_id foot.audio.reparent(foot.attachment) + foot.audio.position = Vector3.ZERO skeleton.add_child(foot.attachment) feet.append(foot) @@ -62,7 +63,7 @@ func _process(delta: float): play(foot.audio) -func _physics_process(_delta): +func _physics_process(_delta: float): var space_state = get_world_3d().direct_space_state for foot in feet: diff --git a/client/player/rotation/RotationComponent.gd b/client/player/rotation/RotationComponent.gd index b56732d..25d602d 100644 --- a/client/player/rotation/RotationComponent.gd +++ b/client/player/rotation/RotationComponent.gd @@ -12,7 +12,7 @@ func _ready(): assert(rotation_speed > 0, "rotation speed must be greater than zero") character.controlled.connect(on_controlled) -func _process(delta): +func _process(delta: float): if absf(angle_difference(root.rotation.y, angle)) < 0.001: return diff --git a/client/player/state/StateComponent.gd b/client/player/state/StateComponent.gd index ba8517f..4c1ebb5 100644 --- a/client/player/state/StateComponent.gd +++ b/client/player/state/StateComponent.gd @@ -19,7 +19,7 @@ func _ready(): current = State.Idle movement = character.get_node("Movement") -func _process(_delta): +func _process(_delta: float): if current == State.Skill: return diff --git a/client/skill/dash/dash.gd b/client/skill/dash/dash.gd index 704b744..e0fea8d 100644 --- a/client/skill/dash/dash.gd +++ b/client/skill/dash/dash.gd @@ -16,7 +16,7 @@ func _ready(): set_physics_process(false) end() -func _physics_process(_delta): +func _physics_process(_delta: float): if movement.direction: direction = movement.direction diff --git a/client/static/Audio.gd b/client/static/Audio.gd new file mode 100644 index 0000000..ec254d6 --- /dev/null +++ b/client/static/Audio.gd @@ -0,0 +1,5 @@ +class_name Audio + +static func mute(enabled: bool): + var master_sound = AudioServer.get_bus_index("Master") + AudioServer.set_bus_mute(master_sound, enabled) \ No newline at end of file diff --git a/client/static/Log.gd b/client/static/Log.gd new file mode 100644 index 0000000..2445fbb --- /dev/null +++ b/client/static/Log.gd @@ -0,0 +1,4 @@ +class_name Log + +static func info(message: String): + print_rich("[color=#808080][%s][/color] %s" % [Global.account.name, message]) \ No newline at end of file diff --git a/client/math/Math.gd b/client/static/Math.gd similarity index 100% rename from client/math/Math.gd rename to client/static/Math.gd diff --git a/client/static/WindowManager.gd b/client/static/WindowManager.gd new file mode 100644 index 0000000..56e1081 --- /dev/null +++ b/client/static/WindowManager.gd @@ -0,0 +1,13 @@ +class_name WindowManager + +static var window_size: Vector2i + +static func toggle_fullscreen(window: Window): + match window.mode: + Window.MODE_FULLSCREEN: + window.mode = Window.MODE_WINDOWED + window.size = window_size + window.move_to_center() + Window.MODE_WINDOWED: + window_size = window.size + window.mode = Window.MODE_FULLSCREEN \ No newline at end of file diff --git a/client/test/benchmark/Benchmark.gd b/client/test/benchmark/Benchmark.gd index 6412b40..771cadc 100644 --- a/client/test/benchmark/Benchmark.gd +++ b/client/test/benchmark/Benchmark.gd @@ -13,6 +13,7 @@ var benchmarks = [ "get_ticks_usec", "get_unix_time_from_system", "get_viewport", + "get_window", "get_world_3d", "gui_get_focus_owner", "script_func_call", @@ -78,6 +79,10 @@ func _get_viewport(): for i in range(n): get_viewport() +func _get_window(): + for i in range(n): + get_window() + func _get_world_3d(): for i in range(n): get_world_3d() diff --git a/client/test/order/TestOrder.gd b/client/test/order/TestOrder.gd index cd24387..9635c13 100644 --- a/client/test/order/TestOrder.gd +++ b/client/test/order/TestOrder.gd @@ -14,11 +14,11 @@ func _ready(): get_tree().process_frame.connect(callback.bind("process_frame")) get_tree().physics_frame.connect(callback.bind("physics_frame")) -func _process(_delta): +func _process(_delta: float): callback("_process") queue_free() -func _physics_process(_delta): +func _physics_process(_delta: float): callback("_physics_process") func _notification(what): diff --git a/client/ui/UI.gd b/client/ui/UI.gd index 3c2573f..fae5f45 100644 --- a/client/ui/UI.gd +++ b/client/ui/UI.gd @@ -12,7 +12,7 @@ func _enter_tree(): reconnect = %Reconnect network = %Network -func _process(_delta): +func _process(_delta: float): var new_focus := get_viewport().gui_get_focus_owner() if new_focus && new_focus.name != "Unfocus": diff --git a/client/ui/chat/ChatInput.gd b/client/ui/chat/ChatInput.gd index babc092..404ce51 100644 --- a/client/ui/chat/ChatInput.gd +++ b/client/ui/chat/ChatInput.gd @@ -6,7 +6,7 @@ func _ready(): focus_exited.connect(on_focus_exited) text_submitted.connect(on_text_submitted) -func _unhandled_key_input(event): +func _unhandled_key_input(event: InputEvent): if UI.focus: return diff --git a/client/ui/debug/FPSLabel.gd b/client/ui/debug/FPSLabel.gd index fdc90f7..8c8a86a 100644 --- a/client/ui/debug/FPSLabel.gd +++ b/client/ui/debug/FPSLabel.gd @@ -1,4 +1,4 @@ extends DebugLabel -func _process(_delta): +func _process(_delta: float): text = str(Engine.get_frames_per_second()) diff --git a/client/ui/debug/PerformanceLabel.gd b/client/ui/debug/PerformanceLabel.gd index 2cf94eb..1b844bc 100644 --- a/client/ui/debug/PerformanceLabel.gd +++ b/client/ui/debug/PerformanceLabel.gd @@ -5,7 +5,7 @@ extends DebugLabel @export var precision := 0.1 @export var suffix := "" -func _process(_delta): +func _process(_delta: float): match monitor: Performance.Monitor.TIME_PROCESS, Performance.Monitor.TIME_PHYSICS_PROCESS: text = str(snapped(Performance.get_monitor(monitor) * 1000, 0.1)) + " ms" diff --git a/client/ui/debug/PositionLabel.gd b/client/ui/debug/PositionLabel.gd index 36ab8b9..4467e38 100644 --- a/client/ui/debug/PositionLabel.gd +++ b/client/ui/debug/PositionLabel.gd @@ -1,6 +1,6 @@ extends DebugLabel -func _process(_delta): +func _process(_delta: float): if Global.player == null: return diff --git a/client/ui/debug/StateLabel.gd b/client/ui/debug/StateLabel.gd index e6a0b82..ec629ca 100644 --- a/client/ui/debug/StateLabel.gd +++ b/client/ui/debug/StateLabel.gd @@ -3,7 +3,7 @@ extends DebugLabel var keys := StateComponent.State.keys() var state: StateComponent -func _process(_delta): +func _process(_delta: float): if !Global.player: return diff --git a/client/ui/debug/VelocityLabel.gd b/client/ui/debug/VelocityLabel.gd index eb4822e..4287316 100644 --- a/client/ui/debug/VelocityLabel.gd +++ b/client/ui/debug/VelocityLabel.gd @@ -1,6 +1,6 @@ extends DebugLabel -func _process(_delta): +func _process(_delta: float): if Global.player == null: return diff --git a/client/ui/settings/Settings.gd b/client/ui/settings/Settings.gd index ef799da..4a5872e 100644 --- a/client/ui/settings/Settings.gd +++ b/client/ui/settings/Settings.gd @@ -1,5 +1,5 @@ extends Control -func _unhandled_input(event): +func _unhandled_input(event: InputEvent): if event.is_action_pressed("menu"): visible = !visible \ No newline at end of file diff --git a/client/world/Sun.gd b/client/world/Sun.gd index bc158e0..2e11fb8 100644 --- a/client/world/Sun.gd +++ b/client/world/Sun.gd @@ -1,5 +1,5 @@ @tool extends DirectionalLight3D -# func _process(_delta): +# func _process(_delta: float): # (%PostProcessing as MeshInstance3D).mesh.surface_get_material(0).set_shader_parameter("light_direction", -global_basis.z) diff --git a/client/world/clouds/Cloud.gd b/client/world/clouds/Cloud.gd index 270166a..6b9b4a0 100644 --- a/client/world/clouds/Cloud.gd +++ b/client/world/clouds/Cloud.gd @@ -2,5 +2,5 @@ extends FogVolume var speed: float = 0.1 -func _process(delta): +func _process(delta: float): position.z += speed * delta diff --git a/client/world/grid/WorldGrid.gd b/client/world/grid/WorldGrid.gd index f3fce50..5bb3de6 100644 --- a/client/world/grid/WorldGrid.gd +++ b/client/world/grid/WorldGrid.gd @@ -14,7 +14,7 @@ var old_pos := Vector3i(NAN, NAN, NAN) func _ready(): set_process(visible) -func _process(_delta): +func _process(_delta: float): current_pos = local_to_map(Global.player.position) if current_pos != old_pos: diff --git a/client/world/utils/LookAtCamera.gd b/client/world/utils/LookAtCamera.gd deleted file mode 100644 index a75dbd9..0000000 --- a/client/world/utils/LookAtCamera.gd +++ /dev/null @@ -1,4 +0,0 @@ -extends Node3D - -func _process(_delta): - look_at(Global.camera.global_position, Vector3.UP, true) diff --git a/client/world/utils/RotateY.gd b/client/world/utils/RotateY.gd deleted file mode 100644 index df387a2..0000000 --- a/client/world/utils/RotateY.gd +++ /dev/null @@ -1,6 +0,0 @@ -extends Node3D - -@export var speed: float = 1.0 - -func _process(delta): - rotate_y(speed * delta)