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.

75 lines
2.6 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
  1. extends Control
  2. var port = null # Defined by command-line argument with default
  3. var player_info = {}
  4. var my_info = {}
  5. var begun = false
  6. var server_playing = true
  7. var global_server_ip = "nv.cosinegaming.com"
  8. var ip = null
  9. var players_done = []
  10. var is_connected = false # Technically this can be done with ENetcetera but it's easier this way
  11. onready var matchmaking = preload("res://scripts/matchmaking.gd").new()
  12. var matchmaker_tcp
  13. func _ready():
  14. add_child(matchmaking)
  15. get_node("GameBrowser/Play").connect("pressed", self, "connect_global_server")
  16. get_node("PlayerSettings/HeroSelect").connect("item_selected", self, "select_hero")
  17. get_node("PlayerSettings/Username").connect("text_changed", self, "resend_name")
  18. get_node("JoinedGameLobby/StartGame").connect("pressed", self, "start_game")
  19. get_node("CustomGame/Server").connect("pressed", self, "_server_init")
  20. get_node("CustomGame/Client").connect("pressed", self, "_client_init")
  21. get_node("CustomGame/Singleplayer").connect("pressed", self, "_singleplayer_init")
  22. get_node("CustomGame/LevelSelect").connect("item_selected", self, "select_level")
  23. get_tree().connect("network_peer_connected", self, "_player_connected")
  24. get_tree().connect("network_peer_disconnected", self, "_player_disconnected")
  25. get_tree().connect("connected_to_server", self, "_connected_ok")
  26. func collect_info():
  27. if not "username" in my_info:
  28. my_info.username = get_node("PlayerSettings/Username").get_text()
  29. if not "hero" in my_info:
  30. my_info.hero = get_node("PlayerSettings/HeroSelect").get_selected_id()
  31. if not "is_right_team" in my_info:
  32. my_info.is_right_team = false # Server assigns team, wait for that
  33. func select_hero(hero):
  34. var description = get_node("PlayerSettings/HeroSelect").hero_text[hero]
  35. get_node("PlayerSettings/HeroDescription").set_text(description)
  36. if is_connected:
  37. rpc("set_hero", get_tree().get_network_unique_id(), hero)
  38. sync func set_hero(peer, hero):
  39. player_info[peer].hero = hero
  40. render_player_list()
  41. func resend_name():
  42. if is_connected:
  43. var name = get_node("PlayerSettings/Username").get_text()
  44. rpc("set_name", get_tree().get_network_unique_id(), name)
  45. sync func set_name(peer, name):
  46. player_info[peer].username = name
  47. render_player_list()
  48. func render_player_list():
  49. if has_node("PlayerSettings"):
  50. var list = ""
  51. var hero_names = get_node("PlayerSettings/HeroSelect").hero_names
  52. for p in player_info:
  53. list += "%-15s" % player_info[p].username
  54. list += "%-20s" % hero_names[player_info[p].hero]
  55. if player_info[p].is_right_team:
  56. list += "Right Team"
  57. else:
  58. list += "Left Team"
  59. list += "\n"
  60. get_node("JoinedGameLobby/PlayerList").set_text(list)