Skip to content

Commit

Permalink
Merge pull request #3114 from t3du/UpdateReadWriteNodes
Browse files Browse the repository at this point in the history
ReadWriteNodes: add outputs
  • Loading branch information
luboslenco authored Dec 24, 2024
2 parents 7bb911b + 5dff34d commit 0553221
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
2 changes: 2 additions & 0 deletions armory/Sources/armory/logicnode/ReadFileNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ReadFileNode extends LogicNode {
if (!useCache) iron.data.Data.cachedBlobs.remove(file);
runOutput(0);
});

if (data == null) runOutput(1);
}

override function get(from: Int): Dynamic {
Expand Down
2 changes: 2 additions & 0 deletions armory/Sources/armory/logicnode/ReadJsonNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ReadJsonNode extends LogicNode {
if (!useCache) iron.data.Data.cachedBlobs.remove(file);
runOutput(0);
});

if (data == null) runOutput(1);
}

override function get(from: Int): Dynamic {
Expand Down
2 changes: 2 additions & 0 deletions armory/Sources/armory/logicnode/WriteFileNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ class WriteFileNode extends LogicNode {
a.click();
js.html.URL.revokeObjectURL(url);
#end

runOutput(0);
}
}
2 changes: 2 additions & 0 deletions armory/Sources/armory/logicnode/WriteJsonNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ class WriteJsonNode extends LogicNode {
a.click();
js.html.URL.revokeObjectURL(url);
#end

runOutput(0);
}
}
13 changes: 10 additions & 3 deletions armory/blender/arm/logicnode/native/LN_read_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ class ReadFileNode(ArmLogicTreeNode):
time the node is executed. Otherwise, cache the file after the
first read and return the cached content.
@output Loaded: activated after the file has been read. If the file
doesn't exist, the output is not activated.
@output Loaded: activated after the file has been read.
@output Not Loaded: If the file doesn't exist the output is activated.
@output Content: the content of the file.
@seeNode Write File
"""
bl_idname = 'LNReadFileNode'
bl_label = 'Read File'
arm_section = 'file'
arm_version = 1
arm_version = 2

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmStringSocket', 'File')
self.add_input('ArmBoolSocket', 'Use cache', default_value=True)

self.add_output('ArmNodeSocketAction', 'Loaded')
self.add_output('ArmNodeSocketAction', 'Not loaded')
self.add_output('ArmStringSocket', 'Content')

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

return NodeReplacement.Identity(self)
13 changes: 10 additions & 3 deletions armory/blender/arm/logicnode/native/LN_read_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ class ReadJsonNode(ArmLogicTreeNode):
time the node is executed. Otherwise, cache the file after the
first read and return the cached content.
@output Loaded: activated after the file has been read. If the file
doesn't exist, the output is not activated.
@output Loaded: activated after the file has been read.
@output Not Loaded: If the file doesn't exist the output is activated.
@output Dynamic: the content of the file.
@seeNode Write JSON
"""
bl_idname = 'LNReadJsonNode'
bl_label = 'Read JSON'
arm_section = 'file'
arm_version = 1
arm_version = 2

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmStringSocket', 'File')
self.add_input('ArmBoolSocket', 'Use cache', default_value=1)

self.add_output('ArmNodeSocketAction', 'Loaded')
self.add_output('ArmNodeSocketAction', 'Not loaded')
self.add_output('ArmDynamicSocket', 'Dynamic')

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

return NodeReplacement.Identity(self)
10 changes: 9 additions & 1 deletion armory/blender/arm/logicnode/native/LN_write_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ class WriteFileNode(ArmLogicTreeNode):
bl_idname = 'LNWriteFileNode'
bl_label = 'Write File'
arm_section = 'file'
arm_version = 1
arm_version = 2

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmStringSocket', 'File')
self.add_input('ArmStringSocket', 'Content')

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

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

return NodeReplacement.Identity(self)
10 changes: 9 additions & 1 deletion armory/blender/arm/logicnode/native/LN_write_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ class WriteJsonNode(ArmLogicTreeNode):
bl_idname = 'LNWriteJsonNode'
bl_label = 'Write JSON'
arm_section = 'file'
arm_version = 1
arm_version = 2

def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmStringSocket', 'File')
self.add_input('ArmDynamicSocket', 'Dynamic')

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

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

return NodeReplacement.Identity(self)

0 comments on commit 0553221

Please sign in to comment.