代码拉取完成,页面将自动刷新
from Consts import *
from time import time, sleep
from traceback import extract_stack
from keyboard import add_hotkey
from threading import Thread
import pygetwindow
@Singleme
class GameManager(Thread):
def __init__(self, behaviors=None):
Thread.__init__(self)
self.cbs = []
self.fps = CLI_FPS
self.isRun = True
self.isRolling = True
self.startTime = time()
self.window = pygetwindow.getActiveWindow()
add_hotkey("q", self.destroy)
# add_hotkey("esc", self.destroy)
add_hotkey("space", self.toggle)
add_hotkey("r", self.resetRolling)
if behaviors:
for b in behaviors:
b.setHandler(self.onHandle)
self.cbs = behaviors
def __cb(self, *args, offset=0, name=None):
if name:
mname = name
else:
es = extract_stack()
mname = es[-2 - offset][2]
if mname:
for cb in self.cbs:
if hasattr(cb, mname):
cbf = getattr(cb, mname)
if callable(cbf):
cbf(*args)
def foo(self, bar='.zZ'):
self.__cb(bar)
def run(self):
lastTime = self.startTime
while self.isRun:
if self.isRolling:
self.__cb(name='update')
else:
if time() - lastTime > 1:
self.__cb(name='idle')
lastTime = time()
sleep(1 / self.fps)
def onHandle(self, what, msg=None):
if WHAT_TOGGLE_TOO_FAST == what:
self.isRolling = False
def add(self, behavior):
behavior.setHandler(self.onHandle)
self.cbs.append(behavior)
def clear(self):
self.cbs.clear()
def destroy(self):
if self.window and self.window.isActive and self.isRun:
self.__cb()
self.isRun = False
def toggle(self):
if self.window and self.window.isActive and self.isRun:
self.isRolling = not self.isRolling
self.__cb(self.isRolling)
def resetRolling(self):
if self.window and self.window.isActive:
self.isRolling = True
self.__cb()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。