2017-04-03 22:29:46 +02:00
|
|
|
from arm.logicnode.arm_nodes import *
|
|
|
|
|
2020-09-08 21:16:20 +02:00
|
|
|
class LoopNode(ArmLogicTreeNode):
|
2020-09-28 15:58:41 +02:00
|
|
|
"""Resembles a for-loop (`for (i in from...to)`) that is executed at
|
|
|
|
once when this node is activated.
|
|
|
|
|
|
|
|
@seeNode While
|
|
|
|
@seeNode Loop Break
|
|
|
|
|
|
|
|
@input From: The value to start the loop from (inclusive)
|
|
|
|
@input To: The value to end the loop at (exclusive)
|
|
|
|
|
|
|
|
@output Loop: Active at every iteration of the loop
|
|
|
|
@output Index: The index for the current iteration
|
|
|
|
@output Done: Activated once when the looping is done
|
|
|
|
"""
|
2017-04-04 23:11:31 +02:00
|
|
|
bl_idname = 'LNLoopNode'
|
2017-04-03 22:29:46 +02:00
|
|
|
bl_label = 'Loop'
|
2020-09-28 15:58:41 +02:00
|
|
|
bl_description = 'Resembles a for-loop that is executed at once when this node is activated'
|
2020-10-27 19:44:37 +01:00
|
|
|
arm_section = 'flow'
|
2020-09-13 11:27:58 +02:00
|
|
|
arm_version = 1
|
2020-09-08 17:03:24 +02:00
|
|
|
|
2017-04-03 22:29:46 +02:00
|
|
|
def init(self, context):
|
2020-09-13 11:27:58 +02:00
|
|
|
super(LoopNode, self).init(context)
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_input('ArmNodeSocketAction', 'In')
|
|
|
|
self.add_input('NodeSocketInt', 'From')
|
|
|
|
self.add_input('NodeSocketInt', 'To')
|
2020-11-17 16:01:15 +01:00
|
|
|
|
2020-09-08 21:49:02 +02:00
|
|
|
self.add_output('ArmNodeSocketAction', 'Loop')
|
|
|
|
self.add_output('NodeSocketInt', 'Index')
|
|
|
|
self.add_output('ArmNodeSocketAction', 'Done')
|
2020-12-15 23:47:38 +01:00
|
|
|
|
|
|
|
def draw_label(self) -> str:
|
|
|
|
inp_from = self.inputs['From']
|
|
|
|
inp_to = self.inputs['To']
|
|
|
|
if inp_from.is_linked and inp_to.is_linked:
|
|
|
|
return self.bl_label
|
|
|
|
|
|
|
|
val_from = 'x' if inp_from.is_linked else inp_from.default_value
|
|
|
|
val_to = 'y' if inp_to.is_linked else inp_to.default_value
|
|
|
|
|
|
|
|
return f'{self.bl_label}: {val_from}...{val_to}'
|