-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3004 from QuantumCoderQC/new-map-nodes
New Map, JSON and Select Output Nodes
- Loading branch information
Showing
11 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package armory.logicnode; | ||
import haxe.Json; | ||
|
||
class JsonStringifyNode extends LogicNode { | ||
|
||
public function new(tree:LogicTree) { | ||
super(tree); | ||
} | ||
|
||
override function get(from: Int):Dynamic { | ||
return Json.stringify(inputs[0].get()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package armory.logicnode; | ||
import haxe.Json; | ||
|
||
class ParseJsonNode extends LogicNode { | ||
|
||
public function new(tree:LogicTree) { | ||
super(tree); | ||
} | ||
|
||
override function get(from: Int):Dynamic { | ||
return Json.parse(inputs[0].get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package armory.logicnode; | ||
|
||
class SelectOutputNode extends LogicNode { | ||
|
||
public function new(tree: LogicTree) { | ||
super(tree); | ||
} | ||
|
||
override function run(from: Int) { | ||
//Get index to run | ||
var outIndex: Int = inputs[1].get(); | ||
// Check if output index found | ||
if(outIndex > (outputs.length - 2) || outIndex < 0) | ||
{ | ||
runOutput(0); | ||
return; | ||
} | ||
runOutput(outIndex + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package armory.logicnode; | ||
|
||
|
||
class SetMapFromArrayNode extends LogicNode { | ||
|
||
public function new(tree:LogicTree) { | ||
super(tree); | ||
} | ||
|
||
override function run(from:Int) { | ||
var map: Map<Dynamic,Dynamic> = inputs[1].get(); | ||
if (map == null) return; | ||
|
||
var keys: Array<Dynamic> = inputs[2].get(); | ||
var values: Array<Dynamic> = inputs[3].get(); | ||
|
||
assert(Error, keys.length == values.length, "Number of keys and values should be equal"); | ||
|
||
for(i in 0...keys.length) { | ||
map[keys[i]] = values[i]; | ||
} | ||
runOutput(0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package armory.logicnode; | ||
|
||
|
||
class StringMapNode extends LogicNode { | ||
|
||
public var property0: Int; | ||
public var map: Map<String, String> = []; | ||
public function new(tree:LogicTree) { | ||
super(tree); | ||
} | ||
|
||
override function run(from: Int) { | ||
map.clear(); | ||
for(i in 0...property0) { | ||
map.set(inputs[i * 2 + 1].get(), inputs[i * 2 + 2].get()); | ||
} | ||
runOutput(0); | ||
} | ||
|
||
override function get(from: Int):Dynamic { | ||
return map; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from arm.logicnode.arm_nodes import * | ||
|
||
class SelectOutputNode(ArmLogicTreeNode): | ||
"""Selects one of multiple outputs depending on the index. | ||
@input In: Action input. | ||
@input Index: Output index to run. | ||
@output Default: Run if output index not present. | ||
""" | ||
|
||
bl_idname = 'LNSelectOutputNode' | ||
bl_label = 'Select output' | ||
arm_version = 1 | ||
min_outputs = 2 | ||
|
||
def __init__(self): | ||
super(SelectOutputNode, self).__init__() | ||
array_nodes[self.get_id_str()] = self | ||
|
||
def arm_init(self, context): | ||
self.add_input('ArmNodeSocketAction', 'In') | ||
self.add_input('ArmIntSocket', 'Index') | ||
|
||
self.add_output('ArmNodeSocketAction', 'Default') | ||
self.add_output('ArmNodeSocketAction', 'Index 0') | ||
|
||
def draw_buttons(self, context, layout): | ||
row = layout.row(align=True) | ||
op = row.operator('arm.node_add_output', text='New', icon='PLUS', emboss=True) | ||
op.node_index = self.get_id_str() | ||
op.socket_type = 'ArmNodeSocketAction' | ||
op.name_format = 'Index {0}' | ||
op.index_name_offset = -1 | ||
column = row.column(align=True) | ||
op = column.operator('arm.node_remove_output', text='', icon='X', emboss=True) | ||
op.node_index = self.get_id_str() | ||
if len(self.outputs) == self.min_outputs: | ||
column.enabled = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from arm.logicnode.arm_nodes import * | ||
|
||
|
||
class ParseJsonNode(ArmLogicTreeNode): | ||
"""Parse a JSON String to Haxe object. | ||
@input JSON: JSON string. | ||
@output Value: Parsed value. | ||
""" | ||
|
||
bl_idname = 'LNParseJsonNode' | ||
bl_label = 'Parse JSON' | ||
arm_version = 1 | ||
|
||
def init(self, context): | ||
self.add_input('ArmStringSocket', 'JSON') | ||
self.add_output('ArmDynamicSocket', 'Value') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from arm.logicnode.arm_nodes import * | ||
|
||
|
||
class JsonStringifyNode(ArmLogicTreeNode): | ||
"""Convert a Haxe object to JSON String. | ||
@input Value: Value to convert. | ||
@output String: JSON String. | ||
""" | ||
|
||
bl_idname = 'LNJsonStringifyNode' | ||
bl_label = 'JSON Stringify' | ||
arm_version = 1 | ||
|
||
def init(self, context): | ||
self.add_input('ArmDynamicSocket', 'Value') | ||
self.add_output('ArmStringSocket', 'JSON') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from arm.logicnode.arm_nodes import * | ||
|
||
|
||
class SetMapFromArrayNode(ArmLogicTreeNode): | ||
"""Set Map From Arrays. | ||
@input In: Set the map. | ||
@input Map: Map to set values. | ||
@input Key: Array of keys to be set. | ||
@input Value: Array of corresponding values for the keys. | ||
""" | ||
|
||
bl_idname = 'LNSetMapFromArrayNode' | ||
bl_label = 'Set Map From Array' | ||
arm_version = 1 | ||
|
||
def init(self, context): | ||
self.add_input('ArmNodeSocketAction', 'In') | ||
self.add_input('ArmDynamicSocket', 'Map') | ||
self.add_input('ArmNodeSocketArray', 'Keys') | ||
self.add_input('ArmNodeSocketArray', 'Values') | ||
|
||
self.add_output('ArmNodeSocketAction', 'Out') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from arm.logicnode.arm_nodes import * | ||
|
||
class StringMapNode(ArmLogicTreeNode): | ||
"""Create String Map. | ||
@input In: Create a map using given keys and values. | ||
@input Key: Key. | ||
@input Value: Value. | ||
@output Out: Run after map is created. | ||
@output Map: The created map. | ||
""" | ||
|
||
bl_idname = 'LNStringMapNode' | ||
bl_label = 'String Map' | ||
arm_version = 1 | ||
|
||
min_inputs = 1 | ||
property0: HaxeIntProperty('property0', name='Number of keys', default=0) | ||
|
||
def __init__(self): | ||
super(StringMapNode, self).__init__() | ||
self.register_id() | ||
|
||
def arm_init(self, context): | ||
self.add_input('ArmNodeSocketAction', 'In') | ||
self.add_output('ArmNodeSocketAction', 'Out') | ||
self.add_output('ArmDynamicSocket', 'Map') | ||
|
||
def add_sockets(self): | ||
self.add_input('ArmStringSocket', f'Key [{self.property0}]') | ||
self.add_input('ArmStringSocket', f'Value [{self.property0}]') | ||
self.property0 += 1 | ||
|
||
def remove_sockets(self): | ||
if self.property0 > 0: | ||
self.inputs.remove(self.inputs.values()[-1]) | ||
self.inputs.remove(self.inputs.values()[-1]) | ||
self.property0 -= 1 | ||
|
||
def draw_buttons(self, context, layout): | ||
row = layout.row(align=True) | ||
|
||
op = row.operator('arm.node_call_func', text='New', icon='PLUS', emboss=True) | ||
op.node_index = self.get_id_str() | ||
op.callback_name = 'add_sockets' | ||
column = row.column(align=True) | ||
op = column.operator('arm.node_call_func', text='', icon='X', emboss=True) | ||
op.node_index = self.get_id_str() | ||
op.callback_name = 'remove_sockets' | ||
if len(self.inputs) == self.min_inputs: | ||
column.enabled = False |