class_name Actor 
extends KinematicBody2D


export(String, "Player", "Enemy", "NPC", "Object") var actor_type
#export var sprite_facing_right: bool = true
export var debug_actor: bool = false


onready var sound_effect_player: AudioStreamPlayer = $AudioStreamPlayer_StateReceiver

onready var movement_component: Movement_StateReceiver = $Movement_StateReceiver

onready var movement_state_machine: StateMachine = $Movement_StateMachine

onready var animated_sprite : AnimatedSprite = $AnimatedSprite_StateReceiver

## Multiplayer Variables
puppet var puppet_pos = Vector2()
puppet var puppet_transform: Transform2D


func _ready() -> void:
	puppet_transform = transform

func _unhandled_input(event: InputEvent) -> void:
	if is_network_master():
		if actor_type == "Player":
			movement_component.process_unhandled_input(event)

func _physics_process(delta: float) -> void:
	# Input based or polling input is not done in _unhandled_input
	# gives us the ability to turn off polling this way
	if is_network_master():
		if actor_type == "Player":
			movement_component.process_physics_input(delta)
		movement_component.process_physics(delta)
		rset("puppet_pos", position)
		rset("puppet_transform", transform)
	else:
		position = puppet_pos
		transform = puppet_transform

func _process(delta: float) -> void:
	if actor_type == "NPC" or actor_type == "Enemy":
		if is_network_master():
			movement_component.process(delta)


