View Javadoc

1   package cz.cuni.amis.pogamut.udk.communication.translator.observer.state;
2   
3   import cz.cuni.amis.fsm.FSMState;
4   import cz.cuni.amis.fsm.FSMTransition;
5   import cz.cuni.amis.fsm.IFSMState;
6   import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
7   import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Player;
8   import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.PlayerListEnd;
9   import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.PlayerListStart;
10  import cz.cuni.amis.pogamut.udk.communication.translator.TranslatorContext;
11  import cz.cuni.amis.pogamut.udk.communication.translator.observer.support.ObserverListState;
12  import cz.cuni.amis.pogamut.udk.communication.translator.shared.events.PlayerListObtained;
13  
14  /**
15   * Takes care of the player list. It stores them inside a List object and when END message comes it sends
16   * them to the world view via PlayerListObtained event.
17   * <p><p>
18   * Last state of the handshake - we switch from this state to the ConfigureMessageExpectedState. 
19   * 
20   * @author Jimmy
21   */
22  @FSMState(map={@FSMTransition(
23  					state=ObserverRunningState.class, 
24  					symbol={PlayerListEnd.class}, 
25  					transition={})}
26  )
27  public class PlayerListState extends ObserverListState<Player, TranslatorContext> {
28  
29  	public PlayerListState() {
30  		super(PlayerListStart.class, Player.class, PlayerListEnd.class);
31  	}
32  	
33  	@Override
34  	public void stateLeaving(TranslatorContext context,
35  			IFSMState<InfoMessage, TranslatorContext> toState, InfoMessage symbol) {
36  		super.stateLeaving(context, toState, symbol);
37  		context.getEventQueue().pushEvent(new PlayerListObtained(getList()));
38  		newList();
39  	}
40  	
41  	@Override
42  	protected void innerStateSymbol(TranslatorContext context,
43  			InfoMessage symbol) {
44  		super.innerStateSymbol(context, symbol);
45  		if (symbol instanceof Player) {
46  			context.getEventQueue().pushEvent((Player)symbol);
47  		}
48  	}
49  
50  }