Merge branch 'logic-sound-2'

This commit is contained in:
Anuken
2024-08-03 00:20:49 -04:00
5 changed files with 112 additions and 1 deletions

View File

@@ -2383,6 +2383,7 @@ lst.getflag = Check if a global flag is set.
lst.setprop = Sets a property of a unit or building. lst.setprop = Sets a property of a unit or building.
lst.effect = Create a particle effect. lst.effect = Create a particle effect.
lst.sync = Sync a variable across the network.\nLimited to 20 times a second per variable. lst.sync = Sync a variable across the network.\nLimited to 20 times a second per variable.
lst.playsound = Plays a sound.\nVolume and pan can be a global value, or calculated based on position.
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.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.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. 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.

View File

@@ -165,6 +165,7 @@ OpalSoPL
BalaM314 BalaM314
Redstonneur1256 Redstonneur1256
ApsZoldat ApsZoldat
Mythril
hexagon-recursion hexagon-recursion
JasonP01 JasonP01
BlueTheCube BlueTheCube

View File

@@ -1,6 +1,7 @@
package mindustry.logic; package mindustry.logic;
import arc.*; import arc.*;
import arc.audio.*;
import arc.files.*; import arc.files.*;
import arc.graphics.*; import arc.graphics.*;
import arc.math.*; import arc.math.*;
@@ -8,6 +9,7 @@ import arc.struct.*;
import arc.util.*; import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -32,7 +34,9 @@ public class GlobalVars{
private ObjectSet<String> privilegedNames = new ObjectSet<>(); private ObjectSet<String> privilegedNames = new ObjectSet<>();
private UnlockableContent[][] logicIdToContent; private UnlockableContent[][] logicIdToContent;
private int[][] contentIdToLogicId; private int[][] contentIdToLogicId;
public static final Seq<String> soundNames = new Seq<>();
public void init(){ public void init(){
putEntryOnly("sectionProcessor"); putEntryOnly("sectionProcessor");
@@ -86,6 +90,17 @@ public class GlobalVars{
put("@ctrlProcessor", ctrlProcessor); put("@ctrlProcessor", ctrlProcessor);
put("@ctrlPlayer", ctrlPlayer); put("@ctrlPlayer", ctrlPlayer);
put("@ctrlCommand", ctrlCommand); 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 && sound.file != null){
String name = sound.file.nameWithoutExtension();
soundNames.add(name);
put("@sfx-" + name, Sounds.getSoundId(sound));
}
}
}
//store base content //store base content

View File

@@ -1,6 +1,7 @@
package mindustry.logic; package mindustry.logic;
import arc.*; import arc.*;
import arc.audio.*;
import arc.graphics.*; import arc.graphics.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; 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 static class SetMarkerI implements LInstruction{
public LMarkerControl type = LMarkerControl.pos; public LMarkerControl type = LMarkerControl.pos;
public LVar id, p1, p2, p3; public LVar id, p1, p2, p3;

View File

@@ -2121,6 +2121,69 @@ public class LStatements{
return LCategory.world; 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";
@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);
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 -> {
id = "@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){
fieldst(table, "x", x, str -> x = str);
fieldst(table, "y", y, str -> y = str);
}else{
fieldst(table, "pan", pan, str -> pan = str);
}
}
@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") @RegisterStatement("setmarker")
public static class SetMarkerStatement extends LStatement{ public static class SetMarkerStatement extends LStatement{