Skip to content

Commit

Permalink
me when translations uwu
Browse files Browse the repository at this point in the history
  • Loading branch information
Misfiy committed Oct 8, 2023
1 parent 7fa1000 commit 89314dd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
16 changes: 8 additions & 8 deletions CandyUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
namespace CandyUtilities;

using Exiled.API.Features;
using Exiled.API.Enums;
using CandyUtilities.Events;
using Scp330 = Exiled.Events.Handlers.Scp330;

public class CandyUtil : Plugin<Config>
public class CandyUtil : Plugin<Config, Translation>
{
public override string Name => "Candy Utilities";
public override string Prefix => "CandyUtils";
public override string Author => "@misfiy";
public override PluginPriority Priority => PluginPriority.Default;
private EventHandler eventHandler;
public override Version Version => new(1, 0, 4);
public override Version RequiredExiledVersion => new(8, 2, 1);

public static CandyUtil Instance;
private Config config;

private EventHandler eventHandler;
public override void OnEnabled()
{
Instance = this;
config = Instance.Config;

RegisterEvents();
base.OnEnabled();
Expand All @@ -26,7 +26,7 @@ public override void OnEnabled()
public override void OnDisabled()
{
UnregisterEvents();
Instance = null;
Instance = null!;
base.OnDisabled();
}
public void RegisterEvents()
Expand All @@ -39,6 +39,6 @@ public void RegisterEvents()
public void UnregisterEvents()
{
Scp330.InteractingScp330 -= eventHandler.OnInteraction;
eventHandler = null;
eventHandler = null!;
}
}
3 changes: 2 additions & 1 deletion CandyUtilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EXILED" Version="7.2.0" />
<PackageReference Include="EXILED" Version="8.2.1" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<PackageReference Include="UnityEngine.Modules" Version="2019.4.15" IncludeAssets="compile" />
</ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ public sealed class Config : IConfig
public bool Debug { get; set; } = false;
[Description("Chance of getting pink candy from bowl")]
public ushort PinkChance { get; set; } = 2;
[Description("Whether or not to show a hint on picking up candy")]
public bool ShouldShowHint { get; set; } = true;
[Description("The text shown when picking up a candy, note %type% gets replaced with the type of candy. If ShouldShowHint is false then this won't do anything.")]
public string TextOnPickup { get; set; } = "You take a piece of %type% candy.";
}
22 changes: 6 additions & 16 deletions EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,21 @@ namespace CandyUtilities.Events;

public sealed class EventHandler
{
private readonly Config config = CandyUtil.Instance.Config;
private readonly Random random = new();
private readonly Dictionary<string, string> candies = new()
{
{ "Rainbow", "<color=#FF0000>R</color><color=#FF7F00>a</color><color=#FFFF00>i</color><color=#00FF00>n</color><color=#0000FF>b</color><color=#4B0082>o</color><color=#8A2BE2>w</color>" },
{ "Yellow", "<color=#FFFF00>Yellow</color>" },
{ "Purple", "<color=#800080>Purple</color>" },
{ "Red", "<color=#FF0000>Red</color>" },
{ "Green", "<color=#008000>Green</color>" },
{ "Blue", "<color=#0000FF>Blue</color>" },
{ "Pink", "<color=#FFC0CB>Pink</color>" }
};

public void OnInteraction(InteractingScp330EventArgs ev)
{
if (!ev.IsAllowed) return;
if (random.Next(1, 101) <= config.PinkChance)
if (random.Next(1, 101) <= CandyUtil.Instance.Config.PinkChance)
{
Log.Debug("Pink candy has been selected!");
ev.Candy = CandyKindID.Pink;
}
if (!config.ShouldShowHint || config.TextOnPickup.Length == 0) return;
string currentCandy = candies[ev.Candy.ToString()];
string text = config.TextOnPickup.Replace("%type%", currentCandy);

if (CandyUtil.Instance.Translation.PickupText.IsEmpty()) return;
string currentCandy = CandyUtil.Instance.Translation.CandyText[ev.Candy];
string text = CandyUtil.Instance.Translation.PickupText.Replace("%type%", currentCandy);
ev.Player.ShowHint(text);
Log.Debug("Candy picked up: " + text);
Log.Debug("Candy picked up:\n " + text);
}
}
23 changes: 23 additions & 0 deletions Translation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Exiled.API.Interfaces;
using InventorySystem.Items.Usables.Scp330;
using System.ComponentModel;

namespace CandyUtilities
{
public sealed class Translation : ITranslation
{
[Description("The text shown when picking up a candy, note %type% gets replaced with the type of candy. If ShouldShowHint is false then this won't do anything.")]
public string PickupText { get; set; } = "You take a piece of %type% candy.";
[Description("Dictionary of candies and the respective text to show based on them")]
public Dictionary<CandyKindID, string> CandyText { get; set; } = new()
{
{ CandyKindID.Rainbow, "<color=#FF0000>R</color><color=#FF7F00>a</color><color=#FFFF00>i</color><color=#00FF00>n</color><color=#0000FF>b</color><color=#4B0082>o</color><color=#8A2BE2>w</color>" },
{ CandyKindID.Yellow, "<color=#FFFF00>Yellow</color>" },
{ CandyKindID.Purple, "<color=#800080>Purple</color>" },
{ CandyKindID.Red, "<color=#FF0000>Red</color>" },
{ CandyKindID.Green, "<color=#008000>Green</color>" },
{ CandyKindID.Blue, "<color=#0000FF>Blue</color>" },
{ CandyKindID.Pink, "<color=#FFC0CB>Pink</color>" }
};
}
}

0 comments on commit 89314dd

Please sign in to comment.