asdf
This commit is contained in:
parent
75f68b1f59
commit
e25b04f8cb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -59,13 +59,13 @@ class CharacterStatusNode(BaseNode):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Add output ports
|
# Add output ports
|
||||||
self.add_output("HP: Current", painter_func=get_draw_stat_port((255, 0, 0)))
|
self.add_output("HP: Current", painter_func=get_draw_stat_port((217, 36, 78)))
|
||||||
self.add_output("HP: Total", painter_func=get_draw_stat_port((255, 0, 0)))
|
self.add_output("HP: Total", painter_func=get_draw_stat_port((217, 36, 78)))
|
||||||
self.add_output("MP: Current", painter_func=get_draw_stat_port((0, 0, 255)))
|
self.add_output("MP: Current", painter_func=get_draw_stat_port((35, 124, 213)))
|
||||||
self.add_output("MP: Total", painter_func=get_draw_stat_port((0, 0, 255)))
|
self.add_output("MP: Total", painter_func=get_draw_stat_port((35, 124, 213)))
|
||||||
self.add_output("FP: Current", painter_func=get_draw_stat_port((0, 255, 0)))
|
self.add_output("FP: Current", painter_func=get_draw_stat_port((36, 197, 28)))
|
||||||
self.add_output("FP: Total", painter_func=get_draw_stat_port((0, 255, 0)))
|
self.add_output("FP: Total", painter_func=get_draw_stat_port((36, 197, 28)))
|
||||||
self.add_output("EXP", painter_func=get_draw_stat_port((127, 255, 212)))
|
self.add_output("EXP", painter_func=get_draw_stat_port((52, 195, 250)))
|
||||||
|
|
||||||
self.set_name("Character Status (API Disconnected)")
|
self.set_name("Character Status (API Disconnected)")
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
"""
|
"""
|
||||||
Convert to Percent Node
|
Convert to Percent Node
|
||||||
|
|
||||||
This node takes an input string formatted as "numerator/denom" (e.g., "50/50"),
|
This node takes two numerical inputs (A and B), computes (A / B) * 100,
|
||||||
splits it into two numbers, computes (numerator / denom) * 100, and outputs the result
|
and outputs the result as a float formatted to 4 decimal places. If an error
|
||||||
as a float formatted to 4 decimal places. If an error occurs, an error message is stored.
|
occurs, an error message is stored. The node's title is always "Convert to Percent".
|
||||||
The node's title is always "Convert to Percent".
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from NodeGraphQt import BaseNode
|
from NodeGraphQt import BaseNode
|
||||||
@ -17,8 +16,9 @@ class ConvertToPercentNode(BaseNode):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ConvertToPercentNode, self).__init__()
|
super(ConvertToPercentNode, self).__init__()
|
||||||
# Add one input port (expects a string in "numerator/denom" format).
|
# Add two input ports for separate numerator and denominator.
|
||||||
self.add_input("in")
|
self.add_input("Numerator")
|
||||||
|
self.add_input("Denominator")
|
||||||
# Add one output port.
|
# Add one output port.
|
||||||
self.add_output("Percent")
|
self.add_output("Percent")
|
||||||
# Initialize internal value.
|
# Initialize internal value.
|
||||||
@ -29,34 +29,37 @@ class ConvertToPercentNode(BaseNode):
|
|||||||
self.values = {}
|
self.values = {}
|
||||||
|
|
||||||
def process_input(self):
|
def process_input(self):
|
||||||
input_port = self.input(0)
|
numerator_input = self.input(0)
|
||||||
connected_ports = input_port.connected_ports() if input_port is not None else []
|
denominator_input = self.input(1)
|
||||||
if connected_ports:
|
|
||||||
connected_output = connected_ports[0]
|
numerator = self.get_connected_value(numerator_input)
|
||||||
parent_node = connected_output.node()
|
denominator = self.get_connected_value(denominator_input)
|
||||||
port_name = connected_output.name()
|
|
||||||
# Use parent's values dictionary if available, else use its value attribute.
|
try:
|
||||||
if hasattr(parent_node, 'values') and isinstance(parent_node.values, dict):
|
numerator = float(numerator)
|
||||||
input_value = parent_node.values.get(port_name, "")
|
denominator = float(denominator)
|
||||||
else:
|
if denominator == 0:
|
||||||
input_value = getattr(parent_node, 'value', "")
|
raise ZeroDivisionError("Division by zero")
|
||||||
input_str = str(input_value).strip()
|
percent = (numerator / denominator) * 100
|
||||||
try:
|
formatted_percent = f"{percent:.4f}"
|
||||||
parts = input_str.split('/')
|
self.value = formatted_percent
|
||||||
if len(parts) != 2:
|
except Exception as e:
|
||||||
raise ValueError("Input must be in the format 'num/denom'")
|
self.value = f"Error: {e}"
|
||||||
numerator = float(parts[0].strip())
|
|
||||||
denominator = float(parts[1].strip())
|
|
||||||
if denominator == 0:
|
|
||||||
raise ZeroDivisionError("Division by zero")
|
|
||||||
percent = (numerator / denominator) * 100
|
|
||||||
formatted_percent = f"{percent:.4f}"
|
|
||||||
self.value = formatted_percent
|
|
||||||
except Exception as e:
|
|
||||||
self.value = f"Error: {e}"
|
|
||||||
else:
|
|
||||||
self.value = "No Input"
|
|
||||||
# Always keep the title static.
|
# Always keep the title static.
|
||||||
self.set_name(self.NODE_NAME)
|
self.set_name(self.NODE_NAME)
|
||||||
# Store the computed value in the values dictionary under the output port key.
|
# Store the computed value in the values dictionary under the output port key.
|
||||||
self.values["Percent"] = self.value
|
self.values["Percent"] = self.value
|
||||||
|
|
||||||
|
def get_connected_value(self, input_port):
|
||||||
|
"""
|
||||||
|
Helper function to retrieve the value from a connected port.
|
||||||
|
"""
|
||||||
|
if input_port and input_port.connected_ports():
|
||||||
|
connected_output = input_port.connected_ports()[0]
|
||||||
|
parent_node = connected_output.node()
|
||||||
|
port_name = connected_output.name()
|
||||||
|
if hasattr(parent_node, 'values') and isinstance(parent_node.values, dict):
|
||||||
|
return parent_node.values.get(port_name, "0")
|
||||||
|
return getattr(parent_node, 'value', "0")
|
||||||
|
return "0"
|
||||||
|
@ -30,7 +30,7 @@ class DataNode(BaseNode):
|
|||||||
self.add_text_input('value', 'Value', text='')
|
self.add_text_input('value', 'Value', text='')
|
||||||
# Initialize the value from the widget property.
|
# Initialize the value from the widget property.
|
||||||
self.process_widget_event()
|
self.process_widget_event()
|
||||||
self.set_name(f"Data Node: {self.value}")
|
self.set_name(f"Data Node")
|
||||||
|
|
||||||
def post_create(self):
|
def post_create(self):
|
||||||
"""
|
"""
|
||||||
@ -50,7 +50,7 @@ class DataNode(BaseNode):
|
|||||||
"""
|
"""
|
||||||
current_text = self.get_property('value')
|
current_text = self.get_property('value')
|
||||||
self.value = current_text
|
self.value = current_text
|
||||||
self.set_name(f"Data Node: {self.value}")
|
self.set_name(f"Data Node")
|
||||||
|
|
||||||
def property_changed(self, property_name):
|
def property_changed(self, property_name):
|
||||||
"""
|
"""
|
||||||
@ -113,9 +113,8 @@ class DataNode(BaseNode):
|
|||||||
"""
|
"""
|
||||||
Receives data from connected nodes and updates the internal value.
|
Receives data from connected nodes and updates the internal value.
|
||||||
"""
|
"""
|
||||||
print(f"DataNode received data from {source_port_name}: {data}") # Debugging
|
|
||||||
self.set_property('value', str(data)) # Ensure it's always stored as a string
|
self.set_property('value', str(data)) # Ensure it's always stored as a string
|
||||||
self.set_name(f"Data Node: {data}")
|
self.set_name(f"Data Node")
|
||||||
|
|
||||||
# Transmit data further if there's an output connection
|
# Transmit data further if there's an output connection
|
||||||
output_port = self.output(0)
|
output_port = self.output(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user