Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Launch Music for Each Planet #8901

Merged
merged 7 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/mindustry/audio/SoundControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void update(){
if(state.isMenu()){
silenced = false;
if(ui.planet.isShown()){
play(Musics.launch);
play(ui.planet.state.planet.launchMusic);
}else if(ui.editor.isShown()){
play(Musics.editor);
}else{
Expand Down
16 changes: 16 additions & 0 deletions core/src/mindustry/mod/ContentParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import arc.*;
import arc.assets.*;
import arc.assets.loaders.MusicLoader.*;
import arc.assets.loaders.SoundLoader.*;
import arc.audio.*;
import arc.files.*;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class ContentParser{
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
ObjectSet<Class<?>> implicitNullable = ObjectSet.with(TextureRegion.class, TextureRegion[].class, TextureRegion[][].class, TextureRegion[][][].class);
ObjectMap<String, AssetDescriptor<?>> sounds = new ObjectMap<>();
ObjectMap<String, AssetDescriptor<?>> musics = new ObjectMap<>();
Seq<ParseListener> listeners = new Seq<>();

ObjectMap<Class<?>, FieldParser> classParsers = new ObjectMap<>(){{
Expand Down Expand Up @@ -270,6 +272,20 @@ public class ContentParser{
sounds.put(path, desc);
return sound;
});
put(Music.class, (type, data) -> {
if(fieldOpt(Musics.class, data) != null) return fieldOpt(Musics.class, data);
if(Vars.headless) return new Music();

String name = "music/" + data.asString();
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";

if(musics.containsKey(path)) return ((MusicParameter)musics.get(path).params).music;
var music = new Music();
AssetDescriptor<?> desc = Core.assets.load(path, Music.class, new MusicParameter(music));
desc.errored = Throwable::printStackTrace;
musics.put(path, desc);
return music;
});
put(Objectives.Objective.class, (type, data) -> {
if(data.isString()){
var cont = locateAny(data.asString());
Expand Down
4 changes: 4 additions & 0 deletions core/src/mindustry/type/Planet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mindustry.type;

import arc.*;
import arc.audio.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g3d.*;
Expand All @@ -15,6 +16,7 @@
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.game.EventType.ContentInitEvent;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.graphics.g3d.*;
import mindustry.graphics.g3d.PlanetGrid.*;
Expand Down Expand Up @@ -128,6 +130,8 @@ public class Planet extends UnlockableContent{
public boolean allowLaunchToNumbered = true;
/** Icon as displayed in the planet selection dialog. This is a string, as drawables are null at load time. */
public String icon = "planet";
/** Plays in the planet dialog when this planet is selected. */
public Music launchMusic = Musics.launch;
/** Default core block for launching. */
public Block defaultCore = Blocks.coreShard;
/** Sets up rules on game load for any sector on this planet. */
Expand Down