implement demo player backend

This commit is contained in:
cidoku 2025-03-10 01:05:03 -03:00
parent b427621690
commit 5122e83a7e

View File

@ -3627,7 +3627,6 @@ class gui(QtGui.QWidget):
self.onImportEvidence(True)
#thread.start_new_thread(self.tcp_thread, ())
self.tcpthread = TCP_Thread(self)
self.tcpthread.MS_Chat.connect(self.netmsg_ms)
self.tcpthread.newChar.connect(self.onPVPacket)
@ -3642,6 +3641,21 @@ class gui(QtGui.QWidget):
self.tcpthread.timerUpdate.connect(self.start_pause_timers)
self.tcpthread.start()
# self.demoplayer = DemoPlayer(self)
# self.demoplayer.MS_Chat.connect(self.netmsg_ms)
# self.demoplayer.newChar.connect(self.onPVPacket)
# self.demoplayer.newBackground.connect(self.setBackground)
# self.demoplayer.OOC_Log.connect(self.ooclog.append)
# self.demoplayer.IC_Log.connect(self.icLog.append)
# self.demoplayer.charSlots.connect(partial(self.charselect.setCharList, self.charlist))
# self.demoplayer.showCharSelect.connect(self.charselect.showCharSelect)
# self.demoplayer.allEvidence.connect(self.allEvidence)
# self.demoplayer.updatePlayerList.connect(self.updatePlayerList)
# self.demoplayer.rainbowColor.connect(self.text.setStyleSheet)
# self.demoplayer.timerUpdate.connect(self.start_pause_timers)
# self.demoplayer.load_demo('test.demo')
# self.demoplayer.step()
self.icchatinput.setFocus()
class TCP_Thread(QtCore.QThread):
@ -3724,7 +3738,56 @@ class TCP_Thread(QtCore.QThread):
self.send_attempts = 0
handle_packets(self, total)
class DemoPlayer(QtCore.QObject):
connectionError = QtCore.pyqtSignal(str, str, str)
MS_Chat = QtCore.pyqtSignal(list)
newChar = QtCore.pyqtSignal(str)
newBackground = QtCore.pyqtSignal(str, bool)
IC_Log = QtCore.pyqtSignal(str)
OOC_Log = QtCore.pyqtSignal(str)
charSlots = QtCore.pyqtSignal()
showCharSelect = QtCore.pyqtSignal()
allEvidence = QtCore.pyqtSignal(list)
rainbowColor = QtCore.pyqtSignal(str)
updatePlayerList = QtCore.pyqtSignal(str, int, int, str)
timerUpdate = QtCore.pyqtSignal(int, int, int)
def __init__(self, parent):
super(DemoPlayer, self).__init__(parent)
self.parent = parent
self.paused = False
self.demo = []
self.demo_length = len(self.demo)
self.index = 0
self.wait_timer = QtCore.QTimer(self)
self.wait_timer.setSingleShot(True)
self.wait_timer.timeout.connect(self.timer_done)
def step(self):
packet = self.demo[self.index]
self.index += 1
print packet
if packet[0] == "wait":
self.wait_timer.start(int(packet[1]))
else:
handle_packets(self, [packet])
self.step()
def load_demo(self, file='test.demo'):
last_line = ""
self.demo = []
with open(file) as f:
for line in f:
last_line = last_line + line
if last_line.strip()[-1] == "%":
self.demo.append(last_line.split("#")[:-1])
last_line = ""
self.demo_length = len(self.demo)
def timer_done(self):
self.step()
def handle_packets(caller, total):
for network in total:
header = network[0]