master
Dorian HODIN 2 years ago
parent 1bac56becf
commit 6a4f2db396

Binary file not shown.

@ -1,14 +1,11 @@
<CascadingBlazoredModal>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<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>
</CascadingBlazoredModal>

@ -0,0 +1,50 @@
<CascadingValue Value="@this">
<div class="container">
<div class="row">
<div class="col-6">
<div>Available items:</div>
<div>
<div class="css-grid">
@foreach (var item in Items)
{
<CraftingItem Item="item" NoDrop="true" />
}
</div>
</div>
</div>
<div class="col-6">
<div>Recipe</div>
<div>
<div class="css-recipe">
<CraftingItem Index="0" />
<CraftingItem Index="1" />
<CraftingItem Index="2" />
<CraftingItem Index="3" />
<CraftingItem Index="4" />
<CraftingItem Index="5" />
<CraftingItem Index="6" />
<CraftingItem Index="7" />
<CraftingItem Index="8" />
</div>
</div>
<div>Result</div>
<div>
<CraftingItem Item="RecipeResult" />
</div>
</div>
<div class="col-12">
<div>Actions</div>
<div class="actions" id="actions">
</div>
</div>
</div>
</div>
</CascadingValue>

@ -0,0 +1,80 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using ProjetBlazor.Models;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
namespace ProjetBlazor.Components
{
public partial class Crafting
{
private Item _recipeResult;
public Crafting()
{
Actions = new ObservableCollection<CraftingAction>();
Actions.CollectionChanged += OnActionsCollectionChanged;
this.RecipeItems = new List<Item> { null, null, null, null, null, null, null, null, null };
}
public ObservableCollection<CraftingAction> Actions { get; set; }
public Item CurrentDragItem { get; set; }
[Parameter]
public List<Item> Items { get; set; }
public List<Item> RecipeItems { get; set; }
public Item RecipeResult
{
get => this._recipeResult;
set
{
if (this._recipeResult == value)
{
return;
}
this._recipeResult = value;
this.StateHasChanged();
}
}
[Parameter]
public List<CraftingRecipe> Recipes { get; set; }
/// <summary>
/// Gets or sets the java script runtime.
/// </summary>
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
public void CheckRecipe()
{
RecipeResult = null;
// Get the current model
var currentModel = string.Join("|", this.RecipeItems.Select(s => s != null ? s.Name : string.Empty));
this.Actions.Add(new CraftingAction { Action = $"Items : {currentModel}" });
foreach (var craftingRecipe in Recipes)
{
// Get the recipe model
var recipeModel = string.Join("|", craftingRecipe.Have.SelectMany(s => s));
this.Actions.Add(new CraftingAction { Action = $"Recipe model : {recipeModel}" });
if (currentModel == recipeModel)
{
RecipeResult = craftingRecipe.Give;
}
}
}
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
}
}

@ -0,0 +1,19 @@
.css-grid {
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
display: grid;
width: 286px;
}
.css-recipe {
grid-template-columns: repeat(3,minmax(0,1fr));
gap: 10px;
display: grid;
width: 212px;
}
.actions {
border: 1px solid black;
height: 250px;
overflow: scroll;
}

@ -0,0 +1,16 @@
window.Crafting =
{
AddActions: function (data) {
data.forEach(element => {
var div = document.createElement('div');
div.innerHTML = 'Action: ' + element.action + ' - Index: ' + element.index;
if (element.item) {
div.innerHTML += ' - Item Name: ' + element.item.name;
}
document.getElementById('actions').appendChild(div);
});
}
}

@ -6,7 +6,7 @@ namespace ProjetBlazor.Components
{
public string Action { get; set; }
public int Index { get; set; }
public Item Item { get; set; }
public Item? Item { get; set; }
}
}

@ -1,9 +0,0 @@
namespace ProjetBlazor.Models
{
public class Cake
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Cost { get; set; }
}
}

@ -1,18 +0,0 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}

@ -1,48 +0,0 @@
@page "/fetchdata"
<PageTitle>Weather forecast</PageTitle>
@using ProjetBlazor.Data
@inject WeatherForecastService ForecastService
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from a service.</p>
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
}

@ -1,5 +1,6 @@
@using System.Globalization
@using Blazorise
@using Components
@page "/"
@ -14,21 +15,6 @@ Welcome to your new app.
<p>
<b>CurrentCulture</b>: @CultureInfo.CurrentCulture
</p>
<Card>
<CardHeader>
<div class="card-header">
My Templated Component
</div>
</CardHeader>
<CardBody>
<div class="card-body">
<h5>Welcome To Template Component</h5>
</div>
</CardBody>
<CardFooter>
<div class="card-footer text-muted">
Click Here
</div>
</CardFooter>
</Card>
<div>
<Crafting Items="Items" Recipes="Recipes" />
</div>

@ -1,14 +1,32 @@
using ProjetBlazor.Models;
using Microsoft.AspNetCore.Components;
using ProjetBlazor.Components;
using ProjetBlazor.Models;
using ProjetBlazor.Services;
namespace ProjetBlazor.Pages
{
public partial class Index
{
private Cake CakeItem = new Cake()
[Inject]
public IDataService DataService { get; set; }
public List<Item> Items { get; set; } = new List<Item>();
private List<CraftingRecipe> Recipes { get; set; } = new List<CraftingRecipe>();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
base.OnAfterRenderAsync(firstRender);
if (!firstRender)
{
Id = 1,
Name = "Black Forest",
Cost = 50
};
return;
}
Items = await DataService.List(0, await DataService.Count());
Recipes = await DataService.GetRecipes();
StateHasChanged();
}
}
}

@ -30,6 +30,7 @@
<script src="_framework/blazor.server.js"></script>
<script src="_content/Blazored.Modal/blazored.modal.js"></script>
<script src="Components/Crafting.razor.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">

@ -1,5 +1,6 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components;
using ProjetBlazor.Components;
using ProjetBlazor.Factories;
using ProjetBlazor.Models;
@ -172,5 +173,24 @@ namespace ProjetBlazor.Services
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
public Task<List<CraftingRecipe>> GetRecipes()
{
var items = new List<CraftingRecipe>
{
new CraftingRecipe
{
Give = new Item { DisplayName = "Diamond", Name = "diamond" },
Have = new List<List<string>>
{
new List<string> { "dirt", "dirt", "dirt" },
new List<string> { "dirt", null, "dirt" },
new List<string> { "dirt", "dirt", "dirt" }
}
}
};
return Task.FromResult(items);
}
}
}

@ -1,4 +1,5 @@
using ProjetBlazor.Models;
using ProjetBlazor.Components;
using ProjetBlazor.Models;
namespace ProjetBlazor.Services
{
@ -15,5 +16,7 @@ namespace ProjetBlazor.Services
Task Update(int id, ItemModel model);
Task Delete(int id);
Task<List<CraftingRecipe>> GetRecipes();
}
}

@ -1,23 +0,0 @@
@inherits LayoutComponentBase
<PageTitle>ProjetBlazor</PageTitle>
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
<div class="px-4">
<CultureSelector />
</div>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>

@ -1,70 +0,0 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row ::deep a, .top-row .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
}
.top-row a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row:not(.auth) {
display: none;
}
.top-row.auth {
justify-content: space-between;
}
.top-row a, .top-row .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}

@ -11,7 +11,7 @@
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="list">
<span class"oi oi-list-rich" aria-hidden="true"></span> List
<span class="oi oi-list-rich" aria-hidden="true"></span> List
</NavLink>
</div>
<div class="nav-item px-3">
@ -19,16 +19,6 @@
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</div>
</nav>
</div>

File diff suppressed because one or more lines are too long

@ -32,18 +32,10 @@ build_metadata.AdditionalFiles.CssScope =
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcQWRkLnJhem9y
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Pages/Counter.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcQ291bnRlci5yYXpvcg==
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Pages/Edit.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcRWRpdC5yYXpvcg==
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Pages/FetchData.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcRmV0Y2hEYXRhLnJhem9y
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Pages/Index.razor]
build_metadata.AdditionalFiles.TargetPath = UGFnZXNcSW5kZXgucmF6b3I=
build_metadata.AdditionalFiles.CssScope =
@ -64,14 +56,14 @@ build_metadata.AdditionalFiles.CssScope =
build_metadata.AdditionalFiles.TargetPath = X0ltcG9ydHMucmF6b3I=
build_metadata.AdditionalFiles.CssScope =
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Components/Crafting.razor]
build_metadata.AdditionalFiles.TargetPath = Q29tcG9uZW50c1xDcmFmdGluZy5yYXpvcg==
build_metadata.AdditionalFiles.CssScope = b-c5pe2f0rgk
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Components/CraftingItem.razor]
build_metadata.AdditionalFiles.TargetPath = Q29tcG9uZW50c1xDcmFmdGluZ0l0ZW0ucmF6b3I=
build_metadata.AdditionalFiles.CssScope = b-au53a972a0
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Shared/MainLayout.razor]
build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXE1haW5MYXlvdXQucmF6b3I=
build_metadata.AdditionalFiles.CssScope = b-6fq4tjte4h
[C:/Users/Dorian/Documents/Blazor/Code/ProjetBlazor/Shared/NavMenu.razor]
build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXE5hdk1lbnUucmF6b3I=
build_metadata.AdditionalFiles.CssScope = b-kggv4tdhwh

@ -1 +1 @@
dd8b7458651039b989a936360e40d856d9c6a3af
a6db260dd09fce3e1910e4b0025973704e2c951f

@ -89,3 +89,5 @@ C:\Users\Dorian\Documents\Blazor\Code\ProjetBlazor\bin\Debug\net6.0\fr-FR\Projet
C:\Users\Dorian\Documents\Blazor\Code\ProjetBlazor\obj\Debug\net6.0\ProjetBlazor.Resources.Pages.List.fr-FR.resources
C:\Users\Dorian\Documents\Blazor\Code\ProjetBlazor\obj\Debug\net6.0\ProjetBlazor.csproj.GenerateResource.cache
C:\Users\Dorian\Documents\Blazor\Code\ProjetBlazor\obj\Debug\net6.0\fr-FR\ProjetBlazor.resources.dll
C:\Users\Dorian\Documents\Blazor\Code\ProjetBlazor\obj\Debug\net6.0\scopedcss\Components\Crafting.razor.rz.scp.css
C:\Users\Dorian\Documents\Blazor\Code\ProjetBlazor\obj\Debug\net6.0\scopedcss\Components\CraftingItem.razor.rz.scp.css

File diff suppressed because one or more lines are too long

@ -0,0 +1,19 @@
.css-grid[b-c5pe2f0rgk] {
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
display: grid;
width: 286px;
}
.css-recipe[b-c5pe2f0rgk] {
grid-template-columns: repeat(3,minmax(0,1fr));
gap: 10px;
display: grid;
width: 212px;
}
.actions[b-c5pe2f0rgk] {
border: 1px solid black;
height: 250px;
overflow: scroll;
}

@ -0,0 +1,6 @@
.item[b-au53a972a0] {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}

@ -1,5 +1,32 @@
@import '_content/Blazored.Modal/Blazored.Modal.bundle.scp.css';
/* _content/ProjetBlazor/Components/Crafting.razor.rz.scp.css */
.css-grid[b-c5pe2f0rgk] {
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
display: grid;
width: 286px;
}
.css-recipe[b-c5pe2f0rgk] {
grid-template-columns: repeat(3,minmax(0,1fr));
gap: 10px;
display: grid;
width: 212px;
}
.actions[b-c5pe2f0rgk] {
border: 1px solid black;
height: 250px;
overflow: scroll;
}
/* _content/ProjetBlazor/Components/CraftingItem.razor.rz.scp.css */
.item[b-au53a972a0] {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}
/* _content/ProjetBlazor/Shared/MainLayout.razor.rz.scp.css */
.page[b-6fq4tjte4h] {
position: relative;

@ -1,3 +1,30 @@
/* _content/ProjetBlazor/Components/Crafting.razor.rz.scp.css */
.css-grid[b-c5pe2f0rgk] {
grid-template-columns: repeat(4,minmax(0,1fr));
gap: 10px;
display: grid;
width: 286px;
}
.css-recipe[b-c5pe2f0rgk] {
grid-template-columns: repeat(3,minmax(0,1fr));
gap: 10px;
display: grid;
width: 212px;
}
.actions[b-c5pe2f0rgk] {
border: 1px solid black;
height: 250px;
overflow: scroll;
}
/* _content/ProjetBlazor/Components/CraftingItem.razor.rz.scp.css */
.item[b-au53a972a0] {
width: 64px;
height: 64px;
border: 1px solid;
overflow: hidden;
}
/* _content/ProjetBlazor/Shared/MainLayout.razor.rz.scp.css */
.page[b-6fq4tjte4h] {
position: relative;

@ -1,6 +1,6 @@
{
"Version": 1,
"Hash": "dLxZrm9JhkQrHpfVnOEzTPN/Um+szn29UlCvlC1crJE=",
"Hash": "a/XDG19R4UMCyCt38hxsXXwEOf4lm79LhUAWYOunxH4=",
"Source": "ProjetBlazor",
"BasePath": "_content/ProjetBlazor",
"Mode": "Default",
@ -713,6 +713,23 @@
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "C:\\Users\\Dorian\\.nuget\\packages\\blazorise\\1.1.3.1\\staticwebassets\\vendors\\Pickr.js"
},
{
"Identity": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\ProjetBlazor\\Components\\Crafting.razor.js",
"SourceId": "ProjetBlazor",
"SourceType": "Discovered",
"ContentRoot": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\ProjetBlazor\\",
"BasePath": "_content/ProjetBlazor",
"RelativePath": "Components/Crafting.razor.js",
"AssetKind": "All",
"AssetMode": "All",
"AssetRole": "Primary",
"RelatedAsset": "",
"AssetTraitName": "",
"AssetTraitValue": "",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "Components\\Crafting.razor.js"
},
{
"Identity": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\ProjetBlazor\\obj\\Debug\\net6.0\\scopedcss\\bundle\\ProjetBlazor.styles.css",
"SourceId": "ProjetBlazor",

File diff suppressed because one or more lines are too long

@ -1,5 +1,9 @@
{
"Files": [
{
"Id": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\ProjetBlazor\\Components\\Crafting.razor.js",
"PackagePath": "staticwebassets\\Components\\Crafting.razor.js"
},
{
"Id": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\ProjetBlazor\\obj\\Debug\\net6.0\\scopedcss\\projectbundle\\ProjetBlazor.bundle.scp.css",
"PackagePath": "staticwebassets\\ProjetBlazor.bundle.scp.css"

@ -1,5 +1,21 @@
<Project>
<ItemGroup>
<StaticWebAsset Include="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\staticwebassets\Components\Crafting.razor.js))">
<SourceType>Package</SourceType>
<SourceId>ProjetBlazor</SourceId>
<ContentRoot>$(MSBuildThisFileDirectory)..\staticwebassets\</ContentRoot>
<BasePath>_content/ProjetBlazor</BasePath>
<RelativePath>Components/Crafting.razor.js</RelativePath>
<AssetKind>All</AssetKind>
<AssetMode>All</AssetMode>
<AssetRole>Primary</AssetRole>
<RelatedAsset></RelatedAsset>
<AssetTraitName></AssetTraitName>
<AssetTraitValue></AssetTraitValue>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<OriginalItemSpec>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\staticwebassets\Components\Crafting.razor.js))</OriginalItemSpec>
</StaticWebAsset>
<StaticWebAsset Include="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\staticwebassets\css\bootstrap\bootstrap.min.css))">
<SourceType>Package</SourceType>
<SourceId>ProjetBlazor</SourceId>

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Loading…
Cancel
Save