Skip to content

Commit

Permalink
Merge pull request #3987 from kwvanderlinde/bugfix/3986-rptok-opacity…
Browse files Browse the repository at this point in the history
…-zero

Fix old tokens being given zero opacity when added to a campaign
  • Loading branch information
cwisniew authored Apr 21, 2023
2 parents aa6334c + a229e07 commit f8c384d
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/main/java/net/rptools/maptool/model/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.swing.Icon;
import javax.swing.ImageIcon;
Expand Down Expand Up @@ -291,7 +292,7 @@ public enum Update {
private transient Color visionOverlayColor;

// Jamz: allow token alpha channel modification
private float tokenOpacity = 1.0f;
private @Nonnull Float tokenOpacity = 1.0f;

private String speechName = "";

Expand Down Expand Up @@ -673,31 +674,17 @@ public Color getHaloColor() {
return haloColor;
}

/** @return The token opacity, in the range [0.0f, 1.0f]. */
public float getTokenOpacity() {
if (tokenOpacity < 0.0f) {
tokenOpacity = 1.0f;
}

return tokenOpacity;
}

/**
* Set the token opacity from a string trimmed to [0.05f, 1.0f]
*
* @param alpha the String of the opacity value.
* @return the float of the opacity
*/
public float setTokenOpacity(String alpha) {
return setTokenOpacity(Float.parseFloat(alpha));
}

/**
* Set the token opacity from a float trimmed to [0.05f, 1.0f]
* Set the token opacity from a float trimmed to [0.0f, 1.0f]
*
* @param alpha the float of the opacity.
* @return the float of the opacity trimmed.
*/
public float setTokenOpacity(float alpha) {
public void setTokenOpacity(float alpha) {
if (alpha > 1.0f) {
alpha = 1.0f;
}
Expand All @@ -706,8 +693,6 @@ public float setTokenOpacity(float alpha) {
}

tokenOpacity = alpha;

return tokenOpacity;
}

/**
Expand Down Expand Up @@ -2520,6 +2505,12 @@ protected Object readResolve() {
gmNotesType = SyntaxConstants.SYNTAX_STYLE_NONE;
}

// Pre 1.13
if (tokenOpacity == null) {
tokenOpacity = 1.f;
}
tokenOpacity = Math.max(0.f, Math.min(tokenOpacity, 1.f));

return this;
}

Expand Down Expand Up @@ -2720,7 +2711,7 @@ public void updateProperty(Zone zone, Update update, List<TokenPropertyValueDto>
setIsAlwaysVisible(parameters.get(0).getBoolValue());
break;
case setTokenOpacity:
setTokenOpacity(parameters.get(0).getStringValue());
setTokenOpacity(Float.parseFloat(parameters.get(0).getStringValue()));
break;
case setTerrainModifier:
setTerrainModifier(parameters.get(0).getDoubleValue());
Expand Down

0 comments on commit f8c384d

Please sign in to comment.