Cleanup
This commit is contained in:
parent
ba37eca0c9
commit
bfec08ff02
@ -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)
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -9,7 +9,7 @@ func _init():
|
||||
func _ready():
|
||||
enemy = owner
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float):
|
||||
if !Global.player:
|
||||
return
|
||||
|
||||
|
@ -20,7 +20,7 @@ func _ready():
|
||||
attractor = %Attractor
|
||||
sound = %Sound
|
||||
|
||||
func _process(delta):
|
||||
func _process(delta: float):
|
||||
if !collected_by:
|
||||
return
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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()
|
@ -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 != ""
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
@ -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)
|
||||
name_changed.emit(new_name)
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
5
client/static/Audio.gd
Normal file
5
client/static/Audio.gd
Normal file
@ -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)
|
4
client/static/Log.gd
Normal file
4
client/static/Log.gd
Normal file
@ -0,0 +1,4 @@
|
||||
class_name Log
|
||||
|
||||
static func info(message: String):
|
||||
print_rich("[color=#808080][%s][/color] %s" % [Global.account.name, message])
|
13
client/static/WindowManager.gd
Normal file
13
client/static/WindowManager.gd
Normal file
@ -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
|
@ -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()
|
||||
|
@ -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):
|
||||
|
@ -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":
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
extends DebugLabel
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float):
|
||||
text = str(Engine.get_frames_per_second())
|
||||
|
@ -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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
extends DebugLabel
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float):
|
||||
if Global.player == null:
|
||||
return
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
extends DebugLabel
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta: float):
|
||||
if Global.player == null:
|
||||
return
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
extends Control
|
||||
|
||||
func _unhandled_input(event):
|
||||
func _unhandled_input(event: InputEvent):
|
||||
if event.is_action_pressed("menu"):
|
||||
visible = !visible
|
@ -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)
|
||||
|
@ -2,5 +2,5 @@ extends FogVolume
|
||||
|
||||
var speed: float = 0.1
|
||||
|
||||
func _process(delta):
|
||||
func _process(delta: float):
|
||||
position.z += speed * delta
|
||||
|
@ -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:
|
||||
|
@ -1,4 +0,0 @@
|
||||
extends Node3D
|
||||
|
||||
func _process(_delta):
|
||||
look_at(Global.camera.global_position, Vector3.UP, true)
|
@ -1,6 +0,0 @@
|
||||
extends Node3D
|
||||
|
||||
@export var speed: float = 1.0
|
||||
|
||||
func _process(delta):
|
||||
rotate_y(speed * delta)
|
Loading…
Reference in New Issue
Block a user