1 package cz.cuni.amis.pogamut.ut2004.storyworld.place;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashSet;
6 import java.util.List;
7 import java.util.Set;
8
9 import com.thoughtworks.xstream.annotations.XStreamAlias;
10 import com.thoughtworks.xstream.annotations.XStreamImplicit;
11 import com.thoughtworks.xstream.annotations.XStreamOmitField;
12
13 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
14 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
15 import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.MapPointListObtained;
16 import cz.cuni.amis.utils.collections.MyCollections;
17
18
19
20
21
22
23 @XStreamAlias("base")
24 public class SPStoryPlaceBase extends SPStoryPlace {
25
26 @XStreamOmitField
27 private static Set immutableEmptySet = Collections.unmodifiableSet(new HashSet());
28
29 @XStreamOmitField
30 private Set<NavPoint> navPoints = new HashSet<NavPoint>();
31
32 @XStreamImplicit(itemFieldName="nav")
33 private List<String> navPointIds = new ArrayList<String>();
34
35 public SPStoryPlaceBase(String name, SPStoryPlace inside, String[] navPoints) {
36 super(name, inside);
37 navPointIds.addAll(MyCollections.asList(navPoints));
38 }
39
40
41
42
43 private SPStoryPlaceBase readResolve() {
44 navPoints = new HashSet<NavPoint>();
45 return this;
46 }
47
48
49
50
51
52
53
54
55 @Override
56 public Set<NavPoint> getNavPoints() {
57 return navPoints;
58 }
59
60 protected void setVirtualPlaces(NavPoint[] places) {
61 navPoints.clear();
62 navPoints.addAll(MyCollections.asList(places));
63 }
64
65 protected void setVirtualPlaces(String[] names) {
66 navPointIds.clear();
67 navPointIds.addAll(MyCollections.asList(names));
68 }
69
70 protected void bountNavPoints(MapPointListObtained map) {
71 NavPoint[] navPoints = new NavPoint[navPointIds.size()];
72 int i = 0;
73 for (String id : navPointIds) {
74 NavPoint navPoint = map.getNavPoints().get(UnrealId.get(id));
75 if (navPoint == null) {
76 throw new RuntimeException("nav point " +id + " can't be found in the map");
77 }
78 navPoints[i++] = navPoint;
79 }
80 setVirtualPlaces(navPoints);
81 }
82
83
84
85
86
87 @Override
88 public Set<SPStoryPlace> getContainsPlaces() {
89 return immutableEmptySet;
90 }
91
92
93
94
95
96 @Override
97 public Set<SPStoryPlace> getContainsAllPlaces() {
98 return immutableEmptySet;
99 }
100
101 }