Skip to content

Commit

Permalink
Merge pull request #4791 from kwvanderlinde/bugfix/4789-duplicate-tok…
Browse files Browse the repository at this point in the history
…en-IDs

Replace token IDs on imported maps
  • Loading branch information
cwisniew authored May 23, 2024
2 parents bf7fd9f + 414ceac commit 50db900
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@
import net.rptools.parser.ParserException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;

/** */
public class ZoneRenderer extends JComponent
implements DropTargetListener, Comparable<ZoneRenderer> {
public class ZoneRenderer extends JComponent implements DropTargetListener {

private static final long serialVersionUID = 3832897780066104884L;
private static final Logger log = LogManager.getLogger(ZoneRenderer.class);
Expand Down Expand Up @@ -3566,15 +3564,6 @@ private void onGridChanged(GridChanged event) {
repaintDebouncer.dispatch();
}

//
// COMPARABLE
public int compareTo(@NotNull ZoneRenderer o) {
if (o != this) {
return (int) (zone.getCreationTime() - o.zone.getCreationTime());
}
return 0;
}

// Begin token common macro identification
private List<Token> highlightCommonMacros = new ArrayList<Token>();

Expand Down
25 changes: 3 additions & 22 deletions src/main/java/net/rptools/maptool/model/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,6 @@ public String toString() {

public static final DrawablePaint DEFAULT_FOG = new DrawableColorPaint(Color.black);

// The zones should be ordered. We could have the server assign each zone
// an incrementing number as new zones are created, but that would take a lot
// more elegance than we really need. Instead, let's just keep track of the
// time when it was created. This should give us sufficient granularity, because
// seriously -- what's the likelihood of two GMs separately creating a new zone at exactly
// the same millisecond since the epoch?
private long creationTime = System.currentTimeMillis();

private GUID id = new GUID(); // Ideally would be 'final', but that complicates imported()
Expand Down Expand Up @@ -478,10 +472,6 @@ public String toString() {
drawablesByLayer.put(Layer.BACKGROUND, backgroundDrawables);
}

/**
* Note: When adding new fields to this class, make sure to update all constructors, {@link
* #imported()}, {@link #readResolve()}, and potentially {@link #optimize()}.
*/
public Zone() {
// TODO: Was this needed?
// setGrid(new SquareGrid());
Expand Down Expand Up @@ -611,16 +601,11 @@ public DrawablePaint getFogPaint() {
}

/**
* Note: When adding new fields to this class, make sure to update all constructors, {@link
* #imported()}, {@link #readResolve()}, and potentially {@link #optimize()}.
* Create a new zone with old zone's properties and with new token ids.
*
* <p>JFJ 2010-10-27 Don't forget that since there are new zones AND new tokens created here from
* the old one being passed in, if you have any data that needs to transfer over, you will need to
* manually copy it as is done below for various items.
*/

/**
* Create a new zone with old zone's properties and with new token ids.
*
* @param zone The zone to copy.
*/
Expand All @@ -637,6 +622,7 @@ public Zone(Zone zone) {
public Zone(Zone zone, boolean keepIds) {
if (keepIds) {
this.id = zone.getId();
this.creationTime = zone.creationTime;
}

backgroundPaint = zone.backgroundPaint;
Expand Down Expand Up @@ -755,14 +741,9 @@ public GUID getId() {

/**
* Should be invoked only when a Zone has been imported from an external source and needs to be
* cleaned up before being used. Currently this cleanup consists of allocating a new GUID, setting
* the creation time to `now', and resetting the initiative list (setting the related zone and
* clearing the model).
* cleaned up before being used.
*/
public void imported() {
id = new GUID();
creationTime = System.currentTimeMillis();
initiativeList.setZone(this);
initiativeList.clearModel();
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/rptools/maptool/util/PersistenceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ public static PersistedMap loadMap(File mapFile) throws IOException {
z.setName(n);
z.imported(); // Resets creation timestamp and init panel, among other things
z.optimize(); // Collapses overlaid or redundant drawables

// Make sure the imported zone is as fresh as possible (new IDs all the way down).
persistedMap.zone = new Zone(z, false);
} else {
// TODO: Not a map but it is something with a property.xml file in it.
// Should we have a filetype property in there?
Expand Down

0 comments on commit 50db900

Please sign in to comment.