Closed loteque closed 1 year ago
PlayerManager
.
Quick sketch of what a player manager would look like: PlayerManager.gd
extends Node2D
devices = [dev_guid]
players = {player_id : dev_id}
set:
get:
func _get_new_player_id() -> int:
func _get_new_device_id() -> int:
func _get_dev_guid() -> int:
func _add_player(player_id: int, dev_id: int, dev_guid: String):
var player = load(PlayerController.gd).new(player_id, dev_id, dev_guid)
$parent.add_child(player).name(dev_guid)
func _remove_player(dev_id: int):
get_player_by_dev_id(dev_id).queue_free
_on_joypad_connect(player):
_add_player(_get_new_player_id(), _get_new_dev_id(), _get_dev_guid())
_on_joypad_disconnect(dev_id):
_remove_player(dev_id)