summaryrefslogtreecommitdiff
path: root/Scripts/NumberNode.gd
blob: 41c5d4a4ea2010d48cba5404f55a23c226980399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extends Node2D
class_name NumberNode

@export_group("Values")
@export var value : int
@export var modifier : float
enum Operations {
	NONE,
	ADDITION,
	SUBTRACTION,
	MULTIPLICATION,
	DIVISION,
}
@export var modifier_operation : Operations
## Scan for mouse as a target. Uncheck if player / AI.
@export var do_scanning : bool = true

@export_group("Visuals")
@export_subgroup("Visual Nodes")
@export var label : Label
@export var label_modifier : Label
@export var sprite : Sprite2D
@export var sprite_modifier : Sprite2D
@export_subgroup("Visual Values")
@export var color : Color = Color.BLACK
@export var min_scale : float
@export var max_scale : float

func _ready():
	update_visuals()

func _process(_delta):
	pass

func join_from(node : NumberNode):
	node.value += self.value
	
	if self.modifier_operation == Operations.ADDITION:
		node.value += roundi(self.modifier)
	if self.modifier_operation == Operations.SUBTRACTION:
		node.value -= roundi(self.modifier)
	if self.modifier_operation == Operations.MULTIPLICATION:
		node.value = roundi(float(node.value) * self.modifier)
	if self.modifier_operation == Operations.DIVISION:
		node.value = roundi(float(node.value) / float(self.modifier))
	
	node.position = self.position
	node.update_visuals()

	queue_free()

func update_visuals():
	label.text = str(self.value)
	sprite.modulate = color

	if self.modifier_operation == Operations.ADDITION:
		label_modifier.text = "+ " + str(self.modifier)
		sprite_modifier.visible = true
		label_modifier.visible = true
	if self.modifier_operation == Operations.SUBTRACTION:
		label_modifier.text = "- " + str(self.modifier)
		sprite_modifier.visible = true
		label_modifier.visible = true
	if self.modifier_operation == Operations.MULTIPLICATION:
		label_modifier.text = "× " + str(self.modifier)
		sprite_modifier.visible = true
		label_modifier.visible = true
	if self.modifier_operation == Operations.DIVISION:
		label_modifier.text = "÷ " + str(self.modifier)
		sprite_modifier.visible = true
		label_modifier.visible = true
	if self.modifier_operation == Operations.NONE:
		sprite_modifier.visible = false
		label_modifier.visible = false