Fixed On-Screen OCR region Overlay

This commit is contained in:
2025-02-16 21:07:26 -07:00
parent e30ba4ec4f
commit 6888b55612
5 changed files with 108 additions and 131 deletions

View File

@ -1,46 +1,44 @@
#!/usr/bin/env python3
"""
Flyff Character Status Node (New Version):
- Has no inputs/outputs.
- Creates an OCR region in data_collector.
- Periodically grabs raw text from that region, parses it here in the node,
and sets data_manager's HP, MP, FP, EXP accordingly.
- Also updates its own text fields with the parsed values.
Flyff Character Status Node:
- Creates an OCR region in data_collector.
- Periodically grabs raw text from that region and updates status.
"""
import re
from OdenGraphQt import BaseNode
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtCore import QTimer # Corrected import
from Modules import data_manager, data_collector
class FlyffCharacterStatusNode(BaseNode):
__identifier__ = 'bunny-lab.io.flyff_character_status_node'
NODE_NAME = 'Flyff - Character Status'
__identifier__ = "bunny-lab.io.flyff_character_status_node"
NODE_NAME = "Flyff - Character Status"
def __init__(self):
super(FlyffCharacterStatusNode, self).__init__()
# Prevent duplicates
if data_manager.character_status_collector_exists:
QMessageBox.critical(None, "Error", "Only one Flyff Character Status Collector node is allowed.")
raise Exception("Duplicate Character Status Node.")
data_manager.character_status_collector_exists = True
# Add text fields for display
self.add_text_input('hp', 'HP', text="HP: 0/0")
self.add_text_input('mp', 'MP', text="MP: 0/0")
self.add_text_input('fp', 'FP', text="FP: 0/0")
self.add_text_input('exp', 'EXP', text="EXP: 0%")
self.add_text_input("hp", "HP", text="HP: 0/0")
self.add_text_input("mp", "MP", text="MP: 0/0")
self.add_text_input("fp", "FP", text="FP: 0/0")
self.add_text_input("exp", "EXP", text="EXP: 0%")
# Create a unique region id for this node (or just "character_status")
self.region_id = "character_status"
data_collector.create_ocr_region(self.region_id, x=250, y=50, w=180, h=130)
# Start the data_collector background thread (if not already started)
data_collector.start_collector()
# Set the node name
self.set_name("Flyff - Character Status")
# Set up a timer to periodically update character stats
self.timer = QTimer()
self.timer.timeout.connect(self.process_input)
self.timer.start(1000) # Update every second
def parse_character_stats(self, raw_text):
"""
Extract HP, MP, FP, EXP from the raw OCR text lines.
@ -52,6 +50,8 @@ class FlyffCharacterStatusNode(BaseNode):
exp_value = 0.0
if len(lines) >= 4:
print("Processing OCR Lines:", lines) # Debugging output
# line 1: HP
hp_match = re.search(r"(\d+)\s*/\s*(\d+)", lines[0])
if hp_match:
@ -82,15 +82,14 @@ class FlyffCharacterStatusNode(BaseNode):
def process_input(self):
"""
Called periodically by the global timer in your main application (borealis.py).
Called periodically to update character status from OCR.
"""
# Grab raw text from data_collector
raw_text = data_collector.get_raw_text(self.region_id)
print("Raw OCR Text:", raw_text) # Debugging OCR text reading
# Parse it
hp_c, hp_t, mp_c, mp_t, fp_c, fp_t, exp_v = self.parse_character_stats(raw_text)
# Update data_manager
# Update the data manager with the parsed values
data_manager.set_data_bulk({
"hp_current": hp_c,
"hp_total": hp_t,
@ -101,8 +100,8 @@ class FlyffCharacterStatusNode(BaseNode):
"exp": exp_v
})
# Update the node's text fields
self.set_property('hp', f"HP: {hp_c}/{hp_t}")
self.set_property('mp', f"MP: {mp_c}/{mp_t}")
self.set_property('fp', f"FP: {fp_c}/{fp_t}")
self.set_property('exp', f"EXP: {exp_v}%")
# Update the node's UI text fields
self.set_property("hp", f"HP: {hp_c}/{hp_t}")
self.set_property("mp", f"MP: {mp_c}/{mp_t}")
self.set_property("fp", f"FP: {fp_c}/{fp_t}")
self.set_property("exp", f"EXP: {exp_v}%")