From 78646f512e087eccd3200c858ac480a2091b7ae9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 12 Sep 2026 11:50:15 -0400 Subject: [PATCH] Made small data patch sounds load as one-shot wavs instead of streams --- .../mindustry/editor/data/MapAudioView.java | 23 +++++++++++++++---- core/src/mindustry/logic/LStatements.java | 2 +- core/src/mindustry/mod/DataAudioLoader.java | 3 ++- gradle.properties | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/src/mindustry/editor/data/MapAudioView.java b/core/src/mindustry/editor/data/MapAudioView.java index 533b98e9a3..5074376fe5 100644 --- a/core/src/mindustry/editor/data/MapAudioView.java +++ b/core/src/mindustry/editor/data/MapAudioView.java @@ -38,10 +38,15 @@ public class MapAudioView implements AssetView{ Fi file = asset.getCacheFile(); var audioSource = (AudioSource)Core.assets.getOrNull(DataAudioLoader.prefix + asset.name, (Class)(type == DataAssetType.music ? Music.class : Sound.class)); - if(file == null || audioSource == null || !audioSource.valid()){ + if(file == null || audioSource == null || (!audioSource.valid() && !audioSource.isLazy())){ list.button(Icon.warning, Styles.graySquarei, iconMed, () -> ui.showInfo(file == null ? "@asset.broken" : "@asset.audio.invalid")).size(h); }else{ list.button(Icon.play, Styles.graySquarei, iconMed, () -> { + if(!audioSource.valid() && !audioSource.isLazy()){ + ui.showInfo("@asset.audio.invalid"); + return; + } + if(lastPlaying != null && lastPlaying.countPlaying() > 0){ lastPlaying.stop(); if(lastPlaying == audioSource){ @@ -56,16 +61,26 @@ public class MapAudioView implements AssetView{ lastPlaying = s; s.play(control.sound.uiBus); } - }).update(i -> i.getStyle().imageUp = audioSource != null && audioSource.countPlaying() > 0 ? Icon.pause : Icon.play).size(h); + }).update(i -> i.getStyle().imageUp = (!audioSource.isLazy() && !audioSource.valid()) ? Icon.warning : audioSource.countPlaying() > 0 ? Icon.pause : Icon.play).size(h); } float w = (mobile ? 390f : 450f); list.table(Styles.grayPanel, in -> { + in.left(); in.table(v -> { v.left(); - v.add("[accent]" + asset.name).labelAlign(Align.left).left().ellipsis(true).width(w / 2f); + v.add("[accent]" + asset.name).labelAlign(Align.left).left().ellipsis(true).width(audioSource instanceof Music ? w / 2f : w * 0.8f); v.row(); - v.add("[lightgray][[" + (audioSource == null ? "?" : UI.formatTime(audioSource.getLength() * 60f)) + "]").left(); + if(audioSource != null){ + Runnable addTime = () -> v.add("[lightgray][[" + UI.formatTime(audioSource.getLength() * 60f) + "]").left(); + + if(audioSource.valid()){ + addTime.run(); + }else if(audioSource instanceof Sound s){ + //force-load sounds when viewing so that length/invalid status is shown + s.checkLazyLoad(addTime); + } + } }).width(w / 2f).tooltip("dp-" + asset.name.replace(' ', '_')); if(audioSource instanceof Music m){ diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index 3f3e9288ae..1491fa884c 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -2394,7 +2394,7 @@ public class LStatements{ private static String soundCategory(String entryName){ String normalized = entryName.replace('\\', '/'); int end = normalized.lastIndexOf('/'); - if(end < 0) return "Data Patch"; + if(end < 0) return "data patch"; int start = normalized.lastIndexOf('/', end - 1); return normalized.substring(start + 1, end); diff --git a/core/src/mindustry/mod/DataAudioLoader.java b/core/src/mindustry/mod/DataAudioLoader.java index ed32ce8d0f..4f523f5aa9 100644 --- a/core/src/mindustry/mod/DataAudioLoader.java +++ b/core/src/mindustry/mod/DataAudioLoader.java @@ -30,7 +30,8 @@ public class DataAudioLoader{ } Fi file = asset.getCacheFile(); - Sound sound = Vars.headless || file == null ? new Sound() : Sound.createStream(file); + //large sounds become streams, standard ones don't + Sound sound = Vars.headless || file == null ? new Sound() : file.length() > 100_000 ? Sound.createStream(file) : Sound.createLazy(file); loadedSounds.add(sound); Sounds.registerSound(sound, nextSoundId ++); diff --git a/gradle.properties b/gradle.properties index cab1cd4ae9..d2f03ad7ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ org.gradle.caching=true org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 android.enableR8.fullMode=false -archash=5f58c6eda0 +archash=68a04fab6e