forked from BVengo/sound-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVolumeConfig.java
More file actions
67 lines (54 loc) · 1.94 KB
/
VolumeConfig.java
File metadata and controls
67 lines (54 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.bvengo.soundcontroller.config;
import com.bvengo.soundcontroller.VolumeData;
import java.util.HashMap;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
public class VolumeConfig {
private static VolumeConfig instance;
public static final int CONFIG_VERSION = 4;
private final HashMap<Identifier, VolumeData> soundVolumes;
public boolean subtitlesEnabled = false;
private VolumeConfig() {
soundVolumes = new HashMap<>();
ConfigParser.loadConfig(this);
updateVolumes();
ConfigParser.saveConfig(this);
}
public static VolumeConfig getInstance() {
if (instance == null) {
instance = new VolumeConfig();
}
return instance;
}
public void save() {
ConfigParser.saveConfig(this);
}
private void updateVolumes() {
// Update map with any sounds missing from the config file
for (SoundEvent soundEvent : BuiltInRegistries.SOUND_EVENT) {
if (soundEvent != SoundEvents.EMPTY) {
Identifier soundId = soundEvent.location();
soundVolumes.putIfAbsent(soundId, new VolumeData(soundId));
}
}
}
public HashMap<Identifier, VolumeData> getVolumes() {
return soundVolumes;
}
public VolumeData getVolumeData(Identifier soundId) {
return soundVolumes.getOrDefault(soundId, new VolumeData(soundId));
}
public float getAdjustedVolume(SoundInstance sound) {
VolumeData volumeData = getVolumeData(sound.getIdentifier());
return volumeData.getAdjustedVolume(sound);
}
public boolean areSubtitlesEnabled() {
return subtitlesEnabled;
}
public void toggleSubtitles() {
subtitlesEnabled = !subtitlesEnabled;
}
}