Skip to content

Commit

Permalink
simpler code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael-Danilov committed Jan 3, 2025
1 parent f430916 commit 6aff71f
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public enum Sample {

INSTANCE;

String playOnComplete;

@NotNull
private final Set<String> missingAssets = new HashSet<>();

Expand Down Expand Up @@ -52,13 +50,9 @@ private void load(String asset) {
String assetFile = ModdingMode.getSoundById("sound/" + asset);

Sound sound = Gdx.audio.newSound(Gdx.files.internal("../assets/" + assetFile));


sounds.put(asset, sound);

} catch (Exception e) {
missingAssets.add(asset);
playOnComplete = null;
EventCollector.logException(e, asset);
}
}
Expand All @@ -78,12 +72,17 @@ public void play(String id, float leftVolume, float rightVolume, float rate) {
}
GameLoop.instance().soundExecutor.execute(() -> {
Sound sound = sounds.get(id);
//PUtil.slog("sound", "playing " + id);

if(sound==null) {
load(id);
}

sound = sounds.get(id);

if (sound != null) {
sound.play(leftVolume, rate, 0);
} else {
playOnComplete = id;
GameLoop.instance().soundExecutor.execute(() -> load(id));
EventCollector.logException("Sound " + id + " not found");
}
});
}
Expand Down

0 comments on commit 6aff71f

Please sign in to comment.