Skip to content

Commit

Permalink
Rewrote rich-text tags to be much much better
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Feb 25, 2024
1 parent ac5b72a commit 7b4140f
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 203 deletions.
64 changes: 64 additions & 0 deletions SU.LorePage/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;

namespace SU.LorePage;

Expand All @@ -15,4 +16,67 @@ public static string GetCurrentDate()
{
return DateTime.Now.AddYears(200).ToString("yyyy-MM-dd");
}

/// <summary>
/// Parses the content of a lore page. This includes replacing
/// - [date] with the current date
/// - [color=colorName] content [/color] with <span class="color-colorName"> content </span>
/// - [block=color] content [/block] with <p class="block block-color"> content </p>
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string ParseContent(string content)
{
// First we escape any HTML tags
content = content.Replace("<", "&lt;");
content = content.Replace(">", "&gt;");

// Then we replace the placeholders
content = content.Replace("[date]", GetCurrentDate());
content = ParseColor(content);
content = ParseBlock(content);
return content;
}

private static string ParseColor(string content)
{
int startIndex;
while ((startIndex = content.IndexOf("[color=")) != -1)
{
var endIndex = content.IndexOf("]", startIndex);
if (endIndex == -1)
break;

var colorName = content.Substring(startIndex + 7, endIndex - startIndex - 7);
var closingTagIndex = content.IndexOf("[/color]", endIndex);
if (closingTagIndex == -1)
break;

var replacement = $"<span class=\"color-{colorName}\">{content.Substring(endIndex + 1, closingTagIndex - endIndex - 1)}</span>";
content = content.Remove(startIndex, closingTagIndex - startIndex + 8).Insert(startIndex, replacement);
}

return content;
}

private static string ParseBlock(string content)
{
int startIndex;
while ((startIndex = content.IndexOf("[block=")) != -1)
{
var endIndex = content.IndexOf("]", startIndex);
if (endIndex == -1)
break;

var colorName = content.Substring(startIndex + 7, endIndex - startIndex - 7);
var closingTagIndex = content.IndexOf("[/block]", endIndex);
if (closingTagIndex == -1)
break;

var replacement = $"<p class=\"block block-{colorName}\">{content.Substring(endIndex + 1, closingTagIndex - endIndex - 1)}</p>";
content = content.Remove(startIndex, closingTagIndex - startIndex + 8).Insert(startIndex, replacement);
}

return content;
}
}
37 changes: 18 additions & 19 deletions SU.LorePage/Layout/Screen.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@using Markdig
@using Markdig.Syntax
@using System.Diagnostics
@inject HttpClient Http
@inject IJSRuntime JsRuntime
@inject NavigationManager NavigationManager
Expand Down Expand Up @@ -207,11 +208,22 @@
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
var document = Markdown.Parse(responseString, pipeline);
responseString = document.Descendants<CodeBlock>().First().Lines.ToString();

// Some tags modify the content in a way where we need to replace them before rendering.
responseString = responseString.Replace("[date]", Helpers.GetCurrentDate());


var stopWatch = new Stopwatch();
stopWatch.Start();
var content = responseString.ToCharArray();
try
{
content = Helpers.ParseContent(responseString).ToCharArray();
}
catch (Exception e)
{
Console.Error.WriteLine($"Failed to parse content: {e.Message}");
IsLoading = false;
return;
}
stopWatch.Stop();
Console.WriteLine($"Parsing content took: {stopWatch.ElapsedMilliseconds}ms");
var contentString = "";
var currentSpeed = DefaultTextSpeed;
var functionsToCall = new List<string>();
Expand Down Expand Up @@ -293,21 +305,6 @@
{
await Console.Error.WriteLineAsync($"Invalid delay: {tagValue}");
}

break;
case "color":
contentString += $"<span class=\"color-{tagValue}\">";
break;
case "block":
if (tagValue == "none")
{
contentString += "<span></span>";
}
else
{
contentString += $"<span class=\"block block-{tagValue}\"></span>";
}

break;
case "play":
await JsRuntime.InvokeVoidAsync("playAudio", tagValue, Id);
Expand All @@ -319,6 +316,8 @@
break;

default:
i -= tag.Length; // Go back to the start of the tag.
contentString += c;
await Console.Error.WriteLineAsync($"Unknown tag: {tagName}");
break;
}
Expand Down
10 changes: 5 additions & 5 deletions SU.LorePage/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5167",
"applicationUrl": "http://localhost:7501",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7187;http://localhost:5167",
"applicationUrl": "https://localhost:7500;http://localhost:7501",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
2 changes: 1 addition & 1 deletion SU.LorePage/wwwroot/Resources/Company/Syndicate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
TITLE=Company/The Syndicate
BACKLINK=true
```
[color=red]{DATA UNAVAILABLE - CONTACT ENGINEERING}[color=white]
[color=red]{DATA UNAVAILABLE - CONTACT ENGINEERING}[/color]
```
15 changes: 7 additions & 8 deletions SU.LorePage/wwwroot/Resources/Listing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TITLE=File listing
BACKLINK=false
```
Available files:[color=sys][speed=0]
[color=white]Available files:[color=sys][speed=0]
--- BEGIN ---[speed=default]
[button=Person/Nathan.md;Person/Nathan Wilkerson]
Expand All @@ -14,12 +14,11 @@ Available files:[color=sys][speed=0]
[speed=0]--- END ---[speed=default]
[block=warning][color=warn]Warning:[color=white]
[block=warning]These files are classified.
[block=warning]Misuse is punishable by law and
[block=warning]may be prosecuted as treason.
[block=none]
[/color][color=warn][block=warning]Warning:
These files are classified. Misuse is punishable by law and may be prosecuted as treason.
[/block][/color]
[color=sys][speed=0]-----------------------------------------------------[speed=default]
[color=white]Access level: L3[color=sys]
[speed=0]-----------------------------------------------------[speed=default]
[/color]Access level: L3[color=sys]
[speed=0]-----------------------------------------------------[speed=default][/color]
[/color]
```
17 changes: 9 additions & 8 deletions SU.LorePage/wwwroot/Resources/Materials/BlueSpaceCrystals.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@
TITLE=File: Materials/Blue Space Crystals
BACKLINK=true
```
[color=sys]Summary[color=white]
[color=white]
[color=sys]Summary[/color]
Blue Space Crystals, often reffered to as BSC, are a rare and valuable resource used in the production of AI cores and other electronic components.
The crystals act as a catalyst in blue space reactions, allowing teleportation and communication over vast distances.
Found exclusively in the deepest reaches of space, these crystals are a key resource for NanoTrasen and are heavily guarded.
[color=sys]Discovery and Origin[color=white]
[color=sys]Discovery and Origin[/color]
The discovery of BSCs dates back to the early 22nd century, when a NanoTrasen research vessel stumbled upon a small asteroid field in the outer reaches of the galaxy.
The asteroid field was found to be rich in BSCs, and the discovery was kept a secret for years, as NanoTrasen worked to secure the area and establish mining operations.
The exact origin of BSCs is unkown. Some theories propose that they are remnants of ancient cosmic events, perhaps formed during the violent birth of galaxies or the cataclysmic death of massive stars.
Others suggest a more exotic origin, hinting at the involvement of phenomena such as wormholes or the mysterious blue space itself.
[color=sys]Physical Characteristics[color=white]
[color=sys]Physical Characteristics[/color]
BSCs are small, translucent crystals, with a distinct blue hue. They are highly resistant to damage and decay, and are known to emit a faint blue glow when exposed to certain types of radiation.
Under certain lighting conditions, they exhibit a subtle iridescence, casting shimmering reflections reminiscent of distant nebulae.
No matter the form or size, BSCs are exceptionally hard and resilient, surpassing even the most durable of known materials.
They are also highly resistant to temperature extremes, and are known to withstand the harsh conditions of space without any signs of degradation.
[color=sys]Unique Properties and Uses[color=white]
[color=sys]Unique Properties and Uses[/color]
1. Energy Amplification: BSCs are known to amplify and stabilize energy fields, making them ideal for use in the construction electronic components.
2. Navigational Aids: BSCs are sensitive to cosmic energy fields and can be used as a navigational aid in deep space, allowing for more accurate and efficient travel.
3. Blue Space Communication: BSCs are a key component in the construction of blue space communication arrays, allowing for near-instantaneous communication over vast distances.
[color=sys]Security and Handling[color=white]
[color=sys]Security and Handling[/color]
Due to their rarity and value, BSCs are heavily guarded and are only handled by trained professionals.
The mining and processing of BSCs is a highly regulated process, and is only carried out by NanoTrasen personnel with the highest security clearance.
Expand All @@ -39,9 +40,9 @@ Due to the unique properties of BSCs, they are also highly sought after by vario
For more information, please refer to documents below.
[button=Company/Syndicate.md;The Syndicate]
[color=red]{MISSING ACCESS}[color=white]
[color=red]{MISSING ACCESS}[color=white]
[color=red]{MISSING ACCESS}[/color]
[color=red]{MISSING ACCESS}[/color]
[color=sys][speed=0]------------- End of file -------------[speed=default][color=white]
[color=sys][speed=0]------------- End of file -------------[speed=default][/color][/color]
```
42 changes: 22 additions & 20 deletions SU.LorePage/wwwroot/Resources/Person/Nathan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,73 @@
TITLE=File: Person/NATHAN-WILKERSON
BACKLINK=true
```
[color=white]
Personal Information
[color=sys][speed=0]--- BEGIN ---[speed=default]
[color=white]Legal Name: Nathan Wilkerson
[color=sys][speed=0]--- BEGIN ---[speed=default][/color]
Legal Name: Nathan Wilkerson
Designation: NT-L-9259::928
Current Age: 26
Species: Slime
Sex / Gender: Male / Male
Height: 1.83 meters
Place of Birth: [button=Places/NT-L-9259.md;NT-L-9259]
[color=sys][speed=0]--- END ---[speed=default]
[color=sys][speed=0]--- END ---[speed=default][/color]
Employment
[color=sys][speed=0]--- BEGIN ---[speed=default][color=white]
[color=sys][speed=0]--- BEGIN ---[speed=default][/color]
Current Employer: NanoTrasen
Current Rank: Chief Engineer
Former Ranks: Engineer at NT-L-9259
Research Subject at NT-L-9259
Current Assignment: Sector Umbra
[color=sys][speed=0]--- END ---[speed=default]
[color=sys][speed=0]--- END ---[speed=default][/color]
Description
[color=sys][speed=0]--- BEGIN ---[speed=default]
[color=white]NT-L-9259::928, known legally as Nathan Wilkerson, is a Slime created on NT-L-9259 for research purposes.
[color=sys][speed=0]--- BEGIN ---[speed=default][/color]
NT-L-9259::928, known legally as Nathan Wilkerson, is a Slime created on NT-L-9259 for research purposes.
He was granted citizenship and employment at NanoTrasen after showing great learning capabilities and loyalty to the company.
But because of [color=red]{MISSING ACCESS}[color=white], Nathan must be monitored at all times.
But because of [color=red]{MISSING ACCESS}[/color], Nathan must be monitored at all times.
For more information, please refer to the incident reports below.
[color=sys][speed=0]--- END ---[speed=default][color=white]
[color=sys][speed=0]--- END ---[speed=default][/color]
Incident Reports
[color=sys][speed=0]--- BEGIN ---[speed=default][color=white]
[color=info]Incident 23-02-2224:[color=white]
[color=sys][speed=0]--- BEGIN ---[speed=default][/color]
[color=info]Incident 23-02-2224:[/color]
Subject: Nathan Wilkerson
Location: Sector Umbra
Description: Inspection notes for shift: [button=Person/Nathan/Mildred.23.2.2024.md;View]
Conclusion: N / A
[color=info]Incident 27-01-2224:[color=white]
[color=info]Incident 27-01-2224:[/color]
Subject: Nathan Wilkerson
Location: Sector Umbra
Description: Subject failed to properly oversee the construction of a Singularity Engine, resulting in a containment breach.
Conclusion: Nanobots were deployed to contain the breach. No further action was taken.
[color=info]Incident 27-01-2224:[color=white]
[color=info]Incident 27-01-2224:[/color]
Subject: Nathan Wilkerson
Location: Sector Umbra
Description: Subject set up a Tesla Engine incorrectly, resulting in total loss of the station. ERT was called in to deal with the great loss of life.
Conclusion: Subject was reprimanded and forced to 30 hours of engineering classes. No further action was taken.
[color=info]Incident 3-11-2223:[color=white]
[color=info]Incident 3-11-2223:[/color]
Subject: Nathan Wilkerson
Location: Sector Salamander
Description: Subject was found to be in possession of a large amount of illegal substances. Subject was detained and questioned.
Conclusion: Subject was released after questioning. No further action was taken.
[color=info]Incident 12-08-2223:[color=white]
[color=info]Incident 12-08-2223:[/color]
Subject: Nathan Wilkerson
Location: [color=red]{MISSING ACCESS}[color=white]
Description: [color=red]{MISSING ACCESS}[color=white]
Conclusion: [color=red]{MISSING ACCESS}[color=white]. No further action was taken.
Location: [color=red]{MISSING ACCESS}[/color]
Description: [color=red]{MISSING ACCESS}[/color]
Conclusion: [color=red]{MISSING ACCESS}[/color]. No further action was taken.
[color=sys][speed=0]--- END ---[speed=default][color=white]
[color=sys][speed=0]--- END ---[speed=default][/color]
[color=sys][speed=0]------------- End of file -------------[speed=default]
[color=sys][speed=0]------------- End of file -------------[speed=default][/color]
[/color]
```
11 changes: 7 additions & 4 deletions SU.LorePage/wwwroot/Resources/Person/Nathan/Mildred.23.2.2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
TITLE=File: Person/NATHAN-WILKERSON/Incident-23-02-2224
BACKLINK=true
```
Incident 23-02-2224
[color=white]
[color=info]Incident 23-02-2224[/color]
By: Commander Mildred
Location: Sector Umbra
For: Nathan Wilkerson (NT-L-9259::928)
NOTE: This is a file scan. The formatting will be off.
[block=info][color=info]NOTE:[/color] This is a file scan. The formatting will be off.[/block]
[color=sys][speed=0]--- BEGIN FILE SCAN ---[speed=default]
[color=sys][speed=0]--- BEGIN FILE SCAN ---[speed=default][/color]
Commander Mildred Inspection Notes.
Expand Down Expand Up @@ -42,5 +43,7 @@ Service
Security
- Messy, as was the case with most departments aside from Cargo and Science. Noteably, howver, Perma was in an uninhabitable state.
[color=sys][speed=0]--- END ---[speed=default]
[color=sys][speed=0]--- END ---[speed=default][/color]
[color=sys][speed=0]------------- End of file -------------[speed=default][/color][/color]
```
Loading

0 comments on commit 7b4140f

Please sign in to comment.