Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LolaLollipop committed Jan 9, 2024
1 parent c3637a2 commit 30b8aa7
Show file tree
Hide file tree
Showing 21 changed files with 219 additions and 167 deletions.
182 changes: 86 additions & 96 deletions RueI/RueI.csproj
Original file line number Diff line number Diff line change
@@ -1,99 +1,89 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
<Title>RueI</Title>
<Copyright>CC0 1.0</Copyright>
<Version>2.0.4</Version>
<Authors>Rue &lt;3, Override (some help)</Authors>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>universal hint framework for scp:sl</Description>
<RepositoryUrl>https://github.com/Ruemena/RueI</RepositoryUrl>
<PackageProjectUrl>https://github.com/Ruemena/RueI</PackageProjectUrl>
<PackageTags>scpsl;hints;scp;exiled;nwapi</PackageTags>
<AssemblyVersion>2.0.4</AssemblyVersion>
<FileVersion>2.0.4</FileVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>various fixes, improvements to docs, new reflection helpers, and general cleanup</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Optimize>True</Optimize>
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebugType>portable</DebugType>
</PropertyGroup>

<ItemGroup>
<Compile Remove="RueI\Displays\Interfaces\Roles.cs" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
<Title>RueI</Title>
<Copyright>CC0 1.0</Copyright>
<Version>2.0.4</Version>
<Authors>Rue &lt;3, Override (some help)</Authors>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>universal hint framework for scp:sl</Description>
<RepositoryUrl>https://github.com/Ruemena/RueI</RepositoryUrl>
<PackageProjectUrl>https://github.com/Ruemena/RueI</PackageProjectUrl>
<PackageTags>scpsl;hints;scp;exiled;nwapi</PackageTags>
<AssemblyVersion>2.0.4</AssemblyVersion>
<FileVersion>2.0.4</FileVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>various fixes, improvements to docs, new reflection helpers, and general cleanup</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<None Remove="RueI\Constants.cs~RF13edd36.TMP" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>../References/Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>../References/Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>../References/Mirror.dll</HintPath>
</Reference>
<Reference Include="NorthwoodLib">
<HintPath>../References/NorthwoodLib.dll</HintPath>
</Reference>
<Reference Include="PluginAPI">
<HintPath>../References/PluginAPI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>../References/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>../References/UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Immutable">
<HintPath>../References/System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Optimize>True</Optimize>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<Compile Remove="RueI\Displays\Interfaces\Roles.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="RueI\Constants.cs~RF13edd36.TMP" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>../References/Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>../References/Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>../References/Mirror.dll</HintPath>
</Reference>
<Reference Include="NorthwoodLib">
<HintPath>../References/NorthwoodLib.dll</HintPath>
</Reference>
<Reference Include="PluginAPI">
<HintPath>../References/PluginAPI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>../References/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>../References/UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Immutable">
<HintPath>../References/System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
/// </remarks>
public class AutoElement
{
private record PeriodicUpdate(TimeSpan time, int priority, JobToken token);
/// <summary>
/// Represents a periodic update for an <see cref="AutoElement"/>.
/// </summary>
/// <param name="time">How often the <see cref="AutoElement"/> should schedule an auto-update.</param>
/// <param name="priority">The priority of the scheduled job.</param>
public record PeriodicUpdate(TimeSpan time, int priority = 10);

private const int AUTOUPDATEPRIORITY = 5;

Expand All @@ -29,7 +34,7 @@ private record PeriodicUpdate(TimeSpan time, int priority, JobToken token);

private readonly IElemReference<Element> reference = DisplayCore.GetReference<Element>();

private PeriodicUpdate? periodicUpdate;
private (PeriodicUpdate update, JobToken token)? autoUpdate = null;

static AutoElement()
{
Expand Down Expand Up @@ -68,23 +73,32 @@ public AutoElement(Roles roles, Element element)
public Roles Roles { get; set; }

/// <summary>
/// Disables this <see cref="AutoElement"/>.
/// Gets or sets a <see cref="PeriodicUpdate"/> indicating how often this <see cref="AutoElement"/> should
/// schedule an update for players with the element, or <c>null</c> if it should not auto-update.
/// </summary>
public virtual void Disable()
public PeriodicUpdate? UpdateEvery
{
AutoElements.Remove(this);
get => autoUpdate?.update;

set
{
if (value != null)
{
autoUpdate = (value, new());
}
else
{
autoUpdate = null;
}
}
}

/// <summary>
/// Schedules an update for all players with one of the <see cref="Roles"/> every <paramref name="span"/>.
/// Disables this <see cref="AutoElement"/>.
/// </summary>
/// <param name="span">How often to schedule an update.</param>
/// <param name="priority">The priority of the update.</param>
/// <returns>A reference to this <see cref="AutoElement"/>.</returns>
public AutoElement UpdateEvery(TimeSpan span, int priority = 35)
public virtual void Disable()
{
periodicUpdate = new(span, priority, new());
return this;
AutoElements.Remove(this);
}

/// <summary>
Expand All @@ -102,9 +116,9 @@ protected virtual void GiveTo(DisplayCore core)
core.AddAsReference(reference, creator!(core));
}

if (periodicUpdate != null)
if (autoUpdate != null)
{
ScheduleUpdate(core, periodicUpdate);
ScheduleUpdate(core, autoUpdate.Value);
}
}

Expand All @@ -116,9 +130,9 @@ protected virtual void RemoveFrom(DisplayCore core)
{
core.RemoveReference(reference);

if (periodicUpdate != null)
if (autoUpdate != null)
{
core.Scheduler.KillJob(periodicUpdate.token);
core.Scheduler.KillJob(autoUpdate.Value.token);
}
}

Expand All @@ -144,8 +158,8 @@ private static void OnRoleChanged(ReferenceHub hub, PlayerRoleBase prevRole, Pla
}
}

private static void ScheduleUpdate(DisplayCore core, PeriodicUpdate update)
private static void ScheduleUpdate(DisplayCore core, (PeriodicUpdate update, JobToken token) autoUpdate)
{
core.Scheduler.Schedule(update.time, () => ScheduleUpdate(core, update), update.token);
core.Scheduler.Schedule(autoUpdate.update.time, () => ScheduleUpdate(core, autoUpdate), autoUpdate.token);
}
}
10 changes: 5 additions & 5 deletions RueI/RueI/Displays/DisplayCore.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace RueI.Displays;

using RueI.Elements;
using RueI.Displays.Scheduling;
using RueI.Elements;
using RueI.Extensions;

/// <summary>
Expand Down Expand Up @@ -41,14 +41,14 @@ protected DisplayCore(ReferenceHub hub)
public Scheduler Scheduler { get; }

/// <summary>
/// Gets a dictionary containing the DisplayCores for each ReferenceHub.
/// Gets the <see cref="ReferenceHub"/> that this display is for.
/// </summary>
internal static Dictionary<ReferenceHub, DisplayCore> DisplayCores { get; } = new();
public ReferenceHub Hub { get; }

/// <summary>
/// Gets the <see cref="ReferenceHub"/> that this display is for.
/// Gets a dictionary containing the DisplayCores for each ReferenceHub.
/// </summary>
internal ReferenceHub Hub { get; }
internal static Dictionary<ReferenceHub, DisplayCore> DisplayCores { get; } = new();

/// <summary>
/// Gets or sets a value indicating whether or not updates will currently be ignored.
Expand Down
13 changes: 9 additions & 4 deletions RueI/RueI/Displays/ElemCombiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

using NorthwoodLib.Pools;

using RueI.Extensions;
using RueI.Elements;
using RueI.Extensions;
using RueI.Parsing.Records;

/// <summary>
Expand All @@ -32,6 +32,7 @@ public static string Combine(IEnumerable<Element> enumElems)
}

StringBuilder sb = StringBuilderPool.Shared.Rent();

float totalOffset = 0;

float lastPosition = 0;
Expand All @@ -54,7 +55,7 @@ public static string Combine(IEnumerable<Element> enumElems)
if (i != 0)
{
float calcedOffset = CalculateOffset(lastPosition, lastOffset, funcPos);
sb.Append($"<line-height={calcedOffset}px>\n</line-height>");
sb.Append($"<line-height={calcedOffset}px>\n<line-height=40.665>");
totalOffset += calcedOffset;
}
else
Expand All @@ -70,8 +71,12 @@ public static string Combine(IEnumerable<Element> enumElems)
}

ListPool<Element>.Shared.Return(elements);
sb.Insert(0, $"<line-height={totalOffset}px>\n</line-height>");
sb.Append(Constants.ZeroWidthSpace);
sb.Insert(0, $"<line-height={totalOffset}px>\n<line-height=40.665><size=0>.</size>");

// a zero width space is appended here to ensure that trailing newlines still occur
// since this is after all tags have been closed, its guaranteed to not
// do anything at all except stop trailing newlines
sb.Append("<size=0>.");
return StringBuilderPool.Shared.ToStringReturn(sb);
}

Expand Down
8 changes: 5 additions & 3 deletions RueI/RueI/Displays/Scheduling/JobToken.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace RueI.Displays.Scheduling;

/// <summary>
/// Represents a reference to any number of <see cref="Records.ScheduledJob"/>.
/// Represents a reference to any number of <see cref="ScheduledJob"/>.
/// </summary>
/// <remarks>
/// A <see cref="JobToken"/> provides a unique identifier for a <see cref="Records.ScheduledJob"/> within any number of <see cref="Scheduler"/>s. In other words, a <see cref="JobToken"/> can reference multiple (or no) <see cref="Records.ScheduledJob"/>, but only a single <see cref="Records.ScheduledJob"/> with the given <see cref="JobToken"/> can exist in a <see cref="Scheduler"/>.
/// A <see cref="JobToken"/> provides a unique identifier for a <see cref="ScheduledJob"/> within any number of
/// <see cref="Scheduler"/>s. In other words, a <see cref="JobToken"/> can reference multiple (or no) jobs,
/// but only a single job with the given <see cref="JobToken"/> can exist in a <see cref="Scheduler"/>.
/// </remarks>
/// <seealso cref="Records.ScheduledJob"/>
/// <seealso cref="ScheduledJob"/>
public class JobToken
{
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion RueI/RueI/Displays/Scheduling/Records/BatchJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/// <summary>
/// Defines a number of <see cref="ScheduledJob"/>s that will performed at a certain time.
/// </summary>
internal class BatchJob
///
internal record BatchJob
{
/// <summary>
/// Initializes a new instance of the <see cref="BatchJob"/> class.
Expand Down
Loading

0 comments on commit 30b8aa7

Please sign in to comment.