extends Node
class_name PlayerObject

signal first_point_triggerd
signal match_point_triggerd
signal winner_triggerd
signal point_given_sound
signal player_point_given
signal player_point_taken

@export
var id: int

@export
var player_name: String

@export
var player_score: int

var is_first_point: bool = true

var character: Texture = load("res://noCharacter.png")

func _init(new_name: String, new_id: int) -> void:
	player_name = new_name
	id = new_id
	player_score = 0

func add_point() -> void:
	if player_score < Settings.winning_score:
		player_score += 1
		player_point_given.emit()
		if player_score == 1 && is_first_point:
			is_first_point = false
			first_point_triggerd.emit()
		elif player_score == Settings.winning_score - 1:
			match_point_triggerd.emit()
		elif player_score == Settings.winning_score:
			winner_triggerd.emit()
		else:
			point_given_sound.emit()

func minus_point() -> void:
	if player_score > 0:
		player_score -= 1
		player_point_taken.emit()
		if player_score == 0:
			is_first_point = true

func reset_points() -> void:
	player_score = 0
	is_first_point = true
