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  
23  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.MapList;
24  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
25  import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
26  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
27  import cz.cuni.amis.utils.collections.ObservableCollection;
28  
29  /**
30   * Class that keeps track of the players that are currently in the server.
31   * 
32   * @author Lennard de Rijk
33   * @author M.P. Korstanje
34   * 
35   */
36  public class GameData extends AbstractData {
37  
38  	private final ObservingCollection<Player> players;
39  	private final ObservableCollection<Waypoint> waypoints;
40  	private final ObservableCollection<MapList> maps;
41  
42  	public GameData() {
43  		players = new ObservingCollection<Player>();
44  		waypoints = new ObservableCollection<Waypoint>(
45  				new LinkedList<Waypoint>());
46  		maps = new ObservableCollection<MapList>(new LinkedList<MapList>());
47  
48  	}
49  
50  	@Override
51  	public void serverChanged(IUT2004Server server) {
52  		players.removeObserved();
53  		waypoints.clear();
54  		maps.clear();
55  		if (server != null) {
56  			players.setObserved(server.getPlayers());
57  			waypoints.addAll(server.getMap().vertexSet());
58  			maps.addAll(server.getAvailableMaps());
59  		}
60  	}
61  
62  	public ObservableCollection<MapList> getAvailableMaps() {
63  		return maps;
64  	}
65  
66  	public ObservableCollection<Player> getPlayers() {
67  		return players;
68  	}
69  
70  	public ObservableCollection<Waypoint> getWaypoints() {
71  		return waypoints;
72  	}
73  
74  }