diff --git a/classes/deck/nodes/general/numeric_constant.gd b/classes/deck/nodes/general/numeric_constant.gd new file mode 100644 index 0000000..1f6c1cf --- /dev/null +++ b/classes/deck/nodes/general/numeric_constant.gd @@ -0,0 +1,20 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Numeric Constant" + node_type = name.to_snake_case() + + add_output_port( + DeckType.Types.NUMERIC, + "Value", + "spinbox:unbounded:0.0001", + Port.UsageType.VALUE_REQUEST, + ) + + +func _value_request(_from_port: int) -> Variant: + return ports[0].value diff --git a/classes/deck/nodes/math/pi_constant.gd b/classes/deck/nodes/math/pi_constant.gd new file mode 100644 index 0000000..159953e --- /dev/null +++ b/classes/deck/nodes/math/pi_constant.gd @@ -0,0 +1,21 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "PI Constant" + node_type = "pi_constant" + description = "The Pi constant." + + add_output_port( + DeckType.Types.NUMERIC, + "π Value", + "", + Port.UsageType.VALUE_REQUEST + ) + + +func _value_request(_on_output_port: int) -> float: + return PI diff --git a/classes/deck/nodes/math/scalar_add.gd b/classes/deck/nodes/math/scalar_add.gd new file mode 100644 index 0000000..c42bb0d --- /dev/null +++ b/classes/deck/nodes/math/scalar_add.gd @@ -0,0 +1,53 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Add Numbers" + node_type = "scalar_add" + description = "Adds two numbers together." + + add_input_port( + DeckType.Types.NUMERIC, + "Number A", + "spinbox:unbounded:0.0001", + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Number B", + "spinbox:unbounded:0.0001", + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result" + ) + + +func _value_request(_on_output_port: int) -> Variant: + var va = await resolve_input_port_value_async(0) + var vb = await resolve_input_port_value_async(1) + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + return va + vb + + +func _receive(on_input_port: int, data: Variant) -> void: + var va + var vb + if on_input_port == 0: + va = data + vb = await resolve_input_port_value_async(1) + else: + va = await resolve_input_port_value_async(0) + vb = data + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + send(0, va + vb) diff --git a/classes/deck/nodes/math/scalar_divide.gd b/classes/deck/nodes/math/scalar_divide.gd new file mode 100644 index 0000000..2ef0af8 --- /dev/null +++ b/classes/deck/nodes/math/scalar_divide.gd @@ -0,0 +1,53 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Divide Numbers" + node_type = "scalar_divide" + description = "Divide one number by another." + + add_input_port( + DeckType.Types.NUMERIC, + "Number A", + "spinbox:unbounded:0.0001", + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Number B", + "spinbox:unbounded:0.0001", + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result" + ) + + +func _value_request(_on_output_port: int) -> Variant: + var va = await resolve_input_port_value_async(0) + var vb = await resolve_input_port_value_async(1) + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + return va / vb + + +func _receive(on_input_port: int, data: Variant) -> void: + var va + var vb + if on_input_port == 0: + va = data + vb = await resolve_input_port_value_async(1) + else: + va = await resolve_input_port_value_async(0) + vb = data + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + send(0, va / vb) diff --git a/classes/deck/nodes/math/scalar_exponentiate.gd b/classes/deck/nodes/math/scalar_exponentiate.gd new file mode 100644 index 0000000..28a8bdc --- /dev/null +++ b/classes/deck/nodes/math/scalar_exponentiate.gd @@ -0,0 +1,54 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Raise Number to Power" + node_type = "scalar_exponentiate" + description = "Raise one number to the power of another (exponentiation)." + aliases = ["exponentiate", "square", "cube", "quad"] + + add_input_port( + DeckType.Types.NUMERIC, + "Base", + "spinbox:unbounded:0.0001", + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Exponent", + "spinbox:unbounded:0.0001", + ).set_value(2) + + add_output_port( + DeckType.Types.NUMERIC, + "Result" + ) + + +func _value_request(_on_output_port: int) -> Variant: + var va = await resolve_input_port_value_async(0) + var vb = await resolve_input_port_value_async(1) + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + return va ** vb + + +func _receive(on_input_port: int, data: Variant) -> void: + var va + var vb + if on_input_port == 0: + va = data + vb = await resolve_input_port_value_async(1) + else: + va = await resolve_input_port_value_async(0) + vb = data + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + send(0, va ** vb) diff --git a/classes/deck/nodes/math/scalar_log.gd b/classes/deck/nodes/math/scalar_log.gd new file mode 100644 index 0000000..a8c6f56 --- /dev/null +++ b/classes/deck/nodes/math/scalar_log.gd @@ -0,0 +1,34 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Natural Logarithm" + node_type = "scalar_log" + description = "Returns the natural logarithm of the number (base e)." + + add_input_port( + DeckType.Types.NUMERIC, + "Number", + "spinbox:unbounded:0.0001", + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result", + ) + + +func _value_request(_on_output_port: int) -> float: + var v = await resolve_input_port_value_async(0) + v = DeckType.convert_value(v, DeckType.Types.NUMERIC) + + return log(v) + + +func _receive(_to_input_port: int, data: Variant) -> void: + var v = DeckType.convert_value(data, DeckType.Types.NUMERIC) + + send(0, log(v)) diff --git a/classes/deck/nodes/math/scalar_multiply.gd b/classes/deck/nodes/math/scalar_multiply.gd new file mode 100644 index 0000000..8ecb74b --- /dev/null +++ b/classes/deck/nodes/math/scalar_multiply.gd @@ -0,0 +1,53 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Multiply Numbers" + node_type = "scalar_multiply" + description = "Multiply two numbers." + + add_input_port( + DeckType.Types.NUMERIC, + "Number A", + "spinbox:unbounded:0.0001", + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Number B", + "spinbox:unbounded:0.0001", + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result" + ) + + +func _value_request(_on_output_port: int) -> Variant: + var va = await resolve_input_port_value_async(0) + var vb = await resolve_input_port_value_async(1) + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + return va * vb + + +func _receive(on_input_port: int, data: Variant) -> void: + var va + var vb + if on_input_port == 0: + va = data + vb = await resolve_input_port_value_async(1) + else: + va = await resolve_input_port_value_async(0) + vb = data + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + send(0, va * vb) diff --git a/classes/deck/nodes/math/scalar_round.gd b/classes/deck/nodes/math/scalar_round.gd new file mode 100644 index 0000000..6def5f2 --- /dev/null +++ b/classes/deck/nodes/math/scalar_round.gd @@ -0,0 +1,49 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Round Number" + node_type = "scalar_round" + description = "Rounds a number to the nearest whole number." + + add_virtual_port( + DeckType.Types.STRING, + "Function", + "singlechoice:round:floor:ceil" + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Number", + "spinbox:unbounded:0.0001" + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result" + ) + + +func _round(v: float) -> float: + match get_virtual_ports()[0].value: + "floor": + return floorf(v) + "ceil": + return ceilf(v) + _: + return roundf(v) + + +func _value_request(on_output_port: int) -> Variant: + var v = await resolve_input_port_value_async(0) + v = DeckType.convert_value(v, DeckType.Types.NUMERIC) + + return _round(v) + + +func _receive(_to_input_port: int, data: Variant) -> void: + var v = DeckType.convert_value(data, DeckType.Types.NUMERIC) + send(0, _round(v)) diff --git a/classes/deck/nodes/math/scalar_subtract.gd b/classes/deck/nodes/math/scalar_subtract.gd new file mode 100644 index 0000000..2e811a6 --- /dev/null +++ b/classes/deck/nodes/math/scalar_subtract.gd @@ -0,0 +1,53 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Subtract Numbers" + node_type = "scalar_subtract" + description = "Subtracts one number from another." + + add_input_port( + DeckType.Types.NUMERIC, + "Number A", + "spinbox:unbounded:0.0001", + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Number B", + "spinbox:unbounded:0.0001", + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result" + ) + + +func _value_request(_on_output_port: int) -> Variant: + var va = await resolve_input_port_value_async(0) + var vb = await resolve_input_port_value_async(1) + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + return va - vb + + +func _receive(on_input_port: int, data: Variant) -> void: + var va + var vb + if on_input_port == 0: + va = data + vb = await resolve_input_port_value_async(1) + else: + va = await resolve_input_port_value_async(0) + vb = data + + va = DeckType.convert_value(va, DeckType.Types.NUMERIC) + vb = DeckType.convert_value(vb, DeckType.Types.NUMERIC) + + send(0, va - vb) diff --git a/classes/deck/nodes/math/scalar_trig.gd b/classes/deck/nodes/math/scalar_trig.gd new file mode 100644 index 0000000..c41d26d --- /dev/null +++ b/classes/deck/nodes/math/scalar_trig.gd @@ -0,0 +1,69 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends DeckNode + + +func _init() -> void: + name = "Trigonometry" + node_type = "scalar_trig" + description = "A selection of trigonometric functions on numbers." + + aliases = [ + "sine", "cosine", "tangent", + "arcsin", "acos", "arccos", "arctan", "atan", + "sinh", "cosh", "tanh", + "asinh", "acosh", "atanh", + ] + + add_virtual_port( + DeckType.Types.STRING, + "Function", + "singlechoice:sin:cos:tan:asin:acos:atan:asinh:acosh:atanh", + ) + + add_input_port( + DeckType.Types.NUMERIC, + "Angle", + "spinbox:unbounded:0.0001", + ) + + add_output_port( + DeckType.Types.NUMERIC, + "Result", + ) + + +func _do(v: float) -> float: + match get_virtual_ports()[0].value: + "cos": + return cos(v) + "tan": + return tan(v) + "asin": + return asin(v) + "acos": + return acos(v) + "atan": + return atan(v) + "asinh": + return asinh(v) + "acosh": + return acosh(v) + "atanh": + return atanh(v) + _: + return sin(v) + + +func _value_request(_on_output_port: int) -> float: + var v = await resolve_input_port_value_async(0) + v = DeckType.convert_value(v, DeckType.Types.NUMERIC) + + return _do(v) + + +func _receive(on_input_port: int, data: Variant) -> void: + var v = DeckType.convert_value(data, DeckType.Types.NUMERIC) + + send(0, _do(v)) diff --git a/graph_node_renderer/descriptors/single_choice_descriptor.gd b/graph_node_renderer/descriptors/single_choice_descriptor.gd index 28550a5..7dc4c71 100644 --- a/graph_node_renderer/descriptors/single_choice_descriptor.gd +++ b/graph_node_renderer/descriptors/single_choice_descriptor.gd @@ -21,3 +21,9 @@ func _setup(port: Port, _node: DeckNode) -> void: func(_id: int): port.set_value.call(box.get_item_text(box.get_selected_id())) ) + + if port.value != null: + for i in box.get_item_count(): + if box.get_item_text(i) == port.value: + box.select(i) + break diff --git a/graph_node_renderer/descriptors/spin_box_descriptor.gd b/graph_node_renderer/descriptors/spin_box_descriptor.gd index a69e659..f11f91a 100644 --- a/graph_node_renderer/descriptors/spin_box_descriptor.gd +++ b/graph_node_renderer/descriptors/spin_box_descriptor.gd @@ -7,6 +7,7 @@ extends DescriptorContainer func _setup(port: Port, _node: DeckNode) -> void: + spin_box.tooltip_text = port.label if port.value != null: spin_box.value = float(port.value) if "unbounded" in descriptor: diff --git a/graph_node_renderer/descriptors/spin_box_descriptor.tscn b/graph_node_renderer/descriptors/spin_box_descriptor.tscn index 3bb5d4f..8ca70b9 100644 --- a/graph_node_renderer/descriptors/spin_box_descriptor.tscn +++ b/graph_node_renderer/descriptors/spin_box_descriptor.tscn @@ -10,3 +10,4 @@ script = ExtResource("2_cxb6h") unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 +step = 0.0