Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Map editor v1.0 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
superRaptor911 committed Aug 17, 2020
1 parent 96ccf3f commit a1094b1
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 22 deletions.
1 change: 0 additions & 1 deletion Maps/BaseLevel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var unit_data_dict = {
var spawned_units_ids = Array()

func _ready():

MusicMan.music_player.stop()

if capture_mod:
Expand Down
4 changes: 1 addition & 3 deletions Maps/Dust/Zm_Dust.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 1 addition & 3 deletions Maps/fy_dust/zm_fy_dust.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions Menus/Editor/EditorMapSelector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion Menus/Editor/GameModesMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions Menus/Editor/GameModesMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ __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 )
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 )
Expand Down
80 changes: 74 additions & 6 deletions Menus/Editor/LevelEditorMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
5 changes: 4 additions & 1 deletion Menus/Editor/TDMspawnEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand Down
44 changes: 44 additions & 0 deletions Menus/Editor/ZMspawnEditor.gd
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions Menus/Editor/ZMspawnEditor.tscn
Original file line number Diff line number Diff line change
@@ -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 ]
21 changes: 20 additions & 1 deletion Menus/Lobby/Lobby.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Menus/menuManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Objects/Game_modes/ZombieMod/ZombieMod.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion Objects/Game_modes/ZombieMod/zombieSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Objects/Game_modes/ZombieMod/zombieSpawner.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

0 comments on commit a1094b1

Please sign in to comment.