From 7bf37c708890716f1850a95862cac3b051c042c6 Mon Sep 17 00:00:00 2001 From: Smyler Date: Sat, 8 Jun 2024 18:04:17 +0200 Subject: [PATCH] Warn when requesting a missing sprite --- .../net/smyler/smylib/gui/sprites/SpriteLibrary.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/smylib/core/src/main/java/net/smyler/smylib/gui/sprites/SpriteLibrary.java b/smylib/core/src/main/java/net/smyler/smylib/gui/sprites/SpriteLibrary.java index a7f39941..d1d894b7 100644 --- a/smylib/core/src/main/java/net/smyler/smylib/gui/sprites/SpriteLibrary.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/sprites/SpriteLibrary.java @@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull; import static net.smyler.smylib.Preconditions.checkArgument; import static net.smyler.smylib.Preconditions.checkState; +import static net.smyler.smylib.SmyLib.getLogger; public class SpriteLibrary { @@ -45,11 +46,15 @@ public void registerSprite(@NotNull String identifier, @NotNull Sprite sprite) { } public Sprite getSprite(@NotNull Identifier identifier) { - return this.registered.get(requireNonNull(identifier)); + Sprite sprite = this.readOnly.get(identifier); + if (sprite == null) { + getLogger().warn("Tried to get missing sprite for identifier {}", identifier); + } + return sprite; } public Sprite getSprite(@NotNull String identifier) { - return this.registered.get(Identifier.parse(identifier)); + return this.getSprite(Identifier.parse(identifier)); } /**