Skip to content

Commit

Permalink
Get ones and fives score (#4)
Browse files Browse the repository at this point in the history
* Change name of solution to Greedy

* WIP. Route and mapping working for start game

* Add WebApi and Service for:
 /games     -> StartGame
 /players   -> JoinPlayer
 /diceRolls -> RollDice
 /diceKeeps -> KeepDice

* Add WebApi and Service for:
 /games     -> StartGame
 /players   -> JoinPlayer
 /diceRolls -> RollDice
 /diceKeeps -> KeepDice

* KeepShould
 ResetDiceInTableCenterWhenAllDiceHaveBeenKept

 PassShould
  ResetDiceInTableCenter

* KeepShould
 AddToTurnScore (for a Straight)

* Refactor
 Remove Rolls collection, depend instead on the table center
 Add static class to version events
 Add V2.DiceKept and V2.DiceRolled to explicitly mutate the game stage to and from rolling

PassShould
 NotAllowPlayerToPassWithoutRolling

RollShould
 NotAllowPlayerToRollTwiceBeforeKeepingSomeDice

* Refactor
 Filter out error events when validating whether a player can pass

 Discards domain exceptions so that the command service persists the error events

* Add web tests

* Refactor:
  Creates folders src and tests
  Adds src and test projects for frontend
  Extracts methods in GameApiShould.AllowPlayerToRollDice

* Add Dice component

* Adds github workflow

* WIP unit testing blazor component

* Refactor:
  Decouple DieTests.RotatesCorrectly from the random spins numbers.

* Refactor:
   Includes both api and spa in the Api project
   Animate both new dice and dice whose value has changed
   Changes primitive int to enum to set the value of the die

* Refactor:
   Extracted class RotationCalculator
CalculateForShould.ReturnTheCorrectAnglesFor

* WIP
   Fix drag glitch

Refactor
   Drag functionality into separate components Drag and DragSurface

* Fix api location in github actions

* Remove Die.razor exclusion

* Add or update the Azure App Service build and deployment workflow config

* Fix project location

* Specify project to publish

* Adds rolling functionality

* Refactor spin calculation in RotationCalculator.cs

Adds easing to dice approaching border

* WIP

Add mudblazor
Add alternative drag behaviour with mudblazor

* Cover Spa project

* Cover Spa project

* Delete unused components

* Cover Spa project

* Adds logging for item dropped
  • Loading branch information
david-acm authored Dec 7, 2023
1 parent bd24614 commit 7ae803f
Show file tree
Hide file tree
Showing 68 changed files with 2,217 additions and 377 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/getonesandfivesscore_greedy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - greedy-dev

on:
push:
branches:
- GetOnesAndFivesScore
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.x'
include-prerelease: true

- name: Build with dotnet
run: dotnet build Greedy.WebApi --configuration Release

- name: dotnet publish
run: dotnet publish Greedy.WebApi -c Release -o ${{env.DOTNET_ROOT}}/myapp

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: .net-app

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'greedy-dev'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_5C1211EBD84340F9B0160AD75648B0AE }}
package: .
14 changes: 14 additions & 0 deletions Greedy.Spa/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView DefaultLayout="@typeof(MainLayout)"
RouteData="@routeData"/>
<FocusOnNavigate RouteData="@routeData"
Selector="h1"/>
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
10 changes: 10 additions & 0 deletions Greedy.Spa/Components/AppNavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<MudNavMenu>
<MudNavLink Href="/"
Match="NavLinkMatch.All">
Play
</MudNavLink>
<MudNavLink Href="/about"
Match="NavLinkMatch.All">
About
</MudNavLink>
</MudNavMenu>
23 changes: 23 additions & 0 deletions Greedy.Spa/Components/DiceValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Ardalis.SmartEnum;

namespace Greedy.Spa.Components;

public sealed class DiceValue : SmartEnum<DiceValue, int> {
public static readonly DiceValue None = new("n", 0);
public static readonly DiceValue One = new("⚀", 1);

public static readonly DiceValue Two = new("⚁", 2);

public static readonly DiceValue Three = new("⚂", 3);

public static readonly DiceValue Four = new("⚃", 4);

public static readonly DiceValue Five = new("⚄", 5);

public static readonly DiceValue Six = new("⚅", 6);

private DiceValue(string name, int value) : base(name,
value)
{
}
}
84 changes: 84 additions & 0 deletions Greedy.Spa/Components/Die.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@page "/die"

<PageTitle>Die</PageTitle>

<div class="die-container @Class"
id="@_id"
@onpointerenter="MouseEnter"
@onpointerleave="MouseLeave">
<div class="die">
<div class="one side">
<span class="pip"></span>
</div>
<div class="side two">
<span class="pip"></span>
<span class="pip"></span>
</div>
<div class="side three">
<span class="pip"></span>
<span class="pip"></span>
<span class="pip"></span>
</div>
<div class="four side">
<div class="column">
<span class="pip"></span>
<span class="pip"></span>
</div>
<div class="column">
<span class="pip"></span>
<span class="pip"></span>
</div>
</div>
<div class="five side">
<div class="column">
<span class="pip"></span>
<span class="pip"></span>
</div>
<div class="column">
<span class="pip"></span>
</div>
<div class="column">
<span class="pip"></span>
<span class="pip"></span>
</div>
</div>
<div class="side six">

<div class="column">
<span class="pip"></span>
<span class="pip"></span>
<span class="pip"></span>
</div>

<div class="column">
<span class="pip"></span>
<span class="pip"></span>
<span class="pip"></span>
</div>
</div>
</div>

<div class="die solid">
<div class="one side"></div>
<div class="side two"></div>
<div class="side three"></div>
<div class="four side"></div>
<div class="five side"></div>
<div class="side six"></div>
</div>

<style>
:root {
--die-size: @(Size)px;
}
@($"#{_id}.die-container .die") {
transform-style: preserve-3d;
transform:
rotateX(@($"{AngleFor('x')}deg"))
rotateY(@($"{AngleFor('y')}deg"))
rotateZ(@($"{AngleFor('z')}deg"))
scale3d(@_scale, @_scale, @_scale);
}
</style>

</div>
97 changes: 97 additions & 0 deletions Greedy.Spa/Components/Die.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

namespace Greedy.Spa.Components;

public partial class Die {
private string _id = new string(Guid.NewGuid().ToString().Where(c => !char.IsDigit(c)).ToArray());
private DiceValue _number = DiceValue.None;
private (int, int, int) _rotation;
private double _scale = 1;

[Parameter]
public DiceValue DiceValue { get; set; }

[Parameter]
public int Size { get; set; } = 50;

[Parameter]
public string? Class { get; set; }

[Parameter]
public bool IsDragging { get; set; }

[Inject]
public ILogger<Die> Logger { get; set; }

[Inject]
public IRotationCalculator _rotationCalculator { get; set; }

private double AngleFor(char a) => a switch
{
'x' => _rotation.Item1,
'y' => _rotation.Item2,
'z' => _rotation.Item3,
_ => 0
};

protected override async Task OnInitializedAsync()
{
if (IsDragging)
RotateToValue();
await base.OnInitializedAsync();
}

protected override Task OnParametersSetAsync()
{
if (_number != DiceValue.None && _number != DiceValue) RotateToValue();

return base.OnParametersSetAsync();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender) await DelayedRotateToValue();
// RotateToValue();
await base.OnAfterRenderAsync(firstRender);
}

private async Task DelayedRotateToValue() =>
_ = new Timer(async _ =>
{
await InvokeAsync(async () =>
{
RotateToValue();
StateHasChanged();
});
}, null, 0, -1);

private void RotateToValue()
{
_number = DiceValue;
var rotation = _rotationCalculator.CalculateFor(_number, !IsDragging);
SetRotationTo(rotation);
}

private void SetRotationTo((int, int, int) rotation) =>
_rotation = rotation;

private void MouseLeave(MouseEventArgs e)
{
(int x, int y, int z) = _rotation;
SetRotationTo((x, y - 10, z - 10));
Scale(1);
StateHasChanged();
}

private void MouseEnter(MouseEventArgs e)
{
(int x, int y, int z) = _rotation;
SetRotationTo((x, y + 10, z + 10));
Scale(1.4);
StateHasChanged();
}

private void Scale(double scale) =>
_scale = scale;
}
Loading

0 comments on commit 7ae803f

Please sign in to comment.