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):
|
def setColBg(self, colBg):
|
||||||
self.colBg = 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):
|
def InitPersistent(self, owner, *rgclsTok):
|
||||||
Token.InitPersistent(self, owner)
|
Token.InitPersistent(self, owner)
|
||||||
self.rgclsTok = rgclsTok
|
self.rgclsTok = rgclsTok
|
||||||
|
@ -189,14 +195,12 @@ class AutoJoiner(Token):
|
||||||
def InitTransient(self):
|
def InitTransient(self):
|
||||||
Token.InitTransient(self)
|
Token.InitTransient(self)
|
||||||
self.mpclient_rgtok = {}
|
self.mpclient_rgtok = {}
|
||||||
def run(self):
|
|
||||||
def dgoobLeave(client):
|
def OnLeave(self, client):
|
||||||
for tok in self.mpclient_rgtok[client]:
|
for tok in self.mpclient_rgtok[client]:
|
||||||
print "killing ", tok
|
print "killing ", tok
|
||||||
tok.die()
|
tok.die()
|
||||||
while True:
|
def OnJoin(self, client):
|
||||||
with self.game.evLeave.oob(self, dgoobLeave):
|
|
||||||
client = self.game.evJoin.receive(self)
|
|
||||||
rgtok = []
|
rgtok = []
|
||||||
for clsTok in self.rgclsTok:
|
for clsTok in self.rgclsTok:
|
||||||
if FIter(clsTok):
|
if FIter(clsTok):
|
||||||
|
@ -206,7 +210,7 @@ class AutoJoiner(Token):
|
||||||
rgtok.append(tok)
|
rgtok.append(tok)
|
||||||
self.mpclient_rgtok[client] = rgtok
|
self.mpclient_rgtok[client] = rgtok
|
||||||
|
|
||||||
class AliveWithPlayers(Token):
|
class AliveWithPlayers(LeaveJoinToken):
|
||||||
def InitPersistent(self, owner, *rgclsTok):
|
def InitPersistent(self, owner, *rgclsTok):
|
||||||
Token.InitPersistent(self, owner)
|
Token.InitPersistent(self, owner)
|
||||||
self.rgclsTok = rgclsTok
|
self.rgclsTok = rgclsTok
|
||||||
|
@ -220,11 +224,8 @@ class AliveWithPlayers(Token):
|
||||||
if len(self.rgclient) == 0:
|
if len(self.rgclient) == 0:
|
||||||
for tok in [x for x in self.rgtokOwn]:
|
for tok in [x for x in self.rgtokOwn]:
|
||||||
tok.die()
|
tok.die()
|
||||||
|
def OnJoin(self, client):
|
||||||
def run(self):
|
self.rgclient.append(client)
|
||||||
with self.game.evLeave.oob(self, self.OnLeave):
|
|
||||||
while True:
|
|
||||||
self.rgclient.append(self.game.evJoin.receive(self))
|
|
||||||
if len(self.rgclient) == 1:
|
if len(self.rgclient) == 1:
|
||||||
for clsTok in self.rgclsTok:
|
for clsTok in self.rgclsTok:
|
||||||
if FIter(clsTok):
|
if FIter(clsTok):
|
||||||
|
@ -232,7 +233,7 @@ class AliveWithPlayers(Token):
|
||||||
else:
|
else:
|
||||||
tok = clsTok(self)
|
tok = clsTok(self)
|
||||||
|
|
||||||
class AutoKiller(Token):
|
class AutoKiller(LeaveJoinToken):
|
||||||
def InitTransient(self):
|
def InitTransient(self):
|
||||||
Token.InitTransient(self)
|
Token.InitTransient(self)
|
||||||
self.rgclient = []
|
self.rgclient = []
|
||||||
|
@ -240,10 +241,8 @@ class AutoKiller(Token):
|
||||||
self.rgclient.remove(client)
|
self.rgclient.remove(client)
|
||||||
if len(self.rgclient) == 0:
|
if len(self.rgclient) == 0:
|
||||||
self.game.finish()
|
self.game.finish()
|
||||||
def run(self):
|
def OnJoin(self, client):
|
||||||
with self.game.evLeave.oob(self, self.OnLeave):
|
self.rgclient.append(client)
|
||||||
while True:
|
|
||||||
self.rgclient.append(self.game.evJoin.receive(self))
|
|
||||||
|
|
||||||
#selection oracle
|
#selection oracle
|
||||||
class Selor(TPrs):
|
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(chr(186), ansi.RED, ansi.WHITE), xBar, yBar + 1)
|
||||||
ascr.PutAch(ansi.MkAch("Z", ansi.RED, ansi.WHITE), xBar, yBar + 2)
|
ascr.PutAch(ansi.MkAch("Z", ansi.RED, ansi.WHITE), xBar, yBar + 2)
|
||||||
|
|
||||||
class Joiner(Token):
|
class Joiner(LeaveJoinToken):
|
||||||
def InitPersistent(self, owner):
|
def InitPersistent(self, owner):
|
||||||
Token.InitPersistent(self, owner)
|
Token.InitPersistent(self, owner)
|
||||||
self.msgScroller = self.game.rgtoken("msgscroller")[0]
|
self.msgScroller = self.game.rgtoken("msgscroller")[0]
|
||||||
|
@ -556,11 +556,6 @@ class Joiner(Token):
|
||||||
self.msgScroller.evPost.fire(client.cld.user + " has left! :(")
|
self.msgScroller.evPost.fire(client.cld.user + " has left! :(")
|
||||||
self.board.chat.Add(ChlSys(client, "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):
|
class Lobby(TokenClient):
|
||||||
def InitPersistent(self, owner, client):
|
def InitPersistent(self, owner, client):
|
||||||
TokenClient.InitPersistent(self, owner, client)
|
TokenClient.InitPersistent(self, owner, client)
|
||||||
|
|
Loading…
Reference in a new issue