|
@@ -83,7 +83,7 @@ class PlayerInput(object):
|
|
|
self.game = game
|
|
|
self.observer = self.game.observer
|
|
|
self.save = None
|
|
|
- self.defer = None
|
|
|
+ self.deferred = None
|
|
|
self.queue_game = game.queue_game
|
|
|
|
|
|
# default colors, and useful consts
|
|
@@ -96,8 +96,8 @@ class PlayerInput(object):
|
|
|
def color(self, c):
|
|
|
self.c = c
|
|
|
|
|
|
- def awake(self):
|
|
|
- log.msg("PlayerInput.awake()")
|
|
|
+ def alive(self):
|
|
|
+ log.msg("PlayerInput.alive()")
|
|
|
self.game.queue_player.put(" ")
|
|
|
|
|
|
def prompt(self, prompt, limit, default=''):
|
|
@@ -111,9 +111,9 @@ class PlayerInput(object):
|
|
|
|
|
|
# Note: This clears out the server "keep alive"
|
|
|
self.save = self.observer.save()
|
|
|
- self.observer.connect('player', self.input)
|
|
|
+ self.observer.connect('player', self.get_input)
|
|
|
|
|
|
- self.keepalive = task.LoopingCall(self.awake)
|
|
|
+ self.keepalive = task.LoopingCall(self.alive)
|
|
|
self.keepalive.start(30)
|
|
|
|
|
|
# We need to "hide" the game output.
|
|
@@ -126,12 +126,13 @@ class PlayerInput(object):
|
|
|
# Set "Background of prompt"
|
|
|
self.queue_game.put( " " * limit + "\b" * limit)
|
|
|
|
|
|
- assert(self.defer is None)
|
|
|
+ assert(self.deferred is None)
|
|
|
d = defer.Deferred()
|
|
|
- self.defer = d
|
|
|
+ self.deferred = d
|
|
|
+ log.msg("Return deferred ...", self.deferred)
|
|
|
return d
|
|
|
|
|
|
- def input(self, chunk):
|
|
|
+ def get_input(self, chunk):
|
|
|
""" Data from player (in bytes) """
|
|
|
chunk = chunk.decode('utf-8', 'ignore')
|
|
|
|
|
@@ -142,21 +143,28 @@ class PlayerInput(object):
|
|
|
self.input = self.input[0:-1]
|
|
|
else:
|
|
|
self.queue_game.put("\a")
|
|
|
- if ch == "'\r":
|
|
|
+ if ch == "\r":
|
|
|
self.queue_game.put(self.r + self.nl)
|
|
|
+ log.msg("Restore observer dispatch", self.save)
|
|
|
assert(not self.save is None)
|
|
|
self.observer.load(self.save)
|
|
|
self.save = None
|
|
|
+ log.msg("Disable keepalive")
|
|
|
self.keepalive.stop()
|
|
|
self.keepalive = None
|
|
|
line = self.input
|
|
|
self.input = ''
|
|
|
- assert(not self.defer is None)
|
|
|
- reactor.callLater(0, self.defer.callback, line)
|
|
|
- self.defer = None
|
|
|
+ assert(not self.deferred is None)
|
|
|
+ log.msg(self.deferred)
|
|
|
+ self.deferred.callback(line)
|
|
|
+ # log.msg("callLater in 3 secs defer.callback with line entered...")
|
|
|
+ # reactor.callLater(2, self.deferred.callback, line)
|
|
|
+
|
|
|
+ # Is it possible that setting this to None calleds the callback?
|
|
|
+ self.deferred = None
|
|
|
if ch.isprintable():
|
|
|
if len(self.input) + 1 <= self.limit:
|
|
|
- self.input += c
|
|
|
+ self.input += ch
|
|
|
self.queue_game.put(ch)
|
|
|
else:
|
|
|
self.queue_game.put("\a")
|
|
@@ -232,9 +240,16 @@ class ProxyMenu(object):
|
|
|
self.queue_game.put(self.nl + self.c1 + "Current time " + now.to_datetime_string() + self.nl)
|
|
|
elif key == 'Q':
|
|
|
self.queue_game.put(self.c + key + self.r + self.nl)
|
|
|
+ # This isn't working here, because we don't "stop"...
|
|
|
+ # we just redisplay the menu and keep going. :(
|
|
|
ask = PlayerInput(self.game)
|
|
|
- d = ask.prompt("What is your quest?", 20)
|
|
|
- d.callback(ask.prompt, "What is your favorite color?", 10)
|
|
|
+ d = ask.prompt("What is your quest? ", 20)
|
|
|
+ # d.callback(lambda ignore: ask.prompt("What is your favorite color?", 10))
|
|
|
+
|
|
|
+ d.addCallback(ask.output)
|
|
|
+ # This causes twisted.internet.defer.AlreadyCalledError:
|
|
|
+ d.addCallback(self.welcome_back)
|
|
|
+ return
|
|
|
|
|
|
elif key == 'X':
|
|
|
self.queue_game.put(self.c + key + self.r + self.nl)
|
|
@@ -248,7 +263,7 @@ class ProxyMenu(object):
|
|
|
|
|
|
# Were we asked to do something when we were done here?
|
|
|
if self.defer:
|
|
|
- reactor.CallLater(0, self.defer.callback, None)
|
|
|
+ reactor.CallLater(0, self.defer.callback)
|
|
|
# self.defer.callback()
|
|
|
self.defer = None
|
|
|
return
|
|
@@ -256,6 +271,12 @@ class ProxyMenu(object):
|
|
|
self.keepalive.start(30, True)
|
|
|
self.menu()
|
|
|
|
|
|
+ def welcome_back(self, _):
|
|
|
+ log.msg("welcome_back")
|
|
|
+ self.keepalive.start(30, True)
|
|
|
+ self.menu()
|
|
|
+
|
|
|
+
|
|
|
from mcp import MCP
|
|
|
|
|
|
class Game(protocol.Protocol):
|