mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-10-02 03:00:29 +03:00
Audio bugfixes & data patch logic sound play support
This commit is contained in:
@@ -94,11 +94,8 @@ public class MapAudioView implements AssetView{
|
||||
|
||||
list.button(Icon.trash, Styles.graySquarei, iconMed, () -> {
|
||||
ui.showConfirm("@asset.delete.confirm", () -> {
|
||||
if(audioSource != null){
|
||||
audioSource.dispose();
|
||||
}
|
||||
Core.assets.unload("dp-" + asset.name);
|
||||
assets.remove(asset);
|
||||
state.data.reloadAudio();
|
||||
diag.rebuild();
|
||||
});
|
||||
}).size(h);
|
||||
|
||||
@@ -38,8 +38,6 @@ public class GlobalVars{
|
||||
private UnlockableContent[][] logicIdToContent;
|
||||
private int[][] contentIdToLogicId;
|
||||
|
||||
public static final Seq<String> soundNames = new Seq<>();
|
||||
|
||||
public void init(){
|
||||
putEntryOnly("sectionProcessor");
|
||||
|
||||
@@ -101,7 +99,6 @@ public class GlobalVars{
|
||||
for(Sound sound : Core.assets.getAll(Sound.class, new Seq<>(Sound.class))){
|
||||
if(sound != Sounds.none && sound.file != null){
|
||||
String name = sound.file.nameWithoutExtension();
|
||||
soundNames.add(name);
|
||||
put("@sfx-" + name, Sounds.getSoundId(sound));
|
||||
}
|
||||
}
|
||||
@@ -303,6 +300,10 @@ public class GlobalVars{
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String name){
|
||||
vars.remove(name);
|
||||
}
|
||||
|
||||
public LVar put(String name, Object value){
|
||||
return put(name, value, false);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
@@ -2384,11 +2386,20 @@ public class LStatements{
|
||||
table.button(b -> {
|
||||
b.image(Icon.pencilSmall);
|
||||
|
||||
Seq<String> soundNames = new Seq<>();
|
||||
|
||||
for(var entry : Core.assets.getAllEntries(Sound.class, new Seq<>())){
|
||||
if(entry.value != Sounds.none && entry.value.file != null){
|
||||
soundNames.add(Strings.getFileNameWithoutExtension(entry.key));
|
||||
}
|
||||
}
|
||||
soundNames.sort();
|
||||
|
||||
String soundName = id.startsWith("@sfx-") ? id.substring(5) : id;
|
||||
b.clicked(() -> showSelect(b, GlobalVars.soundNames.toArray(String.class), soundName, t -> {
|
||||
b.clicked(() -> showSelect(b, soundNames.toArray(String.class), soundName, t -> {
|
||||
id = "@sfx-" + t;
|
||||
build(table);
|
||||
}, 2, cell -> cell.size(160, 50)));
|
||||
}, 3, cell -> cell.size(170, 50)));
|
||||
}, Styles.logict, () -> {}).size(40).color(table.color).left().padLeft(-1);
|
||||
|
||||
row(table);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class DataAudioLoader{
|
||||
Log.warn("Duplicate audio file: " + asset.name);
|
||||
continue;
|
||||
}
|
||||
|
||||
Fi file = asset.getCacheFile();
|
||||
Sound sound = Vars.headless || file == null ? new Sound() : Sound.createStream(file);
|
||||
loadedSounds.add(sound);
|
||||
@@ -34,6 +35,8 @@ public class DataAudioLoader{
|
||||
|
||||
if(Vars.headless || !Core.audio.initialized() || sound.file == null) continue;
|
||||
|
||||
Vars.logicVars.put("@sfx-" + prefix + asset.name, nextSoundId - 1, false);
|
||||
|
||||
Core.assets.addAsset(prefix + asset.name, Sound.class, sound);
|
||||
registered.add(prefix + asset.name);
|
||||
}
|
||||
@@ -66,6 +69,7 @@ public class DataAudioLoader{
|
||||
|
||||
if(!Vars.headless){
|
||||
for(String reg : registered){
|
||||
Vars.logicVars.remove("@sfx-" + reg);
|
||||
try{
|
||||
Core.assets.unload(reg);
|
||||
}catch(Exception ignored){ //unloading shouldn't throw an error, but ignore it just in case
|
||||
|
||||
Reference in New Issue
Block a user