Skip to content

Commit

Permalink
Enhance dtr bar display
Browse files Browse the repository at this point in the history
  • Loading branch information
Limiana committed Dec 30, 2024
1 parent e394868 commit 25bd5ef
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Splatoon/Gui/Priority/PriorityPopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ internal int GetOrderedRoleIndex(Job job)

public bool ShouldAutoOpen()
{
return ScriptingProcessor.Scripts.Any(x => !x.IsDisabledByUser && x.InternalData.ContainsPriorityLists() && x.ValidTerritories?.Contains(this.TerritoryType) == true && !P.Config.NoPrioPopupTerritories.Contains(this.TerritoryType)) && !Svc.Condition[ConditionFlag.DutyRecorderPlayback];
return ScriptingProcessor.AnyScriptUsesPriority(this.TerritoryType) && !P.Config.NoPrioPopupTerritories.Contains(this.TerritoryType) && !Svc.Condition[ConditionFlag.DutyRecorderPlayback];
}

public void Open(bool force)
Expand Down
4 changes: 2 additions & 2 deletions Splatoon/Gui/Scripting/TabScripting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void DrawScriptGroup(IEnumerable<SplatoonScript> scripts)
{
P.Config.DisabledScripts.Add(script.InternalData.FullName);
}
ScriptingProcessor.Scripts.ForEach(x => x.UpdateState());
ScriptingProcessor.Scripts.Each(x => x.UpdateState());
}
ImGuiEx.Tooltip(e ? "Enable script".Loc() : "Disable script".Loc());
}
Expand Down Expand Up @@ -332,7 +332,7 @@ void DrawScriptGroup(IEnumerable<SplatoonScript> scripts)
new TickScheduler(() =>
{
script.Disable();
ScriptingProcessor.Scripts = ScriptingProcessor.Scripts.Remove(script);
ScriptingProcessor.RemoveScript(script);
DeleteFileToRecycleBin(script.InternalData.Path);
});
}
Expand Down
3 changes: 2 additions & 1 deletion Splatoon/Services/InfoBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ECommons.EzEventManager;
using ECommons.GameHelpers;
using Splatoon.Gui.Priority;
using Splatoon.SplatoonScripting;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void Update(bool force)
{
try
{
Entry.Shown = true;
Entry.Shown = ScriptingProcessor.AnyScriptUsesPriority();
var newRole = -1;
if(P.PriorityPopupWindow?.Assignments != null)
{
Expand Down
8 changes: 4 additions & 4 deletions Splatoon/Splatoon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ internal void TerritoryChangedEvent(ushort e)
{
ResetLayout(l);
}
ScriptingProcessor.Scripts.ForEach(x => x.Controller.Layouts.Values.Each(ResetLayout));
ScriptingProcessor.Scripts.Each(x => x.Controller.Layouts.Values.Each(ResetLayout));
AttachedInfo.VFXInfos.Clear();
Logger.OnTerritoryChanged();
ScriptingProcessor.TerritoryChanged();
Expand Down Expand Up @@ -505,7 +505,7 @@ internal void Tick(IFramework framework)
ResetLayout(l);
}
}
ScriptingProcessor.Scripts.ForEach(x => x.Controller.Layouts.Values.Each(ResetLayout));
ScriptingProcessor.Scripts.Each(x => x.Controller.Layouts.Values.Each(ResetLayout));
}
}

Expand Down Expand Up @@ -550,8 +550,8 @@ internal void Tick(IFramework framework)
ProcessLayout(i);
}

ScriptingProcessor.Scripts.ForEach(x => { if(x.IsEnabled) x.Controller.Layouts.Values.Each(ProcessLayout); });
ScriptingProcessor.Scripts.ForEach(x => { if(x.IsEnabled || x.InternalData.UnconditionalDraw) x.Controller.Elements.Each(z => S.RenderManager.GetRenderer(z.Value).ProcessElement(z.Value, null, x.InternalData.UnconditionalDraw && x.InternalData.UnconditionalDrawElements.Contains(z.Key))); });
ScriptingProcessor.Scripts.Each(x => { if(x.IsEnabled) x.Controller.Layouts.Values.Each(ProcessLayout); });
ScriptingProcessor.Scripts.Each(x => { if(x.IsEnabled || x.InternalData.UnconditionalDraw) x.Controller.Elements.Each(z => S.RenderManager.GetRenderer(z.Value).ProcessElement(z.Value, null, x.InternalData.UnconditionalDraw && x.InternalData.UnconditionalDrawElements.Contains(z.Key))); });
foreach(var e in InjectedElements)
{
S.RenderManager.GetRenderer(e).ProcessElement(e);
Expand Down
67 changes: 56 additions & 11 deletions Splatoon/SplatoonScripting/ScriptingProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using FFXIVClientStructs.FFXIV.Client.Game;
using Splatoon.Gui.Scripting;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading;
Expand All @@ -12,23 +13,67 @@ namespace Splatoon.SplatoonScripting;

internal static partial class ScriptingProcessor
{
internal static ImmutableList<SplatoonScript> Scripts = ImmutableList<SplatoonScript>.Empty;
private static ImmutableList<SplatoonScript> ScriptsInternal = [];
internal static IReadOnlyList<SplatoonScript> Scripts => ScriptsInternal;
internal static ConcurrentQueue<(string code, string path)> LoadScriptQueue = new();
internal static volatile bool ThreadIsRunning = false;
internal readonly static string[] TrustedURLs = new string[]
{
internal readonly static string[] TrustedURLs =
[
"https://github.com/NightmareXIV/",
"https://www.github.com/NightmareXIV/",
"https://raw.githubusercontent.com/NightmareXIV/",
"https://github.com/PunishXIV/",
"https://www.github.com/PunishXIV/",
"https://raw.githubusercontent.com/PunishXIV/",
"https://nightmarexiv.com/"
};
];
internal static ImmutableList<BlacklistData> Blacklist = ImmutableList<BlacklistData>.Empty;
internal static volatile bool UpdateCompleted = false;
internal static List<string> ForceUpdate = [];

internal static void AddScript(SplatoonScript script)
{
AssertOnFrameworkThread();
ScriptsInternal = ScriptsInternal.Add(script);
S.InfoBar?.Update(true);
}

internal static void RemoveScript(SplatoonScript script)
{
AssertOnFrameworkThread();
ScriptsInternal = ScriptsInternal.Remove(script);
S.InfoBar?.Update(true);
}

internal static void RemoveScripts(Predicate<SplatoonScript> predicate)
{
AssertOnFrameworkThread();
ArgumentNullException.ThrowIfNull(predicate);
ScriptsInternal = ScriptsInternal.RemoveAll(predicate);
S.InfoBar?.Update(true);
}

internal static void ClearScripts()
{
AssertOnFrameworkThread();
ScriptsInternal = ScriptsInternal.Clear();
S.InfoBar?.Update(true);
}

private static void AssertOnFrameworkThread()
{
if(!Svc.Framework.IsInFrameworkUpdateThread)
{
PluginLog.Error($"Operation performed outside of allowed bounds. Please report this to developer.\n{new StackTrace(true)}");
}
}

internal static bool AnyScriptUsesPriority(uint? territory = null)
{
territory ??= Svc.ClientState.TerritoryType;
return ScriptingProcessor.Scripts.Any(x => !x.IsDisabledByUser && x.InternalData.ContainsPriorityLists() && x.ValidTerritories?.Contains(territory.Value) == true);
}

internal static string ExtractNamespaceFromCode(string code)
{
var regex = NamespaceRegex();
Expand Down Expand Up @@ -208,8 +253,8 @@ internal static void ReloadAll()
return;
}
UpdateCompleted = false;
Scripts.ForEach(x => x.Disable());
Scripts = ImmutableList<SplatoonScript>.Empty;
Scripts.Each(x => x.Disable());
ClearScripts();
var dir = Path.Combine(Svc.PluginInterface.GetPluginConfigDirectory(), "Scripts");
if(!Directory.Exists(dir))
{
Expand All @@ -229,7 +274,7 @@ internal static void ReloadScript(SplatoonScript s)
return;
}
s.Disable();
Scripts = Scripts.Remove(s);
RemoveScript(s);
CompileAndLoad(File.ReadAllText(s.InternalData.Path, Encoding.UTF8), s.InternalData.Path, false);
}

Expand All @@ -243,7 +288,7 @@ internal static void ReloadScripts(IEnumerable<SplatoonScript> scripts, bool isF
foreach(var s in scripts)
{
s.Disable();
Scripts = Scripts.Remove(s);
RemoveScript(s);
CompileAndLoad(File.ReadAllText(s.InternalData.Path, Encoding.UTF8), s.InternalData.Path, isFirst);
}
}
Expand Down Expand Up @@ -330,10 +375,10 @@ internal static void CompileAndLoad(string sourceCode, string fpath, bool isFirs
previousVersion = loadedScript.Metadata?.Version ?? 0;
result.path = loadedScript.InternalData.Path;
loadedScript.Disable();
Scripts = Scripts.RemoveAll(x => ReferenceEquals(loadedScript, x));
RemoveScripts(x => ReferenceEquals(loadedScript, x));
rewrite = true;
}
Scripts = Scripts.Add(instance);
AddScript(instance);
if(result.path == null)
{
var dir = Path.Combine(Svc.PluginInterface.GetPluginConfigDirectory(), "Scripts", instance.InternalData.Namespace);
Expand Down Expand Up @@ -779,7 +824,7 @@ internal static void Dispose()
{
Scripts[i].Disable();
}
Scripts = ImmutableList<SplatoonScript>.Empty;
ClearScripts();
}

internal static void LogError(this SplatoonScript s, Exception e, string methodName)
Expand Down

0 comments on commit 25bd5ef

Please sign in to comment.