mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 13:29:54 +00:00
Let journal reimplementation accommodate for new API updates
This commit is contained in:
parent
3b54638cfc
commit
53709a92c7
1 changed files with 30 additions and 10 deletions
|
|
@ -48,11 +48,28 @@ class WatchPipe(QThread):
|
|||
|
||||
class AnimationTimer(QThread):
|
||||
next_frame = pyqtSignal()
|
||||
start_animation = pyqtSignal(int, int)
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.next_frame.emit()
|
||||
time.sleep(1.0 / 60)
|
||||
while not os.path.exists(pipe_path): time.sleep(0.1)
|
||||
|
||||
pipe = open(pipe_path, 'r')
|
||||
pipe.flush()
|
||||
|
||||
while os.path.exists(pipe_path): # Make sure the file still exists and wasn't cleaned up by SyngleChance
|
||||
message = os.read(pipe.fileno(), 256)
|
||||
if len(message) > 0:
|
||||
m = message.decode()
|
||||
if not "," in m: pass
|
||||
x, y = m.split(",")
|
||||
self.start_animation.emit(int(x), int(y))
|
||||
|
||||
while True:
|
||||
self.next_frame.emit()
|
||||
time.sleep(1.0 / 60)
|
||||
|
||||
time.sleep(0.05)
|
||||
|
||||
class Journal(QWidget):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
@ -114,9 +131,9 @@ class Journal(QWidget):
|
|||
|
||||
class Niko(QWidget):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.x, self.y, self.start_y, self.app, self.thread = kwargs['x'], kwargs['y'], kwargs['y'], kwargs['app'], kwargs['thread']
|
||||
self.app, self.thread = kwargs['app'], kwargs['thread']
|
||||
self.screen_height = kwargs['screen_height']
|
||||
del kwargs['x'], kwargs['y'], kwargs['screen_height'], kwargs['app'], kwargs['thread']
|
||||
del kwargs['screen_height'], kwargs['app'], kwargs['thread']
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
|
@ -129,9 +146,12 @@ class Niko(QWidget):
|
|||
self.frames = [QPixmap(os.path.join(base_path, 'images', 'niko{}.png'.format(n))) for n in range(1,4)]
|
||||
self.label.setPixmap(self.frames[1])
|
||||
|
||||
self.show()
|
||||
def start(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.start_y = y
|
||||
|
||||
self.thread.start()
|
||||
self.show()
|
||||
|
||||
def getFrame(self):
|
||||
if ((self.y - self.start_y) % 32 >= 16): return 1
|
||||
|
|
@ -152,15 +172,15 @@ class Niko(QWidget):
|
|||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
if len(sys.argv) == 3:
|
||||
if len(sys.argv) == 2 and sys.argv[1] == "niko":
|
||||
# "Niko-leaves-the-screen" mode
|
||||
x, y = int(sys.argv[1]), int(sys.argv[2])
|
||||
|
||||
thread = AnimationTimer()
|
||||
|
||||
niko = Niko(x = x, y = y, screen_height = app.primaryScreen().size().height(), app = app, thread = thread)
|
||||
niko = Niko(screen_height = app.primaryScreen().size().height(), app = app, thread = thread)
|
||||
|
||||
thread.start_animation.connect(niko.start)
|
||||
thread.next_frame.connect(niko.update)
|
||||
thread.start()
|
||||
|
||||
else:
|
||||
# Author's Journal mode
|
||||
|
|
|
|||
Loading…
Reference in a new issue