Skip to content

Commit

Permalink
Redo logging & formatting (again) (#25)
Browse files Browse the repository at this point in the history
* Redo `SimpleView` semantics to be more in line with how they're
actually used (use collection-constructor pattern rather than delegate
pattern)
* Fragment `LogManager` into `ILogService`, `IPlayerTag`, and rich
variants in `Jailbreak.Formatting`
* Add barebones english translations for logging (will need to go over
again)
  • Loading branch information
Mooshua authored Feb 6, 2024
2 parents c5132ec + 538f64e commit a05d743
Show file tree
Hide file tree
Showing 35 changed files with 1,097 additions and 697 deletions.
39 changes: 18 additions & 21 deletions lang/Jailbreak.English/Generic/GenericCommandNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
Expand All @@ -9,26 +10,22 @@ namespace Jailbreak.English.Generic;

public class GenericCommandNotifications : IGenericCommandNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject Prefix =
new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}JB{ChatColors.Darkred}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};
public static FormatObject PREFIX =
new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}JB{ChatColors.Darkred}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};

public IView PlayerNotFound(string query)
{
return new SimpleView(writer =>
writer
.Line(Prefix, $"Player '{query}' not found!"));
}
public IView PlayerNotFound(string query)
{
return new SimpleView { PREFIX, $"Player '{query}' not found!" };
}

public IView PlayerFoundMultiple(string query)
{
return new SimpleView(writer =>
writer
.Line(Prefix, $"Multiple players found for '{query}'!"));
}
}
public IView PlayerFoundMultiple(string query)
{
return new SimpleView { PREFIX, $"Multiple players found for '{query}'!" };
}
}
34 changes: 34 additions & 0 deletions lang/Jailbreak.English/Logs/LogMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Extensions;

namespace Jailbreak.English.Logs;

public class LogMessages : ILogMessages, ILanguage<Formatting.Languages.English>
{



public IView BEGIN_JAILBREAK_LOGS => new SimpleView()
{
{ "********************************" }, SimpleView.NEWLINE,
{ "***** BEGIN JAILBREAK LOGS *****" }, SimpleView.NEWLINE,
{ "********************************" }
};

public IView END_JAILBREAK_LOGS => new SimpleView()
{
{ "********************************" }, SimpleView.NEWLINE,
{ "****** END JAILBREAK LOGS ******" }, SimpleView.NEWLINE,
{ "********************************" }
};



}
23 changes: 11 additions & 12 deletions lang/Jailbreak.English/Rebel/RebelNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
Expand All @@ -9,16 +10,14 @@ namespace Jailbreak.English.Rebel;

public class RebelNotifications : IRebelNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject Prefix =
new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}Rebel{ChatColors.Darkred}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};
public static FormatObject PREFIX = new HiddenFormatObject($" {ChatColors.Darkred}[{ChatColors.LightRed}Rebel{ChatColors.Darkred}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};

public IView NoLongerRebel => new SimpleView(writer =>
writer
.Line(Prefix, "You are no longer a rebel."));
}
public IView NO_LONGER_REBEL =>
new SimpleView() { PREFIX, "You are no longer a rebel." };
}
84 changes: 41 additions & 43 deletions lang/Jailbreak.English/Teams/RatioNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
Expand All @@ -9,46 +10,43 @@ namespace Jailbreak.English.Teams;

public class RatioNotifications : IRatioNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject Prefix =
new HiddenFormatObject($" {ChatColors.LightRed}[{ChatColors.Red}JB{ChatColors.LightRed}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};

public IView NotEnoughGuards => new SimpleView(writer =>
writer
.Line(Prefix, "There's not enough guards in the queue!"));

public IView PleaseJoinGuardQueue => new SimpleView(writer =>
writer
.Line(Prefix, "Type !guard to become a guard!"));

public IView JoinedGuardQueue => new SimpleView(writer =>
writer
.Line(Prefix, "You've joined the guard queue!"));

public IView AlreadyAGuard => new SimpleView(writer =>
writer
.Line(Prefix, "You're already a guard!"));

public IView YouWereAutobalancedPrisoner => new SimpleView(writer =>
writer
.Line(Prefix, "You were autobalanced to the prisoner team!"));

public IView AttemptToJoinFromTeamMenu => new SimpleView(writer =>
writer
.Line(Prefix, "You were swapped back to the prisoner team!")
.Line(Prefix, "Please use !guard to join the guard team."));

public IView LeftGuard => new SimpleView(writer =>
writer
.Line(Prefix, "You are no longer a guard.")
.Line(Prefix, "Please use !guard if you want to re-join the guard team."));

public IView YouWereAutobalancedGuard => new SimpleView(writer =>
writer
.Line(Prefix, "You are now a guard!"));
}
public static FormatObject PREFIX = new HiddenFormatObject($" {ChatColors.LightRed}[{ChatColors.Red}JB{ChatColors.LightRed}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};

public IView NOT_ENOUGH_GUARDS =>
new SimpleView { PREFIX, "There's not enough guards in the queue!" };

public IView PLEASE_JOIN_GUARD_QUEUE =>
new SimpleView { PREFIX, "Type !guard to become a guard!" };

public IView JOINED_GUARD_QUEUE =>
new SimpleView { PREFIX, "You've joined the guard queue!" };

public IView ALREADY_A_GUARD =>
new SimpleView { PREFIX, "You're already a guard!" };

public IView YOU_WERE_AUTOBALANCED_PRISONER =>
new SimpleView
{
{ PREFIX, "You were autobalanced to the prisoner team!" }, SimpleView.NEWLINE,
{ PREFIX, "Please use !guard to join the guard team." }
};

public IView ATTEMPT_TO_JOIN_FROM_TEAM_MENU =>
new SimpleView { PREFIX, "You were swapped back to the prisoner team!" };

public IView LEFT_GUARD =>
new SimpleView
{
{ PREFIX, "You are no longer a guard." }, SimpleView.NEWLINE,
{ PREFIX, "Please use !guard if you want to re-join the guard team." }
};

public IView YOU_WERE_AUTOBALANCED_GUARD =>
new SimpleView { PREFIX, "You are now a guard!" };
}
86 changes: 42 additions & 44 deletions lang/Jailbreak.English/Warden/WardenNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
Expand All @@ -10,57 +11,54 @@ namespace Jailbreak.English.Warden;

public class WardenNotifications : IWardenNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject Prefix =
new HiddenFormatObject($" {ChatColors.Lime}[{ChatColors.Green}WARDEN{ChatColors.Lime}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};
public static FormatObject PREFIX = new HiddenFormatObject($" {ChatColors.Lime}[{ChatColors.Green}WARDEN{ChatColors.Lime}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};

public IView PickingShortly => new SimpleView(writer =>
writer
.Line(Prefix, "Picking a warden shortly")
.Line(Prefix, "To enter the warden queue, type !warden in chat."));
public IView PICKING_SHORTLY =>
new SimpleView
{
{ PREFIX, "Picking a warden shortly" }, SimpleView.NEWLINE,
{ PREFIX, "To enter the warden queue, type !warden in chat." }
};

public IView NoWardens => new SimpleView(writer =>
writer
.Line(Prefix, "No wardens in queue! The next player to run !warden will become a warden."));
public IView NO_WARDENS =>
new SimpleView { PREFIX, "No wardens in queue! The next player to run !warden will become a warden." };

public IView WardenLeft => new SimpleView(writer =>
writer.Line(Prefix, "The warden has left the game!"));
public IView WARDEN_LEFT =>
new SimpleView { PREFIX, "The warden has left the game!" };

public IView WardenDied => new SimpleView(writer =>
writer.Line(Prefix, "The warden has died!"));
public IView WARDEN_DIED =>
new SimpleView { PREFIX, "The warden has died!" };

public IView BecomeNextWarden => new SimpleView(writer =>
writer.Line(Prefix, "Type !warden to become the next warden"));
public IView BECOME_NEXT_WARDEN =>
new SimpleView { PREFIX, "Type !warden to become the next warden" };

public IView JoinRaffle => new SimpleView(writer =>
writer.Line(Prefix, "You've joined the warden raffle!"));
public IView JOIN_RAFFLE =>
new SimpleView { PREFIX, "You've joined the warden raffle!" };

public IView LeaveRaffle => new SimpleView(writer =>
writer.Line(Prefix, "You've left the warden raffle!"));
public IView LEAVE_RAFFLE =>
new SimpleView { PREFIX, "You've left the warden raffle!" };

public IView PassWarden(CCSPlayerController player)
{
return new SimpleView(writer =>
writer.Line(Prefix, player, "has resigned from being warden!"));
}
public IView PASS_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "has resigned from being warden!" };
}

public IView NewWarden(CCSPlayerController player)
{
return new SimpleView(writer =>
writer.Line(Prefix, player, "is now the warden!"));
}
public IView NEW_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "is now the warden!" };
}

public IView CurrentWarden(CCSPlayerController? player)
{
if (player is not null)
return new SimpleView(writer =>
writer.Line(Prefix, "The current warden is", player));
return new SimpleView(writer =>
writer.Line(Prefix, "There is currently no warden!"));
}
}
public IView CURRENT_WARDEN(CCSPlayerController? player)
{
if (player is not null)
return new SimpleView { PREFIX, "The current warden is", player };
else
return new SimpleView { PREFIX, "There is currently no warden!" };
}
}
70 changes: 70 additions & 0 deletions mod/Jailbreak.Logs/Listeners/LogDamageListeners.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;

using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;

namespace Jailbreak.Logs.Listeners;

public class LogDamageListeners : IPluginBehavior
{
private readonly IRichLogService _logs;

public LogDamageListeners(IRichLogService logs)
{
_logs = logs;
}



[GameEventHandler]
public HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsReal())
return HookResult.Continue;
var grenade = @event.Weapon;

_logs.Append(_logs.Player(player), $"threw a {grenade}");

return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsReal())
return HookResult.Continue;
var attacker = @event.Attacker;

bool isWorld = attacker == null || !attacker.IsReal();
int health = @event.DmgHealth;

if (isWorld)
{
if (health > 0)
{
_logs.Append($"The world hurt", _logs.Player(player), $"for {health} damage");
}
else
{
_logs.Append("The world killed", _logs.Player(player));
}
}
else
{
if (health > 0)
{
_logs.Append( _logs.Player(attacker), "hurt", _logs.Player(player), $"for {health} damage");

Check warning on line 60 in mod/Jailbreak.Logs/Listeners/LogDamageListeners.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'playerController' in 'FormatObject IRichLogService.Player(CCSPlayerController playerController)'.

Check warning on line 60 in mod/Jailbreak.Logs/Listeners/LogDamageListeners.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'playerController' in 'FormatObject IRichLogService.Player(CCSPlayerController playerController)'.
}
else
{
_logs.Append(_logs.Player(attacker!), "killed", _logs.Player(player));
}
}

return HookResult.Continue;
}
}
Loading

0 comments on commit a05d743

Please sign in to comment.