Skip to content

Commit

Permalink
Initial Presets & Color reset fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SebasCapo committed Nov 29, 2021
1 parent deea627 commit f4f9324
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
20 changes: 13 additions & 7 deletions Lights/Configs/Presets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ public class Presets
[Description("How many times this plugin will loop through the preset order.")]
public uint LoopCount { get; set; } = 5;

/// <summary>
/// Gets or sets the minimum amount of time until presets begin getting looped through.
/// </summary>
[Description("The delay until the plugin begins going through the presets.")]
public float InitialDelay { get; set; } = 32;

/// <summary>
/// Gets or sets the minimum amount of time that will pass until next preset is ran.
/// </summary>
Expand All @@ -58,11 +52,23 @@ public class Presets
[Description("The maximum amount of time that might pass until next preset is ran.")]
public float TimeBetweenMax { get; set; } = 82;

/// <summary>
/// Gets or sets the minimum amount of time until presets begin getting looped through.
/// </summary>
[Description("The delay until the plugin begins going through the presets.")]
public float InitialDelay { get; set; } = 32;

/// <summary>
/// Gets or sets a list of presets, one of which will be selected as the first preset ran, taking from <see cref="PerZone"/> and <see cref="PerRoom"/>.
/// </summary>
[Description("One of the presets listed here will be randomly selected to be the first preset ran. (Starting a line with \"!\" will make it be ignored, use this if you don't wanna use this system)")]
public string[] InitialPreset { get; set; } = { "!ignore", "!ignored2" };

/// <summary>
/// Gets or sets the order on which presets will be ran, taking from <see cref="PerZone"/> and <see cref="PerRoom"/>.
/// </summary>
[Description("The order on which presets will be ran.")]
public string[] Order { get; set; } = { "myZonePreset1", "myZonePreset2", "myRoomPreset1", "myRoomPreset2", };
public string[] Order { get; set; } = { "myZonePreset2", "myRoomPreset1", "myRoomPreset2", };

/// <summary>
/// Gets or sets a dictionary containing all <see cref="ZoneType"/>-exclusive presets.
Expand Down
23 changes: 23 additions & 0 deletions Lights/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ private IEnumerator<float> RunBlackouts()

yield return Timing.WaitForSeconds(config.Presets.InitialDelay);

if (!config.Presets.InitialPreset.IsEmpty())
{
var id = config.Presets.InitialPreset[UnityEngine.Random.Range(0, config.Presets.InitialPreset.Length)];

if (!string.IsNullOrEmpty(id) && !id.StartsWith("!"))
{
if (config.Presets.PerZone.TryTriggerPreset(id))
{
Log.Debug($"Automatically ran initial zone preset: \"{id}\"", config.Debug);
yield return Timing.WaitForSeconds(UnityEngine.Random.Range(config.Presets.TimeBetweenMin, config.Presets.TimeBetweenMax));
}
else if (config.Presets.PerRoom.TryTriggerPreset(id))
{
Log.Debug($"Automatically ran initial room preset: \"{id}\"", config.Debug);
yield return Timing.WaitForSeconds(UnityEngine.Random.Range(config.Presets.TimeBetweenMin, config.Presets.TimeBetweenMax));
}
else
{
Log.Error($"Couldn't find any presets with ID \"{id}\", make sure there's no typos.");
}
}
}

for (int i = 0; i < config.Presets.LoopCount; i++)
{
string id;
Expand Down
2 changes: 1 addition & 1 deletion Lights/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static bool TryExecute(this Room room, ModifierType modifierType, float d
{
Plugin.Coroutines.Add(Timing.CallDelayed(duration, () =>
{
room.Color = color;
room.ResetColor();
Plugin.EventHandlers.DisabledTeslas.Remove(id);
}));
}
Expand Down

0 comments on commit f4f9324

Please sign in to comment.