diff --git a/Nodes/__pycache__/flyff_EXP_current.cpython-312.pyc b/Nodes/__pycache__/flyff_EXP_current.cpython-312.pyc new file mode 100644 index 0000000..7e418f8 Binary files /dev/null and b/Nodes/__pycache__/flyff_EXP_current.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_FP_current.cpython-312.pyc b/Nodes/__pycache__/flyff_FP_current.cpython-312.pyc new file mode 100644 index 0000000..1a87d48 Binary files /dev/null and b/Nodes/__pycache__/flyff_FP_current.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_FP_total.cpython-312.pyc b/Nodes/__pycache__/flyff_FP_total.cpython-312.pyc new file mode 100644 index 0000000..0a32247 Binary files /dev/null and b/Nodes/__pycache__/flyff_FP_total.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_HP_current.cpython-312.pyc b/Nodes/__pycache__/flyff_HP_current.cpython-312.pyc new file mode 100644 index 0000000..e1b1f39 Binary files /dev/null and b/Nodes/__pycache__/flyff_HP_current.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_HP_total.cpython-312.pyc b/Nodes/__pycache__/flyff_HP_total.cpython-312.pyc new file mode 100644 index 0000000..f3fd74e Binary files /dev/null and b/Nodes/__pycache__/flyff_HP_total.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_MP_current.cpython-312.pyc b/Nodes/__pycache__/flyff_MP_current.cpython-312.pyc new file mode 100644 index 0000000..b7ecc9f Binary files /dev/null and b/Nodes/__pycache__/flyff_MP_current.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_MP_total.cpython-312.pyc b/Nodes/__pycache__/flyff_MP_total.cpython-312.pyc new file mode 100644 index 0000000..14fdfb4 Binary files /dev/null and b/Nodes/__pycache__/flyff_MP_total.cpython-312.pyc differ diff --git a/Nodes/__pycache__/flyff_character_status_node.cpython-312.pyc b/Nodes/__pycache__/flyff_character_status_node.cpython-312.pyc index d3efe3d..4921b72 100644 Binary files a/Nodes/__pycache__/flyff_character_status_node.cpython-312.pyc and b/Nodes/__pycache__/flyff_character_status_node.cpython-312.pyc differ diff --git a/Nodes/flyff_EXP_current.py b/Nodes/flyff_EXP_current.py new file mode 100644 index 0000000..1ab4591 --- /dev/null +++ b/Nodes/flyff_EXP_current.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Flyff EXP Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "exp" value as a string + - Uses color (48, 116, 143) for its output port + - Displays "exp" in a text field labeled "Value" + - Retrieves the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffEXPCurrentNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_exp_current_node' + NODE_NAME = 'Flyff - EXP' + + def __init__(self): + super(FlyffEXPCurrentNode, self).__init__() + + # 1) Text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Output port also named "value" + self.add_output('value', color=(48, 116, 143)) + + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + self.set_name("Flyff - EXP (API Disconnected)") + + def process_input(self): + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffEXPCurrentNode: HTTP Status Code = {status_code}") + + if status_code == 200: + try: + data = response.json() or {} + except ValueError: + data = {} + + if isinstance(data, list): + data = {} + + self._api_down = False + self.set_name("Flyff - EXP (API Connected)") + + new_value = data.get("exp", "N/A") + print(f"[DEBUG] FlyffEXPCurrentNode: exp = {new_value}") + + new_value_str = str(new_value) + self.set_property('value', new_value_str) + self.transmit_data(new_value_str) + + else: + self._handle_api_error(f"HTTP {status_code} from FlyffEXPCurrentNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffEXPCurrentNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - EXP (API Disconnected)") diff --git a/Nodes/flyff_FP_current.py b/Nodes/flyff_FP_current.py new file mode 100644 index 0000000..5e902c5 --- /dev/null +++ b/Nodes/flyff_FP_current.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Flyff FP Current Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "fp_current" value as a string + - Uses color (36, 116, 32) for its output port + - Displays "fp_current" in a text field labeled "Value" + - Retrieves the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffFPCurrentNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_fp_current_node' + NODE_NAME = 'Flyff - FP Current' + + def __init__(self): + super(FlyffFPCurrentNode, self).__init__() + + # 1) Text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Output port also named "value" + self.add_output('value', color=(36, 116, 32)) + + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + self.set_name("Flyff - FP Current (API Disconnected)") + + def process_input(self): + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffFPCurrentNode: HTTP Status Code = {status_code}") + + if status_code == 200: + try: + data = response.json() or {} + except ValueError: + data = {} + + if isinstance(data, list): + data = {} + + self._api_down = False + self.set_name("Flyff - FP Current (API Connected)") + + new_value = data.get("fp_current", "N/A") + print(f"[DEBUG] FlyffFPCurrentNode: fp_current = {new_value}") + + new_value_str = str(new_value) + self.set_property('value', new_value_str) + self.transmit_data(new_value_str) + + else: + self._handle_api_error(f"HTTP {status_code} from FlyffFPCurrentNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffFPCurrentNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - FP Current (API Disconnected)") diff --git a/Nodes/flyff_FP_total.py b/Nodes/flyff_FP_total.py new file mode 100644 index 0000000..61a0aa5 --- /dev/null +++ b/Nodes/flyff_FP_total.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Flyff FP Total Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "fp_total" value as a string + - Uses color (36, 116, 32) for its output port + - Displays "fp_total" in a text field labeled "Value" + - Retrieves the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffFPTotalNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_fp_total_node' + NODE_NAME = 'Flyff - FP Total' + + def __init__(self): + super(FlyffFPTotalNode, self).__init__() + + # 1) Text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Output port also named "value" + self.add_output('value', color=(36, 116, 32)) + + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + self.set_name("Flyff - FP Total (API Disconnected)") + + def process_input(self): + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffFPTotalNode: HTTP Status Code = {status_code}") + + if status_code == 200: + try: + data = response.json() or {} + except ValueError: + data = {} + + if isinstance(data, list): + data = {} + + self._api_down = False + self.set_name("Flyff - FP Total (API Connected)") + + new_value = data.get("fp_total", "N/A") + print(f"[DEBUG] FlyffFPTotalNode: fp_total = {new_value}") + + new_value_str = str(new_value) + self.set_property('value', new_value_str) + self.transmit_data(new_value_str) + + else: + self._handle_api_error(f"HTTP {status_code} from FlyffFPTotalNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffFPTotalNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - FP Total (API Disconnected)") diff --git a/Nodes/flyff_HP_current.py b/Nodes/flyff_HP_current.py new file mode 100644 index 0000000..5075d4d --- /dev/null +++ b/Nodes/flyff_HP_current.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +""" +Flyff HP Current Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "hp_current" value as a string + - Uses color (126, 36, 57) for its output port + - Displays "hp_current" in a text field labeled "Value" + - Avoids "list indices must be integers" by retrieving the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffHPCurrentNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_hp_current_node' + NODE_NAME = 'Flyff - HP Current' + + def __init__(self): + super(FlyffHPCurrentNode, self).__init__() + + # 1) Add a text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Add an output port also named "value" + self.add_output('value', color=(126, 36, 57)) + + # Start in "disconnected" state + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + # Default node title + self.set_name("Flyff - HP Current (API Disconnected)") + + def process_input(self): + """ + Called periodically by the global timer in borealis.py + """ + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffHPCurrentNode: HTTP Status Code = {status_code}") + + if status_code == 200: + # Attempt to parse JSON + try: + data = response.json() or {} + except ValueError: + data = {} + + # If data is a list, ignore or convert to {} + if isinstance(data, list): + data = {} + + # Mark node as connected + self._api_down = False + self.set_name("Flyff - HP Current (API Connected)") + + # Retrieve hp_current (default "N/A" if missing) + new_value = data.get("hp_current", "N/A") + print(f"[DEBUG] FlyffHPCurrentNode: hp_current = {new_value}") + + # Convert to string + new_value_str = str(new_value) + + # 3) Update the text input property so the user sees it + self.set_property('value', new_value_str) + + # 4) Transmit to downstream nodes + self.transmit_data(new_value_str) + + else: + # Non-200 => disconnected + self._handle_api_error(f"HTTP {status_code} from FlyffHPCurrentNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffHPCurrentNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + """ + Sends 'data' to any connected node via the "value" port. + (Uses self.outputs().get('value') instead of self.output('value')) + """ + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - HP Current (API Disconnected)") diff --git a/Nodes/flyff_HP_total.py b/Nodes/flyff_HP_total.py new file mode 100644 index 0000000..fc01a48 --- /dev/null +++ b/Nodes/flyff_HP_total.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Flyff HP Total Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "hp_total" value as a string + - Uses color (126, 36, 57) for its output port + - Displays "hp_total" in a text field labeled "Value" + - Retrieves the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffHPTotalNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_hp_total_node' + NODE_NAME = 'Flyff - HP Total' + + def __init__(self): + super(FlyffHPTotalNode, self).__init__() + + # 1) Text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Output port also named "value" + self.add_output('value', color=(126, 36, 57)) + + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + self.set_name("Flyff - HP Total (API Disconnected)") + + def process_input(self): + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffHPTotalNode: HTTP Status Code = {status_code}") + + if status_code == 200: + try: + data = response.json() or {} + except ValueError: + data = {} + + if isinstance(data, list): + data = {} + + self._api_down = False + self.set_name("Flyff - HP Total (API Connected)") + + new_value = data.get("hp_total", "N/A") + print(f"[DEBUG] FlyffHPTotalNode: hp_total = {new_value}") + + new_value_str = str(new_value) + self.set_property('value', new_value_str) + self.transmit_data(new_value_str) + + else: + self._handle_api_error(f"HTTP {status_code} from FlyffHPTotalNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffHPTotalNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - HP Total (API Disconnected)") diff --git a/Nodes/flyff_MP_current.py b/Nodes/flyff_MP_current.py new file mode 100644 index 0000000..bf74f05 --- /dev/null +++ b/Nodes/flyff_MP_current.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Flyff MP Current Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "mp_current" value as a string + - Uses color (35, 89, 144) for its output port + - Displays "mp_current" in a text field labeled "Value" + - Retrieves the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffMPCurrentNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_mp_current_node' + NODE_NAME = 'Flyff - MP Current' + + def __init__(self): + super(FlyffMPCurrentNode, self).__init__() + + # 1) Text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Output port also named "value" + self.add_output('value', color=(35, 89, 144)) + + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + self.set_name("Flyff - MP Current (API Disconnected)") + + def process_input(self): + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffMPCurrentNode: HTTP Status Code = {status_code}") + + if status_code == 200: + try: + data = response.json() or {} + except ValueError: + data = {} + + if isinstance(data, list): + data = {} + + self._api_down = False + self.set_name("Flyff - MP Current (API Connected)") + + new_value = data.get("mp_current", "N/A") + print(f"[DEBUG] FlyffMPCurrentNode: mp_current = {new_value}") + + new_value_str = str(new_value) + self.set_property('value', new_value_str) + self.transmit_data(new_value_str) + + else: + self._handle_api_error(f"HTTP {status_code} from FlyffMPCurrentNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffMPCurrentNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - MP Current (API Disconnected)") diff --git a/Nodes/flyff_MP_total.py b/Nodes/flyff_MP_total.py new file mode 100644 index 0000000..1f1cdcd --- /dev/null +++ b/Nodes/flyff_MP_total.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Flyff MP Total Node (Final Combined Version) + - Polls the API at http://127.0.0.1:5000/data + - Outputs only the "mp_total" value as a string + - Uses color (35, 89, 144) for its output port + - Displays "mp_total" in a text field labeled "Value" + - Retrieves the port with self.outputs().get('value') +""" + +import time +import requests +import traceback +from OdenGraphQt import BaseNode + +class FlyffMPTotalNode(BaseNode): + __identifier__ = 'bunny-lab.io.flyff_mp_total_node' + NODE_NAME = 'Flyff - MP Total' + + def __init__(self): + super(FlyffMPTotalNode, self).__init__() + + # 1) Text input property named "value" for UI display + self.add_text_input('value', 'Value', text='N/A') + + # 2) Output port also named "value" + self.add_output('value', color=(35, 89, 144)) + + self._api_down = True + self._last_api_attempt = 0.0 + self._retry_interval = 5.0 + self._last_error_printed = 0.0 + + self.set_name("Flyff - MP Total (API Disconnected)") + + def process_input(self): + current_time = time.time() + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time + + try: + response = requests.get("http://127.0.0.1:5000/data", timeout=1) + status_code = response.status_code + print(f"[DEBUG] FlyffMPTotalNode: HTTP Status Code = {status_code}") + + if status_code == 200: + try: + data = response.json() or {} + except ValueError: + data = {} + + if isinstance(data, list): + data = {} + + self._api_down = False + self.set_name("Flyff - MP Total (API Connected)") + + new_value = data.get("mp_total", "N/A") + print(f"[DEBUG] FlyffMPTotalNode: mp_total = {new_value}") + + new_value_str = str(new_value) + self.set_property('value', new_value_str) + self.transmit_data(new_value_str) + + else: + self._handle_api_error(f"HTTP {status_code} from FlyffMPTotalNode") + self._api_down = True + + except Exception as e: + tb = traceback.format_exc() + self._handle_api_error(f"Exception in FlyffMPTotalNode: {e}\nTraceback:\n{tb}") + self._api_down = True + + def transmit_data(self, data): + output_port = self.outputs().get('value') + if output_port and output_port.connected_ports(): + for connected_port in output_port.connected_ports(): + connected_node = connected_port.node() + if hasattr(connected_node, 'receive_data'): + try: + connected_node.receive_data(data, source_port_name='value') + except Exception as e: + print(f"[ERROR] Error transmitting data to {connected_node}: {e}") + + def _handle_api_error(self, msg): + current_time = time.time() + if (current_time - self._last_error_printed) >= self._retry_interval: + print(f"[ERROR] {msg}") + self._last_error_printed = current_time + + self.set_name("Flyff - MP Total (API Disconnected)") diff --git a/Nodes/flyff_character_status_node.py b/Nodes/flyff_character_status_node.py index 3b7ded2..d48e9dd 100644 --- a/Nodes/flyff_character_status_node.py +++ b/Nodes/flyff_character_status_node.py @@ -5,12 +5,18 @@ Standardized Flyff Character Status Node: - Polls an API for character stats and updates values dynamically. - Uses a global update timer for processing. - Immediately transmits updated values to connected nodes. + - If the API is unreachable, it will wait for 5 seconds before retrying + and log the error only once per retry period. + - Calls self.view.draw_node() after updating the node name, ensuring + the node's bounding box recalculates even when the API is disconnected. + - Port colors adjusted to match earlier styling. """ from OdenGraphQt import BaseNode from Qt import QtCore import requests import traceback +import time class FlyffCharacterStatusNode(BaseNode): __identifier__ = 'bunny-lab.io.flyff_character_status_node' @@ -19,19 +25,41 @@ class FlyffCharacterStatusNode(BaseNode): def __init__(self): super(FlyffCharacterStatusNode, self).__init__() self.values = { - "HP: Current": "N/A", "HP: Total": "N/A", - "MP: Current": "N/A", "MP: Total": "N/A", - "FP: Current": "N/A", "FP: Total": "N/A", - "EXP": "N/A" + "HP: Current": "N/A", + "HP: Total": "N/A", + "MP: Current": "N/A", + "MP: Total": "N/A", + "FP: Current": "N/A", + "FP: Total": "N/A", + "EXP": "N/A" } - for stat in self.values.keys(): - self.add_output(stat) + # Set each output with a custom color: + # (Choose values close to the screenshot for each port.) + self.add_output('HP: Current', color=(126, 36, 57)) + self.add_output('HP: Total', color=(126, 36, 57)) + self.add_output('MP: Current', color=(35, 89, 144)) + self.add_output('MP: Total', color=(35, 89, 144)) + self.add_output('FP: Current', color=(36, 116, 32)) + self.add_output('FP: Total', color=(36, 116, 32)) + self.add_output('EXP', color=(48, 116, 143)) self.set_name("Flyff - Character Status (API Disconnected)") - # Removed self-contained polling timer; global timer now drives updates. + self.view.draw_node() # ensure bounding box updates initially + + # Variables to handle API downtime gracefully: + self._api_down = False + self._last_api_attempt = 0 + self._retry_interval = 5 # seconds to wait before retrying after a failure + self._last_error_printed = 0 def process_input(self): + current_time = time.time() + # If the API is down, only retry after _retry_interval seconds + if self._api_down and (current_time - self._last_api_attempt < self._retry_interval): + return + + self._last_api_attempt = current_time try: response = requests.get("http://127.0.0.1:5000/data", timeout=1) if response.status_code == 200: @@ -39,12 +67,12 @@ class FlyffCharacterStatusNode(BaseNode): if isinstance(data, dict): mapping = { "hp_current": "HP: Current", - "hp_total": "HP: Total", + "hp_total": "HP: Total", "mp_current": "MP: Current", - "mp_total": "MP: Total", + "mp_total": "MP: Total", "fp_current": "FP: Current", - "fp_total": "FP: Total", - "exp": "EXP" + "fp_total": "FP: Total", + "exp": "EXP" } updated = False for key, value in data.items(): @@ -53,18 +81,32 @@ class FlyffCharacterStatusNode(BaseNode): if str(value) != self.values.get(formatted_key, None): self.values[formatted_key] = str(value) updated = True + self._api_down = False if updated: self.set_name("Flyff - Character Status (API Connected)") + self.view.draw_node() # recalc bounding box on connect self.transmit_data() else: - print("[ERROR] Unexpected API response format (not a dict):", data) + if current_time - self._last_error_printed >= self._retry_interval: + print("[ERROR] Unexpected API response format (not a dict):", data) + self._last_error_printed = current_time self.set_name("Flyff - Character Status (API Disconnected)") + self.view.draw_node() # recalc bounding box on disconnect + self._api_down = True else: - print(f"[ERROR] API request failed with status code {response.status_code}") + if current_time - self._last_error_printed >= self._retry_interval: + print(f"[ERROR] API request failed with status code {response.status_code}") + self._last_error_printed = current_time self.set_name("Flyff - Character Status (API Disconnected)") + self.view.draw_node() + self._api_down = True except Exception as e: + if current_time - self._last_error_printed >= self._retry_interval: + print("[ERROR] Error polling API in CharacterStatusNode:", str(e)) + self._last_error_printed = current_time self.set_name("Flyff - Character Status (API Disconnected)") - print("[ERROR] Error polling API in CharacterStatusNode:", str(e)) + self.view.draw_node() + self._api_down = True def transmit_data(self): for stat, value in self.values.items(): diff --git a/debug_processed.png b/debug_processed.png index 41a544d..5e945f8 100644 Binary files a/debug_processed.png and b/debug_processed.png differ diff --git a/debug_screenshot.png b/debug_screenshot.png index fb57647..9fe9c30 100644 Binary files a/debug_screenshot.png and b/debug_screenshot.png differ