forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ion law visuals (space-wizards#22908)
- Loading branch information
1 parent
ba4b03f
commit 681f9a2
Showing
7 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
using Robust.Client.UserInterface.RichText; | ||
using Robust.Shared.Timing; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.UserInterface.RichText; | ||
|
||
/// <summary> | ||
/// Adds a specified length of random characters that scramble at a set rate. | ||
/// </summary> | ||
[UsedImplicitly] | ||
public sealed class ScrambleTag : IMarkupTag | ||
{ | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
|
||
public string Name => "scramble"; | ||
|
||
public string TextBefore(MarkupNode node) | ||
{ | ||
if (!node.Attributes.TryGetValue("rate", out var rateParam) || | ||
!rateParam.TryGetLong(out var rate) || | ||
!node.Attributes.TryGetValue("length", out var lengthParam) || | ||
!lengthParam.TryGetLong(out var length) || | ||
!node.Attributes.TryGetValue("chars", out var charsParam) || | ||
!charsParam.TryGetString(out var chars)) | ||
return string.Empty; | ||
|
||
var seed = (int) (_timing.CurTime.TotalMilliseconds / rate); | ||
var rand = new Random(seed + node.GetHashCode()); | ||
var charOptions = chars.ToCharArray(); | ||
var sb = new StringBuilder(); | ||
for (var i = 0; i < length; i++) | ||
{ | ||
var index = rand.Next() % charOptions.Length; | ||
sb.Append(charOptions[index]); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters