diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index fd1b5e118d..e1e52ad477 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2383,6 +2383,7 @@ lst.getflag = Check if a global flag is set. lst.setprop = Sets a property of a unit or building. lst.effect = Create a particle effect. lst.sync = Sync a variable across the network.\nLimited to 20 times a second per variable. +lst.playsound = Plays a sound either at input position\nif positional or anywhere if global. lst.makemarker = Create a new logic marker in the world.\nAn ID to identify this marker must be provided.\nMarkers currently limited to 20,000 per world. lst.setmarker = Set a property for a marker.\nThe ID used must be the same as in the Make Marker instruction.\n[accent]null []values are ignored. lst.localeprint = Add map locale property value to the text buffer.\nTo set map locale bundles in map editor, check [accent]Map Info > Locale Bundles[].\nIf client is a mobile device, tries to print a property ending in ".mobile" first. diff --git a/core/assets/contributors b/core/assets/contributors index a07a13aadc..17e3262098 100644 --- a/core/assets/contributors +++ b/core/assets/contributors @@ -165,6 +165,7 @@ OpalSoPL BalaM314 Redstonneur1256 ApsZoldat +Mythril hexagon-recursion JasonP01 BlueTheCube diff --git a/core/src/mindustry/logic/GlobalVars.java b/core/src/mindustry/logic/GlobalVars.java index 0164b18b25..47292d4130 100644 --- a/core/src/mindustry/logic/GlobalVars.java +++ b/core/src/mindustry/logic/GlobalVars.java @@ -1,6 +1,7 @@ package mindustry.logic; import arc.*; +import arc.audio.*; import arc.files.*; import arc.graphics.*; import arc.math.*; @@ -8,6 +9,7 @@ import arc.struct.*; import arc.util.*; import mindustry.*; import mindustry.ctype.*; +import mindustry.gen.*; import mindustry.game.*; import mindustry.type.*; import mindustry.world.*; @@ -32,7 +34,9 @@ public class GlobalVars{ private ObjectSet privilegedNames = new ObjectSet<>(); private UnlockableContent[][] logicIdToContent; private int[][] contentIdToLogicId; - + + public static final Seq soundNames = new Seq<>(); + public void init(){ putEntryOnly("sectionProcessor"); @@ -86,6 +90,17 @@ public class GlobalVars{ put("@ctrlProcessor", ctrlProcessor); put("@ctrlPlayer", ctrlPlayer); put("@ctrlCommand", ctrlCommand); + + //sounds + if(Core.assets != null){ + for(Sound sound : Core.assets.getAll(Sound.class, new Seq<>(Sound.class))){ + if(sound != Sounds.none && sound != Sounds.swish){ + String name = sound.file.nameWithoutExtension(); + soundNames.add(name); + put("@sfx-" + name, Sounds.getSoundId(sound)); + } + } + } //store base content diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 481895ea4c..3b7f8c08d3 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1,6 +1,7 @@ package mindustry.logic; import arc.*; +import arc.audio.*; import arc.graphics.*; import arc.math.*; import arc.math.geom.*; @@ -1911,6 +1912,36 @@ public class LExecutor{ } } + public static class PlaySoundI implements LInstruction{ + public boolean positional; + public LVar id, volume, pitch, pan, x, y; + + public PlaySoundI(){ + } + + public PlaySoundI(boolean positional, LVar id, LVar volume, LVar pitch, LVar pan, LVar x, LVar y){ + this.positional = positional; + this.id = id; + this.volume = volume; + this.pitch = pitch; + this.pan = pan; + this.x = x; + this.y = y; + } + + @Override + public void run(LExecutor exec){ + Sound sound = Sounds.getSound(id.numi()); + if(sound == null || sound == Sounds.swish) sound = Sounds.none; //no. + + if(positional){ + sound.at(World.unconv(x.numf()), World.unconv(y.numf()), pitch.numf(), Math.min(volume.numf(), 2f)); + }else{ + sound.play(Math.min(volume.numf() * (Core.settings.getInt("sfxvol") / 100f), 2f), pitch.numf(), pan.numf()); + } + } + } + public static class SetMarkerI implements LInstruction{ public LMarkerControl type = LMarkerControl.pos; public LVar id, p1, p2, p3; diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index 3ca506e0e0..c33aa851ef 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -1,6 +1,7 @@ package mindustry.logic; import arc.*; +import arc.audio.*; import arc.func.*; import arc.graphics.*; import arc.scene.style.*; @@ -2121,6 +2122,82 @@ public class LStatements{ return LCategory.world; } } + + @RegisterStatement("playsound") + public static class PlaySoundStatement extends LStatement{ + public boolean positional; + public String id = "@sfx-pew", volume = "1", pitch = "1", pan = "0", x = "@thisx", y = "@thisy"; + + private transient TextField tfield; + + @Override + public void build(Table table){ + rebuild(table); + } + + void rebuild(Table table){ + table.clearChildren(); + + table.button(positional ? "positional" : "global", Styles.logict, () -> { + positional = !positional; + rebuild(table); + }).size(160f, 40f).pad(4f).color(table.color); + + row(table); + + table.add(" play "); + + tfield = field(table, id, str -> id = str).padRight(0f).get(); + + table.button(b -> { + b.image(Icon.pencilSmall); + + b.clicked(() -> showSelect(b, GlobalVars.soundNames.toArray(String.class), id.substring(4), t -> { + sid("@sfx-" + t); + rebuild(table); + }, 2, cell -> cell.size(160, 50))); + }, Styles.logict, () -> {}).size(40).color(table.color).left().padLeft(-1); + + row(table); + + fieldst(table, "volume", volume, str -> volume = str); + fieldst(table, "pitch", pitch, str -> pitch = str); + + table.row(); + + if(positional){ + table.add("at "); + + fields(table, x, str -> x = str); + + table.add(", "); + + fields(table, y, str -> y = str); + }else{ + fieldst(table, "pan", pan, str -> pan = str); + } + } + + private void sid(String text){ + tfield.setText(text); + id = text; + } + + @Override + public boolean privileged(){ + return true; + } + + @Override + public LInstruction build(LAssembler builder){ + return new PlaySoundI(positional, builder.var(id), builder.var(volume), builder.var(pitch), builder.var(pan), builder.var(x), builder.var(y)); + } + + @Override + public LCategory category(){ + return LCategory.world; + } + } @RegisterStatement("setmarker") public static class SetMarkerStatement extends LStatement{