-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TehGM/dev
- Loading branch information
Showing
27 changed files
with
624 additions
and
74 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
19 changes: 19 additions & 0 deletions
19
Randominator/Generators/BookTitle/BookTitleDependencyInjectionExtensions.cs
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,19 @@ | ||
using TehGM.Randominator.Generators.BookTitle; | ||
using TehGM.Randominator.Generators.BookTitle.Services; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class BookTitleDependencyInjectionExtensions | ||
{ | ||
public static IServiceCollection AddBookTitleGenerator(this IServiceCollection services, Action<BookTitleOptions> configureOptions = null) | ||
{ | ||
if (configureOptions != null) | ||
services.Configure(configureOptions); | ||
|
||
services.AddRandomizer(); | ||
services.AddTransient<IBookTitleGenerator, BookTitleGenerator>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
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,57 @@ | ||
namespace TehGM.Randominator.Generators.BookTitle.Services | ||
{ | ||
public class BookTitleGenerator : IBookTitleGenerator | ||
{ | ||
private readonly IOptionsMonitor<BookTitleOptions> _options; | ||
private readonly IRandomizer _random; | ||
private readonly ILogger _log; | ||
|
||
public BookTitleGenerator(IOptionsMonitor<BookTitleOptions> options, ILogger<BookTitleGenerator> log, IRandomizer randomizer) | ||
{ | ||
this._options = options; | ||
this._random = randomizer; | ||
this._log = log; | ||
} | ||
|
||
public string Generate() | ||
{ | ||
BookTitleOptions options = this._options.CurrentValue; | ||
ICollection<string> segments = new List<string>(3); | ||
//pick if it's A or An for the first word | ||
bool useAWordSet = _random.RollChance(0.5); // 50% chance to pick either list | ||
|
||
string article = useAWordSet ? "A" : "An"; | ||
string word1 = useAWordSet | ||
? this._random.GetRandomValue(options.AWordSet) | ||
: this._random.GetRandomValue(options.AnWordSet); | ||
|
||
//Second or third word | ||
string word2 = this._random.GetRandomValue(options.SecondThirdWordSet); | ||
string word3 = this._random.GetRandomValue(options.SecondThirdWordSet); | ||
|
||
//we probably don't want it to be the same one twice | ||
while (word2 == word3) | ||
word3 = this._random.GetRandomValue(options.SecondThirdWordSet); | ||
// combine it | ||
segments.Add($"{article} {this.CapitalizeSegment(word1)} of {this.CapitalizeSegment(word2)} and {this.CapitalizeSegment(word3)}"); | ||
return string.Join(' ', segments); | ||
} | ||
|
||
|
||
|
||
|
||
private string CapitalizeSegment(string value) | ||
{ | ||
string[] segmentParts = value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
for (int i = 0; i < segmentParts.Length; i++) | ||
{ | ||
if (string.IsNullOrWhiteSpace(segmentParts[i])) | ||
continue; | ||
char[] wordChars = segmentParts[i].ToLowerInvariant().ToCharArray(); | ||
wordChars[0] = char.ToUpperInvariant(wordChars[0]); | ||
segmentParts[i] = new string(wordChars); | ||
} | ||
return string.Join(' ', segmentParts); | ||
} | ||
} | ||
} |
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,43 @@ | ||
namespace TehGM.Randominator.Generators.BookTitle | ||
{ | ||
public class BookTitleOptions | ||
{ | ||
// List of words that follow "A" | ||
public ICollection<string> AWordSet { get; set; } = new string[] | ||
{ | ||
"Song", "Court", "Dream", "Whisper", "Memory", "Battle", | ||
"Shadow", "Curse", "Vision", "Blade", "King", "Story", | ||
"Legend", "Quest", "Kingdom", "Echo", "Fable", "Journey", | ||
"Saga", "Chronicle", "Hero", "Tale", "Legacy", "Prophecy", | ||
"Night", "Dawn", "Frost", "Glimmer", "Light", "Wanderer", | ||
"Bard", "Oath", "Dancer", "Heroine", "Beast", "Mystic", | ||
"Ballad", "House", "Child", "Queen", "Wraith", "Reaper", | ||
"Spark", "World", "Planet", "Plane", "Place", "Space" | ||
}; | ||
|
||
// List of words that follow "An" | ||
public ICollection<string> AnWordSet { get; set; } = new string[] | ||
{ | ||
"Echo", "Honor", "Empire", "Oath", "Adventure", "Allegory", | ||
"Invitation", "Eclipse", "Epic", "Artifact", | ||
"Oracle", "Endeavor", "Era", "Idyll", "Insight", "Infinity", | ||
"Anomaly", "Ambush", "Artifice", "Alliance", "Awakening", | ||
"Atmosphere", "Anthem", "Enigma", "Enlightenment", "Elysium", | ||
"Asylum", "Earth", | ||
}; | ||
|
||
// Shared word set for the second and third parts of the title | ||
public ICollection<string> SecondThirdWordSet { get; set; } = new string[] | ||
{ | ||
"Fire", "Ice", "Thorns", "Roses", "Dreams", "Storms", | ||
"Shadows", "Seas", "Stars", "Chains", "Tides", "Sands", | ||
"Winds", "Bones", "Mysteries", "Legends", "Whispers", "Secrets", | ||
"Embers", "Echoes", "Visions", "Fires", "Legacies", "Fables", | ||
"Fury", "Hopes", "Dusk", "Dawn", "Desires", "Frost", | ||
"Sorrow", "Nights", "Dangers", "Wonders", "Myths", | ||
"Havens", "Hues", "Pathways", "Fates", "Mirrors", | ||
"Blood", "Light", "Tempests", "Voices", "Vices", | ||
"Mirages", "Tales" | ||
}; | ||
} | ||
} |
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,7 @@ | ||
namespace TehGM.Randominator.Generators.BookTitle | ||
{ | ||
public interface IBookTitleGenerator | ||
{ | ||
string Generate(); | ||
} | ||
} |
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
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,46 @@ | ||
<div class="form-group input-group @this.CssClass"> | ||
@if (!string.IsNullOrEmpty(this.Label)) | ||
{ | ||
<FormInputPrepend CssClass="@this.LabelCssClass">@this.Label</FormInputPrepend> | ||
} | ||
|
||
<input id="@this.ID" type="checkbox" class="btn-check" autocomplete="off" value="@this.Value" checked="@this.Value" @onchange="this.OnClickAsync" disabled="@this.Disabled" /> | ||
<label class="btn @this.ToggleCssClass @this.CurrentToggleCssClass" for="@this.ID">@this.CurrentToggleText</label> | ||
</div> | ||
|
||
@code { | ||
[Parameter] | ||
public Guid ID { get; set; } = Guid.NewGuid(); | ||
[Parameter] | ||
public bool Disabled { get; set; } | ||
[Parameter] | ||
public string CssClass { get; set; } | ||
[Parameter] | ||
public string LabelCssClass { get; set; } | ||
[Parameter] | ||
public string ToggleCssClass { get; set; } | ||
[Parameter] | ||
public string Label { get; set; } | ||
[Parameter] | ||
public string OnText { get; set; } = "On"; | ||
[Parameter] | ||
public string OffText { get; set; } = "Off"; | ||
[Parameter] | ||
public string OnCssClass { get; set; } = "btn-success"; | ||
[Parameter] | ||
public string OffCssClass { get; set; } = "btn-danger"; | ||
|
||
private string CurrentToggleText => this.Value ? this.OnText : this.OffText; | ||
private string CurrentToggleCssClass => this.Value ? this.OnCssClass : this.OffCssClass; | ||
|
||
[Parameter] | ||
public bool Value { get; set; } | ||
[Parameter] | ||
public EventCallback<bool> ValueChanged { get; set; } | ||
|
||
private Task OnClickAsync() | ||
{ | ||
this.Value = !this.Value; | ||
return ValueChanged.InvokeAsync(this.Value); | ||
} | ||
} |
Oops, something went wrong.