 [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 |
|
- extends Node
-
- # Public variables
- # ================
-
- onready var matchmaking = preload("res://scripts/matchmaking.gd").new()
-
- remote var players = {}
- var global_server_ip = "nv.cosinegaming.com"
- var matchmaker_tcp
-
- var level
-
- signal info_updated
-
- # Public methods
- # ==============
-
- func start_client(ip="", port=0):
- if not ip:
- ip = util.args.get_value("-ip")
- ip = IP.resolve_hostname(ip)
- if not port:
- port = util.args.get_value("-port")
- var peer = NetworkedMultiplayerENet.new()
- print("Connecting to " + ip + ":" + str(port))
- peer.create_client(ip, port)
- get_tree().set_network_peer(peer)
- get_tree().change_scene("res://scenes/lobby.tscn")
-
- remote func reconnect(ip, port):
- # Reset previously known players
- players = {}
- start_client(ip, port)
-
- func start_server(port=0):
- if not port:
- port = util.args.get_value("-port")
- var peer = NetworkedMultiplayerENet.new()
- print("Starting server on port " + str(port))
- peer.create_server(port, matchmaking.GAME_SIZE)
- get_tree().set_network_peer(peer)
- # As soon as we're listening, let the matchmaker know
- _connect_to_matchmaker(port)
- _register_player(get_tree().get_network_unique_id())
- if util.args.get_value("-silent"):
- set_info("spectating", true)
- get_tree().change_scene("res://scenes/lobby.tscn")
-
- master func set_info(key, value, peer=0):
- if not peer:
- peer = get_tree().get_network_unique_id()
- rpc("_set_info", str(key), value, peer)
-
- # When connectivity is not yet guaranteed, the only one we know is always
- # connected to everyone is the server. So in initial handshakes, it's better to
- # tell the server what to tell everyone to do
- func set_info_from_server(key, value, peer=0):
- if not peer:
- peer = get_tree().get_network_unique_id()
- rpc_id(1, "set_info", key, value, peer)
-
- func start_game():
- rpc_id(1, "_start_game")
-
- sync func reset_state():
- for p in players:
- players[p].begun = false
- # TODO: Do I in fact want to unready everyone automatically?
- players[p].ready = false
- get_node("/root/Level").queue_free()
-
-
- # Private methods
- # ===============
-
- func _ready():
- add_child(matchmaking)
-
- get_tree().connect("network_peer_disconnected", self, "_unregister_player")
- get_tree().connect("network_peer_connected", self, "_register_player")
- get_tree().connect("connected_to_server", self, "_on_connect")
-
- connect("info_updated", self, "_check_info")
-
- remote func _register_player(new_peer):
- if get_tree().is_network_server():
- # I tell new player about all the existing people
- _send_all_info(new_peer)
- set_info("is_right_team", _right_team_next(), new_peer)
-
- sync func _unregister_player(peer):
- players.erase(peer)
- var p = util.get_player(peer)
- if p:
- p.queue_free()
- emit_signal("info_updated")
-
- func _connect_to_matchmaker(game_port):
- var matchmaker_peer = StreamPeerTCP.new()
- matchmaker_peer.connect_to_host("127.0.0.1", matchmaking.SERVER_TO_SERVER_PORT)
- var matchmaker_tcp = PacketPeerStream.new()
- matchmaker_tcp.set_stream_peer(matchmaker_peer)
- matchmaker_tcp.put_var(matchmaking.messages.ready_to_connect)
- matchmaker_tcp.put_var(game_port)
-
- master func _start_game():
- rpc("_pre_configure_game", level)
-
- func _send_all_info(new_peer):
- for p in players:
- if p != new_peer:
- for key in players[p]:
- var val = players[p][key]
- # TODO: This broadcasts every connected peer,
- # which isn't really a problem but it's lazy
- set_info(key, val, p)
-
- func _right_team_next():
- var right_team_count = 0
- for p in players:
- var player = players[p]
- if player.has("is_right_team") and player.is_right_team:
- right_team_count += 1
- return (right_team_count <= players.size() / 2)
-
- sync func _set_info(key, value, peer):
- if not players.has(peer):
- players[peer] = {}
- players[peer][key] = value
- emit_signal("info_updated")
-
- func _on_connect():
- _register_player(get_tree().get_network_unique_id())
- emit_signal("info_updated")
-
- func _check_info():
- # Check for "everyone is ready"
- # Only have 1 person check this, might as well be server
- if get_tree().is_network_server():
- var ready = true
- var all_done = true
- for p in players:
- if not players[p].has("spectating") or not players[p].spectating:
- if not players[p].has("ready") or not players[p].ready:
- ready = false
- if not players[p].has("begun") or not players[p].begun:
- all_done = false
- if all_done:
- rpc("_post_configure_game")
- elif ready:
- # If we're all done, then we don't need to even check a start_game
- start_game()
-
- sync func _spawn_player(p):
- var hero = 0
- if players[p].has("hero"):
- hero = players[p].hero
- var player = load("res://scenes/heroes/" + str(hero) + ".tscn").instance()
- player.set_name(str(p))
- player.set_network_master(p)
- player.player_info = players[p]
- get_node("/root/Level/Players").add_child(player)
-
- func _begin_player(p):
- var player = util.get_player(p)
- player.begin()
-
- sync func _pre_configure_game(level):
-
- var self_peer_id = get_tree().get_network_unique_id()
- var self_begun = players[self_peer_id].begun
-
- if not self_begun:
- get_node("/root/Lobby").hide()
-
- var world = load("res://scenes/levels/%d.tscn" % level).instance()
- get_node("/root").add_child(world)
-
- # Load all players (including self)
- for p in players:
- if not players[p].spectating:
- var existing_player = util.get_player(p)
- if not self_begun or not existing_player:
- _spawn_player(p)
- for p in players:
- if not players[p].spectating:
- # Begin requires all players
- _begin_player(p)
-
- # Why do we check first? Weird error. It's because set_info triggers a
- # start_game if everyone is ready
- # This causes a stack overflow if we call it from here repeatedly
- # So we only change it once, only start_game twice, and avoida segfault
- if not self_begun:
- set_info("begun", true)
-
- sync func _post_configure_game():
- # Begin all players (including self)
- # TODO: What do? Maybe, unpause game?
- pass
-
|