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.

73 lines
2.3 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. func _ready():
  4. if get_tree().is_network_server():
  5. get_node("LevelSelect").show()
  6. get_node("Username").connect("text_changed", self, "_send_name")
  7. get_node("StartGame").connect("pressed", self, "_start_game")
  8. get_node("Spectating").pressed = util.args.get_value("-silent")
  9. get_node("Spectating").connect("pressed", self, "_change_spectating") # TODO
  10. # get_node("CustomGame/LevelSelect").connect("item_selected", self, "select_level") TODO
  11. # _send_name()
  12. func _collect_info():
  13. var my_id = get_tree().get_network_unique_id()
  14. var my_info = networking.players[my_id]
  15. if not "username" in my_info:
  16. my_info.username = get_node("Username").get_text()
  17. if not "hero" in my_info:
  18. my_info.hero = get_node("HeroSelect/Hero").get_selected_id()
  19. if not "is_right_team" in my_info:
  20. my_info.is_right_team = false # Server assigns team, wait for that
  21. func select_hero(hero):
  22. var description = get_node("HeroSelect").hero_text[hero]
  23. get_node("HeroDescription").set_text(description)
  24. var my_id = get_tree().get_network_unique_id()
  25. networking.players[my_id].hero = hero
  26. rpc("set_hero", get_tree().get_network_unique_id(), hero)
  27. sync func set_hero(peer, hero):
  28. networking.players[peer].hero = hero
  29. render_player_list()
  30. func _send_name():
  31. var name = get_node("Username").text
  32. rpc("_set_name", get_tree().get_network_unique_id(), name)
  33. sync func _set_name(peer, name):
  34. networking.players[peer].username = name
  35. render_player_list()
  36. func render_player_list():
  37. if has_node("PlayerSettings"):
  38. var list = ""
  39. var hero_names = get_node("HeroSelect").hero_names
  40. for p in networking.players:
  41. list += "%-15s" % networking.players[p].username
  42. list += "%-20s" % hero_names[networking.players[p].hero]
  43. if networking.players[p].is_right_team:
  44. list += "Right Team"
  45. else:
  46. list += "Left Team"
  47. list += "\n"
  48. get_node("JoinedGameLobby/PlayerList").set_text(list)
  49. sync func assign_team(peer, is_right_team):
  50. networking.players[peer].is_right_team = is_right_team
  51. if peer == get_tree().get_network_unique_id():
  52. if is_right_team:
  53. get_node("Team").set_text("Right Team")
  54. else:
  55. get_node("Team").set_text("Left Team")
  56. render_player_list()
  57. func _start_game():
  58. _collect_info()
  59. var level = 2 # TODO
  60. networking.rpc_id(1, "start_game", level)