Skip to content

Commit

Permalink
Add ability to clamp values in GUIs
Browse files Browse the repository at this point in the history
clamp = FLOOR # Any value smaller than 0.95 is treated as 0
clamp = CEIL  # Any value greater than 0.05 is treated as 1
  • Loading branch information
cam72cam committed Dec 8, 2023
1 parent 9c8eddb commit 8dd18ab
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class GuiBuilder {
private final boolean invert;
private final boolean translucent;
private final boolean toggle;
private final ClampMode clamp;
private final float tlx;
private final float tly;
private final float rotx;
Expand Down Expand Up @@ -102,6 +103,16 @@ public static Vertical from(String pos_y) {
}
}

private enum ClampMode {
NONE, FLOOR, CEIL;
public static ClampMode from(String value) {
if (value != null) {
return valueOf(value.toUpperCase(Locale.ROOT));
}
return NONE;
}
}

private static DataBlock processImports(DataBlock data) throws IOException {
// This is kinda weird as it appends the import to the current block instead of inserting it in the current
// element list. It's definitely a bit of a footgun. The "correct" way to do this would be to make import part
Expand Down Expand Up @@ -167,6 +178,7 @@ protected GuiBuilder(DataBlock data) throws IOException {
this.invert = data.getValue("invert").asBoolean(false);
this.translucent = data.getValue("translucent").asBoolean(data.getValue("hide").asBoolean(false));
this.toggle = data.getValue("toggle").asBoolean(false);
this.clamp = ClampMode.from(data.getValue("clamp").asString());

DataBlock tl = data.getBlock("translate");
if (tl != null) {
Expand Down Expand Up @@ -271,6 +283,13 @@ private float getValue(EntityRollingStock stock) {
value = texture_variant.equals(stock.getTexture()) ? 1 : 0;
}

switch (clamp) {
case FLOOR:
value = value < 0.95 ? 0 : 1;
case CEIL:
value = value < 0.05 ? 0 : 1;
}

if (invert) {
value = 1 - value;
}
Expand Down

0 comments on commit 8dd18ab

Please sign in to comment.