diff options
Diffstat (limited to 'Scripts/NumberNode.gd')
-rw-r--r-- | Scripts/NumberNode.gd | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Scripts/NumberNode.gd b/Scripts/NumberNode.gd new file mode 100644 index 0000000..ca80530 --- /dev/null +++ b/Scripts/NumberNode.gd @@ -0,0 +1,66 @@ +extends Node2D +class_name NumberNode + +@export_group("Values") +@export var value : int +@export var modifier : int +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 += self.modifier + if self.modifier_operation == Operations.SUBTRACTION: + node.value -= self.modifier + if self.modifier_operation == Operations.MULTIPLICATION: + node.value = 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) + if self.modifier_operation == Operations.SUBTRACTION: + label_modifier.text = "- " + str(self.modifier) + if self.modifier_operation == Operations.MULTIPLICATION: + label_modifier.text = "× " + str(self.modifier) + if self.modifier_operation == Operations.DIVISION: + label_modifier.text = "÷ " + str(self.modifier) + if self.modifier_operation == Operations.NONE: + sprite_modifier.visible = false + label_modifier.visible = false |