extends "res://scripts/obsticle_base.gd"

var operation: GameEngine.OPS
var value: int
@onready var screenObject: MeshInstance3D = $Screen
@onready var signObject: MeshInstance3D = $Screen/Sign
var screenGreenMat: StandardMaterial3D = preload("res://materials/sign_green.material")
var screenRedMat: StandardMaterial3D = preload("res://materials/sign_red.material")

func playerHit() -> void:
	GameEngine.getGE().modifyIdas(value, operation)
	physicsBody.queue_free()

func updateSignText(valueIn: int, opSign: String, negative: bool) -> void:
	signObject.mesh.text = opSign + " " + str(valueIn)

	if negative:
		screenObject.mesh.material = screenRedMat
	else:
		screenObject.mesh.material = screenGreenMat

func _ready() -> void:
	var opPreSelected: int = randi() % 100
	var minValue: int = 2
	var maxValue: int = 10
	var opSign: String = ""
	var negative: bool = false
	
	if (opPreSelected < 35):
		operation = GameEngine.OPS.ADD
		opSign = "+"
	elif (opPreSelected < 70):
		operation = GameEngine.OPS.SUB
		opSign = "-"
		negative = true
	elif (opPreSelected < 85):
		operation = GameEngine.OPS.MUL
		opSign = "x"
		maxValue = 5
	elif (opPreSelected < 100):
		operation = GameEngine.OPS.DIV
		opSign = "÷"
		maxValue = 5
		negative = true
	
	value = randi() % maxValue
	if value < minValue:
		value = minValue
		
	updateSignText(value, opSign, negative)
