mirror of
https://github.com/MSWS/TTT.git
synced 2025-12-05 22:20:25 -08:00
Add JetBrains Annotations, reformat
This commit is contained in:
5
Directory.Build.props
Normal file
5
Directory.Build.props
Normal file
@@ -0,0 +1,5 @@
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -10,33 +10,33 @@ public static class Program {
|
||||
|
||||
public static void Main(string[] args) {
|
||||
if (args.Length < 1) {
|
||||
PrintUsage();
|
||||
printUsage();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
var (inputPaths, outputPath) = ParseArguments(args);
|
||||
var (inputPaths, outputPath) = parseArguments(args);
|
||||
|
||||
ValidateInputFiles(inputPaths);
|
||||
validateInputFiles(inputPaths);
|
||||
|
||||
var merged = MergeYamlFiles(inputPaths);
|
||||
var merged = mergeYamlFiles(inputPaths);
|
||||
|
||||
WriteJsonOutput(merged, outputPath);
|
||||
writeJsonOutput(merged, outputPath);
|
||||
}
|
||||
|
||||
private static void PrintUsage() {
|
||||
private static void printUsage() {
|
||||
Console.Error.WriteLine("Usage:");
|
||||
Console.Error.WriteLine(" YamlToJson <input.yml>");
|
||||
Console.Error.WriteLine(
|
||||
" YamlToJson <input1.yml> <input2.yml> ... --out <output.json>");
|
||||
}
|
||||
|
||||
private static (string[] inputPaths, string outputPath) ParseArguments(
|
||||
private static (string[] inputPaths, string outputPath) parseArguments(
|
||||
string[] args) {
|
||||
string outputPath;
|
||||
string[] inputPaths;
|
||||
|
||||
if (args.Length == 1) {
|
||||
inputPaths = new[] { args[0] };
|
||||
inputPaths = [args[0]];
|
||||
outputPath = Path.ChangeExtension(args[0], ".json");
|
||||
} else {
|
||||
var outIndex = Array.IndexOf(args, "--out");
|
||||
@@ -53,7 +53,7 @@ public static class Program {
|
||||
return (inputPaths, outputPath);
|
||||
}
|
||||
|
||||
private static void ValidateInputFiles(string[] inputPaths) {
|
||||
private static void validateInputFiles(string[] inputPaths) {
|
||||
foreach (var input in inputPaths)
|
||||
if (!File.Exists(input)) {
|
||||
Console.Error.WriteLine($"Error: File not found - {input}");
|
||||
@@ -62,7 +62,7 @@ public static class Program {
|
||||
}
|
||||
|
||||
private static Dictionary<string, string>
|
||||
MergeYamlFiles(string[] inputPaths) {
|
||||
mergeYamlFiles(string[] inputPaths) {
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(NullNamingConvention.Instance)
|
||||
.Build();
|
||||
@@ -89,7 +89,7 @@ public static class Program {
|
||||
return merged;
|
||||
}
|
||||
|
||||
private static void WriteJsonOutput(Dictionary<string, string> merged,
|
||||
private static void writeJsonOutput(Dictionary<string, string> merged,
|
||||
string outputPath) {
|
||||
var dir = Path.GetDirectoryName(outputPath);
|
||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace TTT.Locale;
|
||||
/// A custom implementation of <see cref="IStringLocalizer" /> that adds support
|
||||
/// for in-string placeholders like %key% and grammatical pluralization with %s%.
|
||||
/// </summary>
|
||||
public partial class StringLocalizer : IStringLocalizer, IMsgLocalizer {
|
||||
public partial class StringLocalizer : IMsgLocalizer {
|
||||
public static readonly StringLocalizer Instance =
|
||||
new(new JsonLocalizerFactory());
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace TTT.API.Events;
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class EventHandlerAttribute : Attribute {
|
||||
public uint Priority { get; set; } = Events.Priority.DEFAULT;
|
||||
public bool IgnoreCanceled { get; set; } = false;
|
||||
public bool IgnoreCanceled { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -27,7 +27,7 @@ public static class ServiceCollectionExtensions {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a <see cref="IPluginBehavior" /> to the global service collection
|
||||
/// Add a <see cref="ITerrorModule" /> to the global service collection
|
||||
/// </summary>
|
||||
/// <param name="collection"></param>
|
||||
/// <typeparam name="TExtension"></typeparam>
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.Game.Roles;
|
||||
|
||||
namespace TTT.CS2.GameHandlers;
|
||||
|
||||
public class RoundEndHandler(IServiceProvider provider) : IPluginModule {
|
||||
private readonly IEventBus bus = provider.GetRequiredService<IEventBus>();
|
||||
|
||||
private readonly IGameManager games =
|
||||
provider.GetRequiredService<IGameManager>();
|
||||
|
||||
@@ -22,7 +19,7 @@ public class RoundEndHandler(IServiceProvider provider) : IPluginModule {
|
||||
public void Start() { }
|
||||
|
||||
[GameEventHandler]
|
||||
public HookResult OnRoundEnd(EventRoundEnd ev, GameEventInfo _) {
|
||||
public HookResult OnRoundEnd(EventRoundEnd _, GameEventInfo _1) {
|
||||
if (!games.IsGameActive()) return HookResult.Continue;
|
||||
var game = games.ActiveGame ?? throw new InvalidOperationException(
|
||||
"Active game is null, but round end event was triggered.");
|
||||
|
||||
@@ -39,23 +39,7 @@ public class CommandManager(IServiceProvider provider) : ICommandManager {
|
||||
}
|
||||
|
||||
if (!CanExecute(executor, command)) {
|
||||
if (executor == null) {
|
||||
info.ReplySync(localizer[GameMsgs.GENERIC_NO_PERMISSION]);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (command.RequiredFlags.Any(f => !permissions.HasFlags(executor, f))) {
|
||||
info.ReplySync(localizer[
|
||||
GameMsgs.GENERIC_NO_PERMISSION_NODE(string.Join(", ",
|
||||
command.RequiredFlags))]);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
if (command.RequiredGroups.Any(g => permissions.InGroups(executor, g)))
|
||||
return CommandResult.NO_PERMISSION;
|
||||
info.ReplySync(localizer[
|
||||
GameMsgs.GENERIC_NO_PERMISSION_RANK(string.Join(", ",
|
||||
command.RequiredGroups))]);
|
||||
printNoPermission(executor, command, info);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
@@ -75,4 +59,23 @@ public class CommandManager(IServiceProvider provider) : ICommandManager {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void printNoPermission(IOnlinePlayer? executor, ICommand command,
|
||||
ICommandInfo info) {
|
||||
if (executor == null) {
|
||||
info.ReplySync(localizer[GameMsgs.GENERIC_NO_PERMISSION]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.RequiredFlags.Any(f => !permissions.HasFlags(executor, f))) {
|
||||
info.ReplySync(localizer[
|
||||
GameMsgs.GENERIC_NO_PERMISSION_NODE(string.Join(", ",
|
||||
command.RequiredFlags))]);
|
||||
return;
|
||||
}
|
||||
|
||||
info.ReplySync(localizer[
|
||||
GameMsgs.GENERIC_NO_PERMISSION_RANK(string.Join(", ",
|
||||
command.RequiredGroups))]);
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,5 @@ public class PlayerRoleAssignEvent(IPlayer player, IRole role)
|
||||
/// </summary>
|
||||
public IRole Role { get; internal set; } = role;
|
||||
|
||||
public bool IsCanceled { get; set; } = false;
|
||||
public bool IsCanceled { get; set; }
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace TTT.Game;
|
||||
public class GameManager(IServiceProvider provider) : IGameManager {
|
||||
public IGame? ActiveGame { get; private set; }
|
||||
|
||||
public IGame? CreateGame() {
|
||||
public IGame CreateGame() {
|
||||
return ActiveGame = new RoundBasedGame(provider);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using TTT.API.Events;
|
||||
using JetBrains.Annotations;
|
||||
using TTT.API.Events;
|
||||
using TTT.Game.Actions;
|
||||
using TTT.Game.Events.Player;
|
||||
|
||||
@@ -9,6 +10,7 @@ public class GamePlayerActionsListener(IServiceProvider provider)
|
||||
public override string Name => nameof(GamePlayerActionsListener);
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnPlayerKill(PlayerDeathEvent ev) {
|
||||
if (!Games.IsGameActive()) return;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
@@ -25,6 +26,7 @@ public class GameRestartListener(IServiceProvider provider)
|
||||
public override string Name => nameof(GameRestartListener);
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnGameEnd(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.FINISHED) return;
|
||||
Observable.Timer(config.RoundCfg.TimeBetweenRounds, scheduler)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using JetBrains.Annotations;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Role;
|
||||
@@ -11,6 +12,7 @@ public class PlayerCausesEndListener(IServiceProvider provider)
|
||||
public override string Name { get; } = nameof(PlayerCausesEndListener);
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnKill(PlayerDeathEvent ev) {
|
||||
if (!Games.IsGameActive()) return;
|
||||
|
||||
@@ -25,6 +27,7 @@ public class PlayerCausesEndListener(IServiceProvider provider)
|
||||
}
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnLeave(PlayerLeaveEvent ev) {
|
||||
if (!Games.IsGameActive()) return;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using TTT.API.Events;
|
||||
using JetBrains.Annotations;
|
||||
using TTT.API.Events;
|
||||
using TTT.Game.Events.Player;
|
||||
|
||||
namespace TTT.Game.Listeners;
|
||||
@@ -8,6 +9,7 @@ public class PlayerJoinStarting(IServiceProvider provider)
|
||||
public override string Name => nameof(PlayerJoinStarting);
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnJoin(PlayerJoinEvent ev) {
|
||||
if (Games.ActiveGame is not null) return;
|
||||
var playerCount = Finder.GetOnline().Count;
|
||||
|
||||
@@ -29,11 +29,6 @@ public class RoundBasedGame(IServiceProvider provider) : IGame {
|
||||
|
||||
private State state = State.WAITING;
|
||||
|
||||
public SortedDictionary<DateTime, ISet<IAction>> Actions {
|
||||
get;
|
||||
protected set;
|
||||
} = new();
|
||||
|
||||
public ICollection<IPlayer> Players => players;
|
||||
|
||||
public IActionLogger Logger { get; } = new SimpleLogger(provider
|
||||
@@ -115,7 +110,7 @@ public class RoundBasedGame(IServiceProvider provider) : IGame {
|
||||
public void Dispose() {
|
||||
players.Clear();
|
||||
roles.Clear();
|
||||
Actions.Clear();
|
||||
Logger.ClearActions();
|
||||
}
|
||||
|
||||
private void startRound() {
|
||||
|
||||
@@ -4,5 +4,5 @@ namespace TTT.Test.Game.Event;
|
||||
|
||||
public class TestEvent : API.Events.Event, ICancelableEvent {
|
||||
public override string Id => "test.event.testevent";
|
||||
public bool IsCanceled { get; set; } = false;
|
||||
public bool IsCanceled { get; set; }
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Reactive.Testing;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Player;
|
||||
using Xunit;
|
||||
@@ -8,21 +7,17 @@ using Xunit;
|
||||
namespace TTT.Test.Game.Round;
|
||||
|
||||
public class RoundBasedGameTest {
|
||||
private readonly IEventBus bus;
|
||||
private readonly IPlayerFinder finder;
|
||||
|
||||
private readonly IGame game;
|
||||
|
||||
private readonly IGameManager manager;
|
||||
|
||||
private readonly TestScheduler scheduler;
|
||||
|
||||
public RoundBasedGameTest(IServiceProvider provider) {
|
||||
finder = provider.GetRequiredService<IPlayerFinder>();
|
||||
bus = provider.GetRequiredService<IEventBus>();
|
||||
scheduler = provider.GetRequiredService<TestScheduler>();
|
||||
manager = provider.GetRequiredService<IGameManager>();
|
||||
game = manager.CreateGame() ?? throw new InvalidOperationException();
|
||||
var manager = provider.GetRequiredService<IGameManager>();
|
||||
game = manager.CreateGame() ?? throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using JetBrains.Annotations;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Messages;
|
||||
using TTT.API.Player;
|
||||
@@ -27,6 +28,7 @@ public class JoinMessageTest(IEventBus bus, IMessenger msg,
|
||||
public void Dispose() { bus.UnregisterListener(this); }
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnJoin(PlayerJoinEvent ev) {
|
||||
msg.Message(ev.Player, "Hello, World!");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using JetBrains.Annotations;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Messages;
|
||||
using TTT.Game.Events.Player;
|
||||
@@ -28,6 +29,7 @@ public class MessageModificationTest(IEventBus bus, IMessenger messenger) {
|
||||
public void Dispose() { bus.UnregisterListener(this); }
|
||||
|
||||
[EventHandler]
|
||||
[UsedImplicitly]
|
||||
public void OnMessage(PlayerMessageEvent ev) {
|
||||
ev.Message = MODIFIED_MESSAGE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user