add demo recording
This commit is contained in:
parent
1329fb223f
commit
81e71bccb8
31
demo.py
31
demo.py
@ -1,4 +1,5 @@
|
|||||||
import ini, packets
|
import ini, packets
|
||||||
|
import os, time
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
from bisect import bisect_left
|
from bisect import bisect_left
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ class DemoPlayer(QtCore.QObject):
|
|||||||
def step(self, skip_wait=False):
|
def step(self, skip_wait=False):
|
||||||
if self.time >= self.demo_length:
|
if self.time >= self.demo_length:
|
||||||
self.time = 0
|
self.time = 0
|
||||||
|
return
|
||||||
|
|
||||||
packet = self.demo[self.time]
|
packet = self.demo[self.time]
|
||||||
self.parent.demoslider.blockSignals(True)
|
self.parent.demoslider.blockSignals(True)
|
||||||
@ -134,18 +136,29 @@ class DemoPlayer(QtCore.QObject):
|
|||||||
class DemoRecorder():
|
class DemoRecorder():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.demofile = None
|
self.demofile = None
|
||||||
self.savedemo = False
|
self.lasttime = 0
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.savedemo = ini.read_ini_bool("AO2XP.ini", "General", "record demos", False)
|
if not os.path.exists("logs"):
|
||||||
|
|
||||||
if not exists("logs"):
|
|
||||||
os.mkdir("logs")
|
os.mkdir("logs")
|
||||||
|
|
||||||
currtime = time.localtime()
|
currtime = time.localtime()
|
||||||
self.demofile = "logs/%d%-2d%-2d %.2d.%.2d.%.2d.txt" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
self.lasttime = time.time() * 1000
|
||||||
|
self.demofile = "logs/%d-%02d-%02d %02d.%02d.%02d.demo" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
||||||
|
|
||||||
|
def record(self, packet, encode=False):
|
||||||
|
if packet[0][0] in ["FM", "ARUP", "CharsCheck"]:
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(self.demofile, "a") as demofile:
|
||||||
|
currtime = time.time() * 1000
|
||||||
|
diff = currtime - self.lasttime
|
||||||
|
self.lasttime = currtime
|
||||||
|
demofile.write(("wait#%d#%%" % diff) + "\n")
|
||||||
|
|
||||||
|
line = "#".join(packet[0]) + "#%\n"
|
||||||
|
print packet[0][0]
|
||||||
|
if encode:
|
||||||
|
line = line.encode('utf-8')
|
||||||
|
demofile.write(line)
|
||||||
|
|
||||||
def record(self, packet):
|
|
||||||
if self.savedemo:
|
|
||||||
with open(self.demofile, "a") as demofile:
|
|
||||||
demofile.write("#".join(packet[0])+"#%\n")
|
|
21
gameview.py
21
gameview.py
@ -210,12 +210,12 @@ class ChatLogs(QtGui.QTextEdit):
|
|||||||
if self.type == 0:
|
if self.type == 0:
|
||||||
self.logfile = logfile
|
self.logfile = logfile
|
||||||
else:
|
else:
|
||||||
self.logfile = "logs/%d%.2d%.2d_on_%.2d.%.2d.%.2d.txt" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
self.logfile = "logs/%d-%02d-%02d %02d.%02d.%02d.log" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
||||||
else:
|
else:
|
||||||
if self.type == 0:
|
if self.type == 0:
|
||||||
self.logfile = "logs/IC_%d%.2d%.2d_on_%.2d.%.2d.%.2d.txt" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
self.logfile = "logs/IC_%d-%02d-%02d %02d.%02d.%02d.log" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
||||||
else:
|
else:
|
||||||
self.logfile = "logs/OOC_%d%.2d%.2d_on_%.2d.%.2d.%.2d.txt" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
self.logfile = "logs/OOC_%d-%02d-%02d %02d.%02d.%02d.log" % (currtime[0], currtime[1], currtime[2], currtime[3], currtime[4], currtime[5])
|
||||||
else:
|
else:
|
||||||
self.logfile = None
|
self.logfile = None
|
||||||
|
|
||||||
@ -311,6 +311,9 @@ class AOCharMovie(QtGui.QLabel):
|
|||||||
self.m_flipped = flip
|
self.m_flipped = flip
|
||||||
|
|
||||||
def play(self, p_char, p_emote, emote_prefix, scaling = SCALING_AUTO, single_frame_duration = -1):
|
def play(self, p_char, p_emote, emote_prefix, scaling = SCALING_AUTO, single_frame_duration = -1):
|
||||||
|
if not len(p_emote):
|
||||||
|
return
|
||||||
|
|
||||||
if p_emote[0] == "/" or p_emote[0] == "/":
|
if p_emote[0] == "/" or p_emote[0] == "/":
|
||||||
p_emote = p_emote[1:]
|
p_emote = p_emote[1:]
|
||||||
elif "../../characters" in p_emote:
|
elif "../../characters" in p_emote:
|
||||||
@ -3012,10 +3015,10 @@ class gui(QtGui.QWidget):
|
|||||||
self.current_display_speed = 3
|
self.current_display_speed = 3
|
||||||
self.chat_tick_timer.start(self.message_display_speed[self.current_display_speed])
|
self.chat_tick_timer.start(self.message_display_speed[self.current_display_speed])
|
||||||
|
|
||||||
self.blip = self.m_chatmessage[BLIPS]
|
self.blip = self.m_chatmessage[BLIPS].lower()
|
||||||
|
|
||||||
if not self.blip:
|
if not self.blip:
|
||||||
self.blip = self.charlist[charid][2]
|
self.blip = self.charlist[charid][2].lower()
|
||||||
|
|
||||||
path = test_path(
|
path = test_path(
|
||||||
AOpath+"sounds/blips/"+self.blip+".wav",
|
AOpath+"sounds/blips/"+self.blip+".wav",
|
||||||
@ -3652,8 +3655,16 @@ class gui(QtGui.QWidget):
|
|||||||
self.demoplayer.rainbowColor.connect(self.text.setStyleSheet)
|
self.demoplayer.rainbowColor.connect(self.text.setStyleSheet)
|
||||||
self.demoplayer.timerUpdate.connect(self.start_pause_timers)
|
self.demoplayer.timerUpdate.connect(self.start_pause_timers)
|
||||||
|
|
||||||
|
self.start_demo_recorder()
|
||||||
|
|
||||||
self.icchatinput.setFocus()
|
self.icchatinput.setFocus()
|
||||||
|
|
||||||
|
def start_demo_recorder(self):
|
||||||
|
if ini.read_ini_bool("AO2XP.ini", "General", "record demos", False):
|
||||||
|
self.demo_recorder = demo.DemoRecorder()
|
||||||
|
self.demo_recorder.start()
|
||||||
|
self.demo_recorder.record([["SC"] + [char[0] for char in self.charlist]], encode=True)
|
||||||
|
|
||||||
class TCP_Thread(QtCore.QThread):
|
class TCP_Thread(QtCore.QThread):
|
||||||
connectionError = QtCore.pyqtSignal(str, str, str)
|
connectionError = QtCore.pyqtSignal(str, str, str)
|
||||||
MS_Chat = QtCore.pyqtSignal(list)
|
MS_Chat = QtCore.pyqtSignal(list)
|
||||||
|
@ -518,7 +518,6 @@ class AOServerInfo(QtCore.QThread):
|
|||||||
|
|
||||||
del network[0]
|
del network[0]
|
||||||
gotChars = True
|
gotChars = True
|
||||||
print network
|
|
||||||
charlist = [ [char.split('&')[0].decode('utf-8'), 0, "male", True ] for char in network ]
|
charlist = [ [char.split('&')[0].decode('utf-8'), 0, "male", True ] for char in network ]
|
||||||
|
|
||||||
# Disable characters not found in filesystem
|
# Disable characters not found in filesystem
|
||||||
|
@ -3,9 +3,8 @@ from constants import *
|
|||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
def handle_packets(caller, total, record=True):
|
def handle_packets(caller, total, record=True):
|
||||||
# Record the packet if demos enabled
|
# Record the packet if demos enabled
|
||||||
if record:
|
if record and caller.parent.demo_recorder:
|
||||||
pass
|
caller.parent.demo_recorder.record(total)
|
||||||
#caller.parent.demo_recorder.record(total)
|
|
||||||
|
|
||||||
for network in total:
|
for network in total:
|
||||||
header = network[0]
|
header = network[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user