Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions korman/nodes/node_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,72 @@ def export(self, exporter: Exporter, bo, so) -> None:
self._add_py_parameter(pfm, 101, plPythonParameter.kString, self.trigger_for)
self._add_py_parameter(pfm, 102, plPythonParameter.kString, self.trigger_at)


class PlasmaSDLBoolConditionNode(PlasmaNodeBase, bpy.types.Node):
bl_category = "CONDITIONS"
bl_idname = "PlasmaSDLBoolConditionNode"
bl_label = "SDL Boolean Condition"

input_sockets: dict[str, dict[str, Any]] = {
"condition": {
"text": "Condition",
"type": "PlasmaConditionSocket",
},
"variable": {
"text": "Depends on SDL",
"type": "PlasmaSDLTriggererSocket",
},
}

output_sockets: dict[str, dict[str, Any]] = {
"satisfies_true": {
"text": "Trigger on True",
"type": "PlasmaConditionSocket",
"valid_link_nodes": {"PlasmaResponderNode", "PlasmaBasicResponderNode"}
},
"satisfies_false": {
"text": "Trigger on False",
"type": "PlasmaConditionSocket",
"valid_link_nodes": {"PlasmaResponderNode", "PlasmaBasicResponderNode"},
}
}

ffwd_init = BoolProperty(
name="F-Fwd on Init",
description="Fast-forward the matching Responder when the Age loads",
default=True,
options=set()
)

def draw_buttons(self, context, layout: bpy.types.UILayout):
layout.prop(self, "ffwd_init")

def export(self, exporter: Exporter, bo: bpy.types.Object, so: plSceneObject):
condition_node = self.find_input("condition")
variable_node = self.find_input("variable")
if condition_node is None:
self.raise_error("Must be linked to a condition")
if variable_node is None:
self.raise_error("Must be linked to an SDL variable")

# xAgeSDLBoolCondResp only handles one SDL value per modifier. We're exposing two
# node sockets as a convenience to match the behavior of the xAgeSDLBoolRespond node.
# This means we'll potentially be producing two PFMs here.
resp_socket_names = ("satisfies_false", "satisfies_true")
for i, resp_node_iter in enumerate((self.find_outputs(i) for i in resp_socket_names)):
resp_nodes = tuple(resp_node_iter)
if not resp_nodes:
continue

pfm = self._find_create_object(plPythonFileMod, exporter, so=so, suffix=str(i))
pfm.filename = "xAgeSDLBoolCondResp"
self._add_py_parameter(pfm, 1, plPythonParameter.kActivator, condition_node.get_key(exporter, so))
self._add_py_parameter(pfm, 2, plPythonParameter.kString, variable_node.variable_name)
for resp_node in resp_nodes:
self._add_py_parameter(pfm, 3, plPythonParameter.kResponder, resp_node.get_key(exporter, so))
self._add_py_parameter(pfm, 4, plPythonParameter.kBoolean, i == 1)
self._add_py_parameter(pfm, 5, plPythonParameter.kBoolean, self.ffwd_init)

@property
def export_once(self):
return True
Expand Down
42 changes: 30 additions & 12 deletions korman/nodes/node_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,39 @@ def _update_init_sockets(self, defs, sockets):
# Create any missing sockets and spawn any required empties.
for alias, options in defs.items():
working_sockets = [(i, socket) for i, socket in enumerate(sockets) if socket.alias == alias]
num_sockets = options.get("min_sockets", 1)
num_used = sum((1 for i, socket in working_sockets if socket.is_linked))
if not working_sockets:
self._spawn_socket(alias, options, sockets)
elif options.get("spawn_empty", False):
last_socket_id = next(reversed(working_sockets))[0]
for working_id, working_socket in working_sockets:
if working_id == last_socket_id and working_socket.is_linked:
new_socket_id = len(sockets)
new_socket = self._spawn_socket(alias, options, sockets)
desired_id = last_socket_id + 1
if new_socket_id != desired_id:
sockets.move(new_socket_id, desired_id)
elif working_id < last_socket_id and not working_socket.is_linked:
for _ in range(num_sockets):
self._spawn_socket(alias, options, sockets)
else:
last_socket_id = working_sockets[-1][0]
if options.get("spawn_empty", False):
num_sockets = max(num_sockets, num_used + 1)

# Gather the sockets we have that are disconnected and preferentially remove the
# ones from the front of the list until we reach the minimum number of required
# sockets.
sockets_to_kill = len(working_sockets) - num_sockets
if sockets_to_kill > 0:
dead_sockets = [
i for i, (working_id, working_socket) in enumerate(working_sockets)
if not working_socket.is_linked
]
for i in reversed(dead_sockets[:sockets_to_kill]):
# Indices do not update until after the update() function finishes, so
# no need to decrement last_socket_id
sockets.remove(working_socket)
sockets.remove(working_sockets.pop(i)[1])

# Ensure that we have the minimum number of sockets spawned. This code will
# generally not execute.
insert_at = last_socket_id + 1
for i in range(len(working_sockets), num_sockets):
new_socket_id = len(sockets)
new_socket = self._spawn_socket(alias, options, sockets)
if new_socket_id != insert_at:
sockets.move(new_socket_id, insert_at)
insert_at += 1

def _update_extant_sockets(self, defs, sockets):
# Manually enumerate the sockets that are present for their presence and for the
Expand Down
Loading
Loading