Skip to content
Draft
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
170 changes: 170 additions & 0 deletions korman/nodes/node_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,176 @@ def simple_mode(self):
return (not self.is_linked and not self.is_output)


class PlasmaLinkEventNode(PlasmaNodeBase, bpy.types.Node):
bl_category = "CONDITIONS"
bl_idname = "PlasmaLinkEventNode"
bl_label = "Link Event"
bl_width_default = 320

trigger_for = EnumProperty(
name="Trigger For",
items=[
("Me", "Local Player", "Trigger only for the local player"),
("NPCs", "NPCs", "Trigger for NPCs (eg quabs)"),
("Player Avatars", "Player Avatars", "Trigger for player controlled avatars"),
("Everyone", "Everyone", "Trigger for all avatars"),
],
default="Me",
options=set()
)
trigger_on = EnumProperty(
name="Trigger On",
items=[
("Spawn", "Avatar Spawns", "Trigger when an avatar spawns"),
("Link", "Avatar Links", "Trigger when an avatar links"),
],
default="Spawn",
options=set()
)
trigger_direction = EnumProperty(
name="Trigger Direction",
items=[
("In", "In", "Trigger when the avatar links/spawns into the Age"),
("Out", "Out", "Trigger when the avatar links/spawns out of the Age"),
],
default="In",
options=set()
)
trigger_at = EnumProperty(
name="Trigger At",
items=[
("Start", "Event Start", "Trigger when the interesting event begins"),
("End", "Event End", "Trigger when the interesting event ends"),
],
default="Start",
options=set()
)

output_sockets: dict[str, dict[str, Any]] = {
"satisfies": {
"text": "Satisfies",
"type": "PlasmaConditionSocket",
"valid_link_sockets": {"PlasmaConditionSocket", "PlasmaPythonFileNodeSocket"},
},
}

def draw_buttons(self, context, layout):
combo = (self.trigger_for, self.trigger_on, self.trigger_direction)

layout.alert = combo == ("Me", "Spawn", "Out")
layout.prop(self, "trigger_for")
layout.alert = False

layout.prop(self, "trigger_on")
layout.prop(self, "trigger_direction")
layout.prop(self, "trigger_at")

def get_key(self, exporter: Exporter, so) -> plKey[plLogicModifier]:
return self._find_create_key(plLogicModifier, exporter, so=so)

def export(self, exporter: Exporter, bo, so) -> None:
combo = (self.trigger_for, self.trigger_on, self.trigger_direction)
if combo == ("Me", "Spawn", "Out"):
self.raise_error("Cannot trigger when the local player spawns out")

# There is no class in the engine that will fire when someone links in. There are messages,
# though, and they all get to Python in one way or another. So, to fire an event on link
# or spawn, we're going to use a helper script xLinkEventTrigger. It will send a notification
# to a kMultiTrigger LogicMod with a plActivatorActivatorConditionalObject. LMs forward
# all plNotifyMsgs to their conditions, and plAACO activates on any state==1.0 plNotifyMsg,
# assuming that the LogicMod is not already marked as triggered and all of the other conditions
# say that they're in a valid state. Once that LogicMod fires, anything we want can be fired
# off, like other PFMs or Responders. A potential optimization here is to avoid creation
# of the plAACO/plLM thunk if we only have responders attached.
activator = self._find_create_object(plActivatorActivatorConditionalObject, exporter, so=so)
logicmod = self._find_create_object(plLogicModifier, exporter, so=so)
logicmod.addCondition(activator.key)
logicmod.notify = self.generate_notify_msg(exporter, so, "satisfies")
logicmod.setLogicFlag(plLogicModifier.kMultiTrigger, True)
logicmod.setLogicFlag(plLogicModifier.kLocalElement, True)

pfm = self._find_create_object(plPythonFileMod, exporter, so=so)
self._add_py_parameter(pfm, 1, plPythonParameter.kResponder, logicmod.key)
self._add_py_parameter(pfm, 100, plPythonParameter.kString, f"{self.trigger_on} {self.trigger_direction}")
self._add_py_parameter(pfm, 101, plPythonParameter.kString, self.trigger_for)
self._add_py_parameter(pfm, 102, plPythonParameter.kString, self.trigger_at)
pfm.filename = "xLinkEventTrigger"

@property
def export_once(self):
return True


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"},
},
"satisfies_false": {
"text": "Trigger on False",
"type": "PlasmaConditionSocket",
"valid_link_nodes": {"PlasmaResponderNode"},
}
}

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))
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)
pfm.filename = "xAgeSDLBoolCondResp"

@property
def export_once(self):
return True


class PlasmaVolumeReportNode(PlasmaNodeBase, bpy.types.Node):
bl_category = "CONDITIONS"
bl_idname = "PlasmaVolumeReportNode"
Expand Down
48 changes: 36 additions & 12 deletions korman/nodes/node_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
from ..exporter import Exporter

class PlasmaNodeBase:
def _add_py_parameter(self, pfm: plPythonFileMod, id: int, param_type: int, value) -> None:
param = plPythonParameter()
param.id = id
param.valueType = param_type
param.value = value
pfm.addParameter(param)

def generate_notify_msg(self, exporter: Exporter, so: plSceneObject, socket_id: str, idname: Optional[str] = None) -> plNotifyMsg:
notify = plNotifyMsg()
notify.BCastFlags = (plMessage.kNetPropagate | plMessage.kLocalPropagate)
Expand Down Expand Up @@ -339,21 +346,38 @@ 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.
for i in range(len(working_sockets), num_sockets):
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)

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