Skip to content

Commit

Permalink
Remove helper method to create size endec
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Oct 20, 2024
1 parent f576dcd commit a9f4516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/main/java/io/wispforest/owo/ui/core/Size.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.wispforest.owo.ui.core;

import io.wispforest.endec.Endec;
import io.wispforest.endec.StructEndec;
import io.wispforest.endec.impl.StructEndecBuilder;
import org.jetbrains.annotations.ApiStatus;

Expand All @@ -14,7 +13,11 @@
*/
public record Size(int width, int height) {

public static final Endec<Size> ENDEC = createEndec("width", "height");
public static final Endec<Size> ENDEC =StructEndecBuilder.of(
Endec.INT.fieldOf("width", Size::width),
Endec.INT.fieldOf("height", Size::height),
Size::of
);

private static final Size ZERO = new Size(0, 0);

Expand All @@ -36,12 +39,4 @@ public static Size square(int sideLength) {
public static Size zero() {
return ZERO;
}

public static StructEndec<Size> createEndec(String widthName, String heightName) {
return StructEndecBuilder.of(
Endec.INT.fieldOf(widthName, Size::width),
Endec.INT.fieldOf(heightName, Size::height),
Size::of
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ private static void ifPresent(Identifier texture, Consumer<NinePatchTexture> act
Endec.INT.optionalFieldOf("u", (texture) -> texture.u, 0),
Endec.INT.optionalFieldOf("v", (texture) -> texture.v, 0),
PatchSizing.ENDEC.flatFieldOf((texture) -> texture.patchSizing),
Size.createEndec("texture_width", "texture_height").flatFieldOf((texture) -> texture.textureSize),
StructEndecBuilder.of(
Endec.INT.fieldOf("texture_width", Size::width),
Endec.INT.fieldOf("texture_height", Size::height),
Size::of
).flatFieldOf((texture) -> texture.textureSize),
Endec.BOOLEAN.fieldOf("repeat", (texture) -> texture.repeat),
NinePatchTexture::new
);
Expand Down

0 comments on commit a9f4516

Please sign in to comment.