Improved main scene code
This commit is contained in:
parent
19d81aed63
commit
6f49400770
@ -4,6 +4,7 @@ var camera: Camera3D
|
|||||||
var player: Player
|
var player: Player
|
||||||
var players: PlayerManager
|
var players: PlayerManager
|
||||||
var account_id: String
|
var account_id: String
|
||||||
|
var auth_token: String
|
||||||
var interacting_with_ui: bool
|
var interacting_with_ui: bool
|
||||||
var instance_id := OS.get_process_id() % 4
|
var instance_id: int
|
||||||
var username := "user%d" % instance_id
|
var username: String
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Capture mouse
|
Global.instance_id = OS.get_process_id() % 4
|
||||||
#Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
Global.username = "user%d" % Global.instance_id
|
||||||
|
|
||||||
# Mute audio
|
%Login.success.connect(on_login)
|
||||||
var master_sound = AudioServer.get_bus_index("Master")
|
%Login.send_login()
|
||||||
AudioServer.set_bus_mute(master_sound, true)
|
|
||||||
|
mute_audio()
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event.is_action_pressed("toggle_fullscreen"):
|
if event.is_action_pressed("toggle_fullscreen"):
|
||||||
toggle_fullscreen()
|
toggle_fullscreen()
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
|
func mute_audio():
|
||||||
|
var master_sound = AudioServer.get_bus_index("Master")
|
||||||
|
AudioServer.set_bus_mute(master_sound, true)
|
||||||
|
|
||||||
|
func on_login():
|
||||||
|
DisplayServer.window_set_title("%s - %s" % [Global.username, Global.account_id])
|
||||||
|
DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
|
||||||
|
|
||||||
func toggle_fullscreen():
|
func toggle_fullscreen():
|
||||||
var mode = DisplayServer.window_get_mode()
|
var mode = DisplayServer.window_get_mode()
|
||||||
@ -19,6 +29,4 @@ func toggle_fullscreen():
|
|||||||
DisplayServer.WINDOW_MODE_FULLSCREEN:
|
DisplayServer.WINDOW_MODE_FULLSCREEN:
|
||||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
||||||
_:
|
_:
|
||||||
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||||
|
|
||||||
return
|
|
@ -1,24 +1,24 @@
|
|||||||
[gd_scene load_steps=24 format=3 uid="uid://b40y7iuskv1ar"]
|
[gd_scene load_steps=24 format=3 uid="uid://b40y7iuskv1ar"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Game.gd" id="1_uxop2"]
|
[ext_resource type="Script" path="res://Main.gd" id="1_cw3ws"]
|
||||||
[ext_resource type="Script" path="res://network/Client.gd" id="2_00qe8"]
|
[ext_resource type="Script" path="res://network/Client.gd" id="2_8hxcx"]
|
||||||
[ext_resource type="Script" path="res://network/Ping.gd" id="3_fd082"]
|
[ext_resource type="Script" path="res://network/Ping.gd" id="3_d6qf1"]
|
||||||
[ext_resource type="Script" path="res://network/Login.gd" id="4_0illd"]
|
[ext_resource type="Script" path="res://network/Login.gd" id="4_fsx7a"]
|
||||||
[ext_resource type="Script" path="res://network/PlayerAdd.gd" id="5_sd8xh"]
|
[ext_resource type="Script" path="res://network/PlayerAdd.gd" id="5_376ik"]
|
||||||
[ext_resource type="PackedScene" uid="uid://2lcnu3dy54lx" path="res://player/Player.tscn" id="6_jxdko"]
|
[ext_resource type="PackedScene" uid="uid://2lcnu3dy54lx" path="res://player/Player.tscn" id="6_cdj8w"]
|
||||||
[ext_resource type="Script" path="res://network/PlayerMove.gd" id="7_6xfox"]
|
[ext_resource type="Script" path="res://network/PlayerRemove.gd" id="7_2r42o"]
|
||||||
[ext_resource type="Script" path="res://network/PlayerRemove.gd" id="7_ubce6"]
|
[ext_resource type="Script" path="res://network/PlayerMove.gd" id="8_ke1yy"]
|
||||||
[ext_resource type="Script" path="res://world/Sun.gd" id="8_leyo3"]
|
[ext_resource type="Script" path="res://network/PlayerJump.gd" id="9_o8sk8"]
|
||||||
[ext_resource type="Script" path="res://network/PlayerJump.gd" id="8_p6kmr"]
|
[ext_resource type="Script" path="res://network/Chat.gd" id="10_y3len"]
|
||||||
[ext_resource type="Environment" uid="uid://dixa0yso2s1u3" path="res://world/Environment.tres" id="9_4u3r5"]
|
[ext_resource type="Script" path="res://world/Sun.gd" id="11_4jb08"]
|
||||||
[ext_resource type="CameraAttributesPractical" uid="uid://b835orxyqq6w5" path="res://camera/CameraAttributes.tres" id="10_4uslp"]
|
[ext_resource type="Environment" uid="uid://dixa0yso2s1u3" path="res://world/Environment.tres" id="12_cscto"]
|
||||||
[ext_resource type="Script" path="res://network/Chat.gd" id="10_27gvi"]
|
[ext_resource type="CameraAttributesPractical" uid="uid://b835orxyqq6w5" path="res://camera/CameraAttributes.tres" id="13_pvug4"]
|
||||||
[ext_resource type="PackedScene" uid="uid://hnn0n1xc2qt7" path="res://world/Tree.blend" id="12_x8kho"]
|
[ext_resource type="PackedScene" uid="uid://hnn0n1xc2qt7" path="res://world/Tree.blend" id="14_7jtdl"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cb2t7bvvf3gwh" path="res://enemy/slime/Slime.tscn" id="13_hdbbd"]
|
[ext_resource type="PackedScene" uid="uid://cb2t7bvvf3gwh" path="res://enemy/slime/Slime.tscn" id="15_hgl78"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dagn5bf7ou3sd" path="res://ui/UI.tscn" id="14_ofk4r"]
|
[ext_resource type="Script" path="res://world/PlayerManager.gd" id="16_dp6bj"]
|
||||||
[ext_resource type="Script" path="res://camera/Camera.gd" id="15_ym3qc"]
|
[ext_resource type="PackedScene" uid="uid://dagn5bf7ou3sd" path="res://ui/UI.tscn" id="17_43qhq"]
|
||||||
[ext_resource type="Script" path="res://world/PlayerManager.gd" id="16_sjldq"]
|
[ext_resource type="Script" path="res://camera/Camera.gd" id="18_wogcj"]
|
||||||
[ext_resource type="Material" uid="uid://ddy5gkw0k16dq" path="res://shader/OutlineMaterial.tres" id="16_srvfy"]
|
[ext_resource type="Material" uid="uid://ddy5gkw0k16dq" path="res://shader/OutlineMaterial.tres" id="19_d2i56"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_lp0k7"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_lp0k7"]
|
||||||
albedo_color = Color(0, 0, 0, 1)
|
albedo_color = Color(0, 0, 0, 1)
|
||||||
@ -31,20 +31,20 @@ size = Vector3(100, 1, 100)
|
|||||||
size = Vector3(100, 1, 100)
|
size = Vector3(100, 1, 100)
|
||||||
|
|
||||||
[sub_resource type="QuadMesh" id="QuadMesh_7yiqd"]
|
[sub_resource type="QuadMesh" id="QuadMesh_7yiqd"]
|
||||||
material = ExtResource("16_srvfy")
|
material = ExtResource("19_d2i56")
|
||||||
flip_faces = true
|
flip_faces = true
|
||||||
size = Vector2(2, 2)
|
size = Vector2(2, 2)
|
||||||
|
|
||||||
[node name="Main" type="Node"]
|
[node name="Main" type="Node"]
|
||||||
script = ExtResource("1_uxop2")
|
script = ExtResource("1_cw3ws")
|
||||||
|
|
||||||
[node name="Client" type="Node" parent="."]
|
[node name="Client" type="Node" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("2_00qe8")
|
script = ExtResource("2_8hxcx")
|
||||||
|
|
||||||
[node name="Ping" type="Node" parent="Client"]
|
[node name="Ping" type="Node" parent="Client"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("3_fd082")
|
script = ExtResource("3_d6qf1")
|
||||||
packet_type = 1
|
packet_type = 1
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="Client/Ping"]
|
[node name="Timer" type="Timer" parent="Client/Ping"]
|
||||||
@ -52,7 +52,7 @@ autostart = true
|
|||||||
|
|
||||||
[node name="Login" type="Node" parent="Client"]
|
[node name="Login" type="Node" parent="Client"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("4_0illd")
|
script = ExtResource("4_fsx7a")
|
||||||
packet_type = 2
|
packet_type = 2
|
||||||
|
|
||||||
[node name="Timer" type="Timer" parent="Client/Login"]
|
[node name="Timer" type="Timer" parent="Client/Login"]
|
||||||
@ -61,26 +61,26 @@ autostart = true
|
|||||||
|
|
||||||
[node name="PlayerAdd" type="Node" parent="Client"]
|
[node name="PlayerAdd" type="Node" parent="Client"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("5_sd8xh")
|
script = ExtResource("5_376ik")
|
||||||
player_scene = ExtResource("6_jxdko")
|
player_scene = ExtResource("6_cdj8w")
|
||||||
packet_type = 10
|
packet_type = 10
|
||||||
|
|
||||||
[node name="PlayerRemove" type="Node" parent="Client"]
|
[node name="PlayerRemove" type="Node" parent="Client"]
|
||||||
script = ExtResource("7_ubce6")
|
script = ExtResource("7_2r42o")
|
||||||
packet_type = 11
|
packet_type = 11
|
||||||
|
|
||||||
[node name="PlayerMove" type="Node" parent="Client"]
|
[node name="PlayerMove" type="Node" parent="Client"]
|
||||||
script = ExtResource("7_6xfox")
|
script = ExtResource("8_ke1yy")
|
||||||
delay = null
|
delay = null
|
||||||
packet_type = 12
|
packet_type = 12
|
||||||
|
|
||||||
[node name="PlayerJump" type="Node" parent="Client"]
|
[node name="PlayerJump" type="Node" parent="Client"]
|
||||||
script = ExtResource("8_p6kmr")
|
script = ExtResource("9_o8sk8")
|
||||||
packet_type = 13
|
packet_type = 13
|
||||||
|
|
||||||
[node name="Chat" type="Node" parent="Client"]
|
[node name="Chat" type="Node" parent="Client"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("10_27gvi")
|
script = ExtResource("10_y3len")
|
||||||
packet_type = 20
|
packet_type = 20
|
||||||
|
|
||||||
[node name="Statistics" type="Timer" parent="Client"]
|
[node name="Statistics" type="Timer" parent="Client"]
|
||||||
@ -92,29 +92,29 @@ autostart = true
|
|||||||
transform = Transform3D(0.984808, 0.122788, -0.122788, 0, 0.707107, 0.707107, 0.173648, -0.696364, 0.696364, 0, 10, 0)
|
transform = Transform3D(0.984808, 0.122788, -0.122788, 0, 0.707107, 0.707107, 0.173648, -0.696364, 0.696364, 0, 10, 0)
|
||||||
shadow_enabled = true
|
shadow_enabled = true
|
||||||
directional_shadow_mode = 0
|
directional_shadow_mode = 0
|
||||||
script = ExtResource("8_leyo3")
|
script = ExtResource("11_4jb08")
|
||||||
|
|
||||||
[node name="Environment" type="WorldEnvironment" parent="World"]
|
[node name="Environment" type="WorldEnvironment" parent="World"]
|
||||||
environment = ExtResource("9_4u3r5")
|
environment = ExtResource("12_cscto")
|
||||||
camera_attributes = ExtResource("10_4uslp")
|
camera_attributes = ExtResource("13_pvug4")
|
||||||
|
|
||||||
[node name="Trees" type="Node3D" parent="World"]
|
[node name="Trees" type="Node3D" parent="World"]
|
||||||
|
|
||||||
[node name="Tree" parent="World/Trees" instance=ExtResource("12_x8kho")]
|
[node name="Tree" parent="World/Trees" instance=ExtResource("14_7jtdl")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.11323, 0, -7.57074)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.11323, 0, -7.57074)
|
||||||
|
|
||||||
[node name="Tree2" parent="World/Trees" instance=ExtResource("12_x8kho")]
|
[node name="Tree2" parent="World/Trees" instance=ExtResource("14_7jtdl")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.11323, 0, 7.80548)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.11323, 0, 7.80548)
|
||||||
|
|
||||||
[node name="Enemies" type="Node3D" parent="World"]
|
[node name="Enemies" type="Node3D" parent="World"]
|
||||||
|
|
||||||
[node name="Slime" parent="World/Enemies" instance=ExtResource("13_hdbbd")]
|
[node name="Slime" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -3.79687)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -3.79687)
|
||||||
|
|
||||||
[node name="Slime2" parent="World/Enemies" instance=ExtResource("13_hdbbd")]
|
[node name="Slime2" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.00829, 1.28057, -1.95247)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.00829, 1.28057, -1.95247)
|
||||||
|
|
||||||
[node name="Slime3" parent="World/Enemies" instance=ExtResource("13_hdbbd")]
|
[node name="Slime3" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -0.306177)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -0.306177)
|
||||||
|
|
||||||
[node name="Floor" type="MeshInstance3D" parent="World"]
|
[node name="Floor" type="MeshInstance3D" parent="World"]
|
||||||
@ -128,9 +128,9 @@ shape = SubResource("BoxShape3D_yg2lt")
|
|||||||
|
|
||||||
[node name="Players" type="Node3D" parent="."]
|
[node name="Players" type="Node3D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("16_sjldq")
|
script = ExtResource("16_dp6bj")
|
||||||
|
|
||||||
[node name="UI" parent="." instance=ExtResource("14_ofk4r")]
|
[node name="UI" parent="." instance=ExtResource("17_43qhq")]
|
||||||
|
|
||||||
[node name="Viewport" type="SubViewportContainer" parent="."]
|
[node name="Viewport" type="SubViewportContainer" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
@ -155,7 +155,7 @@ current = true
|
|||||||
fov = 90.0
|
fov = 90.0
|
||||||
size = 10.0
|
size = 10.0
|
||||||
far = 100.0
|
far = 100.0
|
||||||
script = ExtResource("15_ym3qc")
|
script = ExtResource("18_wogcj")
|
||||||
center = NodePath("..")
|
center = NodePath("..")
|
||||||
follow_speed = 5.0
|
follow_speed = 5.0
|
||||||
|
|
@ -1,29 +1,26 @@
|
|||||||
extends PacketHandler
|
extends PacketHandler
|
||||||
|
|
||||||
var auth_token: String
|
signal success
|
||||||
|
signal failure
|
||||||
func _ready():
|
|
||||||
DisplayServer.window_set_title(Global.username)
|
|
||||||
send_login()
|
|
||||||
|
|
||||||
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
|
func handle_packet(data: PackedByteArray, _peer: PacketPeer):
|
||||||
var buffer := StreamPeerBuffer.new()
|
var buffer := StreamPeerBuffer.new()
|
||||||
buffer.data_array = data
|
buffer.data_array = data
|
||||||
|
|
||||||
var error := buffer.get_8()
|
var error := buffer.get_8()
|
||||||
if error != 0:
|
if error != 0:
|
||||||
print("[%s] Login failed." % Global.username)
|
print("[%s] Login failed." % Global.username)
|
||||||
|
failure.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
Global.account_id = buffer.get_string()
|
Global.account_id = buffer.get_string()
|
||||||
auth_token = buffer.get_string()
|
Global.auth_token = buffer.get_string()
|
||||||
|
|
||||||
print("[%s] Login succeeded." % Global.username)
|
print("[%s] Login succeeded." % Global.username)
|
||||||
print("[%s] ID: %s" % [Global.username, Global.account_id])
|
print("[%s] ID: %s" % [Global.username, Global.account_id])
|
||||||
print("[%s] Auth token: %s" % [Global.username, auth_token])
|
print("[%s] Auth token: %s" % [Global.username, Global.auth_token])
|
||||||
|
|
||||||
DisplayServer.window_set_title("%s - %s" % [Global.username, Global.account_id])
|
success.emit()
|
||||||
DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
|
|
||||||
|
|
||||||
func send_login():
|
func send_login():
|
||||||
if is_logged_in():
|
if is_logged_in():
|
||||||
@ -37,4 +34,4 @@ func send_login():
|
|||||||
print("[%s] Connecting..." % Global.username)
|
print("[%s] Connecting..." % Global.username)
|
||||||
|
|
||||||
func is_logged_in() -> bool:
|
func is_logged_in() -> bool:
|
||||||
return auth_token != ""
|
return Global.auth_token != ""
|
@ -21,10 +21,7 @@ func send_ping():
|
|||||||
buffer.put_8(count)
|
buffer.put_8(count)
|
||||||
%Client.send(buffer.data_array)
|
%Client.send(buffer.data_array)
|
||||||
history[count] = get_time()
|
history[count] = get_time()
|
||||||
count += 1
|
count = (count + 1) % HISTORY_SIZE
|
||||||
|
|
||||||
if count >= HISTORY_SIZE:
|
|
||||||
count = 0
|
|
||||||
|
|
||||||
func get_time() -> float:
|
func get_time() -> float:
|
||||||
return Time.get_unix_time_from_system()
|
return Time.get_unix_time_from_system()
|
||||||
|
@ -11,7 +11,7 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Client"
|
config/name="Client"
|
||||||
run/main_scene="res://world/Main.tscn"
|
run/main_scene="res://Main.tscn"
|
||||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||||
config/icon="res://ui/icon.svg"
|
config/icon="res://ui/icon.svg"
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ func _unhandled_input(event):
|
|||||||
|
|
||||||
if event.is_action_pressed("open_chat"):
|
if event.is_action_pressed("open_chat"):
|
||||||
call_deferred("grab_focus")
|
call_deferred("grab_focus")
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
func _on_focus_entered():
|
func _on_focus_entered():
|
||||||
Global.interacting_with_ui = true
|
Global.interacting_with_ui = true
|
||||||
|
Loading…
Reference in New Issue
Block a user