Add a map-loader sctipt

This commit is contained in:
2025-01-28 19:32:38 +01:00
parent b54ffaeb0d
commit 9b1ab02b94
32 changed files with 16268 additions and 2790 deletions

View File

@ -43,6 +43,13 @@ offset_right = 497.0
offset_bottom = 220.0
text = "192.168.0.28"
[node name="Maps" type="ItemList" parent="."]
layout_mode = 0
offset_left = 995.0
offset_top = 111.0
offset_right = 1595.0
offset_bottom = 624.0
[connection signal="player_connected" from="." to="." method="_on_player_connected"]
[connection signal="player_disconnected" from="." to="." method="_on_player_disconnected"]
[connection signal="server_disconnected" from="." to="." method="_on_server_disconnected"]

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bo8jemggniu3c"]
[ext_resource type="PackedScene" uid="uid://c1v6kb00y77ij" path="res://scenes/maps/el_test.tscn" id="1_25xw6"]
[ext_resource type="PackedScene" uid="uid://c1v6kb00y77ij" path="res://scenes/maps/maps/el_test.tscn" id="1_25xw6"]
[node name="ChooseTeam" type="Node3D"]

View File

@ -23,6 +23,14 @@ func _ready() -> void:
multiplayer.connected_to_server.connect(_on_connected_ok)
multiplayer.connection_failed.connect(_on_connected_fail)
multiplayer.server_disconnected.connect(_on_server_disconnected)
var map_dir := DirAccess.open("res://scenes/maps/maps/")
if map_dir:
map_dir.list_dir_begin()
var file_name = map_dir.get_next()
while file_name != "":
$Maps.add_item(file_name)
file_name = map_dir.get_next()
func join_game(address = ""):
address = address_input.text
@ -50,7 +58,12 @@ func remove_multiplayer_peer():
# do Lobby.load_game.rpc(filepath)
@rpc("call_local", "reliable")
func load_game():
get_tree().change_scene_to_file("res://scenes/maps/el_test.tscn")
var chosen_map_index = $Maps.get_selected_items()[0]
var chosen_map = $Maps.get_item_text(chosen_map_index)
print(chosen_map)
var path_tmpl := "res://scenes/maps/maps/%s"
var path := path_tmpl % chosen_map
get_tree().change_scene_to_file(path)
# Every peer will call this when they have loaded the game scene.
@rpc("any_peer", "call_local", "reliable")