select: listen to multiple events at once
This commit is contained in:
parent
c96f0e8698
commit
9bde1fdb76
27
engine.py
27
engine.py
|
@ -34,6 +34,33 @@ class Event(TPrs):
|
||||||
if ev in tok.mpevDgoob and tok.mpevDgoob[ev](value):
|
if ev in tok.mpevDgoob and tok.mpevDgoob[ev](value):
|
||||||
raise Event.OobBreakException()
|
raise Event.OobBreakException()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def select(cls, tok, *rgev):
|
||||||
|
for ev in rgev:
|
||||||
|
ev.rgtk.append(tok)
|
||||||
|
chNotify = tok.chEv
|
||||||
|
fOob = False
|
||||||
|
while True:
|
||||||
|
evRcv, value = chNotify.receive()
|
||||||
|
if evRcv in tok.mpevDgoob:
|
||||||
|
if tok.mpevDgoob[ev](value):
|
||||||
|
fOob = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
for ev in rgev:
|
||||||
|
if ev != evRcv:
|
||||||
|
ev.rgtk.remove(tok)
|
||||||
|
if fOob:
|
||||||
|
raise Event.OobBreakException()
|
||||||
|
return evRcv, value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def selectDg(cls, tok, *rgev_dg):
|
||||||
|
rgev, rgdg = zip(*rgev_dg)
|
||||||
|
ev, value = cls.select(tok, *rgev)
|
||||||
|
rgdg[rgev.index(ev)](value)
|
||||||
|
|
||||||
def fire(self, value = None):
|
def fire(self, value = None):
|
||||||
self.stkValue.append(value)
|
self.stkValue.append(value)
|
||||||
self.game.queueEv.append(self)
|
self.game.queueEv.append(self)
|
||||||
|
|
Loading…
Reference in a new issue