Skip to content

Commit

Permalink
Custom Launch Music for Each Planet (#8901)
Browse files Browse the repository at this point in the history
* plant

* what

* literal ctrl+c ctrl+v

* more music

* issue

* feedback

* commit return
  • Loading branch information
Mythril382 authored Nov 30, 2023
1 parent 0afed49 commit 5fe2825
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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 @@ -61,6 +62,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 @@ -284,6 +286,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

0 comments on commit 5fe2825

Please sign in to comment.