Journal update to check for save_progress.oneshot and display the note

This commit is contained in:
KockaAdmiralac 2018-03-10 23:03:55 +01:00
parent 4fd06b9a82
commit 3f4f14e719
1 changed files with 34 additions and 17 deletions

View File

@ -6,8 +6,15 @@ from PyQt5.QtCore import Qt, QEvent, QThread, pyqtSignal, QRect, QRectF, QTimer,
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget, QLabel from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget, QLabel
from PyQt5.QtGui import QIcon, QPixmap, QPainter from PyQt5.QtGui import QIcon, QPixmap, QPainter
if sys.platform == "win32": pipe_path = '\\\\.\\pipe\\oneshot-journal-to-game' if sys.platform == "win32":
else: pipe_path = '/tmp/oneshot-pipe' pipe_path = '\\\\.\\pipe\\oneshot-journal-to-game'
import ctypes.wintypes
buff = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
ctypes.windll.shell32.SHGetFolderPathW(None, CSIDL_PERSONAL, None, SHGFP_TYPE_CURRENT, buf)
documents_path = os.path.join(buf.value, 'My Games')
else:
pipe_path = '/tmp/oneshot-pipe'
documents_path = os.path.expanduser('~/Documents')
try: base_path = sys._MEIPASS try: base_path = sys._MEIPASS
except AttributeError: base_path = os.path.abspath('.') except AttributeError: base_path = os.path.abspath('.')
@ -20,12 +27,12 @@ class WatchPipe(QThread):
while True: while True:
if os.path.exists(pipe_path): break if os.path.exists(pipe_path): break
else: time.sleep(0.1) else: time.sleep(0.1)
pipe = open(pipe_path, 'r') pipe = open(pipe_path, 'r')
pipe.flush() pipe.flush()
while True: while True:
if not os.path.exists(pipe_path): break # Handle game quitting cleanup if not os.path.exists(pipe_path):
break # Handle game quitting cleanup
message = os.read(pipe.fileno(), 256) message = os.read(pipe.fileno(), 256)
if len(message) > 0: if len(message) > 0:
self.change_image.emit(message.decode()) self.change_image.emit(message.decode())
@ -74,9 +81,10 @@ class Journal(QWidget):
def change_image(self, image): def change_image(self, image):
name, lang = image.split('_', 1) name, lang = image.split('_', 1)
img = os.path.join(base_path, 'images', lang.upper(), '{}.png'.format(name)) if lang == 'en':
if not os.path.exists(img):
img = os.path.join(base_path, 'images', '{}.png'.format(name)) img = os.path.join(base_path, 'images', '{}.png'.format(name))
else:
img = os.path.join(base_path, 'images', lang.upper(), '{}.png'.format(name))
if not os.path.exists(img): return if not os.path.exists(img): return
self.pixmap = QPixmap(img) self.pixmap = QPixmap(img)
self.label.setPixmap(self.pixmap) self.label.setPixmap(self.pixmap)
@ -132,7 +140,16 @@ if __name__ == '__main__':
else: else:
# Author's Journal mode # Author's Journal mode
journal = Journal() journal = Journal()
save_path = os.path.join(documents_path, 'Oneshot', 'save_progress.oneshot')
if os.path.exists(save_path):
with open(save_path, 'rb') as save:
save.seek(-8, os.SEEK_END)
lang = save.read().decode('utf-8')
lang = lang[lang.find('[') + 1:lang.find(']')]
if lang == 'en_US':
lang = 'en'
journal.change_image('save_' + lang)
else:
thread = WatchPipe() thread = WatchPipe()
thread.change_image.connect(journal.change_image) thread.change_image.connect(journal.change_image)
thread.start() thread.start()