WIP: Some stuff
This commit is contained in:
parent
0daaaac0f9
commit
ac5dbb52fa
BIN
godot/assets/models/maps/lowpoly_map/map.glb.import
(Stored with Git LFS)
Normal file
BIN
godot/assets/models/maps/lowpoly_map/map.glb.import
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
godot/assets/models/maps/lowpoly_tdm_1/map.glb.import
(Stored with Git LFS)
BIN
godot/assets/models/maps/lowpoly_tdm_1/map.glb.import
(Stored with Git LFS)
Binary file not shown.
@ -21,6 +21,7 @@ config/icon="res://icon.svg"
|
||||
consts="*res://src/utils/consts.gd"
|
||||
helpers="*res://src/utils/functions.gd"
|
||||
logger="*res://src/utils/logger.gd"
|
||||
ClientConnectorInstance="*res://src/camera/client_connector/client_connector.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
@ -58,6 +59,16 @@ jump={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
next_camera={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
previous_camera={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
14
godot/src/camera/camera_mount/camera_mount.gd
Normal file
14
godot/src/camera/camera_mount/camera_mount.gd
Normal file
@ -0,0 +1,14 @@
|
||||
class_name CameraMount extends Node3D
|
||||
|
||||
@export var camera_name: String
|
||||
@export var input_camera: bool = false
|
||||
@onready var camera: Camera3D = $Camera3D
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
if camera_name == null:
|
||||
camera_name = str(name)
|
||||
ClientConnectorInstance.register_camera(camera_name, input_camera, camera)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
9
godot/src/camera/camera_mount/camera_mount.tscn
Normal file
9
godot/src/camera/camera_mount/camera_mount.tscn
Normal file
@ -0,0 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bg24niws4pbnj"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/camera/camera_mount/camera_mount.gd" id="1_hso0b"]
|
||||
|
||||
[node name="CameraMount" type="Node3D"]
|
||||
script = ExtResource("1_hso0b")
|
||||
camera_name = "ObservingCamera1"
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
44
godot/src/camera/client_connector/client_connector.gd
Normal file
44
godot/src/camera/client_connector/client_connector.gd
Normal file
@ -0,0 +1,44 @@
|
||||
class_name ClientConnector extends Node
|
||||
|
||||
var available_cameras : Dictionary = {}
|
||||
|
||||
var is_conected_to_camera : bool = false
|
||||
var is_connectied_to_input_camera: bool = false
|
||||
|
||||
var current_index: int = 0
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not is_connectied_to_input_camera:
|
||||
if Input.is_action_just_pressed("next_camera"):
|
||||
switch_camera(1)
|
||||
if Input.is_action_just_pressed("previous_camera"):
|
||||
switch_camera(-1)
|
||||
|
||||
func switch_camera(direction: int):
|
||||
if available_cameras.size() > 0:
|
||||
current_index = (current_index + direction) % available_cameras.size()
|
||||
if current_index < 0:
|
||||
current_index = available_cameras.size() - 1 # Wrap around for negative index
|
||||
var camera_dict: Dictionary = available_cameras.values()[current_index]
|
||||
camera_dict.get("camera").make_current()
|
||||
is_conected_to_camera = true
|
||||
if camera_dict.get("input_camera"):
|
||||
is_connectied_to_input_camera = true
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not is_conected_to_camera:
|
||||
switch_camera(0)
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
func register_camera(camera_name: String, input_camera: bool, camera: Camera3D):
|
||||
available_cameras[camera_name] = {
|
||||
"camera": camera,
|
||||
"input_camera": input_camera,
|
||||
}
|
||||
|
||||
func remove_camera(camera_name: String, ):
|
||||
available_cameras.erase(camera_name)
|
6
godot/src/camera/client_connector/client_connector.tscn
Normal file
6
godot/src/camera/client_connector/client_connector.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dwih53ng38mk5"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/camera/client_connector/client_connector.gd" id="1_htv8i"]
|
||||
|
||||
[node name="ClientConnector" type="Node"]
|
||||
script = ExtResource("1_htv8i")
|
@ -1,6 +1,5 @@
|
||||
class_name EntryPoint extends Node
|
||||
|
||||
|
||||
signal load_level(level: String)
|
||||
|
||||
func _on_load_level():
|
||||
@ -24,10 +23,22 @@ func _ready() -> void:
|
||||
if err != OK:
|
||||
push_error("Couldn't start the game, err: " + str(err))
|
||||
#load_level.connect(_on_load_level)
|
||||
main_menu.start_game.connect(start_server)
|
||||
main_menu.create_server.connect(start_server)
|
||||
main_menu.join_server.connect(join_server)
|
||||
|
||||
func start_server():
|
||||
server.start_server()
|
||||
var err := server.start_server()
|
||||
if err != OK:
|
||||
var warning := AcceptDialog.new()
|
||||
warning.title = "Error"
|
||||
warning.dialog_text = "Couldn't start the sercer, err " + str(err)
|
||||
warning.get_ok_button().text = "Gotcha"
|
||||
warning.visible = true
|
||||
main_menu.add_child(warning)
|
||||
warning.popup_centered()
|
||||
|
||||
func join_server():
|
||||
var err := server.join_server("127.0.0.1", 27015)
|
||||
|
||||
# -- Parse command line arguments
|
||||
func parse_args() -> void:
|
||||
|
@ -4,7 +4,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://dt7rhpcor1wh7" path="res://src/interfaces/main_menu/main_menu.tscn" id="2_dd6gs"]
|
||||
[ext_resource type="PackedScene" uid="uid://dkvbrav2sgs7m" path="res://src/server/server.tscn" id="3_uv83k"]
|
||||
|
||||
[node name="Entrypoint" type="EntryPoint"]
|
||||
[node name="Entrypoint" type="Node"]
|
||||
script = ExtResource("1_ce80t")
|
||||
|
||||
[node name="LevelPlaceholder" type="Node3D" parent="."]
|
||||
@ -13,5 +13,3 @@ editor_description = "This node should be used for storing the map that is curre
|
||||
[node name="MainMenu" parent="." instance=ExtResource("2_dd6gs")]
|
||||
|
||||
[node name="Server" parent="." instance=ExtResource("3_uv83k")]
|
||||
|
||||
[connection signal="start_game" from="MainMenu" to="." method="_on_main_menu_start_game"]
|
||||
|
@ -1,7 +1,12 @@
|
||||
class_name MainMenu extends Control
|
||||
|
||||
signal start_game()
|
||||
signal create_server()
|
||||
signal join_server()
|
||||
|
||||
|
||||
func _on_create_server_pressed() -> void:
|
||||
emit_signal("start_game")
|
||||
emit_signal("create_server")
|
||||
|
||||
|
||||
func _on_join_server_pressed() -> void:
|
||||
emit_signal("join_server")
|
||||
|
@ -60,8 +60,5 @@ text = "Create server"
|
||||
layout_mode = 2
|
||||
text = "Join Server"
|
||||
|
||||
[node name="PlayContaner" type="HBoxContainer" parent="MainContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[connection signal="pressed" from="MainContainer/MainButtonsRow/MainButtons/Create Server" to="." method="_on_create_server_pressed"]
|
||||
[connection signal="pressed" from="MainContainer/MainButtonsRow/MainButtons/Join Server" to="." method="_on_join_server_pressed"]
|
||||
|
11
godot/src/scenes/levels/base/client_space/client_space.gd
Normal file
11
godot/src/scenes/levels/base/client_space/client_space.gd
Normal file
@ -0,0 +1,11 @@
|
||||
class_name ClientSpace extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://84qxu04nc7ue"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/scenes/levels/base/client_space/client_space.gd" id="1_1m0ys"]
|
||||
|
||||
[node name="ClientSpace" type="Node3D"]
|
||||
script = ExtResource("1_1m0ys")
|
35
godot/src/scenes/levels/base/map_controller.gd
Normal file
35
godot/src/scenes/levels/base/map_controller.gd
Normal file
@ -0,0 +1,35 @@
|
||||
class_name MapController extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# -- We need to add the client space to the level
|
||||
var err : Error
|
||||
err = add_client_space()
|
||||
if err != OK:
|
||||
logger.error("can't load the client space")
|
||||
pass # Replace with function body.
|
||||
|
||||
func add_client_space() -> Error :
|
||||
return load_scene("levels/base/client_space/client_space.tscn")
|
||||
|
||||
func load_scene(rel_path: String) -> Error :
|
||||
var path := consts.SCENES_PATH + rel_path
|
||||
logger.info("loading scene from " + path)
|
||||
if not ResourceLoader.exists(path):
|
||||
logger.error("scene " + path + " doesn't exist")
|
||||
return ERR_DOES_NOT_EXIST
|
||||
var scene: PackedScene = ResourceLoader.load(path)
|
||||
if scene.can_instantiate():
|
||||
# -- TODO: May we should case to a real type instead
|
||||
var node: Variant = scene.instantiate()
|
||||
logger.info("loading scene: " + path)
|
||||
add_child(node)
|
||||
else:
|
||||
logger.error("can't initialize")
|
||||
return ERR_CANT_OPEN
|
||||
return OK
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
958
godot/src/scenes/levels/maps/br_lowpoly.tscn
Normal file
958
godot/src/scenes/levels/maps/br_lowpoly.tscn
Normal file
File diff suppressed because one or more lines are too long
@ -3,13 +3,63 @@ class_name Server extends Node
|
||||
# -- TODO: Server must have a list of maps instead of just one
|
||||
# var map_list_file_path: String = ""
|
||||
|
||||
@export var staring_map: String = ""
|
||||
@export var staring_map: String = "br_lowpoly"
|
||||
var current_map_hash: String = ""
|
||||
|
||||
var port: int = 27015
|
||||
var player_limit: int = 10
|
||||
var profile_id: String
|
||||
|
||||
@export var players: Dictionary = {}
|
||||
|
||||
@onready var level_placeholder: Node3D = $LevelPlaceholder
|
||||
|
||||
func _ready() -> void:
|
||||
# -- TODO: Implement the server for this
|
||||
profile_id = "dummy"
|
||||
multiplayer.peer_connected.connect(on_player_connected)
|
||||
multiplayer.connected_to_server.connect(on_connected_to_server)
|
||||
multiplayer.peer_disconnected.connect(on_player_disconnected)
|
||||
|
||||
func on_player_connected(id: int) -> void:
|
||||
if multiplayer.is_server():
|
||||
register_player(id)
|
||||
logger.info("player is connected, id " + str(id))
|
||||
sync_map_from_server.rpc_id(id)
|
||||
|
||||
func on_player_disconnected(id: int) -> void:
|
||||
if multiplayer.is_server():
|
||||
logger.info("player is disconnected, id " + str(id))
|
||||
|
||||
func on_connected_to_server() -> void:
|
||||
logger.info("connected to server")
|
||||
send_profile_id.rpc_id(1, "guest")
|
||||
|
||||
@rpc("any_peer", "reliable", "call_remote")
|
||||
func send_profile_id(profile_id: String) -> void:
|
||||
var id : int
|
||||
if multiplayer.get_remote_sender_id() != 0:
|
||||
id = multiplayer.get_remote_sender_id()
|
||||
else:
|
||||
id = 1
|
||||
players[id]["profile_id"] = profile_id
|
||||
players[id]["username"] = "some_username"
|
||||
players[id]["game_data"] = {
|
||||
"team": consts.TEAM_DEFEND,
|
||||
"is_alive": false,
|
||||
"stats": {
|
||||
"kills": 0,
|
||||
"headshots": 0,
|
||||
"assits": 0,
|
||||
},
|
||||
}
|
||||
logger.info("getting profile from the server: id " + profile_id)
|
||||
logger.warning("not implemented yet")
|
||||
|
||||
@rpc("authority", "reliable", "call_remote")
|
||||
func sync_map_from_server() -> void:
|
||||
load_map()
|
||||
|
||||
func read_config_file(path: String) -> Error :
|
||||
var err : Error
|
||||
var config := ConfigFile.new()
|
||||
@ -21,7 +71,53 @@ func read_config_file(path: String) -> Error :
|
||||
|
||||
return OK
|
||||
|
||||
func load_map() -> Error:
|
||||
var path_tmpl := consts.SCENES_PATH + "levels/maps/%s.tscn"
|
||||
var path := path_tmpl % staring_map
|
||||
logger.info("Loading map from " + path)
|
||||
|
||||
if not ResourceLoader.exists(path):
|
||||
logger.error("map " + staring_map + " doesn't exist")
|
||||
return ERR_DOES_NOT_EXIST
|
||||
var scene: PackedScene = ResourceLoader.load(path)
|
||||
if scene.can_instantiate():
|
||||
var node: MapController = scene.instantiate()
|
||||
for c in level_placeholder.get_children():
|
||||
level_placeholder.remove_child(c)
|
||||
c.queue_free()
|
||||
level_placeholder.add_child(node)
|
||||
else:
|
||||
logger.error("Can't initialize")
|
||||
return ERR_CANT_OPEN
|
||||
return OK
|
||||
|
||||
func start_server() -> Error :
|
||||
print("Starting")
|
||||
var peer := ENetMultiplayerPeer.new()
|
||||
logger.info("starting a server the port: " + str(port))
|
||||
var err := peer.create_server(port, player_limit)
|
||||
if err:
|
||||
return err
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
if not OS.has_feature("dedicated_server"):
|
||||
register_player(1)
|
||||
send_profile_id(profile_id)
|
||||
# -- Loading map into the placeholder
|
||||
err = load_map()
|
||||
if err != OK:
|
||||
return err
|
||||
# -- Load the desired map to the LevelPlaceholder node
|
||||
return OK
|
||||
|
||||
func join_server(ip: String, port: int) -> Error:
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
logger.info("trying to connect to: " + ip + ":" + str(port))
|
||||
var err = peer.create_client(ip, port)
|
||||
if err != OK:
|
||||
return err
|
||||
multiplayer.multiplayer_peer = peer
|
||||
return OK
|
||||
|
||||
func register_player(id: int) -> void :
|
||||
logger.info("Registering a player: " + str(id))
|
||||
players[id] = {}
|
||||
|
@ -1,6 +1,19 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dkvbrav2sgs7m"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dkvbrav2sgs7m"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/server/server.gd" id="1_53ixn"]
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_mmx2d"]
|
||||
properties/0/path = NodePath(".:staring_map")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath(".:players")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 2
|
||||
|
||||
[node name="Server" type="Node"]
|
||||
script = ExtResource("1_53ixn")
|
||||
|
||||
[node name="LevelPlaceholder" type="Node3D" parent="."]
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_mmx2d")
|
||||
|
@ -2,3 +2,9 @@ extends Node
|
||||
|
||||
const DEFAULT_JUMP_VELOCITY: float = 5
|
||||
const DEFAULT_CHARACTER_SPEED: float = 7.0
|
||||
|
||||
const SCENES_PATH: String = "res://src/scenes/"
|
||||
|
||||
const TEAM_UNDEFINED = "undefined"
|
||||
const TEAM_ATTACK = "attack"
|
||||
const TEAM_DEFEND = "defent"
|
||||
|
Loading…
Reference in New Issue
Block a user