Added Live Screenshot data functionality
This commit is contained in:
@ -3,12 +3,19 @@
|
||||
Flyff Character Status Node:
|
||||
- Creates an OCR region in data_collector.
|
||||
- Periodically grabs raw text from that region and updates status.
|
||||
- ALSO: Captures a screenshot from the same region, converts to base64,
|
||||
and updates data_manager so the Flask server can serve it.
|
||||
"""
|
||||
|
||||
import re
|
||||
import base64
|
||||
from io import BytesIO
|
||||
|
||||
from OdenGraphQt import BaseNode
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
from PyQt5.QtCore import QTimer # Corrected import
|
||||
|
||||
# Import the existing modules
|
||||
from Modules import data_manager, data_collector
|
||||
|
||||
class FlyffCharacterStatusNode(BaseNode):
|
||||
@ -29,7 +36,10 @@ class FlyffCharacterStatusNode(BaseNode):
|
||||
self.add_text_input("exp", "EXP", text="EXP: 0%")
|
||||
|
||||
self.region_id = "character_status"
|
||||
data_collector.create_ocr_region(self.region_id, x=250, y=50, w=180, h=130, color=(255, 255, 0), thickness=2)
|
||||
data_collector.create_ocr_region(
|
||||
self.region_id, x=250, y=50, w=180, h=130,
|
||||
color=(255, 255, 0), thickness=2
|
||||
)
|
||||
|
||||
data_collector.start_collector()
|
||||
self.set_name("Flyff - Character Status")
|
||||
@ -80,14 +90,14 @@ class FlyffCharacterStatusNode(BaseNode):
|
||||
|
||||
def process_input(self):
|
||||
"""
|
||||
Called periodically to update character status from OCR.
|
||||
Called periodically to update character status from OCR,
|
||||
and also capture the screenshot to display via Flask.
|
||||
"""
|
||||
# 1) Update the text-based status (same as before).
|
||||
raw_text = data_collector.get_raw_text(self.region_id)
|
||||
# print("Raw OCR Text:", raw_text) # Debugging OCR text reading
|
||||
|
||||
hp_c, hp_t, mp_c, mp_t, fp_c, fp_t, exp_v = self.parse_character_stats(raw_text)
|
||||
|
||||
# Update the data manager with the parsed values
|
||||
# Update data_manager with the parsed values
|
||||
data_manager.set_data_bulk({
|
||||
"hp_current": hp_c,
|
||||
"hp_total": hp_t,
|
||||
@ -103,3 +113,12 @@ class FlyffCharacterStatusNode(BaseNode):
|
||||
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}%")
|
||||
|
||||
# 2) Capture the screenshot used by OCR and store as base64
|
||||
screenshot_img = data_collector.capture_region_as_image(self.region_id)
|
||||
if screenshot_img:
|
||||
# Convert PIL image to base64
|
||||
buf = BytesIO()
|
||||
screenshot_img.save(buf, format='PNG')
|
||||
image_b64 = base64.b64encode(buf.getvalue()).decode('utf-8')
|
||||
data_manager.set_status_screenshot(image_b64)
|
||||
|
Reference in New Issue
Block a user