-
Notifications
You must be signed in to change notification settings - Fork 704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exec.py discussion #5607
Comments
This (and honestly the |
|
This is a zip archive (with the extension https://github.com/renpy/renpy/blob/master/renpy/main.py#L148-L156 |
It's a bit too footgun, so instead we'll use .rpe.py files to inject the same thing. See the discussion in #5607.
I've removed exec.py from the core engine, and put it into a .rpe.py file. (That's a new feature - .rpe.py files work like .rpes, but don't need zipping up.) The .rpe/.rpe.py files are re-run each time Ren'Py reloads, so you can make the signal you need. Here's the file: import renpy
import time
import os
import threading
# The path to the exec.py file, if it exists.
exec_py_exists = False
# The thread that scans for exec_py.
exec_py_thread = None
# The delay between exec_py scans.
exec_py_delay = 0.1
# Should the thread keep running?
run_scan_thread = True
def run_exec_py():
global exec_py_exists
if exec_py_exists:
exec_py_path = os.path.join(renpy.config.basedir, "exec.py")
try:
with open(exec_py_path, "r") as f:
text = f.read()
except Exception as e:
exec_py_exists = False
return
try:
os.unlink(exec_py_path)
exec_py_exists = False
except Exception as e:
renpy.display.log.write("Failed to remove exec.py:")
renpy.display.log.exception()
return
renpy.python.py_exec(text)
def scan_exec_py():
global exec_py_exists
while run_scan_thread:
time.sleep(.1)
exec_py_path = os.path.join(renpy.config.basedir, "exec.py")
if os.path.exists(exec_py_path) and not exec_py_exists:
exec_py_exists = True
renpy.exports.invoke_in_main_thread(run_exec_py)
def end_scan_thread():
global exec_py_thread
global run_scan_thread
run_scan_thread = False
if exec_py_thread:
exec_py_thread.join()
exec_py_thread = None
renpy.config.quit_callbacks.append(end_scan_thread)
exec_py_thread = threading.Thread(target=scan_exec_py)
exec_py_thread.daemon = True
exec_py_thread.start() |
On topic of the issue itself, I think what I was looking for was |
going to close this as i've had success replacing the functionality i need with |
I have a need to detect when the game autoreloads so that I can inject some code with exec.py to communicate between Ren'Py and my Visual Studio Code extension. Since this is a development aid, I don't want to ask people to add this code to the game themselves.
Currently I'm using the string
Resetting cache.
to detect restarts, but this does not seem very reliable, being prone to false positives or being pulled entirely in a future update of Ren'Py.renpy/renpy/display/im.py
Line 2149 in d3de140
If there was a way to provide this, either as something outputted natively by Ren'Py or something that's configurable that works fine for this use case.
Thanks!
The text was updated successfully, but these errors were encountered: