mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-12-06 02:40:23 -08:00
(commented) support for Call server-to-client sounds
This commit is contained in:
parent
5c6b659ce3
commit
0980495a28
4 changed files with 63 additions and 7 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package mindustry.annotations.impl;
|
||||
|
||||
import arc.*;
|
||||
import arc.audio.*;
|
||||
import arc.files.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.struct.*;
|
||||
|
|
@ -118,9 +120,31 @@ public class AssetsProcess extends BaseProcessor{
|
|||
void processSounds(String classname, String path, String rtype) throws Exception{
|
||||
TypeSpec.Builder type = TypeSpec.classBuilder(classname).addModifiers(Modifier.PUBLIC);
|
||||
MethodSpec.Builder loadBegin = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
CodeBlock.Builder staticb = CodeBlock.builder();
|
||||
|
||||
type.addField(FieldSpec.builder(IntMap.class, "idToSound", Modifier.STATIC, Modifier.PRIVATE).initializer("new IntMap()").build());
|
||||
type.addField(FieldSpec.builder(ObjectIntMap.class, "soundToId", Modifier.STATIC, Modifier.PRIVATE).initializer("new ObjectIntMap()").build());
|
||||
|
||||
type.addMethod(MethodSpec.methodBuilder("getSoundId")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
.addParameter(Sound.class, "sound")
|
||||
.returns(int.class)
|
||||
.addStatement("return soundToId.get(sound, -1)").build());
|
||||
|
||||
type.addMethod(MethodSpec.methodBuilder("getSound")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
.addParameter(int.class, "id")
|
||||
.returns(Sound.class)
|
||||
.addStatement("return (Sound)idToSound.get(id, () -> Sounds.none)").build());
|
||||
|
||||
HashSet<String> names = new HashSet<>();
|
||||
Fi.get(path).walk(p -> {
|
||||
Seq<Fi> files = new Seq<>();
|
||||
Fi.get(path).walk(files::add);
|
||||
|
||||
files.sortComparing(Fi::name);
|
||||
int id = 0;
|
||||
|
||||
for(Fi p : files){
|
||||
String name = p.nameWithoutExtension();
|
||||
|
||||
if(names.contains(name)){
|
||||
|
|
@ -133,14 +157,20 @@ public class AssetsProcess extends BaseProcessor{
|
|||
|
||||
String filepath = path.substring(path.lastIndexOf("/") + 1) + p.path().substring(p.path().lastIndexOf(path) + path.length());
|
||||
|
||||
String filename = "\"" + filepath + "\"";
|
||||
loadBegin.addStatement("arc.Core.assets.load(" + filename + ", " + rtype + ".class).loaded = a -> " + name + " = (" + rtype + ")a", filepath, filepath.replace(".ogg", ".mp3"));
|
||||
staticb.addStatement("soundToId.put($L, $L)", name, id);
|
||||
|
||||
type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), name, Modifier.STATIC, Modifier.PUBLIC).initializer("new arc.audio." + rtype.substring(rtype.lastIndexOf(".") + 1) + "()").build());
|
||||
});
|
||||
loadBegin.addStatement("$T.assets.load($S, $L.class).loaded = a -> { $L = ($L)a; soundToId.put(a, $L); idToSound.put($L, a); }",
|
||||
Core.class, filepath, rtype, name, rtype, id, id);
|
||||
|
||||
type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), name, Modifier.STATIC, Modifier.PUBLIC).initializer("new " + rtype + "()").build());
|
||||
|
||||
id ++;
|
||||
}
|
||||
|
||||
type.addStaticBlock(staticb.build());
|
||||
|
||||
if(classname.equals("Sounds")){
|
||||
type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), "none", Modifier.STATIC, Modifier.PUBLIC).initializer("new arc.audio." + rtype.substring(rtype.lastIndexOf(".") + 1) + "()").build());
|
||||
type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), "none", Modifier.STATIC, Modifier.PUBLIC).initializer("new " + rtype + "()").build());
|
||||
}
|
||||
|
||||
type.addMethod(loadBegin.build());
|
||||
|
|
|
|||
|
|
@ -159,6 +159,22 @@ public class NetClient implements ApplicationListener{
|
|||
clientPacketReliable(type, contents);
|
||||
}
|
||||
|
||||
//TODO enable in build 129
|
||||
/*
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void sound(Sound sound, float volume, float pitch, float pan){
|
||||
if(sound == null) return;
|
||||
|
||||
sound.play(volume * Core.settings.getInt("sfxvol") / 100f, pitch, pan);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void soundAt(Sound sound, float x, float y, float volume, float pitch){
|
||||
if(sound == null) return;
|
||||
|
||||
sound.at(x, y, pitch, volume);
|
||||
}*/
|
||||
|
||||
@Remote(variants = Variant.both, unreliable = true)
|
||||
public static void effect(Effect effect, float x, float y, float rotation, Color color){
|
||||
if(effect == null) return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package mindustry.io;
|
||||
|
||||
import arc.audio.*;
|
||||
import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
|
|
@ -501,6 +502,15 @@ public class TypeIO{
|
|||
return id == -1 ? null : content.item(id);
|
||||
}
|
||||
|
||||
//note that only the standard sound constants in Sounds are supported; modded sounds are not.
|
||||
public static void writeSound(Writes write, Sound sound){
|
||||
write.s(Sounds.getSoundId(sound));
|
||||
}
|
||||
|
||||
public static Sound readSound(Reads read){
|
||||
return Sounds.getSound(read.s());
|
||||
}
|
||||
|
||||
public static void writeWeather(Writes write, Weather item){
|
||||
write.s(item == null ? -1 : item.id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class StatusEffect extends UnlockableContent{
|
|||
if(reloadMultiplier != 1) stats.addPercent(Stat.reloadMultiplier, reloadMultiplier);
|
||||
if(buildSpeedMultiplier != 1) stats.addPercent(Stat.buildSpeedMultiplier, buildSpeedMultiplier);
|
||||
if(damage > 0) stats.add(Stat.damage, damage * 60f, StatUnit.perSecond);
|
||||
if(damage < 0) stats.add(Stat.healing, -(damage * 60f), StatUnit.perSecond);
|
||||
if(damage < 0) stats.add(Stat.healing, -damage * 60f, StatUnit.perSecond);
|
||||
|
||||
boolean reacts = false;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue