diff --git a/Maps/BaseLevel.gd b/Maps/BaseLevel.gd index 789c524..e68c00d 100644 --- a/Maps/BaseLevel.gd +++ b/Maps/BaseLevel.gd @@ -40,7 +40,6 @@ var unit_data_dict = { var spawned_units_ids = Array() func _ready(): - MusicMan.music_player.stop() if capture_mod: diff --git a/Maps/Dust/Zm_Dust.tscn b/Maps/Dust/Zm_Dust.tscn index 4f24c8c..2a919cf 100644 --- a/Maps/Dust/Zm_Dust.tscn +++ b/Maps/Dust/Zm_Dust.tscn @@ -140,9 +140,7 @@ texture = ExtResource( 11 ) position = Vector2( 1913.09, 2003.24 ) texture = ExtResource( 9 ) -[node name="zspawn" type="Node" parent="." groups=[ -"ZspawnPoints", -]] +[node name="zspawn" type="Node" parent="."] [node name="zombieSpawner2" parent="zspawn" instance=ExtResource( 4 )] position = Vector2( 181.779, 1511.38 ) diff --git a/Maps/fy_dust/zm_fy_dust.tscn b/Maps/fy_dust/zm_fy_dust.tscn index 80389a7..dd89014 100644 --- a/Maps/fy_dust/zm_fy_dust.tscn +++ b/Maps/fy_dust/zm_fy_dust.tscn @@ -26,9 +26,7 @@ team_id = 1 position = Vector2( 1818.42, 1062.98 ) team_id = 1 -[node name="zspawn" type="Node" parent="." groups=[ -"ZspawnPoints", -]] +[node name="zspawn" type="Node" parent="."] [node name="zombieSpawner" parent="zspawn" instance=ExtResource( 4 )] position = Vector2( 184.084, 166.124 ) diff --git a/Menus/Editor/EditorMapSelector.gd b/Menus/Editor/EditorMapSelector.gd index 29b66aa..6fee434 100644 --- a/Menus/Editor/EditorMapSelector.gd +++ b/Menus/Editor/EditorMapSelector.gd @@ -35,6 +35,7 @@ func getMapNames(): dir.make_dir("user://" + map_dir_name + "/gameModes/TDM") dir.make_dir("user://" + map_dir_name + "/gameModes/Zombie") dir.make_dir("user://" + map_dir_name + "/minimaps") + dir.make_dir("user://" + map_dir_name + "/levels") dir.open("user://" + map_dir_name + "/maps") dir.list_dir_begin() diff --git a/Menus/Editor/GameModesMenu.gd b/Menus/Editor/GameModesMenu.gd index e3df309..6ffd905 100644 --- a/Menus/Editor/GameModesMenu.gd +++ b/Menus/Editor/GameModesMenu.gd @@ -9,7 +9,8 @@ func _on_TDM_pressed(): func _on_ZOMBIE_pressed(): - pass # Replace with function body. + MusicMan.click() + MenuManager.changeScene("EMS/LEM/GMM/ZM") func _on_back_pressed(): diff --git a/Menus/Editor/GameModesMenu.tscn b/Menus/Editor/GameModesMenu.tscn index 31f61b3..62b8a3a 100644 --- a/Menus/Editor/GameModesMenu.tscn +++ b/Menus/Editor/GameModesMenu.tscn @@ -46,7 +46,7 @@ __meta__ = { } [node name="TDM" type="Button" parent="PanelContainer/Panel/VBoxContainer"] -margin_right = 560.0 +margin_right = 559.0 margin_bottom = 50.0 rect_min_size = Vector2( 0, 50 ) custom_fonts/font = ExtResource( 1 ) @@ -54,7 +54,7 @@ text = "TDM" [node name="ZOMBIE" type="Button" parent="PanelContainer/Panel/VBoxContainer"] margin_top = 100.0 -margin_right = 560.0 +margin_right = 559.0 margin_bottom = 160.0 rect_min_size = Vector2( 0, 60 ) custom_fonts/font = ExtResource( 1 ) diff --git a/Menus/Editor/LevelEditorMenu.gd b/Menus/Editor/LevelEditorMenu.gd index 2bef6e6..c2c534b 100644 --- a/Menus/Editor/LevelEditorMenu.gd +++ b/Menus/Editor/LevelEditorMenu.gd @@ -28,10 +28,9 @@ func _on_back_pressed(): func _on_convert_pressed(): var levelInfo = { name = "Dust II", - minimap = "", + icon = "", game_modes = [ - {bombing = "" }, - {FFA = ""} + ], desc = "", debug = false @@ -47,13 +46,82 @@ func _on_convert_pressed(): base_map = load(file_name).instance() base_map.name = "BaseMap" base_map.force_update = false - + else: + base_map.queue_free() + Logger.notice.showNotice(self, "Failed", + "Map not Found. Create Map by pressing MAP EDITOR.", Color.red) + return + # TDM file_name = "user://custom_maps/gameModes/TDM/" + map_name + ".tscn" if file.file_exists(file_name): + var final_level = Node.new() + var level_node = Node2D.new() + level_node.add_to_group("Level", true) + level_node.set_script(load("res://Maps/BaseLevel.gd")) + final_level.add_child(level_node) + level_node.owner = final_level + level_node.add_child(base_map) + base_map.owner = final_level game_modes[0] = load(file_name).instance() - + final_level.add_child(game_modes[0]) + game_modes[0].owner = final_level + # Save scene + var packed_scene = PackedScene.new() + var result = packed_scene.pack(final_level) + var save_path = "user://custom_maps/levels/TDM_" + game_server.serverInfo.map + ".tscn" + if result == OK: + ResourceSaver.save(save_path, packed_scene) + # Free resources + level_node.remove_child(base_map) + final_level.remove_child(game_modes[0]) + final_level.queue_free() + # Zombie Mod file_name = "user://custom_maps/gameModes/Zombie/" + map_name + ".tscn" if file.file_exists(file_name): + var final_level = Node.new() + var level_node = Node2D.new() + level_node.set_script(load("res://Maps/BaseLevel.gd")) + level_node.add_to_group("Level", true) + final_level.add_child(level_node) + level_node.owner = final_level + level_node.add_child(base_map) + base_map.owner = final_level game_modes[1] = load(file_name).instance() + final_level.add_child(game_modes[1]) + game_modes[1].owner = final_level + # Save scene + var packed_scene = PackedScene.new() + var result = packed_scene.pack(final_level) + var save_path = "user://custom_maps/levels/ZM_" + game_server.serverInfo.map + ".tscn" + if result == OK: + ResourceSaver.save(save_path, packed_scene) + # Free resources + level_node.remove_child(base_map) + final_level.remove_child(game_modes[1]) + final_level.queue_free() + + # Write config + levelInfo.name = game_server.serverInfo.map + levelInfo.icon= "user://custom_maps/minimaps/" + game_server.serverInfo.map + ".png" + + var counter = false + + if game_modes[0]: + levelInfo.game_modes.append("TDM") + levelInfo.game_modes.append("user://custom_maps/levels/TDM_" + game_server.serverInfo.map + ".tscn") + game_modes[0].queue_free() + counter = true + + if game_modes[1]: + levelInfo.game_modes.append("Zombie Mod") + levelInfo.game_modes.append("user://custom_maps/levels/ZM_" + game_server.serverInfo.map + ".tscn") + game_modes[1].queue_free() + counter = true - var level_node = Node2D.new() + base_map.queue_free() + if (not counter): + Logger.notice.showNotice(self, "Failed", + "Game Mode not found. Create a Game Mode by pressing GAME MODE EDITOR.", Color.red) + return + var save_path = "user://custom_maps/" + game_server.serverInfo.map + ".dat" + game_states.save_data(save_path, levelInfo, false) diff --git a/Menus/Editor/TDMspawnEditor.gd b/Menus/Editor/TDMspawnEditor.gd index b9d8777..75e87e6 100644 --- a/Menus/Editor/TDMspawnEditor.gd +++ b/Menus/Editor/TDMspawnEditor.gd @@ -95,6 +95,9 @@ func saveSpawnPoints() -> bool: point.owner = spawn_parent if teams[0] == 0 or teams[1] == 0: + var spawns = $spawns.get_children() + for i in spawns: + i.queue_free() return false remove_child(spawn_parent) @@ -114,7 +117,7 @@ func _on_back_pressed(): if saveSpawnPoints(): MenuManager.changeScene("EMS/LEM/GameModesMenu") else: - Logger.notice($uiLayer, "Error", "Add atleast 1 spawn point for each team.", Color.red) + Logger.notice.showNotice($uiLayer, "Error", "Add atleast 1 spawn point for each team.", Color.red) func _on_spawn_delete_pressed(): diff --git a/Menus/Editor/ZMspawnEditor.gd b/Menus/Editor/ZMspawnEditor.gd new file mode 100644 index 0000000..23dabac --- /dev/null +++ b/Menus/Editor/ZMspawnEditor.gd @@ -0,0 +1,44 @@ +extends "res://Menus/Editor/TDMspawnEditor.gd" + +var zspawn = preload("res://Objects/Game_modes/ZombieMod/zombieSpawner.tscn") + +func saveSpawnPoints() -> bool: + var spawn_parent = $spawns + var points = $editorSpawns.get_children() + + if points.size() == 0: + return false + + var teams = [0,0] + + for i in points: + if i .team_id == 0: + var point = zspawn.instance() + point.position = i.position + teams[i.team_id] += 1 + spawn_parent.add_child(point) + point.owner = spawn_parent + else: + var point = spawn_point.instance() + point.position = i.position + point.team_id = i.team_id + teams[i.team_id] += 1 + spawn_parent.add_child(point) + point.owner = spawn_parent + + if teams[0] == 0 or teams[1] == 0: + var spawns = $spawns.get_children() + for i in spawns: + i.queue_free() + return false + + remove_child(spawn_parent) + var packed_scene = PackedScene.new() + var result = packed_scene.pack(spawn_parent) + var save_path = "user://custom_maps/gameModes/" + gameMode + "/" + game_server.serverInfo.map + ".tscn" + if result == OK: + ResourceSaver.save(save_path, packed_scene) + else: + push_error("An error occurred while saving the scene to disk.") + spawn_parent.queue_free() + return true diff --git a/Menus/Editor/ZMspawnEditor.tscn b/Menus/Editor/ZMspawnEditor.tscn new file mode 100644 index 0000000..e63d945 --- /dev/null +++ b/Menus/Editor/ZMspawnEditor.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Menus/Editor/TDMspawnEditor.tscn" type="PackedScene" id=1] +[ext_resource path="res://Menus/Editor/ZMspawnEditor.gd" type="Script" id=2] +[ext_resource path="res://Menus/Editor/CT_icon.png" type="Texture" id=3] +[ext_resource path="res://Menus/Editor/T_icon.png" type="Texture" id=4] + +[node name="ZMspawnEditor" instance=ExtResource( 1 )] +script = ExtResource( 2 ) +gameMode = "Zombie" + +[node name="ItemList" parent="uiLayer" index="0"] +items = [ "Zombie", ExtResource( 4 ), false, "Counter Terrorist", ExtResource( 3 ), false ] diff --git a/Menus/Lobby/Lobby.gd b/Menus/Lobby/Lobby.gd index 50c1a79..7763eea 100644 --- a/Menus/Lobby/Lobby.gd +++ b/Menus/Lobby/Lobby.gd @@ -15,6 +15,7 @@ func _ready(): game_server.bot_settings.bot_count = 0 game_server.bot_settings.bot_difficulty = 1 loadLevelInfos() + loadCustomMaps() network.connect("player_removed", self, "_on_player_removed") #show IP address for i in IP.get_local_addresses(): @@ -42,7 +43,25 @@ func loadLevelInfos(): Logger.LogError("loadLevelInfos", "Failed to load levels") func loadCustomMaps(): - pass + var dir = Directory.new() + dir.open("user://custom_maps/") + dir.list_dir_begin() + var file_name : String= dir.get_next() + + while file_name != "": + if not dir.current_is_dir(): + if file_name.get_extension() == "dat": + var data = game_states.load_data("user://custom_maps/"+file_name, false) + var img = Image.new() + img.load(data.icon) + print(data.icon) + var img_tex = ImageTexture.new() + img_tex.create_from_image(img) + data.icon = img_tex + levels.append(data) + + file_name = dir.get_next() + func setLevelInfo(info): if selected_level != info: diff --git a/Menus/menuManager.gd b/Menus/menuManager.gd index e4c4429..f3f836c 100644 --- a/Menus/menuManager.gd +++ b/Menus/menuManager.gd @@ -46,7 +46,7 @@ func loadMenu(): addMenu("EMS/LEM/LevelEditor", "res://Menus/Editor/LevelEditor.tscn") addMenu("EMS/LEM/GameModesMenu", "res://Menus/Editor/GameModesMenu.tscn") addMenu("EMS/LEM/GMM/TDM", "res://Menus/Editor/TDMspawnEditor.tscn") - + addMenu("EMS/LEM/GMM/ZM", "res://Menus/Editor/ZMspawnEditor.tscn") finishLoading() func addMenu(name,path): diff --git a/Objects/Game_modes/ZombieMod/ZombieMod.gd b/Objects/Game_modes/ZombieMod/ZombieMod.gd index 782a284..5bcc2ad 100644 --- a/Objects/Game_modes/ZombieMod/ZombieMod.gd +++ b/Objects/Game_modes/ZombieMod/ZombieMod.gd @@ -59,7 +59,7 @@ func _ready(): prop_parent = props[0].get_parent() if get_tree().is_network_server(): - zombie_spawns = get_tree().get_nodes_in_group("ZspawnPoints")[0].get_children() + zombie_spawns = get_tree().get_nodes_in_group("ZspawnPoint") var teams = get_tree().get_nodes_in_group("Team") for i in teams: diff --git a/Objects/Game_modes/ZombieMod/zombieSpawner.gd b/Objects/Game_modes/ZombieMod/zombieSpawner.gd index 359f791..7dfaf9c 100644 --- a/Objects/Game_modes/ZombieMod/zombieSpawner.gd +++ b/Objects/Game_modes/ZombieMod/zombieSpawner.gd @@ -13,7 +13,7 @@ var obj_id = 0 var timer onready var wait_time : float = 1.0 / frequency -onready var level = get_tree().get_nodes_in_group("Level")[0] +var level func set_frequency(f): @@ -24,6 +24,10 @@ func set_frequency(f): func _ready(): + var levels = get_tree().get_nodes_in_group("Level") + if levels.size() > 0: + level = levels[0] + if get_tree().is_network_server(): timer = Timer.new() timer.one_shot = true diff --git a/Objects/Game_modes/ZombieMod/zombieSpawner.tscn b/Objects/Game_modes/ZombieMod/zombieSpawner.tscn index 4f15814..cef99d8 100644 --- a/Objects/Game_modes/ZombieMod/zombieSpawner.tscn +++ b/Objects/Game_modes/ZombieMod/zombieSpawner.tscn @@ -2,5 +2,7 @@ [ext_resource path="res://Objects/Game_modes/ZombieMod/zombieSpawner.gd" type="Script" id=1] -[node name="zombieSpawner" type="Node2D"] +[node name="zombieSpawner" type="Node2D" groups=[ +"ZspawnPoint", +]] script = ExtResource( 1 )