From 24f5e910dd8f575adc483f768422ab51fdf905cc Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Sat, 13 Apr 2024 14:55:31 +0700 Subject: Initial commit. Exists: NumberNode, Player, dragging and dropping, joining NumberNodes --- Scripts/NumberNode.gd | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Scripts/NumberNode.gd (limited to 'Scripts/NumberNode.gd') 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 -- cgit v1.2.3