Split config into sections per track language, add quick toggle per section

This commit is contained in:
ivan tkachenko 2025-07-12 19:33:12 +03:00
parent 13fd51c366
commit 3b055e3d91
1 changed files with 46 additions and 2 deletions

View File

@ -27,36 +27,42 @@ namespace MuzikaGromche
new Track
{
Name = "MuzikaGromche",
Language = Language.RUSSIAN,
WindUpTimer = 46.3f,
Bpm = 130f,
},
new Track
{
Name = "VseVZale",
Language = Language.RUSSIAN,
WindUpTimer = 39f,
Bpm = 138f,
},
new Track
{
Name = "DeployDestroy",
Language = Language.RUSSIAN,
WindUpTimer = 40.7f,
Bpm = 130f,
},
new Track
{
Name = "MoyaZhittya",
Language = Language.ENGLISH,
WindUpTimer = 34.5f,
Bpm = 120f,
},
new Track
{
Name = "Gorgorod",
Language = Language.RUSSIAN,
WindUpTimer = 43.2f,
Bpm = 180f,
},
new Track
{
Name = "Durochka",
Language = Language.RUSSIAN,
WindUpTimer = 37f,
Bpm = 130f,
}
@ -168,11 +174,19 @@ namespace MuzikaGromche
Logger.LogError("Could not load audio file");
}
}
};
public record Language(string Short, string Full)
{
public static readonly Language ENGLISH = new("EN", "English");
public static readonly Language RUSSIAN = new("RU", "Russian");
}
public class Track
{
public string Name;
// Language of the track's lyrics.
public Language Language;
// Wind-up time can and should be shorter than the Start audio track,
// so that the "pop" effect can be baked into the Start audio and kept away
// from the looped part. This also means that the light show starts before
@ -295,12 +309,42 @@ namespace MuzikaGromche
public Config(ConfigFile configFile) : base(PluginInfo.PLUGIN_GUID)
{
var chanceRange = new AcceptableValueRange<int>(0, 100);
var languageSectionButtonExists = new HashSet<Language>();
foreach (var track in Plugin.Tracks)
{
string description = $"Random (relative) chance of selecting track {track.Name}. Set to zero to effectively disable the track.";
var language = track.Language;
string section = $"Tracks.{language.Short}";
// Create section toggle
if (!languageSectionButtonExists.Contains(language))
{
languageSectionButtonExists.Add(language);
string buttonOptionName = $"Toggle all {language.Full} tracks";
string buttonDescription = "Toggle all tracks in this section ON or OFF. Effective immediately.";
string buttonText = "Toggle";
var button = new GenericButtonConfigItem(section, buttonOptionName, buttonDescription, buttonText, () =>
{
if (CanModifyWeightsNow())
{
var tracks = Plugin.Tracks.Where(t => t.Language.Equals(language)).ToList();
var isOff = tracks.All(t => t.Weight.Value == 0);
var newWeight = isOff ? 50 : 0;
foreach (var t in tracks)
{
t.Weight.LocalValue = newWeight;
}
}
});
button.ButtonOptions.CanModifyCallback = CanModifyWeightsNow;
LethalConfigManager.AddConfigItem(button);
}
// Create slider entry for track
string name = $"[{language.Short}] {track.Name}";
string description = $"Language: {language.Full}\n\nRandom (relative) chance of selecting this track.\n\nSet to zero to effectively disable the track.";
track.Weight = configFile.BindSyncedEntry(
new ConfigDefinition("Tracks", track.Name),
new ConfigDefinition(section, track.Name),
50,
new ConfigDescription(description, chanceRange, track));