Public repository for MUR pre alpha
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.

44 lines
1.2 KiB

  1. extends Control
  2. func _ready():
  3. var player_name = local_storage.read_value("player_name", false)
  4. var game_title = "New Game"
  5. if player_name:
  6. game_title += " by " + player_name
  7. find_node("name").set_text(game_title)
  8. find_node("bots").set_pressed(local_storage.read_value("bots", true))
  9. func _draw():
  10. find_node("create").grab_focus()
  11. func _on_create_pressed():
  12. var req = game_server.http()
  13. req.connect_http(self,"_on_game_created")
  14. var server_name = find_node("name").text
  15. var bots = 0
  16. if find_node("bots").is_pressed():
  17. bots = 1
  18. req.post_request('client/game/create', to_json({'name' : server_name, 'bots' : bots}))
  19. func _on_game_created(result, response_code, headers, body):
  20. if result == OK && response_code == HTTPClient.RESPONSE_OK:
  21. var json = JSON.parse(body.get_string_from_utf8())
  22. gamestate.game_name = json.result['name']
  23. client.join_game(game_server.SERVER_ADDR, int(json.result['port']))
  24. queue_free()
  25. func _on_name_text_changed(new_text):
  26. if new_text:
  27. find_node("create").set_disabled(false)
  28. else:
  29. find_node("create").set_disabled(true)
  30. func _on_back_pressed():
  31. queue_free()
  32. get_tree().get_root().get_node("multiplayer_menu").show()