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

Fixes for older campaign compatibility issues. #3653

Merged
merged 3 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/net/rptools/maptool/model/Zone.java
Expand Up @@ -2296,7 +2296,11 @@ public ZoneDto toDto() {
dto.setExposedArea(Mapper.map(exposedArea));
dto.setHasFog(hasFog);
dto.setTopology(Mapper.map(topology));
dto.setFogPaint(fogPaint.toDto());
if (fogPaint == null) { // Account for old campaigns without fog paint
dto.setFogPaint(DEFAULT_FOG.toDto());
} else {
dto.setFogPaint(fogPaint.toDto());
}
dto.setHillVbl(Mapper.map(hillVbl));
dto.setPitVbl(Mapper.map(pitVbl));
dto.setTopologyTerrain(Mapper.map(topologyTerrain));
Expand Down
Expand Up @@ -188,9 +188,13 @@ public void setZoneId(GUID zoneId) {
* @param area Paint the area?
*/
protected void paint(Graphics2D g, boolean border, boolean area) {
if (radius == 0) return;
if (radius == 0) {
return;
}
Zone zone = MapTool.getCampaign().getZone(zoneId);
if (zone == null) return;
if (zone == null) {
return;
}

// Find the proper distance
int gridSize = zone.getGrid().getSize();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/rptools/maptool/model/drawing/Drawable.java
Expand Up @@ -139,11 +139,15 @@ static Drawable fromDto(DrawableDto drawableDto) {
drawable.setRadius(dto.getRadius());
var vertex = dto.getVertex();
drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY()));
drawable.setQuadrant(AbstractTemplate.Quadrant.valueOf(dto.getQuadrant()));
if (!dto.getQuadrant().isEmpty()) {
drawable.setQuadrant(AbstractTemplate.Quadrant.valueOf(dto.getQuadrant()));
}
drawable.setMouseSlopeGreater(dto.getMouseSlopeGreater());
var pathVertex = dto.getPathVertex();
drawable.setPathVertex(new ZonePoint(pathVertex.getX(), pathVertex.getY()));
if (dto.hasName()) drawable.setName(dto.getName().getValue());
if (dto.hasName()) {
drawable.setName(dto.getName().getValue());
}
drawable.setLayer(Zone.Layer.valueOf(dto.getLayer()));
return drawable;
}
Expand Down
Expand Up @@ -122,9 +122,15 @@ protected void paint(Graphics2D g, boolean border, boolean area) {
return;
}
// Need to paint? We need a line and to translate the painting
if (pathVertex == null) return;
if (getRadius() == 0) return;
if (calcPath() == null) return;
if (pathVertex == null) {
return;
}
if (getRadius() == 0) {
return;
}
if (calcPath() == null) {
return;
}

// Paint each element in the path
int gridSize = MapTool.getCampaign().getZone(getZoneId()).getGrid().getSize();
Expand Down Expand Up @@ -164,7 +170,9 @@ public void setVertex(ZonePoint vertex) {
/** @see net.rptools.maptool.model.drawing.AbstractTemplate#setRadius(int) */
@Override
public void setRadius(int squares) {
if (squares == getRadius()) return;
if (squares == getRadius()) {
return;
}
clearPath();
super.setRadius(squares);
}
Expand All @@ -179,13 +187,19 @@ public void setRadius(int squares) {
* @return The new path or <code>null</code> if there is no path.
*/
protected List<CellPoint> calcPath() {
if (getRadius() == 0) return null;
if (pathVertex == null) return null;
if (getRadius() == 0) {
return null;
}
if (pathVertex == null) {
return null;
}
int radius = getRadius();

// Is there a slope?
ZonePoint vertex = getVertex();
if (vertex.equals(pathVertex)) return null;
if (vertex.equals(pathVertex)) {
return null;
}

double dx = pathVertex.x - vertex.x;
double dy = pathVertex.y - vertex.y;
Expand Down Expand Up @@ -298,14 +312,18 @@ public ZonePoint getPathVertex() {
* @param pathVertex The pathVertex to set.
*/
public void setPathVertex(ZonePoint pathVertex) {
if (pathVertex.equals(this.pathVertex)) return;
if (pathVertex.equals(this.pathVertex)) {
return;
}
clearPath();
this.pathVertex = pathVertex;
}

/** Clear the current path. This will cause it to be recalculated during the next draw. */
public void clearPath() {
if (path != null) pool = path;
if (path != null) {
pool = path;
}
path = null;
}

Expand All @@ -315,7 +333,9 @@ public void clearPath() {
* @return Returns the current value of quadrant.
*/
public Quadrant getQuadrant() {
if (quadrant != null) return Quadrant.valueOf(quadrant);
if (quadrant != null) {
return Quadrant.valueOf(quadrant);
}
return null;
}

Expand All @@ -325,8 +345,11 @@ public Quadrant getQuadrant() {
* @param quadrant The quadrant to set.
*/
public void setQuadrant(Quadrant quadrant) {
if (quadrant != null) this.quadrant = quadrant.name();
else this.quadrant = null;
if (quadrant != null) {
this.quadrant = quadrant.name();
} else {
this.quadrant = null;
}
}

/**
Expand Down Expand Up @@ -461,17 +484,29 @@ public Area getArea() {

@Override
public DrawableDto toDto() {

if (getQuadrant() == null) {
calcPath(); // force calculation of the quadrent
}

var dto = LineCellTemplateDto.newBuilder();
dto.setId(getId().toString())
.setLayer(getLayer().name())
.setZoneId(getZoneId().toString())
.setRadius(getRadius())
.setVertex(getVertex().toDto())
.setQuadrant(getQuadrant().name())
.setMouseSlopeGreater(isMouseSlopeGreater())
.setPathVertex(getPathVertex().toDto());
.setMouseSlopeGreater(isMouseSlopeGreater());

if (getQuadrant() != null) {
dto.setQuadrant(getQuadrant().name());
}
if (getPathVertex() != null) {
dto.setPathVertex(getPathVertex().toDto());
}

if (getName() != null) dto.setName(StringValue.of(getName()));
if (getName() != null) {
dto.setName(StringValue.of(getName()));
}

return DrawableDto.newBuilder().setLineCellTemplate(dto).build();
}
Expand Down