Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hexagon geometry #4831

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mark Grid fields as transient
The movement keys, zone, and cell shape have no business being serialized. The cell shape was also removed from the
DTO to match this.
  • Loading branch information
kwvanderlinde committed Jun 11, 2024
commit e90a627f62592485b60bb7a631e1c2f1a020b1f5
28 changes: 12 additions & 16 deletions src/main/java/net/rptools/maptool/model/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 39,6 @@
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.model.TokenFootprint.OffsetTranslator;
import net.rptools.maptool.model.zones.GridChanged;
import net.rptools.maptool.server.Mapper;
import net.rptools.maptool.server.proto.GridDto;
import net.rptools.maptool.util.GraphicsUtil;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -67,12 66,13 @@ public abstract class Grid implements Cloneable {
private static final Dimension NO_DIM = new Dimension();
private static final DirectionCalculator calculator = new DirectionCalculator();
private static Map<Integer, Area> gridShapeCache = new ConcurrentHashMap<>();
protected Map<KeyStroke, Action> movementKeys = null;

protected transient Map<KeyStroke, Action> movementKeys = null;
private transient Zone zone;
private transient Area cellShape;
private int offsetX = 0;
private int offsetY = 0;
private int size;
private Zone zone;
private Area cellShape;

public Grid() {
setSize(AppPreferences.getDefaultGridSize());
Expand All @@ -83,6 83,11 @@ public Grid(Grid grid) {
setOffset(grid.offsetX, grid.offsetY);
}

protected Object readResolve() {
cellShape = createCellShape(getSize());
return this;
}

protected synchronized Map<Integer, Area> getGridShapeCache() {
return gridShapeCache;
}
Expand Down Expand Up @@ -265,10 270,6 @@ public Area getCellShape() {
return cellShape;
}

protected void setCellShape(Area cellShape) {
this.cellShape = cellShape;
}

public BufferedImage getCellHighlight() {
return null;
}
Expand Down Expand Up @@ -371,6 372,7 @@ public void setSize(int size) {
double footprintWidth = token.getFootprint(this).getBounds(this).getWidth() / 2;

// Test for gridless maps
var cellShape = getCellShape();
if (cellShape == null) {
double tokenBoundsWidth = token.getBounds(getZone()).getWidth() / 2;
visionRange = (footprintWidth > tokenBoundsWidth) ? tokenBoundsWidth : tokenBoundsWidth;
Expand Down Expand Up @@ -944,11 946,8 @@ public static Grid fromDto(GridDto dto) {
grid.offsetX = dto.getOffsetX();
grid.offsetY = dto.getOffsetY();
grid.size = dto.getSize();
if (dto.hasCellShape()) {
grid.cellShape = Mapper.map(dto.getCellShape());
} else {
grid.cellShape = null;
}
grid.cellShape = grid.createCellShape(grid.size);

return grid;
}

Expand All @@ -960,9 959,6 @@ public GridDto toDto() {
dto.setOffsetX(offsetX);
dto.setOffsetY(offsetY);
dto.setSize(size);
if (cellShape != null) {
dto.setCellShape(Mapper.map(cellShape));
}
return dto.build();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/rptools/maptool/model/HexGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 191,7 @@ public double getCellOffsetU() {
}

protected Object readResolve() {
super.readResolve();
setDimensions(getSize(), getSize() / hexRatio);
return this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/rptools/maptool/model/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 2105,8 @@ protected Object readResolve() {
playerAlias = null;
}

grid.setZone(this);

// 1.3b76 -> 1.3b77
// adding the exposed area for Individual FOW
if (exposedAreaMeta == null) {
Expand Down
1 change: 0 additions & 1 deletion src/main/proto/data_transfer_objects.proto
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 583,6 @@ message GridDto {
int32 offset_x = 1;
int32 offset_y = 2;
int32 size = 3;
AreaDto cell_shape = 4;
oneof type {
SquareGridDto square_grid = 5;
GridlessGridDto gridless_grid = 6;
Expand Down