本文整理汇总了Python中xatro.world.World.onEvent方法的典型用法代码示例。如果您正苦于以下问题:Python World.onEvent方法的具体用法?Python World.onEvent怎么用?Python World.onEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xatro.world.World
的用法示例。
在下文中一共展示了World.onEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_onEvent_cancel
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import onEvent [as 别名]
def test_onEvent_cancel(self):
"""
You can cancel the deferred returned by onEvent
"""
world = World(MagicMock())
obj = world.create('foo')
d = world.onEvent(obj['id'], 'hey')
d.cancel()
world.emit('hey', obj['id'])
self.assertFailure(d, defer.CancelledError)
示例2: test_onEvent
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import onEvent [as 别名]
def test_onEvent(self):
"""
You can be notified when a certain event happens.
"""
world = World(MagicMock())
obj = world.create('foo')['id']
d = world.onEvent(obj, 'event')
self.assertEqual(d.called, False)
world.emit('event', obj)
self.assertEqual(self.successResultOf(d), 'event')
# shouldn't die calling again
world.emit('event', obj)
示例3: test_creator_dead
# 需要导入模块: from xatro.world import World [as 别名]
# 或者: from xatro.world.World import onEvent [as 别名]
def test_creator_dead(self):
"""
When the creator of energy is dead, the energy is also dead.
XXX I'm not sure if this belongs in the game engine or not. Seems like
a rule that could be changed.
"""
world = World(MagicMock())
thing = world.create('thing')
Charge(thing['id']).execute(world)
energy = thing['energy'][0]
d = world.onEvent(energy, Destroyed(energy))
# to die means to move to None
Move(thing['id'], None).execute(world)
self.assertEqual(d.called, True, "Energy should be destroyed because "
"the creator of the energy died.")