Added Live Screenshot data functionality
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# Modules/data_manager.py
|
||||
import threading
|
||||
import time
|
||||
from flask import Flask, jsonify
|
||||
import base64
|
||||
from flask import Flask, jsonify, Response
|
||||
from PyQt5.QtCore import QMutex
|
||||
|
||||
# Global datastore for character metrics
|
||||
@ -21,6 +21,9 @@ data_mutex = QMutex()
|
||||
# Flag to ensure only one character status collector node exists
|
||||
character_status_collector_exists = False
|
||||
|
||||
# A place to store the screenshot in base64
|
||||
status_screenshot_base64 = ""
|
||||
|
||||
# Flask Application
|
||||
app = Flask(__name__)
|
||||
|
||||
@ -68,6 +71,47 @@ def fp_api():
|
||||
"fp_total": get_data()["fp_total"]
|
||||
})
|
||||
|
||||
@app.route('/status_screenshot')
|
||||
def status_screenshot():
|
||||
"""
|
||||
Returns an HTML page that displays the stored screenshot and
|
||||
automatically refreshes it every second without requiring a manual page reload.
|
||||
"""
|
||||
html = """
|
||||
<html>
|
||||
<head>
|
||||
<title>Live Flyff Character Status</title>
|
||||
<script>
|
||||
// Reload the <img> every second
|
||||
setInterval(function(){
|
||||
var img = document.getElementById('status_img');
|
||||
img.src = '/status_screenshot_data?random=' + Math.random();
|
||||
}, 1000);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<img id="status_img" src="/status_screenshot_data" />
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
return html
|
||||
|
||||
@app.route('/status_screenshot_data')
|
||||
def status_screenshot_data():
|
||||
"""
|
||||
Serves the raw PNG bytes (decoded from base64) used by <img> in /status_screenshot.
|
||||
"""
|
||||
data_mutex.lock()
|
||||
encoded = status_screenshot_base64
|
||||
data_mutex.unlock()
|
||||
|
||||
if not encoded:
|
||||
# No image captured yet, return HTTP 204 "No Content"
|
||||
return "", 204
|
||||
|
||||
raw_img = base64.b64decode(encoded)
|
||||
return Response(raw_img, mimetype='image/png')
|
||||
|
||||
def start_api_server():
|
||||
"""
|
||||
Starts the Flask API server in a separate daemon thread.
|
||||
@ -101,3 +145,12 @@ def set_data_bulk(metrics_dict):
|
||||
data_mutex.lock()
|
||||
data_store.update(metrics_dict)
|
||||
data_mutex.unlock()
|
||||
|
||||
def set_status_screenshot(encoded_str):
|
||||
"""
|
||||
Called by the OCR node to store the base64-encoded screenshot data.
|
||||
"""
|
||||
global status_screenshot_base64
|
||||
data_mutex.lock()
|
||||
status_screenshot_base64 = encoded_str
|
||||
data_mutex.unlock()
|
||||
|
Reference in New Issue
Block a user