Skip to content

Commit

Permalink
Merge pull request #3080 from t3du/ArrayInsertAdd
Browse files Browse the repository at this point in the history
Array Insert Node and Array Add Node: Add First option
  • Loading branch information
luboslenco authored Nov 22, 2024
2 parents 961b213 + 90c3dfb commit f752a47
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
8 changes: 5 additions & 3 deletions Sources/armory/logicnode/ArrayAddNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class ArrayAddNode extends LogicNode {

array = ar.map(item -> Std.string(item));

if (inputs.length > 4) {
for (i in 4...inputs.length) {
if (inputs.length > 5) {
for (i in 5...inputs.length) {
var value: Dynamic = inputs[i].get();

// "Unique Values" options only supports primitive data types
Expand All @@ -33,7 +33,9 @@ class ArrayAddNode extends LogicNode {
var type: Bool = value is Bool || value is Float || value is Int || value is String;

if (!inputs[3].get() || (type ? ar.indexOf(value) : array.indexOf(Std.string(value))) == -1) {
ar.push(value);
if (inputs[4].get())
ar.unshift(value);
else ar.push(value);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions Sources/armory/logicnode/ArrayInsertNode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package armory.logicnode;

class ArrayInsertNode extends LogicNode {

var ar: Array<Dynamic>;

public function new(tree: LogicTree) {
super(tree);
}

override function run(from: Int) {
ar = inputs[1].get();
var index: Int = inputs[2].get();
var value: Dynamic = inputs[3].get();

if (ar == null || value == null) return;

ar.insert(index, value);

runOutput(0);
}

override function get(from: Int): Dynamic {
return ar;
}
}
7 changes: 4 additions & 3 deletions blender/arm/logicnode/array/LN_array_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ArrayAddNode(ArmLogicTreeNode):
"""
bl_idname = 'LNArrayAddNode'
bl_label = 'Array Add'
arm_version = 4
min_inputs = 5
arm_version = 5
min_inputs = 6

def __init__(self):
super(ArrayAddNode, self).__init__()
Expand All @@ -21,6 +21,7 @@ def arm_init(self, context):
self.add_input('ArmNodeSocketArray', 'Array')
self.add_input('ArmBoolSocket', 'Modify Original', default_value=True)
self.add_input('ArmBoolSocket', 'Unique Values')
self.add_input('ArmBoolSocket', 'Add First')
self.add_input('ArmDynamicSocket', 'Value')

self.add_output('ArmNodeSocketAction', 'Out')
Expand All @@ -39,7 +40,7 @@ def draw_buttons(self, context, layout):
column.enabled = False

def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.arm_version not in (0, 3):
if self.arm_version not in (0, 4):
raise LookupError()

return NodeReplacement.Identity(self)
16 changes: 16 additions & 0 deletions blender/arm/logicnode/array/LN_array_insert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from arm.logicnode.arm_nodes import *

class ArrayInsertNode(ArmLogicTreeNode):
"""Inserts the value of the given array at the given index and increases the length of the array."""
bl_idname = 'LNArrayInsertNode'
bl_label = 'Array Insert'
arm_version = 1

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmNodeSocketArray', 'Array')
self.add_input('ArmIntSocket', 'Index')
self.add_input('ArmDynamicSocket', 'Value')

self.add_output('ArmNodeSocketAction', 'Out')
self.add_output('ArmNodeSocketArray', 'Array')

0 comments on commit f752a47

Please sign in to comment.