Skip to content

Commit

Permalink
Fix for recalcitrant bar overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
cwisniew committed Sep 26, 2022
1 parent 8c8f944 commit 4671f4d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected BarTokenOverlayDto.Builder getDto() {
dto.setCommon(getCommonDto());
dto.setThickness(thickness);
dto.setColor(barColor.getRGB());
setSideDto(dto);
return dto;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 4671f4d

Please sign in to comment.