diff --git a/src/CraftSharp/Components/Crafting.razor b/src/CraftSharp/Components/Crafting.razor new file mode 100644 index 0000000..378f220 --- /dev/null +++ b/src/CraftSharp/Components/Crafting.razor @@ -0,0 +1,52 @@ + + + + + + Available items: + + + + @foreach (var item in Items) + { + + } + + + + + + + + Recipe + + + + + + + + + + + + + + + + + Result + + + + + + + Actions + + + + + + + \ No newline at end of file diff --git a/src/CraftSharp/Components/Crafting.razor.cs b/src/CraftSharp/Components/Crafting.razor.cs new file mode 100644 index 0000000..3fc4f9a --- /dev/null +++ b/src/CraftSharp/Components/Crafting.razor.cs @@ -0,0 +1,83 @@ +using CraftSharp.Models; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace CraftSharp.Components +{ + public partial class Crafting + { + private Item _recipeResult; + + [CascadingParameter] + public Crafting Parent { get; set; } + + public Crafting() + { + Actions = new ObservableCollection(); + Actions.CollectionChanged += OnActionsCollectionChanged; + this.RecipeItems = new List { null, null, null, null, null, null, null, null, null }; + } + + public ObservableCollection Actions { get; set; } + public Item CurrentDragItem { get; set; } + + [Parameter] + public List Items { get; set; } + + public List RecipeItems { get; set; } + + public Item RecipeResult + { + get => this._recipeResult; + set + { + if (this._recipeResult == value) + { + return; + } + + this._recipeResult = value; + this.StateHasChanged(); + } + } + + [Parameter] + public List Recipes { get; set; } + + /// + /// Gets or sets the java script runtime. + /// + [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); + } + } +} diff --git a/src/CraftSharp/Components/Crafting.razor.css b/src/CraftSharp/Components/Crafting.razor.css new file mode 100644 index 0000000..1c0cb8b --- /dev/null +++ b/src/CraftSharp/Components/Crafting.razor.css @@ -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; +} diff --git a/src/CraftSharp/Components/Crafting.razor.js b/src/CraftSharp/Components/Crafting.razor.js new file mode 100644 index 0000000..3fcb76d --- /dev/null +++ b/src/CraftSharp/Components/Crafting.razor.js @@ -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); + }); + } +} \ No newline at end of file diff --git a/src/CraftSharp/Components/CraftingAction.cs b/src/CraftSharp/Components/CraftingAction.cs new file mode 100644 index 0000000..fd7294a --- /dev/null +++ b/src/CraftSharp/Components/CraftingAction.cs @@ -0,0 +1,11 @@ +using CraftSharp.Models; + +namespace CraftSharp.Components +{ + public class CraftingAction + { + public string Action { get; set; } + public int Index { get; set; } + public Item Item { get; set; } + } +} diff --git a/src/CraftSharp/Components/CraftingItem.razor b/src/CraftSharp/Components/CraftingItem.razor new file mode 100644 index 0000000..db4ca36 --- /dev/null +++ b/src/CraftSharp/Components/CraftingItem.razor @@ -0,0 +1,14 @@ + + + @if (Item != null) + { + @Item.DisplayName + } + \ No newline at end of file diff --git a/src/CraftSharp/Components/CraftingItem.razor.cs b/src/CraftSharp/Components/CraftingItem.razor.cs new file mode 100644 index 0000000..2087377 --- /dev/null +++ b/src/CraftSharp/Components/CraftingItem.razor.cs @@ -0,0 +1,66 @@ +using CraftSharp.Components; +using CraftSharp.Models; +using Microsoft.AspNetCore.Components; + +namespace Blazor.Components +{ + public partial class CraftingItem + { + [Parameter] + public int Index { get; set; } + + [Parameter] + public Item Item { get; set; } + + [Parameter] + public bool NoDrop { get; set; } + + [CascadingParameter] + public Crafting Parent { get; set; } + + internal void OnDragEnter() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new CraftingAction { Action = "Drag Enter", Item = this.Item, Index = this.Index }); + } + + internal void OnDragLeave() + { + if (NoDrop) + { + return; + } + + Parent.Actions.Add(new CraftingAction { Action = "Drag Leave", Item = this.Item, Index = this.Index }); + } + + internal void OnDrop() + { + if (NoDrop) + { + return; + } + + this.Item = Parent.CurrentDragItem; + Parent.RecipeItems[this.Index] = this.Item; + + Parent.Actions.Add(new CraftingAction { Action = "Drop", Item = this.Item, Index = this.Index }); + + // Check recipe + Parent.CheckRecipe(); + } + + private void OnDragStart() + { + Parent.CurrentDragItem = this.Item; + + Parent.Actions.Add(new CraftingAction { Action = "Drag Start", Item = this.Item, Index = this.Index }); + } + + + } +} diff --git a/src/CraftSharp/Components/CraftingItem.razor.css b/src/CraftSharp/Components/CraftingItem.razor.css new file mode 100644 index 0000000..d6f5ec3 --- /dev/null +++ b/src/CraftSharp/Components/CraftingItem.razor.css @@ -0,0 +1,6 @@ +.item { + width: 64px; + height: 64px; + border: 1px solid; + overflow: hidden; +} diff --git a/src/CraftSharp/Components/CraftingRecipe.cs b/src/CraftSharp/Components/CraftingRecipe.cs new file mode 100644 index 0000000..578b68d --- /dev/null +++ b/src/CraftSharp/Components/CraftingRecipe.cs @@ -0,0 +1,11 @@ +using CraftSharp.Models; + +namespace CraftSharp.Components +{ + public class CraftingRecipe + { + public Item Give { get; set; } + public List> Have { get; set; } + } + +} diff --git a/src/CraftSharp/CraftSharp - Backup (1).csproj b/src/CraftSharp/CraftSharp - Backup (1).csproj new file mode 100644 index 0000000..6fa0141 --- /dev/null +++ b/src/CraftSharp/CraftSharp - Backup (1).csproj @@ -0,0 +1,30 @@ + + + + net6.0 + enable + enable + 41eb41f8-57fb-408a-baab-7328f468e749 + Windows + . + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CraftSharp/CraftSharp - Backup.csproj b/src/CraftSharp/CraftSharp - Backup.csproj new file mode 100644 index 0000000..44789d7 --- /dev/null +++ b/src/CraftSharp/CraftSharp - Backup.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + 41eb41f8-57fb-408a-baab-7328f468e749 + Windows + . + + + + + + + + + + Always + + + + diff --git a/src/CraftSharp/Models/Armor.cs b/src/CraftSharp/Models/Armor.cs deleted file mode 100644 index 506411d..0000000 --- a/src/CraftSharp/Models/Armor.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CraftSharp.Models -{ - public abstract class Armor : Item - { - public int Toughness { get; set; } - } -} diff --git a/src/CraftSharp/Models/Block.cs b/src/CraftSharp/Models/Block.cs deleted file mode 100644 index 22afcfd..0000000 --- a/src/CraftSharp/Models/Block.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CraftSharp.Models -{ - public class Block : Item - { - } -} diff --git a/src/CraftSharp/Models/Boots.cs b/src/CraftSharp/Models/Boots.cs deleted file mode 100644 index 24d1948..0000000 --- a/src/CraftSharp/Models/Boots.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CraftSharp.Models -{ - public class Leggings : Armor - { - } -} diff --git a/src/CraftSharp/Models/Chestplate.cs b/src/CraftSharp/Models/Chestplate.cs deleted file mode 100644 index 9ad13e5..0000000 --- a/src/CraftSharp/Models/Chestplate.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CraftSharp.Models -{ - public class Chestplate : Armor - { - } -} diff --git a/src/CraftSharp/Models/Helmet.cs b/src/CraftSharp/Models/Helmet.cs deleted file mode 100644 index 1ab1e4d..0000000 --- a/src/CraftSharp/Models/Helmet.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CraftSharp.Models -{ - public class Helmet : Armor - { - } -} diff --git a/src/CraftSharp/Models/Item.cs b/src/CraftSharp/Models/Item.cs index 868610f..dd642cd 100644 --- a/src/CraftSharp/Models/Item.cs +++ b/src/CraftSharp/Models/Item.cs @@ -1,10 +1,11 @@ namespace CraftSharp.Models { - public abstract class Item + public class Item { public int Id { get; set; } public string Name { get; set; } public int StackSize { get; set; } + public string ImageBase64 { get; set; } public Rarities Rarity { get; set; } } } diff --git a/src/CraftSharp/Models/ItemModel.cs b/src/CraftSharp/Models/ItemModel.cs new file mode 100644 index 0000000..1bfd9c2 --- /dev/null +++ b/src/CraftSharp/Models/ItemModel.cs @@ -0,0 +1,40 @@ +using System.ComponentModel.DataAnnotations; + + +namespace CraftSharp.Models +{ + public class ItemModel + { + public int Id { get; set; } + [Required] + [StringLength(50, ErrorMessage = "Le nom affiché ne doit pas dépasser 50 caractères.")] + public string DisplayName { get; set; } + + [Required] + [StringLength(50, ErrorMessage = "Le nom ne doit pas dépasser 50 caractères.")] + [RegularExpression(@"^[a-z''-'\s]{1,40}$", ErrorMessage = "Seulement les caractères en minuscule sont acceptées.")] + public string Name { get; set; } + + [Required] + [Range(1, 64)] + public int StackSize { get; set; } + + [Required] + [Range(1, 125)] + public int MaxDurability { get; set; } + + public List EnchantCategories { get; set; } + + public List RepairWith { get; set; } + + [Required] + [Range(typeof(bool), "true", "true", ErrorMessage = "Vous devez accepter les conditions.")] + public bool AcceptCondition { get; set; } + + [Required(ErrorMessage = "L'image de l'item est obligatoire !")] + public byte[] ImageContent { get; set; } + + public string ImageBase64 { get; set; } + + } +} diff --git a/src/CraftSharp/Models/Leggings.cs b/src/CraftSharp/Models/Leggings.cs deleted file mode 100644 index 8a1c758..0000000 --- a/src/CraftSharp/Models/Leggings.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CraftSharp.Models -{ - public class Boots : Armor - { - } -} diff --git a/src/CraftSharp/Models/Tool.cs b/src/CraftSharp/Models/Tool.cs deleted file mode 100644 index 31cd287..0000000 --- a/src/CraftSharp/Models/Tool.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CraftSharp.Models -{ - public class Tool : Item - { - public int Damages { get; set; } - } -} diff --git a/src/CraftSharp/Services/IDataService.cs b/src/CraftSharp/Services/IDataService.cs new file mode 100644 index 0000000..5956a53 --- /dev/null +++ b/src/CraftSharp/Services/IDataService.cs @@ -0,0 +1,21 @@ +using CraftSharp.Components; +using CraftSharp.Models; + +namespace Blazor.Services +{ + public interface IDataService + { + Task Add(ItemModel model); + + Task Count(); + + Task> List(int currentPage, int pageSize); + Task GetById(int id); + + Task Update(int id, ItemModel model); + Task Delete(int id); + + Task> GetRecipes(); + } +} +