Fixed several issues

This commit is contained in:
Robert Vokac 2024-10-02 20:25:29 +02:00
parent 37b6617596
commit 571d1b304f
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
6 changed files with 86 additions and 6 deletions

View File

@ -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, &gt;1 is faster, &lt;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, &gt;1 is faster, &lt;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, &gt;1 is faster, &lt;1 is slower
*/
public void setPitch(long soundId, float pitch);

View File

@ -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 + "}";
}
}

View File

@ -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;
}
}

View File

@ -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
// <https://www.gnu.org/licenses/> 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);
}

View File

@ -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
// <https://www.gnu.org/licenses/> 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
}
}

View File

@ -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