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

@ -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")