Added:
/trunk/games/room - simple/transcripts
/trunk/games/room - simple/transcripts/combat.sword.txt
/trunk/mudlib/commands/transcript.py
/trunk/mudlib/services/transcript.py
/trunk/mudlib/transcript.py
=======================================
--- /dev/null
+++ /trunk/games/room - simple/transcripts/combat.sword.txt Sat Dec 25
00:29:47 2010
@@ -0,0 +1,14 @@
+transcript
+001. 00:00:00 ob ACTOR1 = spawn human
+002. 00:00:00 ob ACTOR2 = spawn human
+003. 00:00:00 ob SWORD1 = spawn sword in ACTOR1
+004. 00:00:00 ob SWORD2 = spawn sword in ACTOR2
+005. 00:00:00 ACTOR1: wield sword
+006. 00:00:00 ACTOR2: wield sword
+007. 00:00:00 ACTOR1: attack ACTOR2
+008. 00:00:00 ACTOR1.. identify SWORD1 as tool
+009. 00:00:00 ACTOR1.. focus on ACTOR2
+010. 00:00:00 ACTOR1.. use SWORD1 on ACTOR2
+011. 00:00:00 ACTOR2.. defense check
+012. 00:00:00 ACTOR2.. possible damage modification
+repeat from 008.
=======================================
--- /dev/null
+++ /trunk/mudlib/commands/transcript.py Sat Dec 25 00:29:47 2010
@@ -0,0 +1,24 @@
+from mudlib import DeveloperCommand
+
+class Transcript(DeveloperCommand):
+ __verbs__ = [ 'transcript' ]
+
+ @staticmethod
+ def Run(context):
+ transcriptNames = sorrows.transcript.GetTranscriptNames()
+
+ commandArgument = context.argString.strip().lower()
+ if commandArgument == "":
+ context.user.Tell("<list> | [transcript name]")
+ return
+ elif commandArgument == "list":
+ context.user.Tell("Found %d transcripts:" %
len(transcriptNames))
+ for transcriptName in transcriptNames:
+ context.user.Tell(transcriptName)
+ return
+
+ if commandArgument not in transcriptNames:
+ context.user.Tell("Unrecognised transcript: "+ commandArgument)
+ return
+
+ sorrows.transcript.Load(commandArgument)
=======================================
--- /dev/null
+++ /trunk/mudlib/services/transcript.py Sat Dec 25 00:29:47 2010
@@ -0,0 +1,32 @@
+import os
+
+from mudlib import Service, Transcript
+
+TRANSCRIPT_SUFFIX = ".txt"
+
+class TranscriptService(Service):
+ __sorrows__ = 'transcript'
+
+ def Run(self):
+ # Locate and verify the files existence.
+ transcriptPath =
os.path.join(sorrows.services.gameScriptPath, "transcripts")
+ if not os.path.exists(transcriptPath):
+ raise RuntimeError("Failed to locate transcript path")
+ self.transcriptPath = transcriptPath
+
+ def Load(self, transcriptName):
+ transcriptFilePath = os.path.join(self.transcriptPath,
transcriptName + TRANSCRIPT_SUFFIX)
+ if not os.path.exists(transcriptFilePath):
+ raise RuntimeError("Failed to locate transcript '%s'" %
fileName)
+
+ transcript = Transcript()
+ transcript.ReadFile(transcriptFilePath)
+
+ return transcript
+
+ def GetTranscriptNames(self):
+ l = []
+ for transcriptName in os.listdir(self.transcriptPath):
+ if transcriptName.endswith(TRANSCRIPT_SUFFIX):
+ l.append(transcriptName[:-len(TRANSCRIPT_SUFFIX)])
+ return l
=======================================
--- /dev/null
+++ /trunk/mudlib/transcript.py Sat Dec 25 00:29:47 2010
@@ -0,0 +1,36 @@
+#
+# IDEA:
+# - Maybe remove line numbers and replace them with labels.
+#
+#
+
+import re, logging
+
+LINE_TEMPLATE = "(?P<lineNumber>[0-9]{3})\.
(?P<timeHours>[0-9]{2}):(?P<timeMinutes>[0-9]{2}):(?P<timeSeconds>[0-9]{2})
(?P<command>.*)"
+LINE_RE = re.compile(LINE_TEMPLATE)
+
+class Transcript(object):
+ def __init__(self):
+ self.lines = []
+
+ def ReadFile(self, filePath):
+ # Prepare the file for execution.
+ with open(filePath, "r") as f:
+ line = f.readline()
+ while line != "":
+ line = line.strip()
+ self._ProcessLine(line)
+ line = f.readline()
+
+ def _ProcessLine(self, line):
+ match = LINE_RE.match(line)
+ if match is None:
+ return
+
+ lineNumber = match.group("lineNumber") # Ignore this for now.
+ timeHours = match.group("timeHours") # Ignore these for now.
+ timeMinutes = match.group("timeMinutes")
+ timeSeconds = match.group("timeSeconds")
+ command = match.group("command")
+
+ logging.root.info("LINE %s", command)