diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-15 13:12:19 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-15 13:12:19 -0500 |
commit | cb18193a2b599853813dbc5fc128406250741a3c (patch) | |
tree | ed0bdf277412aae7e2da9d1021e9888bb1e1f4fa /src/com | |
parent | 370ce6c579828b50651d3636d9502f9c3b87ad15 (diff) | |
download | fourpuzzle-cb18193a2b599853813dbc5fc128406250741a3c.tar.gz fourpuzzle-cb18193a2b599853813dbc5fc128406250741a3c.tar.bz2 fourpuzzle-cb18193a2b599853813dbc5fc128406250741a3c.zip |
Engine: Atomicized Maps
Previously, MapViewGameState preformed all of its actions directly on the internal map. However, this would result in the map being exactly the same when reloaded, which was not wanted. So, copy() functions have been added to several places so a copy of the internal map is provided for MapViewGameState.
Diffstat (limited to 'src/com')
5 files changed, 57 insertions, 1 deletions
diff --git a/src/com/fourisland/fourpuzzle/database/Database.java b/src/com/fourisland/fourpuzzle/database/Database.java index 5f37d61..922ab60 100755 --- a/src/com/fourisland/fourpuzzle/database/Database.java +++ b/src/com/fourisland/fourpuzzle/database/Database.java | |||
@@ -128,7 +128,7 @@ public class Database { | |||
128 | 128 | ||
129 | public static Map getMap(String key) | 129 | public static Map getMap(String key) |
130 | { | 130 | { |
131 | return maps.get(key); | 131 | return maps.get(key).copy(); |
132 | } | 132 | } |
133 | 133 | ||
134 | } | 134 | } |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 1511fea..33a8516 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |||
@@ -63,6 +63,22 @@ public class Map { | |||
63 | setMusicType(musicType); | 63 | setMusicType(musicType); |
64 | } | 64 | } |
65 | 65 | ||
66 | public Map copy() | ||
67 | { | ||
68 | Map temp; | ||
69 | if (getMusicType() == MapMusicType.Specified) | ||
70 | { | ||
71 | temp = new Map(getSize().width, getSize().height, getChipSet(), getMusic()); | ||
72 | } else { | ||
73 | temp = new Map(getSize().width, getSize().height, getChipSet(), getMusicType()); | ||
74 | } | ||
75 | |||
76 | temp.mapData = new Vector<HashMap<Integer,Integer>>(getMapData()); | ||
77 | temp.events = getEvents().copy(this); | ||
78 | |||
79 | return temp; | ||
80 | } | ||
81 | |||
66 | private Dimension size; | 82 | private Dimension size; |
67 | public Dimension getSize() | 83 | public Dimension getSize() |
68 | { | 84 | { |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java index 8de4e3c..7120a91 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java | |||
@@ -19,6 +19,18 @@ public class EventList extends Vector<LayerEvent> { | |||
19 | setParentMap(parentMap); | 19 | setParentMap(parentMap); |
20 | } | 20 | } |
21 | 21 | ||
22 | public EventList copy(Map parentMap) | ||
23 | { | ||
24 | EventList temp = new EventList(parentMap); | ||
25 | |||
26 | for (LayerEvent ev : this) | ||
27 | { | ||
28 | temp.add(ev.copy()); | ||
29 | } | ||
30 | |||
31 | return temp; | ||
32 | } | ||
33 | |||
22 | @Override | 34 | @Override |
23 | public boolean add(LayerEvent o) | 35 | public boolean add(LayerEvent o) |
24 | { | 36 | { |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 1bbe3bb..b1e9bdc 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java | |||
@@ -45,6 +45,18 @@ public class LayerEvent extends AbstractEvent implements Event { | |||
45 | this.label = label; | 45 | this.label = label; |
46 | } | 46 | } |
47 | 47 | ||
48 | public LayerEvent copy() | ||
49 | { | ||
50 | LayerEvent temp = new LayerEvent(getLocation().x, getLocation().y, getLabel()); | ||
51 | |||
52 | for (PossibleEvent pe : events) | ||
53 | { | ||
54 | temp.addEvent(pe.copy()); | ||
55 | } | ||
56 | |||
57 | return temp; | ||
58 | } | ||
59 | |||
48 | private String label; | 60 | private String label; |
49 | public String getLabel() | 61 | public String getLabel() |
50 | { | 62 | { |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index 62d356a..f8934f4 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java | |||
@@ -96,6 +96,22 @@ public class PossibleEvent { | |||
96 | calltime = builder.calltime; | 96 | calltime = builder.calltime; |
97 | callback = builder.callback; | 97 | callback = builder.callback; |
98 | } | 98 | } |
99 | |||
100 | public PossibleEvent copy() | ||
101 | { | ||
102 | PossibleEvent temp = new Builder() | ||
103 | .graphic(graphic) | ||
104 | .layer(layer) | ||
105 | .animation(animation) | ||
106 | .movement(movement) | ||
107 | .calltime(calltime) | ||
108 | .callback(callback) | ||
109 | .build(); | ||
110 | |||
111 | temp.getPreconditions().addAll(preconditions); | ||
112 | |||
113 | return temp; | ||
114 | } | ||
99 | 115 | ||
100 | public EventGraphic getGraphic() | 116 | public EventGraphic getGraphic() |
101 | { | 117 | { |