Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ASS.Pages/ASS.Pages.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<AssemblyName>ASS.Pages</AssemblyName>
<Configurations>LabAPI;Exiled</Configurations>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'LabAPI|AnyCPU' ">
<TargetName>ASS.Pages-LabAPI</TargetName>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Exiled|AnyCPU' ">
<TargetName>ASS.Pages-Exiled</TargetName>
</PropertyGroup>

<Import Project="../plugin.props" />

<ItemGroup>
<PackageReference Include="Northwood.LabAPI" Version="1.1.5" />
<PackageReference Include="Lib.Harmony" Version="$(HarmonyVersion)" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopVersion)" />
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp.dll" HintPath="$(SL_REFERENCES)\Assembly-CSharp-Publicized.dll" Private="false" />
<Reference Include="NorthwoodLib.dll" HintPath="$(SL_REFERENCES)\NorthwoodLib.dll" Private="false" />
<Reference Include="CommandSystem.Core.dll" HintPath="$(SL_REFERENCES)\CommandSystem.Core.dll" Private="false" />
<Reference Include="Mirror.dll" HintPath="$(SL_REFERENCES)\Mirror-Publicized.dll" Private="false" />
<Reference Include="Unity.TextMeshPro" HintPath="$(SL_REFERENCES)\Unity.TextMeshPro.dll" Private="false" />
<Reference Include="UnityEngine.CoreModule.dll" HintPath="$(SL_REFERENCES)\UnityEngine.CoreModule.dll" Private="false" />
<Reference Include="Exiled.API.dll" HintPath="$(SL_REFERENCES)\Exiled.API.dll" Private="false" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ASS\ASS.csproj" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions ASS.Pages/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace ASS.Pages
{
#if EXILED
using Exiled.API.Interfaces;

public class Config : IConfig
#elif LABAPI
public class Config
#endif
{
#if EXILED
public bool IsEnabled { get; set; } = true;
#endif

public bool Debug { get; set; }
}
}
16 changes: 16 additions & 0 deletions ASS.Pages/Features/ASSPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ASS.Pages.Features
{
using System;
using System.Collections.Generic;
using ASS.Features.Interfaces;
using LabApi.Features.Wrappers;

public class ASSPage : IASSObject
{
public List<IASSObject>? Children { get; set; }

public Predicate<Player>? Viewers { get; set; }

public int Priority { get; set; }
}
}
58 changes: 58 additions & 0 deletions ASS.Pages/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace ASS.Pages
{
using System;

using LabApi.Features;
using LabApi.Loader.Features.Plugins;

#if EXILED
public class Main : Exiled.API.Features.Plugin<Config>
#elif LABAPI
public class Main : Plugin
#endif
{
public override string Name => "ASS.Pages";

public override string Author => "@Someone";

public override Version Version { get; } = new(1, 0, 0);

#if EXILED
public override string Prefix => "ASS_Pages";
#elif LABAPI
public override string Description => "Adds pages to ASS";

public override Version RequiredApiVersion { get; } = new(LabApiProperties.CompiledVersion);
#endif

#if EXILED
public override void OnEnabled()
{
Enabled();
}

public override void OnDisabled()
{
Disabled();
}
#elif LABAPI
public override void Enable()
{
Enabled();
}

public override void Disable()
{
Disabled();
}
#endif

private void Enabled()
{
}

private void Disabled()
{
}
}
}
6 changes: 6 additions & 0 deletions ASS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASS", "ASS\ASS.csproj", "{5
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASS.Example", "ASS.Example\ASS.Example.csproj", "{537BC30F-80F8-4A91-9D24-25E23B7BA28B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASS.Pages", "ASS.Pages\ASS.Pages.csproj", "{2E38C870-CAFF-4B9D-A539-23E87DF283EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
LabAPI|Any CPU = LabAPI|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{537BC30F-80F8-4A91-9D24-25E23B7BA28B}.LabAPI|Any CPU.Build.0 = LabAPI|Any CPU
{537BC30F-80F8-4A91-9D24-25E23B7BA28B}.Exiled|Any CPU.ActiveCfg = Exiled|Any CPU
{537BC30F-80F8-4A91-9D24-25E23B7BA28B}.Exiled|Any CPU.Build.0 = Exiled|Any CPU
{2E38C870-CAFF-4B9D-A539-23E87DF283EE}.LabAPI|Any CPU.ActiveCfg = LabAPI|Any CPU
{2E38C870-CAFF-4B9D-A539-23E87DF283EE}.LabAPI|Any CPU.Build.0 = LabAPI|Any CPU
{2E38C870-CAFF-4B9D-A539-23E87DF283EE}.Exiled|Any CPU.ActiveCfg = Exiled|Any CPU
{2E38C870-CAFF-4B9D-A539-23E87DF283EE}.Exiled|Any CPU.Build.0 = Exiled|Any CPU
EndGlobalSection
EndGlobal
73 changes: 73 additions & 0 deletions ASS/Features/ASSExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace ASS.Features
{
using System;
using System.Collections.Generic;
using System.Linq;
using ASS.Features.Interfaces;
using ASS.Features.Settings;
using LabApi.Features.Wrappers;
using NorthwoodLib.Pools;

public static class ASSExtensions
{
public static List<ASSBase> GetAllSettings(this IASSObject assObject)
{
List<ASSBase> settings = [];
List<IASSObject> previousObjects = ListPool<IASSObject>.Shared.Rent();
InternalGetAllSettings(assObject, settings, previousObjects);
ListPool<IASSObject>.Shared.Return(previousObjects);
return settings;
}

public static List<ASSBase> GetViewableSettingsOrdered(this IASSObject assObject, Player? viewer)
{
if (viewer == null)
return [];
List<ASSBase> settings = [];
List<IASSObject> previousGroups = ListPool<IASSObject>.Shared.Rent();
InternalGetViewableSettingsOrdered(assObject, settings, previousGroups, viewer);
ListPool<IASSObject>.Shared.Return(previousGroups);
return settings;
}

private static void InternalGetAllSettings(IASSObject assObject, List<ASSBase> current, List<IASSObject> previousObjects)
{
if (assObject is ISettingsObject settings)
current.AddRange(settings.Settings);

if (assObject.Children == null)
return;
previousObjects.Add(assObject);
foreach (IASSObject group in assObject.Children)
{
if (previousObjects.Contains(group))
throw new InvalidOperationException("ASS objects cannot reference themselves within their children.");
InternalGetAllSettings(group, current, previousObjects);
}

previousObjects.Remove(assObject);
}

private static void InternalGetViewableSettingsOrdered(IASSObject assObject, List<ASSBase> current, List<IASSObject> previousChildren, Player viewer)
{
if (assObject is ISettingsObject settingsObject)
{
if (assObject.Viewers == null || assObject.Viewers(viewer))
current.AddRange(settingsObject.Settings);
}

if (assObject.Children == null)
return;
previousChildren.Add(assObject);
foreach (IASSObject obj in assObject.Children.Where(obj => (obj.Viewers?.Invoke(viewer) ?? true)).OrderByDescending(group => group.Priority))
{
if (previousChildren.Contains(obj))
throw new InvalidOperationException("ASS objects cannot reference themselves within their children.");

InternalGetViewableSettingsOrdered(obj, current, previousChildren, viewer);
}

previousChildren.Remove(assObject);
}
}
}
23 changes: 12 additions & 11 deletions ASS/Features/ASSNetworking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ASS.Features
using ASS.Events.EventArgs;
using ASS.Events.Handlers;
using ASS.Features.Collections;
using ASS.Features.Interfaces;
using ASS.Features.MirrorUtils;
using ASS.Features.MirrorUtils.Messages;
using ASS.Features.Settings;
Expand Down Expand Up @@ -38,9 +39,9 @@ public static class ASSNetworking
/// </summary>
public static Dictionary<Player, ASSBase[]> ReceivedSettings { get; } = new();

public static List<ASSGroup> Groups { get; } = [];
public static List<IASSObject> Objects { get; } = [];

public static IEnumerable<ASSBase> Settings { get; } = Groups.SelectMany(group => group.GetAllSettings());
public static IEnumerable<ASSBase> Settings { get; } = Objects.SelectMany(obj => obj.GetAllSettings());

public static Dictionary<Player, int> Versions { get; } = new();

Expand All @@ -66,7 +67,7 @@ public static class ASSNetworking
/// <remarks>
/// Useful if you want to force only a certain group or 2 to be visible to a player (like a setting controlling what settings you can see, then the group of settings you're looking at).
/// </remarks>
public static Dictionary<Player, ASSGroup[]> PlayerOverrides { get; } = new();
public static Dictionary<Player, IASSObject[]> PlayerOverrides { get; } = new();

public static bool TryGetSetting<T>(Player player, int id, [NotNullWhen(true)] out T? value)
where T : ASSBase
Expand Down Expand Up @@ -160,10 +161,10 @@ public static void SendSSSIncludingASS(Player player, ServerSpecificSettingBase[
}
}

public static void RegisterGroups(IEnumerable<ASSGroup> groups, IEnumerable<Player>? toUpdate = null)
public static void RegisterObjects(IEnumerable<IASSObject> groups, IEnumerable<Player>? toUpdate = null)
{
groups = groups.Where(group => group != null);
Groups.AddRange(groups);
Objects.AddRange(groups);

if (toUpdate is null)
return;
Expand All @@ -175,7 +176,7 @@ public static void RegisterGroups(IEnumerable<ASSGroup> groups, IEnumerable<Play
public static void UnregisterGroups(IEnumerable<ASSGroup> groups, IEnumerable<Player>? toUpdate = null)
{
groups = groups.Where(group => group != null);
Groups.RemoveAll(groups.Contains);
Objects.RemoveAll(groups.Contains);

if (toUpdate is null)
return;
Expand Down Expand Up @@ -238,18 +239,18 @@ internal static void SendByFilter(Func<ReferenceHub, bool> filter)

internal static IEnumerable<ASSBase> GetRegisteredSorted(Player player)
{
IEnumerable<ASSGroup> groups;
IEnumerable<IASSObject> objects;

if (PlayerOverrides.TryGetValue(player, out ASSGroup[] groupArray))
if (PlayerOverrides.TryGetValue(player, out IASSObject[] objArray))
{
groups = groupArray;
objects = objArray;
}
else
{
groups = Groups;
objects = Objects;
}

return groups.OrderByDescending(group => group.Priority).SelectMany(group => group.GetViewableSettingsOrdered(player));
return objects.OrderByDescending(obj => obj.Priority).SelectMany(obj => obj.GetViewableSettingsOrdered(player));
}

internal static void ProcessResponseMessage(NetworkConnectionToClient conn, SSSClientResponse message)
Expand Down
65 changes: 5 additions & 60 deletions ASS/Features/Collections/ASSGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ namespace ASS.Features.Collections
using System;
using System.Collections.Generic;
using System.Linq;

using ASS.Features.Interfaces;
using ASS.Features.Settings;

using LabApi.Features.Wrappers;

using NorthwoodLib.Pools;

public class ASSGroup
public class ASSGroup : IASSObject, ISettingsObject
{
public ASSGroup(IEnumerable<ASSBase> settings, int priority = 0, Predicate<Player>? viewers = null, IEnumerable<ASSGroup>? subGroups = null)
public ASSGroup(IEnumerable<ASSBase> settings, int priority = 0, Predicate<Player>? viewers = null, IEnumerable<IASSObject>? subGroups = null)
{
Settings = settings.ToList();
Priority = priority;
Viewers = viewers;
SubGroups = subGroups?.ToList();
Children = subGroups?.ToList();
}

public List<ASSBase> Settings { get; set; }
Expand All @@ -26,59 +24,6 @@ public ASSGroup(IEnumerable<ASSBase> settings, int priority = 0, Predicate<Playe

public Predicate<Player>? Viewers { get; set; }

public List<ASSGroup>? SubGroups { get; set; }

public List<ASSBase> GetAllSettings()
{
List<ASSBase> settings = [];
List<ASSGroup> previousGroups = ListPool<ASSGroup>.Shared.Rent();
InternalGetAllSettings(settings, previousGroups);
ListPool<ASSGroup>.Shared.Return(previousGroups);
return settings;
}

public List<ASSBase> GetViewableSettingsOrdered(Player? viewer)
{
if (viewer == null)
return [];
List<ASSBase> settings = [];
List<ASSGroup> previousGroups = ListPool<ASSGroup>.Shared.Rent();
InternalGetViewableSettingsOrdered(settings, previousGroups, viewer);
ListPool<ASSGroup>.Shared.Return(previousGroups);
return settings;
}

private void InternalGetAllSettings(List<ASSBase> current, List<ASSGroup> previousGroups)
{
current.AddRange(Settings);
if (SubGroups == null)
return;
previousGroups.Add(this);
foreach (ASSGroup group in SubGroups)
{
if (previousGroups.Contains(group))
throw new InvalidOperationException("ASSGroups cannot reference themselves within subgroups.");
group.InternalGetAllSettings(current, previousGroups);
}

previousGroups.Remove(this);
}

private void InternalGetViewableSettingsOrdered(List<ASSBase> current, List<ASSGroup> previousGroups, Player viewer)
{
if (Viewers == null || Viewers(viewer))
current.AddRange(Settings);
if (SubGroups == null)
return;
previousGroups.Add(this);
foreach (ASSGroup group in SubGroups.Where(group => group.Viewers == null || group.Viewers(viewer)).OrderByDescending(group => group.Priority))
{
if (previousGroups.Contains(group))
throw new InvalidOperationException("ASSGroups cannot reference themselves within subgroups.");
group.InternalGetViewableSettingsOrdered(current, previousGroups, viewer);
}

previousGroups.Remove(this);
}
public List<IASSObject>? Children { get; set; }
}
}
Loading