View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package nl.tudelft.goal.ut2004.visualizer.data;
18  
19  import java.util.LinkedList;
20  
21  import nl.tudelft.goal.ut2004.visualizer.util.ObservingCollection;
22  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.MapList;
23  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
24  import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
25  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
26  import cz.cuni.amis.utils.collections.ObservableCollection;
27  
28  /**
29   * Class that keeps track of the players that are currently in the server.
30   * 
31   * @author Lennard de Rijk
32   * @author M.P. Korstanje
33   * 
34   */
35  public class GameData extends AbstractData {
36  
37  	private final ObservingCollection<Player> players;
38  	private final ObservableCollection<Waypoint> waypoints;
39  	private final ObservableCollection<MapList> maps;
40  	
41      /** Most rescent message containing info about the player's score. */
42  	//Map<UnrealId, PlayerScore> lastPlayerScore = null;
43  
44  	/** Most rescent message containing info about the player team's score. */
45  	//Map<Integer, TeamScore> lastTeamScore = null;
46  	
47  
48  	public GameData() {
49  		players = new ObservingCollection<Player>();
50  		waypoints = new ObservableCollection<Waypoint>(new LinkedList<Waypoint>());
51  		maps = new ObservableCollection<MapList>(new LinkedList<MapList>());
52  		
53  	}
54  
55  	@Override
56  	public void serverChanged(IUT2004Server server) {
57  		players.removeObserved();
58  		waypoints.clear();
59  		maps.clear();
60  //		lastPlayerScore.clear();
61  //		lastTeamScore.clear();
62  		
63  		if (server != null) {
64  			players.setObserved(server.getPlayers());
65  			waypoints.addAll(server.getMap().vertexSet());
66  			maps.addAll(server.getAvailableMaps());
67  			
68  		}
69  	}
70  
71  	public ObservableCollection<MapList> getAvailableMaps() {
72  		return maps;
73  	}
74  
75  	public ObservableCollection<Player> getPlayers() {
76  		return players;
77  	}
78  
79  	public ObservableCollection<Waypoint> getWaypoints() {
80  		return waypoints;
81  	}
82  
83  
84  	
85  	
86  //	/**
87  //	 * PlayerScore listener.
88  //	 */
89  //	private class PlayerScoreListener implements IWorldEventListener<PlayerScore>
90  //	{
91  //		@Override
92  //		public void notify(PlayerScore event)
93  //		{
94  //			synchronized(lastPlayerScore) {
95  //				lastPlayerScore.put(event.getId(), event);
96  //			}
97  //		}
98  //
99  //		/**
100 //		 * Constructor. Registers itself on the given WorldView object.
101 //		 * @param worldView WorldView object to listent to.
102 //		 */
103 //		public PlayerScoreListener(IWorldView worldView)
104 //		{
105 //			worldView.addEventListener(PlayerScore.class, this);
106 //		}
107 //	}
108 //
109 //	/** PlayerScore listener */
110 //	private PlayerScoreListener playerScoreListener;
111 //
112 //	/*========================================================================*/
113 //	
114 //	/**
115 //	 * TeamScore listener.
116 //	 */
117 //	private class TeamScoreListener implements IWorldObjectEventListener<TeamScore, WorldObjectUpdatedEvent<TeamScore>>
118 //	{
119 //		/**
120 //		 * Constructor. Registers itself on the given WorldView object.
121 //		 * @param worldView WorldView object to listent to.
122 //		 */
123 //		public TeamScoreListener(IWorldView worldView)
124 //		{
125 //			worldView.addObjectListener(TeamScore.class, WorldObjectUpdatedEvent.class, this);
126 //		}
127 //
128 //		@Override
129 //		public void notify(WorldObjectUpdatedEvent<TeamScore> event) {
130 //			synchronized(lastTeamScore) {
131 //				lastTeamScore.put(event.getObject().getTeam(), event.getObject());
132 //			}
133 //		}
134 //	}
135 //
136 //	/** TeamScore listener */
137 //	private TeamScoreListener teamScoreListener;
138 
139 }