From cb18193a2b599853813dbc5fc128406250741a3c Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 15 Feb 2009 13:12:19 -0500 Subject: 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. --- src/com/fourisland/fourpuzzle/database/Database.java | 2 +- src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | 16 ++++++++++++++++ .../fourpuzzle/gamestate/mapview/event/EventList.java | 12 ++++++++++++ .../fourpuzzle/gamestate/mapview/event/LayerEvent.java | 12 ++++++++++++ .../gamestate/mapview/event/PossibleEvent.java | 16 ++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) (limited to 'src') 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 { public static Map getMap(String key) { - return maps.get(key); + return maps.get(key).copy(); } } 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 { setMusicType(musicType); } + public Map copy() + { + Map temp; + if (getMusicType() == MapMusicType.Specified) + { + temp = new Map(getSize().width, getSize().height, getChipSet(), getMusic()); + } else { + temp = new Map(getSize().width, getSize().height, getChipSet(), getMusicType()); + } + + temp.mapData = new Vector>(getMapData()); + temp.events = getEvents().copy(this); + + return temp; + } + private Dimension size; public Dimension getSize() { 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 { setParentMap(parentMap); } + public EventList copy(Map parentMap) + { + EventList temp = new EventList(parentMap); + + for (LayerEvent ev : this) + { + temp.add(ev.copy()); + } + + return temp; + } + @Override public boolean add(LayerEvent o) { 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 { this.label = label; } + public LayerEvent copy() + { + LayerEvent temp = new LayerEvent(getLocation().x, getLocation().y, getLabel()); + + for (PossibleEvent pe : events) + { + temp.addEvent(pe.copy()); + } + + return temp; + } + private String label; public String getLabel() { 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 { calltime = builder.calltime; callback = builder.callback; } + + public PossibleEvent copy() + { + PossibleEvent temp = new Builder() + .graphic(graphic) + .layer(layer) + .animation(animation) + .movement(movement) + .calltime(calltime) + .callback(callback) + .build(); + + temp.getPreconditions().addAll(preconditions); + + return temp; + } public EventGraphic getGraphic() { -- cgit 1.4.1