diff --git a/src/main/java/net/rptools/maptool/model/drawing/BlastTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/BlastTemplate.java index 0028700b65..7464cde575 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/BlastTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/BlastTemplate.java @@ -22,6 +22,7 @@ import javax.annotation.Nonnull; import net.rptools.maptool.model.GUID; import net.rptools.maptool.model.Zone; +import net.rptools.maptool.model.ZonePoint; import net.rptools.maptool.server.proto.drawing.BlastTemplateDto; import net.rptools.maptool.server.proto.drawing.DrawableDto; @@ -188,4 +189,18 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setBlastTemplate(dto).build(); } + + public static BlastTemplate fromDto(BlastTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new BlastTemplate(id, dto.getOffsetX(), dto.getOffsetY()); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + drawable.setDirection(AbstractTemplate.Direction.valueOf(dto.getDirection())); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/BurstTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/BurstTemplate.java index f3ca1d2b58..c0943d056d 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/BurstTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/BurstTemplate.java @@ -22,6 +22,7 @@ import javax.annotation.Nonnull; import net.rptools.maptool.model.GUID; import net.rptools.maptool.model.Zone; +import net.rptools.maptool.model.ZonePoint; import net.rptools.maptool.server.proto.drawing.BurstTemplateDto; import net.rptools.maptool.server.proto.drawing.DrawableDto; @@ -132,4 +133,17 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setBurstTemplate(dto).build(); } + + public static BurstTemplate fromDto(BurstTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new BurstTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/ConeTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/ConeTemplate.java index 7f0fc97074..85d1288948 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/ConeTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/ConeTemplate.java @@ -350,4 +350,18 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setConeTemplate(dto).build(); } + + public static ConeTemplate fromDto(ConeTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new ConeTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + drawable.setDirection(AbstractTemplate.Direction.valueOf(dto.getDirection())); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/Cross.java b/src/main/java/net/rptools/maptool/model/drawing/Cross.java index 26b53347de..58ed13e4b4 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/Cross.java +++ b/src/main/java/net/rptools/maptool/model/drawing/Cross.java @@ -74,6 +74,19 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setCrossDrawable(dto).build(); } + public static Cross fromDto(CrossDrawableDto dto) { + var id = GUID.valueOf(dto.getId()); + var startPoint = dto.getStartPoint(); + var endPoint = dto.getEndPoint(); + var drawable = + new Cross(id, startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } + @Override public java.awt.Rectangle getBounds(Zone zone) { if (bounds == null) { diff --git a/src/main/java/net/rptools/maptool/model/drawing/Drawable.java b/src/main/java/net/rptools/maptool/model/drawing/Drawable.java index ed8f641462..034fa9fcc2 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/Drawable.java +++ b/src/main/java/net/rptools/maptool/model/drawing/Drawable.java @@ -16,13 +16,9 @@ import java.awt.Graphics2D; import java.awt.geom.Area; -import java.util.ArrayList; import javax.annotation.Nonnull; -import net.rptools.maptool.model.CellPoint; import net.rptools.maptool.model.GUID; import net.rptools.maptool.model.Zone; -import net.rptools.maptool.model.ZonePoint; -import net.rptools.maptool.server.Mapper; import net.rptools.maptool.server.proto.drawing.DrawableDto; import org.apache.logging.log4j.LogManager; @@ -50,198 +46,27 @@ public interface Drawable { DrawableDto toDto(); static Drawable fromDto(DrawableDto drawableDto) { - switch (drawableDto.getDrawableTypeCase()) { - case SHAPE_DRAWABLE -> { - var dto = drawableDto.getShapeDrawable(); - var shape = Mapper.map(dto.getShape()); - var id = GUID.valueOf(dto.getId()); - var drawable = new ShapeDrawable(id, shape, dto.getUseAntiAliasing()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case RECTANGLE_DRAWABLE -> { - var dto = drawableDto.getRectangleDrawable(); - var id = GUID.valueOf(dto.getId()); - var startPoint = dto.getStartPoint(); - var endPoint = dto.getEndPoint(); - var drawable = - new Rectangle( - id, startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case OVAL_DRAWABLE -> { - var dto = drawableDto.getOvalDrawable(); - var id = GUID.valueOf(dto.getId()); - var startPoint = dto.getStartPoint(); - var endPoint = dto.getEndPoint(); - var drawable = - new Oval(id, startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case CROSS_DRAWABLE -> { - var dto = drawableDto.getCrossDrawable(); - var id = GUID.valueOf(dto.getId()); - var startPoint = dto.getStartPoint(); - var endPoint = dto.getEndPoint(); - var drawable = - new Cross(id, startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case DRAWN_LABEL -> { - var dto = drawableDto.getDrawnLabel(); - var id = GUID.valueOf(dto.getId()); - var bounds = dto.getBounds(); - var drawable = - new DrawnLabel(id, dto.getText(), Mapper.map(dto.getBounds()), dto.getFont()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case LINE_SEGMENT -> { - var dto = drawableDto.getLineSegment(); - var id = GUID.valueOf(dto.getId()); - var drawable = new LineSegment(id, dto.getWidth(), dto.getSquareCap()); - var points = drawable.getPoints(); - var pointDtos = dto.getPointsList(); - pointDtos.forEach(p -> points.add(Mapper.map(p))); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case DRAWABLES_GROUP -> { - var dto = drawableDto.getDrawablesGroup(); - var id = GUID.valueOf(dto.getId()); - var elements = new ArrayList(); - var elementDtos = dto.getDrawnElementsList(); - elementDtos.forEach(e -> elements.add(DrawnElement.fromDto(e))); - var drawable = new DrawablesGroup(id, elements); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case RADIUS_CELL_TEMPLATE -> { - var dto = drawableDto.getRadiusCellTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new RadiusCellTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case LINE_CELL_TEMPLATE -> { - var dto = drawableDto.getLineCellTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new LineCellTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - var pathVertex = dto.getPathVertex(); - drawable.setPathVertex(new ZonePoint(pathVertex.getX(), pathVertex.getY())); - if (dto.hasName()) { - drawable.setName(dto.getName().getValue()); - } - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case RADIUS_TEMPLATE -> { - var dto = drawableDto.getRadiusTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new RadiusTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case BURST_TEMPLATE -> { - var dto = drawableDto.getBurstTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new BurstTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case CONE_TEMPLATE -> { - var dto = drawableDto.getConeTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new ConeTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - drawable.setDirection(AbstractTemplate.Direction.valueOf(dto.getDirection())); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case BLAST_TEMPLATE -> { - var dto = drawableDto.getBlastTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new BlastTemplate(id, dto.getOffsetX(), dto.getOffsetY()); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - drawable.setDirection(AbstractTemplate.Direction.valueOf(dto.getDirection())); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case LINE_TEMPLATE -> { - var dto = drawableDto.getLineTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new LineTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - 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())); - drawable.setDoubleWide(dto.getDoubleWide()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - return drawable; - } - case WALL_TEMPLATE -> { - var dto = drawableDto.getWallTemplate(); - var id = GUID.valueOf(dto.getId()); - var drawable = new WallTemplate(id); - drawable.setRadius(dto.getRadius()); - var vertex = dto.getVertex(); - drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); - drawable.setMouseSlopeGreater(dto.getMouseSlopeGreater()); - var pathVertex = dto.getPathVertex(); - drawable.setPathVertex(new ZonePoint(pathVertex.getX(), pathVertex.getY())); - drawable.setDoubleWide(dto.getDoubleWide()); - if (dto.hasName()) drawable.setName(dto.getName().getValue()); - drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); - - var cellpoints = new ArrayList(); - for (var point : dto.getPointsList()) - cellpoints.add(new CellPoint(point.getX(), point.getY())); - drawable.setPath(cellpoints); - - return drawable; - } + return switch (drawableDto.getDrawableTypeCase()) { + case SHAPE_DRAWABLE -> ShapeDrawable.fromDto(drawableDto.getShapeDrawable()); + case RECTANGLE_DRAWABLE -> Rectangle.fromDto(drawableDto.getRectangleDrawable()); + case OVAL_DRAWABLE -> Oval.fromDto(drawableDto.getOvalDrawable()); + case CROSS_DRAWABLE -> Cross.fromDto(drawableDto.getCrossDrawable()); + case DRAWN_LABEL -> DrawnLabel.fromDto(drawableDto.getDrawnLabel()); + case LINE_SEGMENT -> LineSegment.fromDto(drawableDto.getLineSegment()); + case DRAWABLES_GROUP -> DrawablesGroup.fromDto(drawableDto.getDrawablesGroup()); + case RADIUS_CELL_TEMPLATE -> RadiusCellTemplate.fromDto(drawableDto.getRadiusCellTemplate()); + case LINE_CELL_TEMPLATE -> LineCellTemplate.fromDto(drawableDto.getLineCellTemplate()); + case RADIUS_TEMPLATE -> RadiusTemplate.fromDto(drawableDto.getRadiusTemplate()); + case BURST_TEMPLATE -> BurstTemplate.fromDto(drawableDto.getBurstTemplate()); + case CONE_TEMPLATE -> ConeTemplate.fromDto(drawableDto.getConeTemplate()); + case BLAST_TEMPLATE -> BlastTemplate.fromDto(drawableDto.getBlastTemplate()); + case LINE_TEMPLATE -> LineTemplate.fromDto(drawableDto.getLineTemplate()); + case WALL_TEMPLATE -> WallTemplate.fromDto(drawableDto.getWallTemplate()); default -> { LogManager.getLogger(Drawable.class) .warn("unknown DrawableDto type: " + drawableDto.getDrawableTypeCase()); - return null; + yield null; } - } + }; } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/DrawablesGroup.java b/src/main/java/net/rptools/maptool/model/drawing/DrawablesGroup.java index a7323a65a8..4065a5d74b 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/DrawablesGroup.java +++ b/src/main/java/net/rptools/maptool/model/drawing/DrawablesGroup.java @@ -109,6 +109,19 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setDrawablesGroup(dto).build(); } + public static DrawablesGroup fromDto(DrawablesGroupDto dto) { + var id = GUID.valueOf(dto.getId()); + var elements = new ArrayList(); + var elementDtos = dto.getDrawnElementsList(); + elementDtos.forEach(e -> elements.add(DrawnElement.fromDto(e))); + var drawable = new DrawablesGroup(id, elements); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } + @Override protected void draw(Zone zone, Graphics2D g) { // This should never be called diff --git a/src/main/java/net/rptools/maptool/model/drawing/DrawnLabel.java b/src/main/java/net/rptools/maptool/model/drawing/DrawnLabel.java index 30ec5f2fbf..eeda8cf6c2 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/DrawnLabel.java +++ b/src/main/java/net/rptools/maptool/model/drawing/DrawnLabel.java @@ -127,4 +127,15 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setDrawnLabel(dto).build(); } + + public static DrawnLabel fromDto(DrawnLabelDto dto) { + var id = GUID.valueOf(dto.getId()); + var bounds = dto.getBounds(); + var drawable = new DrawnLabel(id, dto.getText(), Mapper.map(dto.getBounds()), dto.getFont()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/LineCellTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/LineCellTemplate.java index dafb4ae8c6..fec9380ed0 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/LineCellTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/LineCellTemplate.java @@ -470,4 +470,19 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setLineCellTemplate(dto).build(); } + + public static LineCellTemplate fromDto(LineCellTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new LineCellTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + var pathVertex = dto.getPathVertex(); + drawable.setPathVertex(new ZonePoint(pathVertex.getX(), pathVertex.getY())); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/LineSegment.java b/src/main/java/net/rptools/maptool/model/drawing/LineSegment.java index 2500779cd2..68c268e396 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/LineSegment.java +++ b/src/main/java/net/rptools/maptool/model/drawing/LineSegment.java @@ -112,6 +112,19 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setLineSegment(dto).build(); } + public static LineSegment fromDto(LineSegmentDrawableDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new LineSegment(id, dto.getWidth(), dto.getSquareCap()); + var points = drawable.getPoints(); + var pointDtos = dto.getPointsList(); + pointDtos.forEach(p -> points.add(Mapper.map(p))); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } + private Area createLineArea() { if (points.size() < 1) { return null; diff --git a/src/main/java/net/rptools/maptool/model/drawing/LineTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/LineTemplate.java index fb096eb1ad..dff43ffb95 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/LineTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/LineTemplate.java @@ -520,4 +520,24 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setLineTemplate(dto).build(); } + + public static LineTemplate fromDto(LineTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new LineTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + 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())); + drawable.setDoubleWide(dto.getDoubleWide()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/Oval.java b/src/main/java/net/rptools/maptool/model/drawing/Oval.java index 624f6de0a5..9123ed0c9f 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/Oval.java +++ b/src/main/java/net/rptools/maptool/model/drawing/Oval.java @@ -89,4 +89,17 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setOvalDrawable(dto).build(); } + + public static Oval fromDto(OvalDrawableDto dto) { + var id = GUID.valueOf(dto.getId()); + var startPoint = dto.getStartPoint(); + var endPoint = dto.getEndPoint(); + var drawable = + new Oval(id, startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/RadiusCellTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/RadiusCellTemplate.java index 6f3e8ed5b3..5f4af61aa3 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/RadiusCellTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/RadiusCellTemplate.java @@ -294,4 +294,17 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setRadiusCellTemplate(dto).build(); } + + public static RadiusCellTemplate fromDto(RadiusCellTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new RadiusCellTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/RadiusTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/RadiusTemplate.java index b154e0c46e..5542cac729 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/RadiusTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/RadiusTemplate.java @@ -175,4 +175,17 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setRadiusTemplate(dto).build(); } + + public static RadiusTemplate fromDto(RadiusTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new RadiusTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } } diff --git a/src/main/java/net/rptools/maptool/model/drawing/Rectangle.java b/src/main/java/net/rptools/maptool/model/drawing/Rectangle.java index 00d369a203..b0dbfa771e 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/Rectangle.java +++ b/src/main/java/net/rptools/maptool/model/drawing/Rectangle.java @@ -73,6 +73,19 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setRectangleDrawable(dto).build(); } + public static Rectangle fromDto(RectangleDrawableDto dto) { + var id = GUID.valueOf(dto.getId()); + var startPoint = dto.getStartPoint(); + var endPoint = dto.getEndPoint(); + var drawable = + new Rectangle(id, startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } + @Override public java.awt.Rectangle getBounds(Zone zone) { if (bounds == null) { diff --git a/src/main/java/net/rptools/maptool/model/drawing/ShapeDrawable.java b/src/main/java/net/rptools/maptool/model/drawing/ShapeDrawable.java index 7c91ee20fe..fede411fa6 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/ShapeDrawable.java +++ b/src/main/java/net/rptools/maptool/model/drawing/ShapeDrawable.java @@ -99,6 +99,17 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setShapeDrawable(dto).build(); } + public static ShapeDrawable fromDto(ShapeDrawableDto dto) { + var shape = Mapper.map(dto.getShape()); + var id = GUID.valueOf(dto.getId()); + var drawable = new ShapeDrawable(id, shape, dto.getUseAntiAliasing()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + return drawable; + } + @Override protected void draw(Zone zone, Graphics2D g) { Object oldAA = applyAA(g); diff --git a/src/main/java/net/rptools/maptool/model/drawing/WallTemplate.java b/src/main/java/net/rptools/maptool/model/drawing/WallTemplate.java index 274eb1fa27..eb0697aaa1 100644 --- a/src/main/java/net/rptools/maptool/model/drawing/WallTemplate.java +++ b/src/main/java/net/rptools/maptool/model/drawing/WallTemplate.java @@ -15,9 +15,11 @@ package net.rptools.maptool.model.drawing; import com.google.protobuf.StringValue; +import java.util.ArrayList; import java.util.List; import net.rptools.maptool.model.CellPoint; import net.rptools.maptool.model.GUID; +import net.rptools.maptool.model.Zone; import net.rptools.maptool.model.ZonePoint; import net.rptools.maptool.server.proto.drawing.DrawableDto; import net.rptools.maptool.server.proto.drawing.WallTemplateDto; @@ -101,4 +103,28 @@ public DrawableDto toDto() { return DrawableDto.newBuilder().setWallTemplate(dto).build(); } + + public static WallTemplate fromDto(WallTemplateDto dto) { + var id = GUID.valueOf(dto.getId()); + var drawable = new WallTemplate(id); + drawable.setRadius(dto.getRadius()); + var vertex = dto.getVertex(); + drawable.setVertex(new ZonePoint(vertex.getX(), vertex.getY())); + drawable.setMouseSlopeGreater(dto.getMouseSlopeGreater()); + var pathVertex = dto.getPathVertex(); + drawable.setPathVertex(new ZonePoint(pathVertex.getX(), pathVertex.getY())); + drawable.setDoubleWide(dto.getDoubleWide()); + if (dto.hasName()) { + drawable.setName(dto.getName().getValue()); + } + drawable.setLayer(Zone.Layer.valueOf(dto.getLayer())); + + var cellpoints = new ArrayList(); + for (var point : dto.getPointsList()) { + cellpoints.add(new CellPoint(point.getX(), point.getY())); + } + drawable.setPath(cellpoints); + + return drawable; + } }