def connect(self): return if toggle_music: self.player.play() if toggle_fx: for sound, event in self.connections: dispatcher.connect(sound.play, signal=event, priority=dispatcher.UI_PRIORITY)
def do_when(func, event, condition=lambda *args: True): def wrap_(**kw): if robustApply(condition, **kw): func() dispatcher.disconnect(wrap_, signal=event, weak=False) dispatcher.connect(wrap_, signal=event, weak=False)
def setup_creature_role(self): self.is_creature = True gamecard = self.gamecard self.power = 0 #gamecard.power self.toughness = 0 #gamecard.toughness self.damage = 0 #gamecard.currentDamage() #dispatcher.connect(self.change_value, signal=PowerToughnessModifiedEvent(), sender=gamecard) # XXX This will lead to a lot of events each time priority is passed # but I'm not sure how to do it otherwise for cards like "Coat of Arms", which use a lambda function # or for damage self.text = Label("", size=34, background=True, shadow=False, halign="center", valign="center") #self.text._scale = anim.animate(0, 2.0, dt=0.25, method="sine") self.text.scale = 2.0 #self.text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") self.text.orig_pos = euclid.Vector3(0, -self.height * 0.25, 0.001) self.text.zoom_pos = euclid.Vector3(self.width * 1.375, -self.height * 0.454, 0.01) self.text.pos = self.text.orig_pos #self.damage_text = Label("", size=34, background=True, shadow=False, halign="center", valign="center", color=(1., 0., 0., 1.)) #self.damage_text._scale = anim.animate(0.0, 0.0, dt=0.25, method="sine") #self.damage_text.scale = 0.4 #self.damage_text.visible = 0 #self.damage_text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") #self.damage_text.zoom_pos = euclid.Vector3(self.width*(1-.375),-self.height*0.454, 0.01) #self.damage_text.pos = self.damage_text.zoom_pos self.change_value() self.draw = self.draw_creature dispatcher.connect(self.change_value, signal=TimestepEvent())
def setup_creature_role(self): self.is_creature = True gamecard = self.gamecard self.power = 0 #gamecard.power self.toughness = 0 #gamecard.toughness self.damage = 0 #gamecard.currentDamage() #dispatcher.connect(self.change_value, signal=PowerToughnessModifiedEvent(), sender=gamecard) # XXX This will lead to a lot of events each time priority is passed # but I'm not sure how to do it otherwise for cards like "Coat of Arms", which use a lambda function # or for damage self.text = Label("", size=34, background=True, shadow=False, halign="center", valign="center") #self.text._scale = anim.animate(0, 2.0, dt=0.25, method="sine") self.text.scale = 2.0 #self.text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") self.text.orig_pos = euclid.Vector3(0,-self.height*0.25,0.001) self.text.zoom_pos = euclid.Vector3(self.width*1.375,-self.height*0.454, 0.01) self.text.pos = self.text.orig_pos #self.damage_text = Label("", size=34, background=True, shadow=False, halign="center", valign="center", color=(1., 0., 0., 1.)) #self.damage_text._scale = anim.animate(0.0, 0.0, dt=0.25, method="sine") #self.damage_text.scale = 0.4 #self.damage_text.visible = 0 #self.damage_text._pos.set(euclid.Vector3(0,0,0)) #_transition(dt=0.25, method="sine") #self.damage_text.zoom_pos = euclid.Vector3(self.width*(1-.375),-self.height*0.454, 0.01) #self.damage_text.pos = self.damage_text.zoom_pos self.change_value() self.draw = self.draw_creature dispatcher.connect(self.change_value, signal=TimestepEvent())
def buildup(source): def controller_changed(sender, original): if sender == source: source._echo_controller = sender.controller dispatcher.connect(controller_changed, signal=ControllerChanged(), weak=False) source._echo_controller = source.controller source._echo_func = controller_changed
def entering_play(self): self.is_tapped = False self.tapping = anim.animate(0, 0, dt=0.3) self.highlighting = anim.animate(0, 0, dt=0.2) self.zooming = anim.animate(0, 0, dt=0.2) self.pos_transition = "ease_out_circ" #"ease_out_back" self._pos.set_transition(dt=0.4, method=self.pos_transition) #self._pos.y = anim.animate(guicard._pos.y, guicard._pos.y, dt=0.4, method="ease_out") self._orientation.set_transition(dt=0.3, method="sine") self.can_layout = True if self.gamecard.types == Creature: self.setup_creature_role() # Check for counters dispatcher.connect(self.add_counter, signal=CounterAddedEvent(), sender=self.gamecard) dispatcher.connect(self.remove_counter, signal=CounterRemovedEvent(), sender=self.gamecard) dispatcher.connect(self.type_modified, signal=TypesModifiedEvent(), sender=self.gamecard) self.counters = [ Counter(counter.ctype) for counter in self.gamecard.counters ] self.layout_counters()
def entering_play(self): self.is_tapped = False self.tapping = anim.animate(0, 0, dt=0.3) self.highlighting = anim.animate(0, 0, dt=0.2) self.zooming = anim.animate(0, 0, dt=0.2) self.pos_transition = "ease_out_circ" #"ease_out_back" self._pos.set_transition(dt=0.4, method=self.pos_transition) #self._pos.y = anim.animate(guicard._pos.y, guicard._pos.y, dt=0.4, method="ease_out") self._orientation.set_transition(dt=0.3, method="sine") self.can_layout = True if self.gamecard.types == Creature: self.setup_creature_role() # Check for counters dispatcher.connect(self.add_counter, signal=CounterAddedEvent(), sender=self.gamecard) dispatcher.connect(self.remove_counter, signal=CounterRemovedEvent(), sender=self.gamecard) dispatcher.connect(self.type_modified, signal=TypesModifiedEvent(), sender=self.gamecard) self.counters = [Counter(counter.ctype) for counter in self.gamecard.counters] self.layout_counters()
def enable_sound(self): self.update_sound_volume() if not self.sound_on: self.sound_on = True for sound, event in self.connections: dispatcher.connect(sound.vplay, signal=event, priority=dispatcher.UI_PRIORITY)
def until_end_of_turn(*restores): dispatcher.connect(combine(*restores), signal=CleanupEvent(), weak=False, expiry=1)
def make_connections(self, player1_info, player2_info): player1, self_color, self_avatar_data = player1_info player2, other_color, other_avatar_data = player2_info self_avatar = pyglet.image.load('avatar.png', StringIO(self_avatar_data)) other_avatar = pyglet.image.load('avatar.png', StringIO(other_avatar_data)) if not self_color: self_color = colors.compute_color_from_image(self_avatar) if not other_color: other_color = colors.compute_color_from_image(other_avatar) self.player1 = player1 self.player2 = player2 self.mainplayer_status.setup_player(player1, self_color, self_avatar) self.otherplayer_status.setup_player(player2, other_color, other_avatar) self.phase_status.setup_player_colors(player1, self_color, other_color) self.player_hand.setup_player(self_color) self.otherplayer_hand.setup_player(other_color) self.zone_animator.setup(self.mainplayer_status, self.otherplayer_status, self.stack, self.mainplay,self.otherplay,self.table) dispatcher.connect(self.stack.finalize_announcement, signal=engine.GameEvent.AbilityPlacedOnStack()) dispatcher.connect(self.stack.remove_ability, signal=engine.GameEvent.AbilityCanceled()) dispatcher.connect(self.player_hand.add_card, signal=engine.GameEvent.CardEnteredZone(), sender=player1.hand, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.player_hand.remove_card, signal=engine.GameEvent.CardLeftZone(), sender=player1.hand, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.player_hand.remove_card, signal=engine.GameEvent.CardCeasesToExist(), sender=player1.hand, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_hand.add_card, signal=engine.GameEvent.CardEnteredZone(), sender=player2.hand, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_hand.remove_card, signal=engine.GameEvent.CardLeftZone(), sender=player2.hand, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_hand.remove_card, signal=engine.GameEvent.CardCeasesToExist(), sender=player2.hand, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.animate_life, signal=engine.GameEvent.LifeGainedEvent(),sender=player1, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.animate_life, signal=engine.GameEvent.LifeGainedEvent(),sender=player2, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.animate_life, signal=engine.GameEvent.LifeLostEvent(),sender=player1, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.animate_life, signal=engine.GameEvent.LifeLostEvent(),sender=player2, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.manapool.update_mana, signal=engine.GameEvent.ManaAdded(), sender=player1.manapool, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.manapool.update_mana, signal=engine.GameEvent.ManaSpent(), sender=player1.manapool, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.manapool.clear_mana, signal=engine.GameEvent.ManaCleared(), sender=player1.manapool, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.manapool.update_mana, signal=engine.GameEvent.ManaAdded(), sender=player2.manapool, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.manapool.update_mana, signal=engine.GameEvent.ManaSpent(), sender=player2.manapool, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.manapool.clear_mana, signal=engine.GameEvent.ManaCleared(), sender=player2.manapool, priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.phase_bar.new_turn, signal=engine.GameEvent.NewTurnEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.phase_bar.set_phase, signal=engine.GameEvent.GameStepEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.phase_status.new_turn, signal=engine.GameEvent.NewTurnEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.phase_status.set_phase, signal=engine.GameEvent.GameStepEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.phase_status.change_focus, signal=engine.GameEvent.GameFocusEvent(), priority=dispatcher.UI_PRIORITY) #dispatcher.connect(self.game_status.log_event, signal=engine.GameEvent.LogEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.new_turn, signal=engine.GameEvent.NewTurnEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.new_turn, signal=engine.GameEvent.NewTurnEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplayer_status.pass_priority, signal=engine.GameEvent.HasPriorityEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplayer_status.pass_priority, signal=engine.GameEvent.HasPriorityEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplay.card_tapped, signal=engine.GameEvent.CardTapped(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplay.card_tapped, signal=engine.GameEvent.CardTapped(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplay.card_untapped, signal=engine.GameEvent.CardUntapped(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplay.card_untapped, signal=engine.GameEvent.CardUntapped(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplay.card_attached, signal=engine.GameEvent.AttachedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplay.card_attached, signal=engine.GameEvent.AttachedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.mainplay.card_unattached, signal=engine.GameEvent.UnAttachedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.otherplay.card_unattached, signal=engine.GameEvent.UnAttachedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.priority_stop, signal=engine.GameEvent.HasPriorityEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.play_ability, signal=engine.GameEvent.AbilityPlayedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.new_turn, signal=engine.GameEvent.NewTurnEvent(), priority=dispatcher.UI_PRIORITY) self.soundfx.connect()
def register(self): dispatcher.connect(self.new_turn, signal=GameEvent.NewTurnEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.enter_zone, signal=GameEvent.CardEnteredZone(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.leave_zone, signal=GameEvent.CardLeftZone(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.enter_stack, signal=GameEvent.AbilityAnnounced(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.leave_stack, signal=GameEvent.AbilityRemovedFromStack(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.controller_changed, signal=GameEvent.ControllerChanged(), priority=dispatcher.UI_PRIORITY) #dispatcher.connect(self.setup_redzone, signal=GameEvent.AttackStepEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.select_attacker, signal=GameEvent.AttackerSelectedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.reset_attackers, signal=GameEvent.AttackersResetEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.declare_attackers, signal=GameEvent.DeclareAttackersEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.select_blocker, signal=GameEvent.BlockerSelectedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.reset_blockers, signal=GameEvent.BlockersResetEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.reorder_blockers, signal=GameEvent.BlockersReorderedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.end_combat, signal=GameEvent.EndCombatEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.card_damage, signal=GameEvent.DealsDamageToEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.player_life, signal=GameEvent.LifeGainedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.player_life, signal=GameEvent.LifeLostEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.invalid_target, signal=GameEvent.InvalidTargetEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.targeted_by, signal=GameEvent.TargetedByEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.select_card, signal=GameEvent.CardSelectedEvent(), priority=dispatcher.UI_PRIORITY) dispatcher.connect(self.deselect_all, signal=GameEvent.AllDeselectedEvent(), priority=dispatcher.UI_PRIORITY)