-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce sound_info.json and add everything needed to load it
This PR does not switch to using the new data files for sounds. It's purely technical background work. The old sound handler should be removed in a followup, along with all of it's components.
- Loading branch information
1 parent
e5b9af8
commit 0371a53
Showing
18 changed files
with
151,089 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.core; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Managers are classes that manage a specific aspect of the mod. | ||
* This can be parsing and handling events from an aspect of Minecraft, | ||
* or holding data that is used throughout the mod. | ||
*/ | ||
public abstract class Manager { | ||
/** | ||
* Create a manager with certain dependencies. | ||
* @param dependencies The list of managers that this manager depends on. | ||
* A manager only needs to declare dependency on another manager, | ||
* if it is used during initialization. | ||
* (Dependency does not matter when everything is initialized) | ||
*/ | ||
protected Manager(List<Manager> dependencies) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.core; | ||
|
||
import com.wynnvp.wynncraftvp.managers.json.JsonManager; | ||
import com.wynnvp.wynncraftvp.managers.sound.SoundManager; | ||
|
||
public final class Managers { | ||
// Managers with no dependencies, kept in alphabetical order | ||
public static final JsonManager Json = new JsonManager(); | ||
public static final SoundManager Sound = new SoundManager(); | ||
|
||
// Managers with dependencies, kept in dependency order (then alphabetical) | ||
|
||
// Initialization method for all managers | ||
public static void initialize() { | ||
// no-op, class loading this class will initialize all managers | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/wynnvp/wynncraftvp/managers/json/JsonManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.json; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.wynnvp.wynncraftvp.core.Manager; | ||
import com.wynnvp.wynncraftvp.managers.sound.dialogue.DialogueHolder; | ||
import com.wynnvp.wynncraftvp.managers.sound.dialogue.json.DialogueHolderDeserializer; | ||
import java.util.List; | ||
|
||
public class JsonManager extends Manager { | ||
public static final Gson GSON = new GsonBuilder() | ||
.registerTypeAdapter(DialogueHolder.class, new DialogueHolderDeserializer()) | ||
.enableComplexMapKeySerialization() | ||
.setPrettyPrinting() | ||
.serializeNulls() | ||
.create(); | ||
|
||
public JsonManager() { | ||
super(List.of()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/wynnvp/wynncraftvp/managers/sound/SoundManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound; | ||
|
||
import com.wynnvp.wynncraftvp.ModCore; | ||
import com.wynnvp.wynncraftvp.core.Manager; | ||
import com.wynnvp.wynncraftvp.core.Managers; | ||
import com.wynnvp.wynncraftvp.managers.sound.dialogue.DialogueHolder; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.sounds.SoundEvent; | ||
|
||
public class SoundManager extends Manager { | ||
// The path of the file that contains the sound information, currently as a bundled resource | ||
private static final String SOUND_INFO_FILE = "/assets/wynnvp/sound_info.json"; | ||
|
||
private DialogueHolder dialogueHolder = DialogueHolder.EMPTY; | ||
|
||
public SoundManager() { | ||
super(List.of()); | ||
|
||
// Load the sound info from the json file | ||
loadSounds(); | ||
|
||
// Register the sounds as sound events | ||
registerSounds(); | ||
} | ||
|
||
private void loadSounds() { | ||
try (InputStream resourceAsStream = SoundManager.class.getResourceAsStream(SOUND_INFO_FILE)) { | ||
if (resourceAsStream == null) { | ||
ModCore.error("Could not find bundled sound info file, sounds will not be loaded."); | ||
return; | ||
} | ||
|
||
DialogueHolder dialogueHolder = | ||
Managers.Json.GSON.fromJson(new InputStreamReader(resourceAsStream), DialogueHolder.class); | ||
|
||
if (dialogueHolder == null) { | ||
ModCore.error("Could not load sound info file, sounds will not be loaded."); | ||
return; | ||
} | ||
|
||
this.dialogueHolder = dialogueHolder; | ||
ModCore.info("Loaded %d dialogue sounds." | ||
.formatted(dialogueHolder.dialogues().count())); | ||
} catch (Exception e) { | ||
ModCore.error("Error loading sound info file: " + e.getMessage()); | ||
} | ||
} | ||
|
||
private void registerSounds() { | ||
dialogueHolder.dialogues().forEach(dialogueData -> { | ||
ResourceLocation resourceLocation = | ||
ResourceLocation.fromNamespaceAndPath(ModCore.MODID, dialogueData.dialogueId()); | ||
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(resourceLocation); | ||
Registry.register(BuiltInRegistries.SOUND_EVENT, resourceLocation, soundEvent); | ||
}); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/ContextDialogueHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import java.util.List; | ||
|
||
public record ContextDialogueHolder(List<DialogueData> dialogues) {} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/DialogueContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public record DialogueContextHolder(LinkedHashMap<String, ContextDialogueHolder> contexts) { | ||
public Stream<DialogueData> dialogues() { | ||
return contexts.values().stream().map(ContextDialogueHolder::dialogues).flatMap(List::stream); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/DialogueData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* A record to hold all data for a dialogue line. | ||
* | ||
* @param dialogueInfo The unique information about the dialogue | ||
* @param lineInfo The information about the line itself, including the NPC and the line numbers | ||
* @param soundSettings The sound settings for the dialogue | ||
*/ | ||
public record DialogueData( | ||
DialogueInfo dialogueInfo, DialogueLineInfo lineInfo, ResolvedDialogueSoundSettings soundSettings) { | ||
/** | ||
* Get the dialogue ID for the dialogue line. This ID is also the file name for the sound file, and the key for the | ||
* sound event. | ||
* @return The dialogue ID | ||
*/ | ||
public String dialogueId() { | ||
if (dialogueInfo.fileOverride() != null) { | ||
return dialogueInfo.fileOverride(); | ||
} | ||
|
||
return ("%s-%s-%s-%d" | ||
.formatted( | ||
dialogueInfo.content(), | ||
dialogueInfo.context(), | ||
lineInfo.npc(), | ||
lineInfo.line().current())) | ||
.toLowerCase(Locale.ROOT); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/DialogueHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import java.util.Optional; | ||
import java.util.TreeMap; | ||
import java.util.stream.Stream; | ||
import org.joml.Vector3f; | ||
|
||
public record DialogueHolder(TreeMap<String, DialogueContextHolder> content) { | ||
public static final DialogueHolder EMPTY = new DialogueHolder(new TreeMap<>()); | ||
|
||
public static final DialogueSoundSettings DEFAULT_SETTINGS = new DialogueSoundSettings() { | ||
@Override | ||
public Optional<Boolean> followPlayer() { | ||
return Optional.of(false); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> falloff() { | ||
return Optional.of(0); | ||
} | ||
|
||
@Override | ||
public Optional<Vector3f> position() { | ||
return Optional.of(new Vector3f()); | ||
} | ||
}; | ||
|
||
public Stream<DialogueData> dialogues() { | ||
return content.values().stream().flatMap(DialogueContextHolder::dialogues); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/DialogueInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
/** | ||
* A record to hold generic information about a dialogue line, which is used to identify the dialogue, making it a key | ||
* for identifying the sound to play. | ||
* | ||
* @param content The content the dialogue is from | ||
* @param context The dialogue context, which identifies the current dialogue (e.g. "caravanCrashed" in tutorial). | ||
* This can also be numbered from 1 to n, in the order the NPC says them | ||
* (mainly used for porting the old names to the new system). | ||
* @param fileOverride The file to use instead of using the default file for the dialogue | ||
*/ | ||
public record DialogueInfo(String content, String context, String fileOverride) {} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/DialogueLineInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import com.wynnvp.wynncraftvp.utils.type.CappedValue; | ||
|
||
/** | ||
* @param npc The NPC the dialogue is from, using the name it appears as text in the game. | ||
* This value is optional and can be null, if the NPC is not known. | ||
* @param line The current/total number of the dialogue in the context. | ||
* (e.g 2/5, if the current dialogue is "[2/5]" in the game) | ||
* This value is optional and can be null, if the line is not specified. | ||
* @param dialogue The voiced dialogue line itself | ||
*/ | ||
public record DialogueLineInfo(String npc, CappedValue line, String dialogue) {} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/DialogueSoundSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import java.util.Optional; | ||
import org.joml.Vector3f; | ||
|
||
/** | ||
* An interface for providing sound settings for a dialogue line. | ||
* For more information, see {@link ResolvedDialogueSoundSettings}. | ||
*/ | ||
public interface DialogueSoundSettings { | ||
Optional<Boolean> followPlayer(); | ||
|
||
Optional<Integer> falloff(); | ||
|
||
Optional<Vector3f> position(); | ||
} |
17 changes: 17 additions & 0 deletions
17
...in/java/com/wynnvp/wynncraftvp/managers/sound/dialogue/ResolvedDialogueSoundSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright © Team-VoW 2024. | ||
* This file is released under AGPLv3. See LICENSE for full license details. | ||
*/ | ||
package com.wynnvp.wynncraftvp.managers.sound.dialogue; | ||
|
||
import org.joml.Vector3f; | ||
|
||
/** | ||
* A record to hold the sound settings for a dialogue line. | ||
* This class' fields should match {@link DialogueSoundSettings}. | ||
* | ||
* @param followPlayer Whether the sound should follow the player or not | ||
* @param falloff The falloff of the sound | ||
* @param position The position of the sound | ||
*/ | ||
public record ResolvedDialogueSoundSettings(boolean followPlayer, int falloff, Vector3f position) {} |
Oops, something went wrong.