Code updates

This commit is contained in:
Speiger 2025-02-22 06:22:13 +01:00
parent 6c4e036e46
commit 9036a7391a
10 changed files with 259 additions and 42 deletions

View File

@ -17,13 +17,11 @@ import speiger.src.coreengine.assets.base.IAssetProvider;
import speiger.src.coreengine.math.vector.matrix.Matrix4f; import speiger.src.coreengine.math.vector.matrix.Matrix4f;
import speiger.src.coreengine.rendering.gui.font.Font; import speiger.src.coreengine.rendering.gui.font.Font;
import speiger.src.coreengine.rendering.gui.font.FontManager; import speiger.src.coreengine.rendering.gui.font.FontManager;
import speiger.src.coreengine.rendering.gui.font.TextStyle;
import speiger.src.coreengine.rendering.gui.font.glyth.Glyth; import speiger.src.coreengine.rendering.gui.font.glyth.Glyth;
import speiger.src.coreengine.rendering.gui.font.glyth.IGlythSheetInfo; import speiger.src.coreengine.rendering.gui.font.glyth.IGlythSheetInfo;
import speiger.src.coreengine.rendering.gui.font.glyth.MissingGlyth; import speiger.src.coreengine.rendering.gui.font.glyth.MissingGlyth;
import speiger.src.coreengine.rendering.gui.font.glyth.UnbakedGlyth;
import speiger.src.coreengine.rendering.gui.font.glyth.UnbakedGlyth.GlythBaker; import speiger.src.coreengine.rendering.gui.font.glyth.UnbakedGlyth.GlythBaker;
import speiger.src.coreengine.rendering.gui.font.providers.IFontProvider;
import speiger.src.coreengine.rendering.gui.font.providers.STBTrueTypeProvider;
import speiger.src.coreengine.rendering.input.devices.FileDrop; import speiger.src.coreengine.rendering.input.devices.FileDrop;
import speiger.src.coreengine.rendering.input.devices.Joystick; import speiger.src.coreengine.rendering.input.devices.Joystick;
import speiger.src.coreengine.rendering.input.devices.Keyboard; import speiger.src.coreengine.rendering.input.devices.Keyboard;
@ -42,9 +40,12 @@ import speiger.src.coreengine.rendering.tesselation.buffer.VertexBuilder;
import speiger.src.coreengine.rendering.tesselation.format.VertexTypes; import speiger.src.coreengine.rendering.tesselation.format.VertexTypes;
import speiger.src.coreengine.rendering.textures.custom.Drawable; import speiger.src.coreengine.rendering.textures.custom.Drawable;
import speiger.src.coreengine.rendering.textures.custom.DynamicTexture; import speiger.src.coreengine.rendering.textures.custom.DynamicTexture;
import speiger.src.coreengine.rendering.utils.GLFunctions;
import speiger.src.coreengine.rendering.utils.GLStateTracker; import speiger.src.coreengine.rendering.utils.GLStateTracker;
import speiger.src.coreengine.rendering.utils.values.GLBlendFactor;
import speiger.src.coreengine.rendering.utils.values.GLDataType; import speiger.src.coreengine.rendering.utils.values.GLDataType;
import speiger.src.coreengine.rendering.utils.values.GLMode; import speiger.src.coreengine.rendering.utils.values.GLMode;
import speiger.src.coreengine.rendering.utils.values.IGLValue.ISourceFactor;
import speiger.src.coreengine.rendering.utils.values.textures.GLTextureFormat; import speiger.src.coreengine.rendering.utils.values.textures.GLTextureFormat;
import speiger.src.coreengine.utils.eventbus.EventBus; import speiger.src.coreengine.utils.eventbus.EventBus;
import speiger.src.coreengine.utils.helpers.IOUtils; import speiger.src.coreengine.utils.helpers.IOUtils;
@ -83,7 +84,6 @@ public class NewInputTest {
System.out.println("Testing: "+GL.getCapabilities().OpenGL41); System.out.println("Testing: "+GL.getCapabilities().OpenGL41);
System.out.println("Testing: "+Integer.divideUnsigned(-1, 255)); System.out.println("Testing: "+Integer.divideUnsigned(-1, 255));
IFontProvider provider = STBTrueTypeProvider.create(AssetLocation.of("font/roboto/font.json"), assets);
guiShader.get().proView.set(new Matrix4f().ortho(0, 0, window.width(), window.height(), 1000, -1000)); guiShader.get().proView.set(new Matrix4f().ortho(0, 0, window.width(), window.height(), 1000, -1000));
int size = 512; int size = 512;
@ -107,22 +107,6 @@ public class NewInputTest {
drawable.upload(texture.id(), base * 3, base * 3, base, base, base * 2, base * 2); drawable.upload(texture.id(), base * 3, base * 3, base, base, base * 2, base * 2);
drawable.close(); drawable.close();
} }
else if(T.key() == GLFW.GLFW_KEY_Z) {
T.cancel();
System.out.println("Testing");
// texture.bind();
UnbakedGlyth data = provider.glythData("C".codePointAt(0), 0, 18.5F, 2F);
data.bake(new GlythBaker() {
@Override
public Glyth bake(IGlythSheetInfo info) {
int width = info.width();
int height = info.height();
info.upload(texture.id(), half - (width >> 1), half - (height >> 1));
System.out.println("Test2: "+width+", "+height);
return null;
}
});
}
else if(T.key() == GLFW.GLFW_KEY_U) { else if(T.key() == GLFW.GLFW_KEY_U) {
MissingGlyth glyth = new MissingGlyth(18.5F, 4F); MissingGlyth glyth = new MissingGlyth(18.5F, 4F);
glyth.bake(new GlythBaker() { glyth.bake(new GlythBaker() {
@ -163,10 +147,10 @@ public class NewInputTest {
// String s = "The Quick brown fox Jumps over the Lazy dog"; // String s = "The Quick brown fox Jumps over the Lazy dog";
float offset = font.drawText("The Quick ", 50, 50, -1, buffer, false); float offset = font.drawText("The Quick ", 50, 50, -1, buffer, false);
offset += font.drawText(Font.DEFAULT.with(25F), "Brown ", 50+offset, 50, -1, buffer, false); offset += font.drawText(TextStyle.DEFAULT.size(25F), "Brown ", 50+offset, 50, -1, buffer, false);
offset += font.drawText(Font.DEFAULT, "Fox ", 50+offset, 50, -1, buffer, false); offset += font.drawText(TextStyle.DEFAULT, "§<c=0x24FF00FF>F§<c=r>ox ", 50+offset, 50, -1, buffer, false);
offset += font.drawText(Font.DEFAULT.with(10F), "Jumps ", 50+offset, 50, -1, buffer, false); offset += font.drawText(TextStyle.DEFAULT.size(10F), "Jumps ", 50+offset, 50, -1, buffer, false);
offset += font.drawText(Font.DEFAULT, "over the Lazy dog", 50+offset, 50, -1, buffer, true); offset += font.drawText(TextStyle.DEFAULT, "over the Lazy dog", 50+offset, 50, -1, buffer, true);
// font.drawText(s, 50, 50, -1, buffer, true); // font.drawText(s, 50, 50, -1, buffer, true);
GLStateTracker tracker = GLStateTracker.instance(); GLStateTracker tracker = GLStateTracker.instance();
@ -182,10 +166,12 @@ public class NewInputTest {
model.unbindArray(); model.unbindArray();
guiModel[0].bindArray(); guiModel[0].bindArray();
guiShader.bind(); guiShader.bind();
GLStateTracker.instance().blend.setFunction(GLBlendFactor.SRC_COLOR, GLBlendFactor.ONE_MINUS_SRC_ALPHA, GLBlendFactor.ONE, GLBlendFactor.ZERO).enable();
for(GLDraw draw : draws) { for(GLDraw draw : draws) {
tracker.textures.bind(draw.texture()); tracker.textures.bind(draw.texture());
GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), draw.startVertex(), draw.vertexCount()); GLStateTracker.drawArrays(GLMode.TRIANGLES.glValue(), draw.startVertex(), draw.vertexCount());
} }
GLStateTracker.instance().blend.disable();
guiModel[0].unbindArray(); guiModel[0].unbindArray();
window.handleInput(); window.handleInput();
window.finishFrame(); window.finishFrame();

View File

@ -112,6 +112,14 @@ public class ColorUtils {
public static float getBF(int rgba) { return (rgba & 0xFF) * DEVIDER; } public static float getBF(int rgba) { return (rgba & 0xFF) * DEVIDER; }
public static int getA(int rgba) { return (rgba >> 24) & 0xFF; } public static int getA(int rgba) { return (rgba >> 24) & 0xFF; }
public static float getAF(int rgba) { return ((rgba >> 24) & 0xFF) * DEVIDER; } public static float getAF(int rgba) { return ((rgba >> 24) & 0xFF) * DEVIDER; }
public static int parse(String input) {
try { return Long.decode(input).intValue(); }
catch (Exception e) { return -1; }
}
public static int parse(String input, int defaultValue) {
try { return Long.decode(input).intValue(); }
catch (Exception e) { return defaultValue; }
}
public static String toHex(int rgba, boolean alpha) { return "0x"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1); } public static String toHex(int rgba, boolean alpha) { return "0x"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1); }
public static String toHTML(int rgba, boolean alpha) { return "#"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1); } public static String toHTML(int rgba, boolean alpha) { return "#"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1); }
} }

View File

@ -10,8 +10,8 @@ import speiger.src.coreengine.rendering.gui.font.glyth.UnbakedGlyth.GlythBaker;
import speiger.src.coreengine.rendering.tesselation.buffer.IVertexBuilder; import speiger.src.coreengine.rendering.tesselation.buffer.IVertexBuilder;
public class Font { public class Font {
public static final FontStyle DEFAULT = new FontStyle(AssetLocation.of("default"), 0, 18F); private static final int FORMAT_CODE_POINT = '§';
FontSplitter splitter;
Map<AssetLocation, FontGroup> fonts; Map<AssetLocation, FontGroup> fonts;
GlythBaker baker; GlythBaker baker;
float oversample; float oversample;
@ -22,6 +22,7 @@ public class Font {
this.baker = baker; this.baker = baker;
this.oversample = oversample; this.oversample = oversample;
clearing.accept(this::reset); clearing.accept(this::reset);
splitter = new FontSplitter(this);
} }
private void reset() { private void reset() {
@ -43,19 +44,28 @@ public class Font {
} }
public float drawText(String text, float x, float y, int color, TexturedBuffer buffer, boolean end) { public float drawText(String text, float x, float y, int color, TexturedBuffer buffer, boolean end) {
return drawText(DEFAULT, text, x, y, color, buffer, end); return drawText(TextStyle.DEFAULT, text, x, y, color, buffer, end);
} }
public float drawText(FontStyle style, String text, float x, float y, int color, TexturedBuffer buffer, boolean end) { public float drawText(TextStyle style, String text, float x, float y, int color, TexturedBuffer buffer, boolean end) {
TextStyle[] currentStyle = {style};
int[] currentColor = {currentStyle[0].hasColor() ? currentStyle[0].color() : color};
float xStart = x; float xStart = x;
int previousCodepoint = -1; int previousCodepoint = -1;
for(int i = 0,m=text.length();i<m;) { for(int i = 0,m=text.length();i<m;) {
int codepoint = text.codePointAt(i); int codepoint = text.codePointAt(i);
GlythData data = data(style, codepoint); if(codepoint == FORMAT_CODE_POINT && applyStyle(text, i+1, currentStyle[0], style, T -> {
currentStyle[0] = T;
currentColor[0] = T.hasColor() ? T.color() : color;
})) {
i = text.indexOf('>', i)+1;
continue;
}
GlythData data = data(currentStyle[0].font(), codepoint);
if(previousCodepoint != -1) { if(previousCodepoint != -1) {
x -= data.kerning(previousCodepoint); x -= data.kerning(previousCodepoint);
} }
Glyth glyth = glyth(style, codepoint); Glyth glyth = glyth(currentStyle[0].font(), codepoint);
if(glyth.isValid()) { if(glyth.isValid()) {
float minX = glyth.left() + x; float minX = glyth.left() + x;
float minY = glyth.top() + y; float minY = glyth.top() + y;
@ -63,12 +73,12 @@ public class Font {
float maxY = glyth.bottom() + y; float maxY = glyth.bottom() + y;
IVertexBuilder builder = buffer.builderForTexture(glyth.texture()); IVertexBuilder builder = buffer.builderForTexture(glyth.texture());
builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex(); builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(currentColor[0]).endVertex();
builder.pos(maxX, minY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(-1).endVertex(); builder.pos(maxX, minY, 0F).tex(glyth.maxU(), glyth.minV()).rgba(currentColor[0]).endVertex();
builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex(); builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(currentColor[0]).endVertex();
builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(-1).endVertex(); builder.pos(maxX, maxY, 0F).tex(glyth.maxU(), glyth.maxV()).rgba(currentColor[0]).endVertex();
builder.pos(minX, maxY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(-1).endVertex(); builder.pos(minX, maxY, 0F).tex(glyth.minU(), glyth.maxV()).rgba(currentColor[0]).endVertex();
builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(-1).endVertex(); builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(currentColor[0]).endVertex();
} }
x += data.advance(); x += data.advance();
i += Character.charCount(codepoint); i += Character.charCount(codepoint);
@ -78,6 +88,17 @@ public class Font {
return x - xStart; return x - xStart;
} }
boolean applyStyle(String text, int index, TextStyle style, TextStyle original, Consumer<TextStyle> consumer) {
if(text.length() <= index || text.codePointAt(index) != '<') return false;
int endIndex = text.indexOf('>', index);
if(endIndex == -1) return false;
String[] formatting = text.substring(index+1, endIndex).split(",");
if(formatting.length <= 0) return false;
consumer.accept(style.parseArguments(original, formatting));
return true;
}
public static interface TexturedBuffer { public static interface TexturedBuffer {
public IVertexBuilder builderForTexture(int textureId); public IVertexBuilder builderForTexture(int textureId);
public void end(); public void end();

View File

@ -0,0 +1,28 @@
package speiger.src.coreengine.rendering.gui.font;
public class FontSplitter {
private static final int SPLITTER_CODE_POINT = '§';
Font font;
public FontSplitter(Font font) {
this.font = font;
System.out.println("Testing: "+SPLITTER_CODE_POINT);
}
public float width(String text) {
return width(TextStyle.DEFAULT, text);
}
public float width(TextStyle style, String text) {
float total = 0F;
for(int i = 0,m=text.length();i<m;i++) {
int codePoint = text.codePointAt(i);
total += font.data(style.font(), codePoint).advance();
}
return total;
}
}

View File

@ -3,6 +3,7 @@ package speiger.src.coreengine.rendering.gui.font;
import speiger.src.coreengine.assets.AssetLocation; import speiger.src.coreengine.assets.AssetLocation;
public record FontStyle(AssetLocation font, int style, float size) { public record FontStyle(AssetLocation font, int style, float size) {
public static final FontStyle DEFAULT = new FontStyle(AssetLocation.of("default"), 0, 18F);
public static final int REGULAR = 0; public static final int REGULAR = 0;
public static final int BOLD = 1; public static final int BOLD = 1;
public static final int ITALIC = 2; public static final int ITALIC = 2;

View File

@ -0,0 +1,139 @@
package speiger.src.coreengine.rendering.gui.font;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.utils.helpers.TextUtil;
public record TextStyle(FontStyle font, int styleFlags, int color) {
public static final TextStyle DEFAULT = new TextStyle(FontStyle.DEFAULT);
public static final int NONE = 0;
public static final int UNDERLINE = 1;
public static final int STRIKETHROUGH = 2;
public static final int HAS_COLOR = 4;
public TextStyle(FontStyle font) {
this(font, 0, 0xFFFFFFFF);
}
public TextStyle(FontStyle font, int color) {
this(font, 0, color);
}
public TextStyle color(int color) {
return new TextStyle(font, styleFlags | HAS_COLOR, color);
}
public TextStyle removeColor() {
return new TextStyle(font, styleFlags & ~HAS_COLOR, color);
}
public TextStyle font(FontStyle font) {
return new TextStyle(font, styleFlags, color);
}
public TextStyle font(AssetLocation location) {
return new TextStyle(font.with(location), styleFlags, color);
}
public TextStyle size(float size) {
return new TextStyle(font.with(size), styleFlags, color);
}
public TextStyle bold(boolean value) {
return new TextStyle(font.withBold(value), styleFlags, color);
}
public TextStyle italic(boolean value) {
return new TextStyle(font.withItalic(value), styleFlags, color);
}
public TextStyle underline(boolean value) {
return new TextStyle(font, value ? styleFlags | UNDERLINE : styleFlags & ~UNDERLINE, color);
}
public TextStyle strikethrough(boolean value) {
return new TextStyle(font, value ? styleFlags | STRIKETHROUGH : styleFlags & ~STRIKETHROUGH, color);
}
public TextStyle parseArguments(TextStyle original, String... args) {
AssetLocation font = font().font();
boolean bold = font().bold();
boolean italic = font().italic();
boolean underline = underline();
boolean strikethrough = strikethrough();
int color = color();
boolean hasColor = hasColor();
float size = font().size();
for(int i = 0,m=args.length;i<m;i++) {
String entry = args[i].trim();
if(entry.length() < 3 || entry.charAt(1) != '=') continue;
String data = entry.substring(2);
if(data.length() <= 0) continue;
switch(Character.toLowerCase(entry.charAt(0))) {
case 'f':
if(data.length() == 1 && data.charAt(0) == 'r') font = original.font().font();
else {
AssetLocation newFont = AssetLocation.tryOf(data);
if(newFont != null) font = newFont;
}
break;
case 'c':
if(data.length() == 1 && data.charAt(0) == 'r') {
color = original.color();
hasColor = original.hasColor();
}
else if(data.length() == 1 && data.charAt(0) == 'd') {
color = -1;
hasColor = false;
}
else {
color = ColorUtils.parse(data, color);
hasColor = true;
}
break;
case 's': {
if(data.length() == 1 && data.charAt(0) == 'r') size = original.font().size();
else size = TextUtil.parseFloat(data, size);
break;
}
case 'b':
bold = TextUtil.parseBoolean(data, bold, original.bold());
break;
case 'i':
italic = TextUtil.parseBoolean(data, italic, original.italic());
break;
case 'u':
underline = TextUtil.parseBoolean(data, underline, original.underline());
break;
case 'l':
strikethrough = TextUtil.parseBoolean(data, strikethrough, original.strikethrough());
break;
}
}
if(color != color() || hasColor != hasColor() || bold != bold() || italic != italic() || underline != underline() || strikethrough != strikethrough() || font != font().font() || size != size) {
return new TextStyle(font().with(font, (bold ? FontStyle.BOLD : FontStyle.REGULAR) | (bold ? FontStyle.ITALIC : FontStyle.REGULAR), size), (underline ? UNDERLINE : NONE) | (strikethrough ? STRIKETHROUGH : NONE) | (hasColor ? HAS_COLOR : NONE), color);
}
return this;
}
public boolean hasColor() {
return (styleFlags & HAS_COLOR) != 0;
}
public boolean bold() {
return font.bold();
}
public boolean italic() {
return font.italic();
}
public boolean underline() {
return (styleFlags & UNDERLINE) != 0;
}
public boolean strikethrough() {
return (styleFlags & STRIKETHROUGH) != 0;
}
}

View File

@ -40,7 +40,7 @@ public class ConstrainedContext {
for(int i = 0,m=children.size();i<m;i++) { for(int i = 0,m=children.size();i<m;i++) {
float value = weights[i*2]; float value = weights[i*2];
if(value <= 0F) continue; if(value <= 0F) continue;
bounds[i*2] = value * scale; bounds[i*2] += value * scale;
} }
} }
if(totals[3] > 0F) { if(totals[3] > 0F) {
@ -48,7 +48,7 @@ public class ConstrainedContext {
for(int i = 0,m=children.size();i<m;i++) { for(int i = 0,m=children.size();i<m;i++) {
float value = weights[i*2+1]; float value = weights[i*2+1];
if(value <= 0) continue; if(value <= 0) continue;
bounds[i*2+1] = value * scale; bounds[i*2+1] += value * scale;
} }
} }
} }

View File

@ -91,8 +91,16 @@ public class Constraints {
} }
} }
public static record Weighted(float weight, float padding, boolean inverted) implements ISimpleConstraint { public static record Weighted(float weight, float minimum, float padding, boolean inverted) implements ISimpleConstraint {
public static Weighted of(float weight) { return new Weighted(weight, 0F, false); } public static Weighted of(float weight) { return new Weighted(weight, 0F, 0F, false); }
public static Weighted padded(float weight, float padding) { return new Weighted(weight, 0F, padding, false); }
public static Weighted minimum(float weight, float minimized) { return new Weighted(weight, minimized, 0F, false); }
public static Weighted of(float weight, float minimized, float padding) { return new Weighted(weight, minimized, padding, false); }
public static Weighted inverted(float weight) { return new Weighted(weight, 0F, 0F, true);}
public static Weighted invertedPadded(float weight, float padding) { return new Weighted(weight, 0F, padding, true); }
public static Weighted invertedMinimum(float weight, float minimized) { return new Weighted(weight, minimized, 0F, true); }
public static Weighted inverted(float weight, float minimized, float padding) { return new Weighted(weight, minimized, padding, true); }
@Override @Override
public void apply(IGuiBox owner, IGuiBox parent, Target target, ConstrainedContext context) { public void apply(IGuiBox owner, IGuiBox parent, Target target, ConstrainedContext context) {
@ -105,8 +113,8 @@ public class Constraints {
public void fetch(IGuiBox owner, IGuiBox parent, Target target, ConstrainedContext context) { public void fetch(IGuiBox owner, IGuiBox parent, Target target, ConstrainedContext context) {
if(target.isPosition()) return; if(target.isPosition()) return;
context.addWeight(weight, target.isXAxis()); context.addWeight(weight, target.isXAxis());
context.addBound(minimum, target.isXAxis());
} }
} }
public static record Center() implements ISimpleConstraint { public static record Center() implements ISimpleConstraint {

View File

@ -32,7 +32,16 @@ public interface IConstraint {
public static IConstraint relative(float value) { return Relative.of(value); } public static IConstraint relative(float value) { return Relative.of(value); }
public static IConstraint relative(float value, float padding) { return Relative.of(value, padding); } public static IConstraint relative(float value, float padding) { return Relative.of(value, padding); }
public static IConstraint weightedPos() { return Weighted.of(0F); }
public static IConstraint weightedInvPos() { return Weighted.inverted(0F); }
public static IConstraint weighted(float weight) { return Weighted.of(weight); } public static IConstraint weighted(float weight) { return Weighted.of(weight); }
public static IConstraint weightedPad(float weight, float padding) { return Weighted.padded(weight, padding); }
public static IConstraint weightedMin(float weight, float minimum) { return Weighted.minimum(weight, minimum); }
public static IConstraint weighted(float weight, float minimum, float padding) { return Weighted.of(weight, minimum, padding); }
public static IConstraint weightedInv(float weight) { return Weighted.inverted(weight);}
public static IConstraint weightedInvPad(float weight, float padding) { return Weighted.invertedPadded(weight, padding); }
public static IConstraint weightedInvMin(float weight, float minimum) { return Weighted.invertedMinimum(weight, minimum); }
public static IConstraint weightedInv(float weight, float minimum, float padding) { return Weighted.inverted(weight, minimum, padding); }
public static IConstraint center() { return Center.of(); } public static IConstraint center() { return Center.of(); }
public static IConstraint conditional(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) { return Conditional.of(supplier, onTrue, onFalse); } public static IConstraint conditional(BooleanSupplier supplier, IConstraint onTrue, IConstraint onFalse) { return Conditional.of(supplier, onTrue, onFalse); }

View File

@ -9,6 +9,23 @@ import speiger.src.coreengine.utils.io.GameLog.LogLevel;
public class TextUtil public class TextUtil
{ {
public static boolean parseBoolean(String data, boolean current, boolean original) {
if(data.length() == 1) {
return switch(data.charAt(0)) {
case 'r' -> original;
case 't' -> true;
case 'f' -> false;
default -> current;
};
}
return Boolean.parseBoolean(data);
}
public static float parseFloat(String input, float defaultValue) {
try { return Float.parseFloat(input); }
catch (Exception e) { return defaultValue; }
}
public static String removeSpecialFormatters(String input) { public static String removeSpecialFormatters(String input) {
return input.replaceAll("\\§\\<(.*?)\\>", ""); return input.replaceAll("\\§\\<(.*?)\\>", "");
} }