A team game with an emphasis on movement (with no shooting), inspired by Overwatch and Zineth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
5.7 KiB

[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
[WIP] Split up lobby -> menu, lobby, custom_game lobby.gd had gotten big, bloated, ugly, and hard to read. It needed a refactor. The first thing I did is split up the *GUI* into the logical steps it should be. So the new flow is: - Start the game - Click "Quick Play" - Matchmaking begins on my dedicated server - Start the game - Click "Custom Game" - *Only now* am I presented with server / client options - Start the game - Click "Singleplayer" - Singleplayer NOW, and only now, and NO MATTER WHAT PATH I TAKE, I am taken to the *lobby*, which now is where I: - Choose my name - Choose hero - See list of players - Get my team assigned - Anything else that I might like to put in The point here is that this has *nothing* to do with handshaking / matchmaking / etc! This is just part of the game! At this point I have *already been connected* to the server. I've already been aquainted with my other players. The game has begun. I put the things that don't belong in any of these flows in networking.gd, a sort of model-view sorta thing. All of these flows use some sort of networking thing like `init_server` that tbh should be *completely* abstracted from the UI. It's totally a WIP!!! Above is the IDEA, but below is what I've actually *done*: - Made the scenes, made a passable UI for each one that at least indicates ~what they'll do - Made the corresponding scripts, and split up the lobby script into ABOUT where I think it'll end up, but no promises It still errors all over the place, and it's nowhere near properly organized. PLUS, I'd also like to rewrite a lot of the code / rename things as part of the initial refactor goal of making me able to actually think about networking.
7 years ago
  1. extends Node
  2. # Public variables
  3. # ================
  4. onready var matchmaking = preload("res://scripts/matchmaking.gd").new()
  5. remote var players = {}
  6. var global_server_ip = "nv.cosinegaming.com"
  7. var matchmaker_tcp
  8. var level
  9. signal info_updated
  10. # Public methods
  11. # ==============
  12. func start_client(ip="", port=0):
  13. if not ip:
  14. ip = util.args.get_value("-ip")
  15. ip = IP.resolve_hostname(ip)
  16. if not port:
  17. port = util.args.get_value("-port")
  18. var peer = NetworkedMultiplayerENet.new()
  19. print("Connecting to " + ip + ":" + str(port))
  20. peer.create_client(ip, port)
  21. get_tree().set_network_peer(peer)
  22. get_tree().change_scene("res://scenes/lobby.tscn")
  23. remote func reconnect(ip, port):
  24. # Reset previously known players
  25. players = {}
  26. start_client(ip, port)
  27. func start_server(port=0):
  28. if not port:
  29. port = util.args.get_value("-port")
  30. var peer = NetworkedMultiplayerENet.new()
  31. print("Starting server on port " + str(port))
  32. peer.create_server(port, matchmaking.GAME_SIZE)
  33. get_tree().set_network_peer(peer)
  34. # As soon as we're listening, let the matchmaker know
  35. _connect_to_matchmaker(port)
  36. _register_player(get_tree().get_network_unique_id())
  37. if util.args.get_value("-silent"):
  38. set_info("spectating", true)
  39. get_tree().change_scene("res://scenes/lobby.tscn")
  40. master func set_info(key, value, peer=0):
  41. if not peer:
  42. peer = get_tree().get_network_unique_id()
  43. rpc("_set_info", str(key), value, peer)
  44. # When connectivity is not yet guaranteed, the only one we know is always
  45. # connected to everyone is the server. So in initial handshakes, it's better to
  46. # tell the server what to tell everyone to do
  47. func set_info_from_server(key, value, peer=0):
  48. if not peer:
  49. peer = get_tree().get_network_unique_id()
  50. rpc_id(1, "set_info", key, value, peer)
  51. func start_game():
  52. rpc_id(1, "_start_game")
  53. sync func reset_state():
  54. for p in players:
  55. players[p].begun = false
  56. # TODO: Do I in fact want to unready everyone automatically?
  57. players[p].ready = false
  58. get_node("/root/Level").queue_free()
  59. # Private methods
  60. # ===============
  61. func _ready():
  62. add_child(matchmaking)
  63. get_tree().connect("network_peer_disconnected", self, "_unregister_player")
  64. get_tree().connect("network_peer_connected", self, "_register_player")
  65. get_tree().connect("connected_to_server", self, "_on_connect")
  66. connect("info_updated", self, "_check_info")
  67. remote func _register_player(new_peer):
  68. if get_tree().is_network_server():
  69. # I tell new player about all the existing people
  70. _send_all_info(new_peer)
  71. set_info("is_right_team", _right_team_next(), new_peer)
  72. sync func _unregister_player(peer):
  73. players.erase(peer)
  74. var p = util.get_player(peer)
  75. if p:
  76. p.queue_free()
  77. emit_signal("info_updated")
  78. func _connect_to_matchmaker(game_port):
  79. var matchmaker_peer = StreamPeerTCP.new()
  80. matchmaker_peer.connect_to_host("127.0.0.1", matchmaking.SERVER_TO_SERVER_PORT)
  81. var matchmaker_tcp = PacketPeerStream.new()
  82. matchmaker_tcp.set_stream_peer(matchmaker_peer)
  83. matchmaker_tcp.put_var(matchmaking.messages.ready_to_connect)
  84. matchmaker_tcp.put_var(game_port)
  85. master func _start_game():
  86. rpc("_pre_configure_game", level)
  87. func _send_all_info(new_peer):
  88. for p in players:
  89. if p != new_peer:
  90. for key in players[p]:
  91. var val = players[p][key]
  92. # TODO: This broadcasts every connected peer,
  93. # which isn't really a problem but it's lazy
  94. set_info(key, val, p)
  95. func _right_team_next():
  96. var right_team_count = 0
  97. for p in players:
  98. var player = players[p]
  99. if player.has("is_right_team") and player.is_right_team:
  100. right_team_count += 1
  101. return (right_team_count <= players.size() / 2)
  102. sync func _set_info(key, value, peer):
  103. if not players.has(peer):
  104. players[peer] = {}
  105. players[peer][key] = value
  106. emit_signal("info_updated")
  107. func _on_connect():
  108. _register_player(get_tree().get_network_unique_id())
  109. emit_signal("info_updated")
  110. func _check_info():
  111. # Check for "everyone is ready"
  112. # Only have 1 person check this, might as well be server
  113. if get_tree().is_network_server():
  114. var ready = true
  115. var all_done = true
  116. for p in players:
  117. if not players[p].has("spectating") or not players[p].spectating:
  118. if not players[p].has("ready") or not players[p].ready:
  119. ready = false
  120. if not players[p].has("begun") or not players[p].begun:
  121. all_done = false
  122. if all_done:
  123. rpc("_post_configure_game")
  124. elif ready:
  125. # If we're all done, then we don't need to even check a start_game
  126. start_game()
  127. sync func _spawn_player(p):
  128. var hero = 0
  129. if players[p].has("hero"):
  130. hero = players[p].hero
  131. var player = load("res://scenes/heroes/" + str(hero) + ".tscn").instance()
  132. player.set_name(str(p))
  133. player.set_network_master(p)
  134. player.player_info = players[p]
  135. get_node("/root/Level/Players").add_child(player)
  136. func _begin_player(p):
  137. var player = util.get_player(p)
  138. player.begin()
  139. sync func _pre_configure_game(level):
  140. var self_peer_id = get_tree().get_network_unique_id()
  141. var self_begun = players[self_peer_id].begun
  142. if not self_begun:
  143. get_node("/root/Lobby").hide()
  144. var world = load("res://scenes/levels/%d.tscn" % level).instance()
  145. get_node("/root").add_child(world)
  146. # Load all players (including self)
  147. for p in players:
  148. if not players[p].spectating:
  149. var existing_player = util.get_player(p)
  150. if not self_begun or not existing_player:
  151. _spawn_player(p)
  152. for p in players:
  153. if not players[p].spectating:
  154. # Begin requires all players
  155. _begin_player(p)
  156. # Why do we check first? Weird error. It's because set_info triggers a
  157. # start_game if everyone is ready
  158. # This causes a stack overflow if we call it from here repeatedly
  159. # So we only change it once, only start_game twice, and avoida segfault
  160. if not self_begun:
  161. set_info("begun", true)
  162. sync func _post_configure_game():
  163. # Begin all players (including self)
  164. # TODO: What do? Maybe, unpause game?
  165. pass