diff --git a/src/main/java/net/rptools/maptool/client/ui/token/BarTokenOverlay.java b/src/main/java/net/rptools/maptool/client/ui/token/BarTokenOverlay.java index cf9f3f46f4..1a0cf69f33 100644 --- a/src/main/java/net/rptools/maptool/client/ui/token/BarTokenOverlay.java +++ b/src/main/java/net/rptools/maptool/client/ui/token/BarTokenOverlay.java @@ -18,6 +18,7 @@ import java.awt.Rectangle; import net.rptools.maptool.model.Token; import net.rptools.maptool.server.proto.BarTokenOverlayDto; +import net.rptools.maptool.server.proto.BarTokenOverlayDto.SideDto; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -199,24 +200,33 @@ public enum Side { // } public static BarTokenOverlay fromDto(BarTokenOverlayDto dto) { - switch (dto.getType()) { - case DRAWN -> { - return DrawnBarTokenOverlay.fromDto(dto); - } - case MULTIPLE_IMAGE -> { - return MultipleImageBarTokenOverlay.fromDto(dto); - } - case SINGLE_IMAGE -> { - return SingleImageBarTokenOverlay.fromDto(dto); - } - case TWO_IMAGES -> { - return TwoImageBarTokenOverlay.fromDto(dto); - } - case TWO_TONE -> { - return TwoToneBarTokenOverlay.fromDto(dto); + var bar = + switch (dto.getType()) { + case DRAWN -> DrawnBarTokenOverlay.fromDto(dto); + case MULTIPLE_IMAGE -> MultipleImageBarTokenOverlay.fromDto(dto); + case SINGLE_IMAGE -> SingleImageBarTokenOverlay.fromDto(dto); + case TWO_IMAGES -> TwoImageBarTokenOverlay.fromDto(dto); + case TWO_TONE -> TwoToneBarTokenOverlay.fromDto(dto); + case UNRECOGNIZED -> null; + }; + if (bar != null) { + switch (dto.getSide()) { + case TOP -> bar.setSide(Side.TOP); + case LEFT -> bar.setSide(Side.LEFT); + case RIGHT -> bar.setSide(Side.RIGHT); + case BOTTOM -> bar.setSide(Side.BOTTOM); } } - return null; + return bar; + } + + protected void setSideDto(BarTokenOverlayDto.Builder dto) { + switch (side) { + case TOP -> dto.setSide(SideDto.TOP); + case BOTTOM -> dto.setSide(SideDto.BOTTOM); + case LEFT -> dto.setSide(SideDto.LEFT); + case RIGHT -> dto.setSide(SideDto.RIGHT); + } } public abstract BarTokenOverlayDto toDto(); diff --git a/src/main/java/net/rptools/maptool/client/ui/token/DrawnBarTokenOverlay.java b/src/main/java/net/rptools/maptool/client/ui/token/DrawnBarTokenOverlay.java index a609abb067..fb9f301b39 100644 --- a/src/main/java/net/rptools/maptool/client/ui/token/DrawnBarTokenOverlay.java +++ b/src/main/java/net/rptools/maptool/client/ui/token/DrawnBarTokenOverlay.java @@ -134,6 +134,7 @@ protected BarTokenOverlayDto.Builder getDto() { dto.setCommon(getCommonDto()); dto.setThickness(thickness); dto.setColor(barColor.getRGB()); + setSideDto(dto); return dto; } diff --git a/src/main/java/net/rptools/maptool/client/ui/token/MultipleImageBarTokenOverlay.java b/src/main/java/net/rptools/maptool/client/ui/token/MultipleImageBarTokenOverlay.java index 6bcf0c99bd..031aa3f2f4 100644 --- a/src/main/java/net/rptools/maptool/client/ui/token/MultipleImageBarTokenOverlay.java +++ b/src/main/java/net/rptools/maptool/client/ui/token/MultipleImageBarTokenOverlay.java @@ -126,6 +126,7 @@ public static BarTokenOverlay fromDto(BarTokenOverlayDto dto) { public BarTokenOverlayDto toDto() { var dto = BarTokenOverlayDto.newBuilder().setCommon(getCommonDto()); + setSideDto(dto); dto.addAllAssetIds( Arrays.asList(assetIds).stream().map(a -> a.toString()).collect(Collectors.toList())); return dto.setType(BarTokenOverlayDto.BarTokenOverlayTypeDto.MULTIPLE_IMAGE).build(); diff --git a/src/main/java/net/rptools/maptool/client/ui/token/SingleImageBarTokenOverlay.java b/src/main/java/net/rptools/maptool/client/ui/token/SingleImageBarTokenOverlay.java index 5d14af7191..d9dc419fa0 100644 --- a/src/main/java/net/rptools/maptool/client/ui/token/SingleImageBarTokenOverlay.java +++ b/src/main/java/net/rptools/maptool/client/ui/token/SingleImageBarTokenOverlay.java @@ -150,6 +150,7 @@ public static BarTokenOverlay fromDto(BarTokenOverlayDto dto) { public BarTokenOverlayDto toDto() { var dto = BarTokenOverlayDto.newBuilder().setCommon(getCommonDto()); dto.addAssetIds(assetId.toString()); + setSideDto(dto); return dto.setType(BarTokenOverlayDto.BarTokenOverlayTypeDto.SINGLE_IMAGE).build(); } } diff --git a/src/main/java/net/rptools/maptool/client/ui/token/TwoImageBarTokenOverlay.java b/src/main/java/net/rptools/maptool/client/ui/token/TwoImageBarTokenOverlay.java index b54297521e..2f268fe4b3 100644 --- a/src/main/java/net/rptools/maptool/client/ui/token/TwoImageBarTokenOverlay.java +++ b/src/main/java/net/rptools/maptool/client/ui/token/TwoImageBarTokenOverlay.java @@ -174,6 +174,7 @@ public BarTokenOverlayDto toDto() { var dto = BarTokenOverlayDto.newBuilder().setCommon(getCommonDto()); dto.addAssetIds(bottomAssetId.toString()); dto.addAssetIds(topAssetId.toString()); + setSideDto(dto); return dto.setType(BarTokenOverlayDto.BarTokenOverlayTypeDto.TWO_IMAGES).build(); } } diff --git a/src/main/java/net/rptools/maptool/client/ui/token/TwoToneBarTokenOverlay.java b/src/main/java/net/rptools/maptool/client/ui/token/TwoToneBarTokenOverlay.java index ca1a3eaa9d..379aa18968 100644 --- a/src/main/java/net/rptools/maptool/client/ui/token/TwoToneBarTokenOverlay.java +++ b/src/main/java/net/rptools/maptool/client/ui/token/TwoToneBarTokenOverlay.java @@ -120,6 +120,7 @@ public static TwoToneBarTokenOverlay fromDto(BarTokenOverlayDto dto) { public BarTokenOverlayDto toDto() { var dto = getDto(); dto.setBgColor(bgColor.getRGB()); + setSideDto(dto); return dto.setType(BarTokenOverlayDto.BarTokenOverlayTypeDto.TWO_TONE).build(); } }