Skip to content

Commit

Permalink
Initial commit of Blazor based Kill Team Name Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
DevJonny committed Jun 25, 2019
0 parents commit 874c379
Show file tree
Hide file tree
Showing 25 changed files with 1,186 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/.DS_STORE
.idea/*
**/bin/*
**/obj/*
5 changes: 5 additions & 0 deletions KillTeamNameGenerator.Web/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Router AppAssembly="typeof(Program).Assembly">
<NotFoundContent>
<p>Sorry, there's nothing at this address.</p>
</NotFoundContent>
</Router>
16 changes: 16 additions & 0 deletions KillTeamNameGenerator.Web/KillTeamNameGenerator.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KTNameGenerator.Core" Version="1.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview6.19307.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview6.19307.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview6.19307.2" PrivateAssets="all" />
</ItemGroup>

</Project>
101 changes: 101 additions & 0 deletions KillTeamNameGenerator.Web/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
@page "/"
@using System
@using System.Collections.Generic
@using System.Linq
@using System.Threading.Tasks
@using KTNameGenerator.Core
@using KTNameGenerator.Core.Data
@using KTNameGenerator.Core.Model
@using Microsoft.AspNetCore.Components

<h1>Kill Team Name Generator</h1>

<select onchange="@SelectFaction">
@foreach (var faction in Factions)
{
<option value="@faction.Type">@faction.Name</option>
}
</select>

@if (HasSubFactions)
{
<select onchange="@SelectSubFaction">
@foreach (var subFaction in SelectedFaction.SubFactions ?? new SubFaction[0])
{
<option value="@subFaction.Type">@subFaction.Name</option>
}
</select>
}

<select onchange="@SetQuantity">
@foreach (var quantity in Enumerable.Range(1, 20))
{
<option value="@quantity">@quantity</option>
}
</select>

<button onclick="@GenerateNames">Generate @Quantity names</button>

@foreach (var name in Names)
{
<div>@name</div>
}

@functions
{

private IEnumerable<Faction> Factions => FactionData.Factions;
private Faction SelectedFaction { get; set; }
private SubFaction SelectedSubFaction { get; set; }
private string[] Forenames { get; set; } = new string[0];
private string[] Surnames { get; set; } = new string[0];
private int Quantity { get; set; } = 1;
private List<string> Names { get; set; } = new List<string>();

bool HasSubFactions => SelectedFaction.HasSubFactions;

protected override async Task OnInitAsync()
{
SelectedFaction = KillTeam.FactionByType(FactionType.AdeptusAstartes);
SelectedSubFaction = SelectedFaction.SubFactionByType(SubFactionType.Ultramarines);

await base.OnInitAsync();
}

public void SelectFaction(UIChangeEventArgs e)
{
var factionType = (FactionType)Enum.Parse(typeof(FactionType), e.Value.ToString());

SelectedFaction = KillTeam.FactionByType(factionType);

if (HasSubFactions) return;

Forenames = SelectedFaction.Forenames;
Surnames = SelectedFaction.Surnames;
}

public void SelectSubFaction(UIChangeEventArgs e)
{
var subFactionType = (SubFactionType) Enum.Parse(typeof(SubFactionType), e.Value.ToString());

SelectedSubFaction = SelectedFaction.SubFactionByType(subFactionType);

Forenames = SelectedSubFaction.Forenames;
Surnames = SelectedSubFaction.Surnames;
}

public void SetQuantity(UIChangeEventArgs e)
{
Quantity = int.Parse(e.Value.ToString());
}

public void GenerateNames()
{
Names.Clear();

if (HasSubFactions)
Names.AddRange(SelectedFaction.GenerateNames(Quantity, SelectedSubFaction.Type));
else
Names.AddRange(SelectedFaction.GenerateNames(Quantity));
}
}
1 change: 1 addition & 0 deletions KillTeamNameGenerator.Web/Pages/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@layout MainLayout
16 changes: 16 additions & 0 deletions KillTeamNameGenerator.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Blazor.Hosting;

namespace KillTeamNameGenerator.Web
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
BlazorWebAssemblyHost.CreateDefaultBuilder()
.UseBlazorStartup<Startup>();
}
}
15 changes: 15 additions & 0 deletions KillTeamNameGenerator.Web/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@inherits LayoutComponentBase

<div class="sidebar">
<NavMenu />
</div>

<div class="main">
<div class="top-row px-4">
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
27 changes: 27 additions & 0 deletions KillTeamNameGenerator.Web/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">Kill Team Name Generator</a>
<button class="navbar-toggler" @onclick="@ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>

<div class="@NavMenuCssClass" @onclick="@ToggleNavMenu">
<ul class="nav flex-column">
<li class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
</ul>
</div>

@code {
bool collapseNavMenu = true;

string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
19 changes: 19 additions & 0 deletions KillTeamNameGenerator.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using KillTeamNameGenerator.Web.ViewModels;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace KillTeamNameGenerator.Web
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<INameGeneratorViewModel, NameGeneratorViewModel>();
}

public void Configure(IComponentsApplicationBuilder app)
{
app.AddComponent<App>("app");
}
}
}
35 changes: 35 additions & 0 deletions KillTeamNameGenerator.Web/ViewModels/NameGeneratorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using KTNameGenerator.Core;
using KTNameGenerator.Core.Data;
using KTNameGenerator.Core.Model;
using Microsoft.AspNetCore.Components;

namespace KillTeamNameGenerator.Web.ViewModels
{
public interface INameGeneratorViewModel
{
IEnumerable<Faction> Factions { get; }
Faction SelectedFaction { get; set; }
bool HasSubFactions { get; set; }

void SelectFaction(UIChangeEventArgs e);
}

public class NameGeneratorViewModel : INameGeneratorViewModel
{
public IEnumerable<Faction> Factions => FactionData.Factions;
public Faction SelectedFaction { get; set; }

public bool HasSubFactions { get; set; }

public void SelectFaction(UIChangeEventArgs e)
{
var factionType = (FactionType)Enum.Parse(typeof(FactionType), e.Value.ToString());

SelectedFaction = KillTeam.FactionByType(factionType);
HasSubFactions = SelectedFaction.HasSubFactions;
}
}
}
7 changes: 7 additions & 0 deletions KillTeamNameGenerator.Web/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Layouts
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.JSInterop
@using KillTeamNameGenerator.Web
@using KillTeamNameGenerator.Web.Shared

Large diffs are not rendered by default.

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions KillTeamNameGenerator.Web/wwwroot/css/open-iconic/FONT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
SIL OPEN FONT LICENSE Version 1.1

Copyright (c) 2014 Waybury

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
21 changes: 21 additions & 0 deletions KillTeamNameGenerator.Web/wwwroot/css/open-iconic/ICON-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Waybury

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading

0 comments on commit 874c379

Please sign in to comment.