Skip to content

Commit

Permalink
V5.3.0
Browse files Browse the repository at this point in the history
Add multi-thread support for Core functions
Add pos tag support in compatibility adapter
 Add Style component in PlayerUI
  • Loading branch information
MeowServer committed Sep 1, 2024
1 parent 1565d5c commit d7083ab
Show file tree
Hide file tree
Showing 20 changed files with 1,499 additions and 494 deletions.
6 changes: 6 additions & 0 deletions HintServiceExample/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Hint = HintServiceMeow.Core.Models.Hints.Hint;
using MEC;
using System.Collections.Generic;
using HintServiceMeow.UI.Utilities;

namespace HintServiceExample
{
Expand Down Expand Up @@ -41,6 +42,11 @@ public static void OnVerified(VerifiedEventArgs ev)
ShowHintB(ev.Player);
ShowDynamicHintA(ev.Player);
ShowCommonHintA(ev.Player);

var ui = ev.Player.GetPlayerUi();
ui.Style.SetStyle(-50, 1080, Style.StyleType.Italic);
ui.Style.SetColor(-50, 1080, UnityEngine.Color.green);

}

//How to use Hint
Expand Down
33 changes: 33 additions & 0 deletions HintServiceMeow/Commands/GetCompatAssemblyName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CommandSystem;
using HintServiceMeow.Core.Utilities;
using HintServiceMeow.Core.Utilities.Patch;
using System;

namespace HintServiceMeow.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
internal class GetCompatAssemblyName: ICommand
{
public string Command => "GetCompatAssemblyName";

public string[] Aliases => new string[] { "GCAN" };

public string Description => "Get the name of all the assemblies that are using Compatibility Adaptor in HintServiceMeow";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var sb = new System.Text.StringBuilder();

sb.AppendLine("The following assemblies are using Compatibility Adaptor in HintServiceMeow:");

foreach(var name in CompatibilityAdaptor.RegisteredAssemblies)
{
sb.Append("- ");
sb.AppendLine(name);
}

response = sb.ToString();
return true;
}
}
}
99 changes: 85 additions & 14 deletions HintServiceMeow/Core/Models/HintCollection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using HintServiceMeow.Core.Models.Hints;

namespace HintServiceMeow.Core.Models
Expand All @@ -12,44 +13,114 @@ namespace HintServiceMeow.Core.Models
internal class HintCollection
{
private readonly Dictionary<string, List<AbstractHint>> _hintGroups = new Dictionary<string, List<AbstractHint>>();
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();

public IEnumerable<List<AbstractHint>> AllGroups => _hintGroups.Values;
public IEnumerable<List<AbstractHint>> AllGroups
{
get
{
_lock.EnterReadLock();
try
{
return _hintGroups.Values.ToList();
}
finally
{
_lock.ExitReadLock();
}
}
}

public IEnumerable<AbstractHint> AllHints => _hintGroups.Values.SelectMany(x => x);
public IEnumerable<AbstractHint> AllHints
{
get
{
_lock.EnterReadLock();
try
{
return _hintGroups.Values.SelectMany(x => x).ToList();
}
finally
{
_lock.ExitReadLock();
}
}
}

public void AddHint(string assemblyName, AbstractHint hint)
{
if (!_hintGroups.ContainsKey(assemblyName))
_hintGroups[assemblyName] = new List<AbstractHint>();
_lock.EnterWriteLock();
try
{
if (!_hintGroups.ContainsKey(assemblyName))
_hintGroups[assemblyName] = new List<AbstractHint>();

_hintGroups[assemblyName].Add(hint);
_hintGroups[assemblyName].Add(hint);
}
finally
{
_lock.ExitWriteLock();
}
}

public void RemoveHint(string assemblyName, AbstractHint hint)
{
if (!_hintGroups.TryGetValue(assemblyName, out var hintList))
return;
_lock.EnterWriteLock();
try
{
if (!_hintGroups.TryGetValue(assemblyName, out var hintList))
return;

hintList.Remove(hint);
hintList.Remove(hint);
}
finally
{
_lock.ExitWriteLock();
}
}

public void RemoveHint(string assemblyName, Predicate<AbstractHint> predicate)
{
if (!_hintGroups.TryGetValue(assemblyName, out var hintList))
return;
_lock.EnterWriteLock();
try
{
if (!_hintGroups.TryGetValue(assemblyName, out var hintList))
return;

hintList.RemoveAll(predicate);
hintList.RemoveAll(predicate);
}
finally
{
_lock.ExitWriteLock();
}
}

public void ClearHints(string assemblyName)
{
if (_hintGroups.TryGetValue(assemblyName, out var hintList))
hintList.Clear();
_lock.EnterWriteLock();
try
{
if (_hintGroups.TryGetValue(assemblyName, out var hintList))
hintList.Clear();
}
finally
{
_lock.ExitWriteLock();
}
}

public IEnumerable<AbstractHint> GetHints(string assemblyName)
{
return _hintGroups.TryGetValue(assemblyName, out var hintList) ? hintList : new List<AbstractHint>();
_lock.EnterReadLock();
try
{
return _hintGroups.TryGetValue(assemblyName, out var hintList) ? hintList.ToList() : new List<AbstractHint>();
}
finally
{
_lock.ExitReadLock();
}
}
}

}
Loading

0 comments on commit d7083ab

Please sign in to comment.