diff --git a/src/main/java/com/pixelgamelibrary/api/audio/Sound.java b/src/main/java/com/pixelgamelibrary/api/audio/Sound.java index a24ab98..a926791 100644 --- a/src/main/java/com/pixelgamelibrary/api/audio/Sound.java +++ b/src/main/java/com/pixelgamelibrary/api/audio/Sound.java @@ -51,7 +51,7 @@ public interface Sound extends Disposable { /** * Plays the sound with specified volume, pitch, and pan. * @param volume the volume level in the range [0, 1] - * @param pitch the pitch multiplier, where 1 is the default, >1 is faster, <1 is slower + * @param pitch the pitch multiplier, where 1 is the default, >1 is faster, <1 is slower * @param pan panning in the range -1 (left) to 1 (right), 0 is center * @return the ID of the sound instance if successful, or -1 on failure. */ @@ -73,7 +73,7 @@ public interface Sound extends Disposable { /** * Plays the sound in a loop with specified volume, pitch, and pan. * @param volume the volume level in the range [0, 1] - * @param pitch the pitch multiplier, where 1 is the default, >1 is faster, <1 is slower + * @param pitch the pitch multiplier, where 1 is the default, >1 is faster, <1 is slower * @param pan panning in the range -1 (left) to 1 (right), 0 is center * @return the ID of the sound instance if successful, or -1 on failure. */ @@ -128,7 +128,7 @@ public interface Sound extends Disposable { /** * Sets the pitch for the sound instance with the specified ID. * @param soundId the ID of the sound instance - * @param pitch the pitch multiplier, where 1 is the default, >1 is faster, <1 is slower + * @param pitch the pitch multiplier, where 1 is the default, >1 is faster, <1 is slower */ public void setPitch(long soundId, float pitch); diff --git a/src/main/java/com/pixelgamelibrary/api/graphics/Color.java b/src/main/java/com/pixelgamelibrary/api/graphics/Color.java index 174b9f6..48b67d3 100644 --- a/src/main/java/com/pixelgamelibrary/api/graphics/Color.java +++ b/src/main/java/com/pixelgamelibrary/api/graphics/Color.java @@ -26,6 +26,7 @@ import static com.pixelgamelibrary.api.graphics.ColorDepth.BITS_24; import static com.pixelgamelibrary.api.graphics.ColorDepth.BITS_32; import static com.pixelgamelibrary.api.graphics.ColorDepth.BITS_4; import static com.pixelgamelibrary.api.graphics.ColorDepth.BITS_8; +import com.pixelgamelibrary.api.utils.StringUtilsImpl; import java.util.BitSet; import lombok.Data; @@ -362,7 +363,7 @@ public final class Color { * @return the hexadecimal string representation of this color */ public String toHexString() { - return String.format("#%08X", toIntRGBA()); + return "#" + StringUtilsImpl.INSTANCE.padLeft(Integer.toHexString(toIntRGBA()), '0', 8).toUpperCase(); } public static Color valueOf(String hexString) { @@ -620,7 +621,8 @@ public final class Color { @Override public String toString() { // Provide a string representation of the color in RGBA format - return String.format("Color{red=%f, green=%f, blue=%f, alpha=%f}", red, green, blue, alpha); + return "Color{red=" + red + ", green=" + green + ", blue=" + blue + ", alpha=" + alpha + "}"; + } } diff --git a/src/main/java/com/pixelgamelibrary/api/interfaces/Utils.java b/src/main/java/com/pixelgamelibrary/api/interfaces/Utils.java index d29a278..21dbab5 100644 --- a/src/main/java/com/pixelgamelibrary/api/interfaces/Utils.java +++ b/src/main/java/com/pixelgamelibrary/api/interfaces/Utils.java @@ -22,6 +22,8 @@ package com.pixelgamelibrary.api.interfaces; import com.pixelgamelibrary.api.utils.BinaryUtilsImpl; import com.pixelgamelibrary.api.utils.CollectionUtils; import com.pixelgamelibrary.api.utils.ReflectionUtils; +import com.pixelgamelibrary.api.utils.StringUtils; +import com.pixelgamelibrary.api.utils.StringUtilsImpl; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -61,5 +63,8 @@ public interface Utils { default BinaryUtilsImpl binary() { return BinaryUtilsImpl.INSTANCE; } + default StringUtils string() { + return StringUtilsImpl.INSTANCE; + } } diff --git a/src/main/java/com/pixelgamelibrary/api/utils/StringUtils.java b/src/main/java/com/pixelgamelibrary/api/utils/StringUtils.java new file mode 100644 index 0000000..33c0558 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/StringUtils.java @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: Game library. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// + +package com.pixelgamelibrary.api.utils; + +/** + * + * @author robertvokac + */ +public interface StringUtils { + String padLeft(String s, char padChar, int length); +} diff --git a/src/main/java/com/pixelgamelibrary/api/utils/StringUtilsImpl.java b/src/main/java/com/pixelgamelibrary/api/utils/StringUtilsImpl.java new file mode 100644 index 0000000..f4389a4 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/api/utils/StringUtilsImpl.java @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: Game library. +// Copyright (C) 2024 the original author or authors. +// +// This program is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation, either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.pixelgamelibrary.api.utils; + +/** + * + * @author robertvokac + */ +public class StringUtilsImpl implements StringUtils { + + public static final StringUtilsImpl INSTANCE = new StringUtilsImpl(); + + private StringUtilsImpl() { + + } + + @Override + public String padLeft(String s, char padChar, int length) { + StringBuilder sb = new StringBuilder(length); + while (sb.length() < length) { + sb.append(padChar); + } + sb.append(s); + return sb.toString().substring(sb.length() - length); // Return last 'length' characters + } + +} diff --git a/src/test/java/com/pixelgamelibrary/api/graphics/ColorTest.java b/src/test/java/com/pixelgamelibrary/api/graphics/ColorTest.java index 15c2162..38d404c 100644 --- a/src/test/java/com/pixelgamelibrary/api/graphics/ColorTest.java +++ b/src/test/java/com/pixelgamelibrary/api/graphics/ColorTest.java @@ -173,7 +173,7 @@ public class ColorTest { @Test public void testToString() { Color color = new Color(0.5f, 0.5f, 0.5f, 0.75f); - assertEquals("Color{red=0.500000, green=0.500000, blue=0.500000, alpha=0.750000}", color.toString()); + assertEquals("Color{red=0.5, green=0.5, blue=0.5, alpha=0.75}", color.toString()); } @Test