add LeaveJoinToken, which exercises new select API, and refactor various tokens to use it
This commit is contained in:
parent
9bde1fdb76
commit
a36c4bf7ce
69
basetoken.py
69
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,24 +195,22 @@ class AutoJoiner(Token):
|
|||
def InitTransient(self):
|
||||
Token.InitTransient(self)
|
||||
self.mpclient_rgtok = {}
|
||||
def run(self):
|
||||
def dgoobLeave(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)
|
||||
rgtok = []
|
||||
for clsTok in self.rgclsTok:
|
||||
if FIter(clsTok):
|
||||
tok = clsTok[0](self.game, client, *clsTok[1:])
|
||||
else:
|
||||
tok = clsTok(self.game, client)
|
||||
rgtok.append(tok)
|
||||
self.mpclient_rgtok[client] = rgtok
|
||||
|
||||
class AliveWithPlayers(Token):
|
||||
|
||||
def OnLeave(self, client):
|
||||
for tok in self.mpclient_rgtok[client]:
|
||||
print "killing ", tok
|
||||
tok.die()
|
||||
def OnJoin(self, client):
|
||||
rgtok = []
|
||||
for clsTok in self.rgclsTok:
|
||||
if FIter(clsTok):
|
||||
tok = clsTok[0](self.game, client, *clsTok[1:])
|
||||
else:
|
||||
tok = clsTok(self.game, client)
|
||||
rgtok.append(tok)
|
||||
self.mpclient_rgtok[client] = rgtok
|
||||
|
||||
class AliveWithPlayers(LeaveJoinToken):
|
||||
def InitPersistent(self, owner, *rgclsTok):
|
||||
Token.InitPersistent(self, owner)
|
||||
self.rgclsTok = rgclsTok
|
||||
|
@ -220,19 +224,16 @@ class AliveWithPlayers(Token):
|
|||
if len(self.rgclient) == 0:
|
||||
for tok in [x for x in self.rgtokOwn]:
|
||||
tok.die()
|
||||
def OnJoin(self, client):
|
||||
self.rgclient.append(client)
|
||||
if len(self.rgclient) == 1:
|
||||
for clsTok in self.rgclsTok:
|
||||
if FIter(clsTok):
|
||||
tok = clsTok[0](self, clsTok[1:])
|
||||
else:
|
||||
tok = clsTok(self)
|
||||
|
||||
def run(self):
|
||||
with self.game.evLeave.oob(self, self.OnLeave):
|
||||
while True:
|
||||
self.rgclient.append(self.game.evJoin.receive(self))
|
||||
if len(self.rgclient) == 1:
|
||||
for clsTok in self.rgclsTok:
|
||||
if FIter(clsTok):
|
||||
tok = clsTok[0](self, clsTok[1:])
|
||||
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