add LeaveJoinToken, which exercises new select API, and refactor various tokens to use it
This commit is contained in:
parent
9bde1fdb76
commit
a36c4bf7ce
33
basetoken.py
33
basetoken.py
|
@ -181,7 +181,13 @@ class Terminal(Token):
|
|||
|
||||
def setColBg(self, colBg):
|
||||
self.colBg = colBg
|
||||
class AutoJoiner(Token):
|
||||
|
||||
class LeaveJoinToken(Token):
|
||||
def run(self):
|
||||
while True:
|
||||
Event.selectDg(self, (self.game.evLeave, self.OnLeave), (self.game.evJoin, self.OnJoin))
|
||||
|
||||
class AutoJoiner(LeaveJoinToken):
|
||||
def InitPersistent(self, owner, *rgclsTok):
|
||||
Token.InitPersistent(self, owner)
|
||||
self.rgclsTok = rgclsTok
|
||||
|
@ -189,14 +195,12 @@ class AutoJoiner(Token):
|
|||
def InitTransient(self):
|
||||
Token.InitTransient(self)
|
||||
self.mpclient_rgtok = {}
|
||||
def run(self):
|
||||
def dgoobLeave(client):
|
||||
|
||||
def OnLeave(self, client):
|
||||
for tok in self.mpclient_rgtok[client]:
|
||||
print "killing ", tok
|
||||
tok.die()
|
||||
while True:
|
||||
with self.game.evLeave.oob(self, dgoobLeave):
|
||||
client = self.game.evJoin.receive(self)
|
||||
def OnJoin(self, client):
|
||||
rgtok = []
|
||||
for clsTok in self.rgclsTok:
|
||||
if FIter(clsTok):
|
||||
|
@ -206,7 +210,7 @@ class AutoJoiner(Token):
|
|||
rgtok.append(tok)
|
||||
self.mpclient_rgtok[client] = rgtok
|
||||
|
||||
class AliveWithPlayers(Token):
|
||||
class AliveWithPlayers(LeaveJoinToken):
|
||||
def InitPersistent(self, owner, *rgclsTok):
|
||||
Token.InitPersistent(self, owner)
|
||||
self.rgclsTok = rgclsTok
|
||||
|
@ -220,11 +224,8 @@ class AliveWithPlayers(Token):
|
|||
if len(self.rgclient) == 0:
|
||||
for tok in [x for x in self.rgtokOwn]:
|
||||
tok.die()
|
||||
|
||||
def run(self):
|
||||
with self.game.evLeave.oob(self, self.OnLeave):
|
||||
while True:
|
||||
self.rgclient.append(self.game.evJoin.receive(self))
|
||||
def OnJoin(self, client):
|
||||
self.rgclient.append(client)
|
||||
if len(self.rgclient) == 1:
|
||||
for clsTok in self.rgclsTok:
|
||||
if FIter(clsTok):
|
||||
|
@ -232,7 +233,7 @@ class AliveWithPlayers(Token):
|
|||
else:
|
||||
tok = clsTok(self)
|
||||
|
||||
class AutoKiller(Token):
|
||||
class AutoKiller(LeaveJoinToken):
|
||||
def InitTransient(self):
|
||||
Token.InitTransient(self)
|
||||
self.rgclient = []
|
||||
|
@ -240,10 +241,8 @@ class AutoKiller(Token):
|
|||
self.rgclient.remove(client)
|
||||
if len(self.rgclient) == 0:
|
||||
self.game.finish()
|
||||
def run(self):
|
||||
with self.game.evLeave.oob(self, self.OnLeave):
|
||||
while True:
|
||||
self.rgclient.append(self.game.evJoin.receive(self))
|
||||
def OnJoin(self, client):
|
||||
self.rgclient.append(client)
|
||||
|
||||
#selection oracle
|
||||
class Selor(TPrs):
|
||||
|
|
|
@ -535,7 +535,7 @@ class MiChat(Mi):
|
|||
ascr.PutAch(ansi.MkAch(chr(186), ansi.RED, ansi.WHITE), xBar, yBar + 1)
|
||||
ascr.PutAch(ansi.MkAch("Z", ansi.RED, ansi.WHITE), xBar, yBar + 2)
|
||||
|
||||
class Joiner(Token):
|
||||
class Joiner(LeaveJoinToken):
|
||||
def InitPersistent(self, owner):
|
||||
Token.InitPersistent(self, owner)
|
||||
self.msgScroller = self.game.rgtoken("msgscroller")[0]
|
||||
|
@ -556,11 +556,6 @@ class Joiner(Token):
|
|||
self.msgScroller.evPost.fire(client.cld.user + " has left! :(")
|
||||
self.board.chat.Add(ChlSys(client, "has left"))
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
with self.game.evJoin.oob(self, self.OnJoin):
|
||||
self.OnLeave(self.game.evLeave.receive(self))
|
||||
|
||||
class Lobby(TokenClient):
|
||||
def InitPersistent(self, owner, client):
|
||||
TokenClient.InitPersistent(self, owner, client)
|
||||
|
|
Loading…
Reference in a new issue