extends Node


const blinder_template = preload("res://templates/blinder.tscn")
const one_shot_template = preload("res://templates/one_shot.tscn")

const vs_man_level  = preload("res://scenes/multiplayer_test.tscn")

var player : Player
var hud : HUD
var level : Level

func setup_player(player : Player) -> void:
	self.player = player
	if hud:
		hud.register_player(player)

func switch_scene(packed_scene : PackedScene) -> void:
	var blinder = blinder_template.instantiate() as TextureRect
	var tween = create_tween()
	blinder.self_modulate.a = 0
	add_child(blinder)
	tween.tween_property(blinder, "self_modulate:a", 1, .15)
	tween.tween_callback(Callable(get_tree().change_scene_to_packed).bind(packed_scene))
	tween.tween_property(blinder, "self_modulate:a", 0, .15)
	tween.tween_callback(blinder.queue_free)
	pass

@rpc("call_local", "any_peer", "reliable")
func start_vs_man() -> void:
	var setup = get_tree().get_first_node_in_group("scenes")
	setup.queue_free()
	if Multiplayer.is_server():
		var level = vs_man_level.instantiate()
		var spawner = get_tree().get_first_node_in_group("level_spawner") as MultiplayerSpawner
		spawner.add_child(level)
	

func oneshot(stream : AudioStream) -> void:
	var shot = one_shot_template.instantiate()
	shot.stream = stream
	if level:
		level.add_child(shot)
	else:
		add_child(shot)
