Update the drag and drop, still have an error i cant resolve
continuous-integration/drone/push Build is failing Details

Projet
dorian.hodin 2 years ago
parent 0ac6fce12b
commit fe7edad43e

Binary file not shown.

@ -1,9 +1,6 @@
{
"ExpandedNodes": [
"",
"\\Code",
"\\Code\\ProjetBlazor\\Properties"
""
],
"SelectedNode": "\\Code\\BlazorApp.sln",
"PreviewInSolutionExplorer": false
}

Binary file not shown.

Binary file not shown.

@ -9,9 +9,9 @@ build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = Minecraft.Crafting.Api
build_property.RootNamespace = Minecraft.Crafting.Api
build_property.ProjectDir = C:\Users\Dorian\Documents\Blazor\Code\Minecraft.Crafting.Api\
build_property.ProjectDir = C:\Users\doria\source\repos\ProjetBlazor\Code\Minecraft.Crafting.Api\
build_property.RazorLangVersion = 6.0
build_property.SupportLocalizedComponentNames =
build_property.GenerateRazorMetadataSourceChecksumAttributes =
build_property.MSBuildProjectDirectory = C:\Users\Dorian\Documents\Blazor\Code\Minecraft.Crafting.Api
build_property.MSBuildProjectDirectory = C:\Users\doria\source\repos\ProjetBlazor\Code\Minecraft.Crafting.Api
build_property._RazorSourceGeneratorDebug =

@ -1 +1 @@
d3262fc31f365d3ae2c93faff7841ae2ba475b3c
c265d9e9f5fcd34df9ebfe876a1036461508ba75

@ -1 +1 @@
dc37e66f47ae43cee4b2425074d9be0523a82cf5
77c4b4e2e70764d1c091287e1e15be24402e097e

File diff suppressed because one or more lines are too long

@ -1,20 +1,20 @@
{
"format": 1,
"restore": {
"C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj": {}
"C:\\Users\\doria\\source\\repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj": {}
},
"projects": {
"C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj": {
"C:\\Users\\doria\\source\\repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"projectUniqueName": "C:\\Users\\doria\\source\\repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"projectName": "Minecraft.Crafting.Api",
"projectPath": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"packagesPath": "C:\\Users\\Dorian\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\obj\\",
"projectPath": "C:\\Users\\doria\\source\\repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"packagesPath": "C:\\Users\\doria\\.nuget\\packages\\",
"outputPath": "C:\\Users\\doria\\source\\repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\Dorian\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Users\\doria\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
@ -68,7 +68,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.100\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.101\\RuntimeIdentifierGraph.json"
}
}
}

@ -5,18 +5,18 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Dorian\.nuget\packages\</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\doria\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.4.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Dorian\.nuget\packages\" />
<SourceRoot Include="C:\Users\doria\.nuget\packages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.extensions.apidescription.server\3.0.0\build\Microsoft.Extensions.ApiDescription.Server.props" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.apidescription.server\3.0.0\build\Microsoft.Extensions.ApiDescription.Server.props')" />
<Import Project="$(NuGetPackageRoot)swashbuckle.aspnetcore\6.2.3\build\Swashbuckle.AspNetCore.props" Condition="Exists('$(NuGetPackageRoot)swashbuckle.aspnetcore\6.2.3\build\Swashbuckle.AspNetCore.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_Extensions_ApiDescription_Server Condition=" '$(PkgMicrosoft_Extensions_ApiDescription_Server)' == '' ">C:\Users\Dorian\.nuget\packages\microsoft.extensions.apidescription.server\3.0.0</PkgMicrosoft_Extensions_ApiDescription_Server>
<PkgMicrosoft_Extensions_ApiDescription_Server Condition=" '$(PkgMicrosoft_Extensions_ApiDescription_Server)' == '' ">C:\Users\doria\.nuget\packages\microsoft.extensions.apidescription.server\3.0.0</PkgMicrosoft_Extensions_ApiDescription_Server>
</PropertyGroup>
</Project>

@ -9,9 +9,9 @@ build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = Minecraft.Crafting.Api
build_property.RootNamespace = Minecraft.Crafting.Api
build_property.ProjectDir = C:\Users\Dorian\Documents\Blazor\Code\Minecraft.Crafting.Api\
build_property.ProjectDir = C:\Users\doria\source\repos\ProjetBlazor\Code\Minecraft.Crafting.Api\
build_property.RazorLangVersion = 6.0
build_property.SupportLocalizedComponentNames =
build_property.GenerateRazorMetadataSourceChecksumAttributes =
build_property.MSBuildProjectDirectory = C:\Users\Dorian\Documents\Blazor\Code\Minecraft.Crafting.Api
build_property.MSBuildProjectDirectory = C:\Users\doria\source\repos\ProjetBlazor\Code\Minecraft.Crafting.Api
build_property._RazorSourceGeneratorDebug =

@ -265,19 +265,19 @@
]
},
"packageFolders": {
"C:\\Users\\Dorian\\.nuget\\packages\\": {}
"C:\\Users\\doria\\.nuget\\packages\\": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"projectUniqueName": "C:\\Users\\doria\\Source\\Repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"projectName": "Minecraft.Crafting.Api",
"projectPath": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"packagesPath": "C:\\Users\\Dorian\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\obj\\",
"projectPath": "C:\\Users\\doria\\Source\\Repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"packagesPath": "C:\\Users\\doria\\.nuget\\packages\\",
"outputPath": "C:\\Users\\doria\\Source\\Repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\Dorian\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Users\\doria\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
@ -331,7 +331,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.100\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.101\\RuntimeIdentifierGraph.json"
}
}
}

@ -1,16 +1,16 @@
{
"version": 2,
"dgSpecHash": "jinAgCxMwIRFrEI5kUkq9j6tS7O5nXy9V+Kp7wTtk5NHeBQgrSke3YfqxLx1xBbwcLvq/9mU+lZrtGwH8VHPNw==",
"dgSpecHash": "owyzLgO4yVYTIR2lDapMCcrdgkz7FivgvZaVNyumorGhLyhR/dS7DZp43unAO4vZ12llc9JTCb8saKy9SRwiqg==",
"success": true,
"projectFilePath": "C:\\Users\\Dorian\\Documents\\Blazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"projectFilePath": "C:\\Users\\doria\\source\\repos\\ProjetBlazor\\Code\\Minecraft.Crafting.Api\\Minecraft.Crafting.Api.csproj",
"expectedPackageFiles": [
"C:\\Users\\Dorian\\.nuget\\packages\\microsoft.extensions.apidescription.server\\3.0.0\\microsoft.extensions.apidescription.server.3.0.0.nupkg.sha512",
"C:\\Users\\Dorian\\.nuget\\packages\\microsoft.openapi\\1.2.3\\microsoft.openapi.1.2.3.nupkg.sha512",
"C:\\Users\\Dorian\\.nuget\\packages\\newtonsoft.json\\13.0.1\\newtonsoft.json.13.0.1.nupkg.sha512",
"C:\\Users\\Dorian\\.nuget\\packages\\swashbuckle.aspnetcore\\6.2.3\\swashbuckle.aspnetcore.6.2.3.nupkg.sha512",
"C:\\Users\\Dorian\\.nuget\\packages\\swashbuckle.aspnetcore.swagger\\6.2.3\\swashbuckle.aspnetcore.swagger.6.2.3.nupkg.sha512",
"C:\\Users\\Dorian\\.nuget\\packages\\swashbuckle.aspnetcore.swaggergen\\6.2.3\\swashbuckle.aspnetcore.swaggergen.6.2.3.nupkg.sha512",
"C:\\Users\\Dorian\\.nuget\\packages\\swashbuckle.aspnetcore.swaggerui\\6.2.3\\swashbuckle.aspnetcore.swaggerui.6.2.3.nupkg.sha512"
"C:\\Users\\doria\\.nuget\\packages\\microsoft.extensions.apidescription.server\\3.0.0\\microsoft.extensions.apidescription.server.3.0.0.nupkg.sha512",
"C:\\Users\\doria\\.nuget\\packages\\microsoft.openapi\\1.2.3\\microsoft.openapi.1.2.3.nupkg.sha512",
"C:\\Users\\doria\\.nuget\\packages\\newtonsoft.json\\13.0.1\\newtonsoft.json.13.0.1.nupkg.sha512",
"C:\\Users\\doria\\.nuget\\packages\\swashbuckle.aspnetcore\\6.2.3\\swashbuckle.aspnetcore.6.2.3.nupkg.sha512",
"C:\\Users\\doria\\.nuget\\packages\\swashbuckle.aspnetcore.swagger\\6.2.3\\swashbuckle.aspnetcore.swagger.6.2.3.nupkg.sha512",
"C:\\Users\\doria\\.nuget\\packages\\swashbuckle.aspnetcore.swaggergen\\6.2.3\\swashbuckle.aspnetcore.swaggergen.6.2.3.nupkg.sha512",
"C:\\Users\\doria\\.nuget\\packages\\swashbuckle.aspnetcore.swaggerui\\6.2.3\\swashbuckle.aspnetcore.swaggerui.6.2.3.nupkg.sha512"
],
"logs": []
}

@ -1,22 +1,42 @@
<CascadingValue Value="@this">
@using ProjetBlazor.Models;
<CascadingValue Value="@this">
<div><h1>@Localizer["Inventory"]</h1></div>
<div class="css-recipe">
@for (int i = 0; i < Models.InventoryList.Size; i++)
{
<ItemInventory items="@inventory.inventoryItems[i]" Index="@i"/>
<InventoryItem Index=i Item=@this.RecipeItems[i] />
}
</div>
<div class="css-grid">
<InventoryList/>
</div>
<div class="css-grid">
<div><h1>@Localizer["List"]</h1></div>
<DataGrid TItem="Item"
Data="@Items"
TotalItems="8"
PageSize="8"
Filterable
ShowPager
Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="@Localizer["Image"]" Filterable="false" Sortable="false">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 50px; max-width: 150px" />
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="@Localizer["Nom"]" />
<DataGridColumn TItem="Item" Field="@nameof(Item.StackSize)" Caption="@Localizer["Stack"]" Filterable="false" Sortable="false" />
</DataGrid>
</div>
<div class="actions" id="actions">
<div>@Localizer["Actions"]</div>
</div>
</CascadingValue>
</CascadingValue>

@ -1,64 +1,81 @@
using ProjetBlazor.Models;
using ProjetBlazor.Pages;
using Blazored.LocalStorage;
using Blazorise;
using Blazorise.DataGrid;
using Blazorise;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Microsoft.JSInterop;
using ProjetBlazor.Components;
using ProjetBlazor.Models;
using ProjetBlazor.Services;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Text.Json;
using ProjetBlazor.Components;
using Microsoft.Extensions.Localization;
using ProjetBlazor.Models;
namespace ProjetBlazor.Components
{
partial class Inventory
public partial class Inventory
{
public Models.InventoryList inventory = new Models.InventoryList();
public Models.InventoryItem CurrentDragItem { get; set; }
public ObservableCollection<InventoryAction> Actions { get; set; }
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
public IStringLocalizer<Inventory> Localizer { get; set; }
[Inject]
public IStringLocalizer<InventoryList> Localizer { get; set; }
public IDataService DataService { get; set; }
private int totalItem;
[Inject]
public ILocalStorageService LocalStorage { get; set; }
public Item CurrentDragItem { get; set; }
public int CurrentDragItemIndex { get; set; }
[Inject]
public HttpClient Http { get; set; }
private bool choiceSort = false;
public List<Item> RecipeItems { get; set; }
[Parameter]
public List<Item> Items { get; set; } = new List<Item>();
public ObservableCollection<InventoryAction> Actions { get; set; }
[Inject]
internal IJSRuntime JavaScriptRuntime { get; set; }
/// <summary>
/// Constructor
/// </summary>
public Inventory()
{
Actions = new ObservableCollection<InventoryAction>();
Actions.CollectionChanged += OnActionsCollectionChanged;
}
string fileName = "Inventory.json";
string jsonString = File.ReadAllText(fileName);
this.RecipeItems = JsonSerializer.Deserialize<List<Item>>(jsonString)!;
}
/// <summary>
/// method that call the javascript
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
}
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
}
/// <summary>
/// method to sort by name or id simultaneoustly
/// </summary>
private void SortByame()
{
if (e.CancellationToken.IsCancellationRequested)
if (choiceSort)
{
return;
Items.Sort((x, y) => x.Id.CompareTo(y.Id));
choiceSort = !choiceSort;
Actions.Add(new InventoryAction { Action = "Sort by Id" });
}
var response = await LocalStorage.GetItemAsync<String>("list");
if (!e.CancellationToken.IsCancellationRequested)
else
{
inventory = JsonSerializer.Deserialize<Models.InventoryList>(response);
Items.Sort((x, y) => x.Name.CompareTo(y.Name));
choiceSort = !choiceSort;
Actions.Add(new InventoryAction { Action = "Sort by Name" });
}
}

@ -4,7 +4,7 @@
data.forEach(element => {
var div = document.createElement('div');
div.innerHTML = 'Action: ' + element.action + ' - Index: ' + element.index;
div.innerHTML = 'Aaction: ' + element.action + ' - Index: ' + element.index;
if (element.item) {
div.innerHTML += ' - Item Name: ' + element.item.name;

@ -4,13 +4,9 @@ namespace ProjetBlazor.Components
{
public class InventoryAction
{
public InventoryAction(String ac, int num,Item objet) {
Action = ac;
Index = num;
Item = objet;
}
public string Action { get; set; }
public int Index { get; set; }
public Item Item { get; set; }
}
}

@ -1,25 +0,0 @@
@using ProjetBlazor.Models
<CascadingValue Value="@this">
<div class="css-grid">
<div><h1>@Localizer["List"]</h1></div>
<DataGrid TItem="Item"
Data="@items"
TotalItems="8"
PageSize="8"
Filterable
ShowPager
Responsive>
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="@Localizer["Image"]" Filterable="false" Sortable="false">
<DisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.ImageBase64))
{
<img src="data:image/png;base64, @(context.ImageBase64)" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="min-width: 50px; max-width: 150px"/>
}
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="@Localizer["Nom"]"/>
<DataGridColumn TItem="Item" Field="@nameof(Item.StackSize)" Caption="@Localizer["Stack"]" Filterable="false" Sortable="false"/>
</DataGrid>
</div>
</CascadingValue>

@ -1,43 +0,0 @@
using ProjetBlazor.Models;
using ProjetBlazor.Pages;
using ProjetBlazor.Services;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace ProjetBlazor.Components
{
public partial class InventoryList
{
private List<Item> items;
private int totalItem;
[Inject]
public IDataService DataService { get; set; }
[Inject]
public IWebHostEnvironment WebHostEnvironment { get; set;}
[Inject]
public NavigationManager NavigationManager { get; set; }
[CascadingParameter]
public IModalService Modal { get; set; }
[Inject]
public IStringLocalizer<InventoryList> Localizer { get; set; }
[CascadingParameter]
public Inventory Parent { get; set; }
protected override async Task OnInitializedAsync()
{
items = await DataService.GetAll();
totalItem = await DataService.Count();
await base.OnInitializedAsync();
}
}
}

@ -1,21 +0,0 @@
@using ProjetBlazor.Models;
<div
class="item"
ondragover="event.preventDefault();"
draggable="true"
@ondragstart="@OnDragStart"
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
@if (!string.IsNullOrWhiteSpace(Item.ImageBase64))
{
<img src="data:image/png;base64, @(Item.ImageBase64)" class="img-thumbnail" title="Item.DisplayName" alt="Item.DisplayName" style="width: 60px" />
}
else
{
<img src="images/background.png" class="img-thumbnail" title="Item.DisplayName" alt="Item.DisplayName" style="width: 60px"/>
}
</div>

@ -1,43 +0,0 @@
using ProjetBlazor.Models;
using Microsoft.AspNetCore.Components;
using ProjetBlazor.Components;
namespace ProjetBlazor.Components
{
public partial class InventoryListImage
{
[Parameter]
public Item Item { get; set; }
[CascadingParameter]
public Inventory Parent { get; set; }
internal void OnDragEnter()
{
Parent.Actions.Add(new InventoryAction("On drag enter", Item.Id, Item));
return;
}
internal void OnDragLeave()
{
Parent.Actions.Add(new InventoryAction("On drag leave", Item.Id, Item));
return;
}
internal void OnDrop()
{
Parent.Actions.Add(new InventoryAction("On drop", Item.Id, Item));
Parent.CurrentDragItem = null;
return;
}
private void OnDragStart()
{
Parent.CurrentDragItem = new InventoryItem(Item);
Parent.Actions.Add(new InventoryAction("On drag start", Item.Id, Item));
return;
}
}
}

@ -1,29 +1,24 @@
<div ondragover="event.preventDefault();"
draggable=""
@ondragstart="@OnDragStartAsync"
@ondrop="@OnDropAsync"
@using ProjetBlazor.Components;
<div class="item"
ondragover="event.preventDefault();"
draggable="@(Item == null)"
@ondragstart="@OnDragStart"
@ondrop="@OnDrop"
@ondragenter="@OnDragEnter"
@ondragleave="@OnDragLeave">
@if (Items != null)
@ondragleave="@OnDragLeave"
@ondragend="@OnDragEnd">
@if (Item != null)
{
@if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64))
{
<div class="item">
<img src="data:image/png;base64, @(Items.item.ImageBase64)" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="width: 50px; height: 50px" />
<span class="number-item">@Items.Stack</span>
</div>
}
else
{
<div class="item">
<img src="images/background.png" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="width: 100px; height: 100px"/>
<span class="number-item">@Items.Stack</span>
</div>
}
}
else
{
<div class="item">
<div style="position:relative">
<img src="data:image/png;base64, @(Item.ImageBase64)" title="@Item.DisplayName" alt="@Item.DisplayName" style="min-width: 64px; max-width: 64px" />
@if (Item.Num > 0)
{
<div class="number">@(
Item.Num
)</div>
}
</div>
}
</div>

@ -1,131 +1,142 @@
using ProjetBlazor.Models;
using Blazored.LocalStorage;
using Blazorise.Extensions;
using Microsoft.AspNetCore.Components;
using ProjetBlazor.Components;
using System.Text.Json;
namespace ProjetBlazor.Components
{
public partial class ItemInventory
public partial class InventoryItem
{
[Parameter]
public bool NoDrop { get; set; }
public int Index { get; set; }
[Parameter]
public InventoryItem Items { get; set; }
public Item Item { get; set; }
[Parameter]
public int Index { get; set; }
public bool NoDrop { get; set; }
[CascadingParameter]
public Inventory Parent { get; set; }
[Inject]
public ILocalStorageService LocalStorage { get; set; }
public async Task OnDragStartAsync()
/// <summary>
/// method call when a drag enter a slot and send an action
/// </summary>
internal void OnDragEnter()
{
if (this.Items == null)
if (NoDrop)
{
Parent.CurrentDragItem = null;
return;
}
Parent.CurrentDragItem = this.Items;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
this.Items = null;
Parent.inventory.inventoryItems[this.Index] = null ;
await LocalStorage.RemoveItemAsync("data" + this.Index);
await LocalStorage.RemoveItemAsync("stack" + this.Index);
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this.Item, Index = this.Index });
}
public async Task OnDropAsync()
/// <summary>
/// method call when a drag leave a slot and send an action
/// </summary>
internal void OnDragLeave()
{
if (Parent.CurrentDragItem == null)
if (NoDrop)
{
return;
}
if(this.Items == null)
{
this.Items = Parent.CurrentDragItem;
Parent.CurrentDragItem = null;
await LocalStorage.SetItemAsync<Item>("data" + this.Index, this.Items.item);
await LocalStorage.SetItemAsync<int>("stack" + this.Index, this.Items.Stack);
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
return;
}
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
}
/// <summary>
/// method that manage a drop and send an action
/// </summary>
internal void OnDrop()
{
if (Parent.CurrentDragItem.item.Id != this.Items.item.Id)
if (NoDrop == true || Parent.CurrentDragItem == null)
{
this.Items = Parent.CurrentDragItem;
Parent.CurrentDragItem = null;
await LocalStorage.SetItemAsync<Item>("data" + this.Index, this.Items.item);
await LocalStorage.SetItemAsync<int>("stack" + this.Index, this.Items.Stack);
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
return;
}
else
if (this.Item == null)
{
int total = Parent.CurrentDragItem.Stack + this.Items.Stack;
if (total > this.Items.item.StackSize)
Parent.RecipeItems[this.Index] = this.Item;
Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index });
if (Parent.CurrentDragItemIndex != -1)
{
this.Items.Stack = this.Items.item.StackSize;
Parent.CurrentDragItem = null;
await LocalStorage.SetItemAsync<Item>("data" + this.Index, this.Items.item);
await LocalStorage.SetItemAsync<int>("stack" + this.Index, this.Items.Stack);
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
return;
Parent.RecipeItems[Parent.CurrentDragItemIndex] = null;
Parent.Actions.Add(new InventoryAction { Action = "Moove", Item = this.Item, Index = this.Index });
}
else
}
else if (this.Item.Id == Parent.CurrentDragItem.Id)
{
if (this.Item.StackSize > this.Item.Num)
{
this.Items.Stack = total;
Parent.CurrentDragItem = null;
await LocalStorage.SetItemAsync<Item>("data" + this.Index, this.Items.item);
await LocalStorage.SetItemAsync<int>("stack" + this.Index, this.Items.Stack);
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
return;
ItemFactory.Add(this.Item, Parent.CurrentDragItem);
Parent.RecipeItems[this.Index] = this.Item;
Parent.Actions.Add(new InventoryAction { Action = "Drop", Item = this.Item, Index = this.Index });
Parent.Actions.Add(new InventoryAction { Action = "Moove", Item = this.Item, Index = this.Index });
}
}
else if (Parent.CurrentDragItemIndex != -1)
{
Parent.RecipeItems[Parent.CurrentDragItemIndex] = this.Item;
this.Item = ItemFactory.Create(Parent.CurrentDragItem);
Parent.RecipeItems[this.Index] = this.Item;
Parent.Actions.Add(new InventoryAction { Action = "Swap Position", Item = this.Item, Index = this.Index });
}
Parent.RecipeItems[this.Index] = this.Item;
string fileName = "Inventory.json";
string jsonString = JsonSerializer.Serialize(Parent.RecipeItems);
File.WriteAllText(fileName, jsonString);
}
internal void OnDragEnter()
{
if (this.Items == null) return;
Parent.Actions.Add(new InventoryAction("Drag Enter",this.Index,Items.item));
}
/// <summary>
/// method call when darg start and send an action
/// </summary>
internal void OnDragLeave()
private void OnDragStart()
{
if (this.Items == null) return;
Parent.Actions.Add(new InventoryAction("Drag Leave",this.Index,Items.item));
}
Parent.CurrentDragItem = this.Item;
Parent.CurrentDragItemIndex = this.Index;
protected override async Task OnAfterRenderAsync(bool firstRender)
Parent.Actions.Add(new InventoryAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
}
/// <summary>
/// method call when drag end and send an action specialy when outside the inventory
/// </summary>
private void OnDragEnd()
{
base.OnAfterRenderAsync(firstRender);
if (!firstRender)
if (Parent.Actions.Last().Action == "Drag Leave" && Parent.CurrentDragItemIndex != -1 && this.Item != null)
{
return;
this.Item = null;
Parent.Actions.Add(new InventoryAction { Action = "Delete", Item = this.Item, Index = this.Index });
Parent.RecipeItems[this.Index] = null;
string fileName = "Inventoy.json";
string jsonString = JsonSerializer.Serialize(Parent.RecipeItems);
File.WriteAllText(fileName, jsonString);
}
var item = await LocalStorage.GetItemAsync<Item>("data" + this.Index);
int stack = await LocalStorage.GetItemAsync<int>("stack" + this.Index);
if (item != null)
if (Parent.Actions.Last().Action == "Moove" && Parent.CurrentDragItemIndex != -1)
{
this.Items = new Models.InventoryItem(item, stack);
this.Item = null;
Parent.RecipeItems[this.Index] = null;
string fileName = "Inventory.json";
string jsonString = JsonSerializer.Serialize(Parent.RecipeItems);
File.WriteAllText(fileName, jsonString);
}
else
if (Parent.Actions.Last().Action == "Swap Position") // to refresh the displayed item
{
this.Items = null;
this.Item = Parent.RecipeItems[this.Index];
}
StateHasChanged();
return;
}
}
}

@ -1,16 +1,22 @@
.item {
margin: 5% 5% 5% 5%;
width: 100px;
height: 100px;
width: 64px;
height: 64px;
border: 1px solid;
display: flex;
justify-content: center;
background-color: rgba(139, 139, 139, 1);
box-shadow: inset 1.5px 1.5px 0px rgba(55, 55, 55, 0.8), inset -2px -2px 0px #ffffff;
}
.number-item {
position: absolute;
bottom: 5px;
right: 5px;
font-size: 1em;
font-weight: bold;
-webkit-text-stroke: 2px black;
font-family: 'Segoe UI', Tahoma, Verdana, Geneva, Tahoma, sans-serif
.number {
font-family: 'VT323', monospace;
font-size: 24px;
color: #fefefe;
position: relative;
text-shadow: #333 1px 2px 1px;
top: -30px;
right: -40px;
cursor: default;
z-index: 20;
pointer-events: none;
}

@ -1,11 +0,0 @@
@typeparam TItem
<div>
@if ((Items?.Count ?? 0) != 0)
{
@foreach (var item in Items)
{
@ShowTemplate(item);
}
}
</div>

@ -1,13 +0,0 @@
using Microsoft.AspNetCore.Components;
namespace ProjetBlazor.Components
{
public partial class ShowItems<TItem>
{
[Parameter]
public List<TItem> Items { get; set; }
[Parameter]
public RenderFragment<TItem> ShowTemplate { get; set; }
}
}

@ -1,26 +1,55 @@
using ProjetBlazor.Models;
namespace ProjetBlazor.Factories
public static class ItemFactory
{
public static class ItemFactory
public static ItemModel ToModel(Item item, byte[] imageContent)
{
public static ItemModel ToModel(Item item, byte[] imageContent)
return new ItemModel
{
return new ItemModel
{
Id = item.Id,
DisplayName = item.DisplayName,
Name = item.Name,
RepairWith = item.RepairWith,
EnchantCategories = item.EnchantCategories,
MaxDurability = item.MaxDurability,
StackSize = item.StackSize,
ImageContent = imageContent,
ImageBase64 = string.IsNullOrWhiteSpace(item.ImageBase64) ? Convert.ToBase64String(imageContent) : item.ImageBase64
};
}
Id = item.Id,
DisplayName = item.DisplayName,
Name = item.Name,
RepairWith = item.RepairWith,
EnchantCategories = item.EnchantCategories,
MaxDurability = item.MaxDurability,
StackSize = item.StackSize,
ImageContent = imageContent,
ImageBase64 = string.IsNullOrWhiteSpace(item.ImageBase64) ? Convert.ToBase64String(imageContent) : item.ImageBase64
};
}
public static Item Create(ItemModel model)
public static Item Create(ItemModel model)
{
return new Item
{
Id = model.Id,
DisplayName = model.DisplayName,
Name = model.Name,
RepairWith = model.RepairWith,
EnchantCategories = model.EnchantCategories,
MaxDurability = model.MaxDurability,
StackSize = model.StackSize,
CreatedDate = DateTime.Now,
ImageBase64 = Convert.ToBase64String(model.ImageContent),
Num = 1
};
}
public static void Update(Item item, ItemModel model)
{
item.DisplayName = model.DisplayName;
item.Name = model.Name;
item.RepairWith = model.RepairWith;
item.EnchantCategories = model.EnchantCategories;
item.MaxDurability = model.MaxDurability;
item.StackSize = model.StackSize;
item.UpdatedDate = DateTime.Now;
item.ImageBase64 = Convert.ToBase64String(model.ImageContent);
}
public static Item Create(Item model)
{
if (model.Num > 0)
{
return new Item
{
@ -32,20 +61,44 @@ namespace ProjetBlazor.Factories
MaxDurability = model.MaxDurability,
StackSize = model.StackSize,
CreatedDate = DateTime.Now,
ImageBase64 = Convert.ToBase64String(model.ImageContent)
ImageBase64 = model.ImageBase64,
Num = model.Num,
};
}
public static void Update(Item item, ItemModel model)
return new Item
{
item.DisplayName = model.DisplayName;
item.Name = model.Name;
item.RepairWith = model.RepairWith;
item.EnchantCategories = model.EnchantCategories;
item.MaxDurability = model.MaxDurability;
item.StackSize = model.StackSize;
item.UpdatedDate = DateTime.Now;
item.ImageBase64 = Convert.ToBase64String(model.ImageContent);
}
Id = model.Id,
DisplayName = model.DisplayName,
Name = model.Name,
RepairWith = model.RepairWith,
EnchantCategories = model.EnchantCategories,
MaxDurability = model.MaxDurability,
StackSize = model.StackSize,
CreatedDate = DateTime.Now,
ImageBase64 = model.ImageBase64,
Num = 1,
};
}
public static void Update(Item item, Item model)
{
item.DisplayName = model.DisplayName;
item.Name = model.Name;
item.RepairWith = model.RepairWith;
item.EnchantCategories = model.EnchantCategories;
item.MaxDurability = model.MaxDurability;
item.StackSize = model.StackSize;
item.UpdatedDate = DateTime.Now;
item.ImageBase64 = model.ImageBase64;
item.Num = model.Num;
}
public static void Add(Item item, Item model)
{
if (model.Num != 0)
item.Num = model.Num + item.Num;
else
item.Num += 1;
}
}

@ -15,6 +15,7 @@
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
public string ImageBase64 { get; set; }
public int Num { get; set; }
}
}

@ -1,7 +1,4 @@
using ProjetBlazor.Components;
using ProjetBlazor.Models;
using ProjetBlazor.Factories;
using ProjetBlazor.Models;
using ProjetBlazor.Models;
using ProjetBlazor.Services;

Loading…
Cancel
Save