1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.tudelft.goal.ut2004.visualizer.data;
18
19 import java.util.Collection;
20 import java.util.Map;
21
22 import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
23 import cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId;
24 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
25 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
26 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.TeamScore;
27 import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
28
29
30
31
32
33
34
35
36
37 public class GameStatusData extends AbstractData {
38
39
40
41
42 private static final int NUMBER_OF_TEAMS = 2;
43
44
45
46
47 private GameInfo gameInfo;
48
49
50
51
52 private Collection<FlagInfo> flagInfoCollection;
53
54 private Collection<TeamScore> teamScoreCollection;
55
56 public GameStatusData() {
57 super();
58 }
59
60
61
62
63
64
65 @Override
66 public synchronized void serverChanged(IUT2004Server server) {
67 if (server != null) {
68 updateGameInfo(server.getWorldView());
69 updateFlagInfo(server.getWorldView());
70 updateTeamScore(server.getWorldView());
71 } else {
72 clearGameInfo();
73 clearFlagInfo();
74 clearTeamScore();
75 }
76
77 notifyListeners();
78 }
79
80 private void clearTeamScore() {
81 teamScoreCollection = null;
82 }
83
84 private void updateTeamScore(IWorldView view) {
85 Class<TeamScore> teamScoreClass = TeamScore.class;
86 teamScoreCollection = view.getAll(teamScoreClass).values();
87 }
88
89
90
91
92 private void clearFlagInfo() {
93 flagInfoCollection = null;
94 }
95
96
97
98
99 private void clearGameInfo() {
100 gameInfo = null;
101 }
102
103
104
105
106
107
108
109 private void updateGameInfo(IWorldView view) {
110 this.gameInfo = view.getSingle(GameInfo.class);
111 }
112
113
114
115
116
117
118
119 private void updateFlagInfo(IWorldView view) {
120 Map<WorldObjectId, FlagInfo> flags = view.getAll(FlagInfo.class);
121 flagInfoCollection = flags.values();
122 }
123
124
125
126
127
128 public synchronized GameInfo getGameInfo() {
129 return gameInfo;
130 }
131
132
133
134
135 public synchronized Collection<FlagInfo> getFlagInfoCollection() {
136 return flagInfoCollection;
137 }
138
139
140
141
142
143 public synchronized Collection<TeamScore> getTeamScoreCollection() {
144 return teamScoreCollection;
145 }
146
147 }