Browse Source

Add full functionality to custom_game (untested)

Can't test because I haven't added the "start game" button back yet.
master
Luna 7 years ago
parent
commit
d265fcde1b
4 changed files with 39 additions and 30 deletions
  1. +13
    -2
      scripts/custom_game.gd
  2. +1
    -23
      scripts/menu.gd
  3. +0
    -5
      scripts/networking.gd
  4. +25
    -0
      scripts/util.gd

+ 13
- 2
scripts/custom_game.gd View File

@ -5,6 +5,17 @@ onready var networking = preload("res://scripts/networking.gd").new()
func _ready():
add_child(networking)
get_node("Server").connect("pressed", networking, "start_server")
get_node("Client").connect("pressed", networking, "start_client")
get_node("Server").connect("pressed", self, "_start_server")
get_node("Client").connect("pressed", self, "_start_client")
func _start_server():
networking.start_server(_get_port())
func _start_client():
var ip = get_node("IP").text
networking.start_client(ip, _get_port())
func _get_port():
var port = util.args.get_value("-port")
return port

+ 1
- 23
scripts/menu.gd View File

@ -1,8 +1,7 @@
extends "res://scripts/args.gd"
extends Control
func _ready():
randomize()
_parse_args()
_gui_setup()
# GUI
@ -23,23 +22,6 @@ func _singleplayer():
# Command line
func _set_up_options():
var opts = Options.new()
opts.set_banner(('A non-violent MOBA inspired by Overwatch and Zineth'))
opts.add('-singleplayer', false, 'Whether to run singeplayer, starting immediately')
opts.add('-server', false, 'Whether to run as server')
opts.add('-matchmaker', false, 'Whether to be the sole matchmaker')
opts.add('-client', false, 'Immediately connect as client')
opts.add('-silent', false, 'If the server is not playing, merely serving')
opts.add('-port', 54672, 'The port to run a server on or connect to')
opts.add('-hero', 'r', 'Your choice of hero (index)')
opts.add('-level', 'r', 'Your choice of level (index) - server only!')
opts.add('-start-game', false, 'Join as a client and immediately start the game')
opts.add('-ai', true, 'Run this client as AI')
opts.add('-no-record', true, "Don't record this play for AI later")
opts.add('-h', false, "Print help")
return opts
func _option_sel(button_name, option):
var button = get_node(button_name)
if option == "r":
@ -48,10 +30,6 @@ func _option_sel(button_name, option):
option = int(option)
button.select(option)
func _parse_args():
var o = _set_up_options()
o.parse()
# if o.get_value("-silent"):
# server_playing = false
# if o.get_value("-hero"):


+ 0
- 5
scripts/networking.gd View File

@ -20,11 +20,6 @@ func _ready():
func start_client(ip, port):
# collect_info() TODO
var peer = NetworkedMultiplayerENet.new()
# if not ip: TODO
# ip = get_node("CustomGame/IP").get_text()
# ip = IP.resolve_hostname(ip)
# if given_port:
# port = given_port
print("Connecting to " + ip + ":" + str(port))
peer.create_client(ip, port)
get_tree().set_network_peer(peer)


+ 25
- 0
scripts/util.gd View File

@ -2,6 +2,13 @@ extends Node
var version = [0,0,0] # Semantic versioning: [0].[1].[2]
var args
onready var Options = preload("res://scripts/args.gd").new().Options
func _ready():
args = _get_args()
func get_master_player():
var path = "/root/Level/Players/%d" % get_tree().get_network_unique_id()
if has_node(path):
@ -16,3 +23,21 @@ func is_friendly(player):
else:
return true # Doesn't matter, we're headless
func _get_args():
var opts = Options.new()
opts.set_banner(('A non-violent MOBA inspired by Overwatch and Zineth'))
opts.add('-singleplayer', false, 'Whether to run singeplayer, starting immediately')
opts.add('-server', false, 'Whether to run as server')
opts.add('-matchmaker', false, 'Whether to be the sole matchmaker')
opts.add('-client', false, 'Immediately connect as client')
opts.add('-silent', false, 'If the server is not playing, merely serving')
opts.add('-port', 54673, 'The port to run a server on or connect to')
opts.add('-hero', 'r', 'Your choice of hero (index)')
opts.add('-level', 'r', 'Your choice of level (index) - server only!')
opts.add('-start-game', false, 'Join as a client and immediately start the game')
opts.add('-ai', true, 'Run this client as AI')
opts.add('-no-record', true, "Don't record this play for AI later")
opts.add('-h', false, "Print help")
opts.parse()
return opts

Loading…
Cancel
Save