|
|
@ -1,4 +1,5 @@
|
|
|
|
using Blazor.Models;
|
|
|
|
using Blazor.Models;
|
|
|
|
|
|
|
|
using Blazored.LocalStorage;
|
|
|
|
using Blazorise.Extensions;
|
|
|
|
using Blazorise.Extensions;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
|
@ -18,67 +19,67 @@ namespace Blazor.Components
|
|
|
|
[CascadingParameter]
|
|
|
|
[CascadingParameter]
|
|
|
|
public Inventory Parent { get; set; }
|
|
|
|
public Inventory Parent { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDragStart()
|
|
|
|
[Inject]
|
|
|
|
|
|
|
|
public ILocalStorageService LocalStorage { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task OnDragStartAsync()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!this.NoDrop)
|
|
|
|
|
|
|
|
|
|
|
|
if (this.Items == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Parent.CurrentDragItem = this.Items;
|
|
|
|
Parent.CurrentDragItem = this.Items;
|
|
|
|
Parent.inventory.inventoryItems[this.Index] = null;
|
|
|
|
|
|
|
|
this.NoDrop = false;
|
|
|
|
|
|
|
|
if (this.Items == null) return;
|
|
|
|
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
|
|
|
|
Parent.update();
|
|
|
|
this.Items = null;
|
|
|
|
|
|
|
|
Parent.inventory.inventoryItems[this.Index] = null ;
|
|
|
|
|
|
|
|
await LocalStorage.SetItemAsync<Models.InventoryItem>("data" + this.Index, this.Items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDrop()
|
|
|
|
public async Task OnDropAsync()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!this.NoDrop)
|
|
|
|
|
|
|
|
|
|
|
|
if (Parent.CurrentDragItem == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Items = Parent.CurrentDragItem;
|
|
|
|
|
|
|
|
this.NoDrop = true;
|
|
|
|
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
|
|
|
|
Parent.inventory.inventoryItems[this.Index] = this.Items;
|
|
|
|
|
|
|
|
if (this.Items == null) return;
|
|
|
|
|
|
|
|
Parent.Actions.Add(new InventoryAction("On Drop",this.Index,Items.item));
|
|
|
|
|
|
|
|
Parent.update();
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(Parent.CurrentDragItem == null)
|
|
|
|
|
|
|
|
|
|
|
|
if(this.Items == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
this.Items = Parent.CurrentDragItem;
|
|
|
|
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
|
|
|
|
await LocalStorage.SetItemAsync<Models.InventoryItem>("data" + this.Index, this.Items);
|
|
|
|
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Parent.CurrentDragItem.item.Id != this.Items.item.Id)
|
|
|
|
if (Parent.CurrentDragItem.item.Id != this.Items.item.Id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Items = Parent.CurrentDragItem;
|
|
|
|
this.Items = Parent.CurrentDragItem;
|
|
|
|
this.NoDrop= true;
|
|
|
|
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.inventory.inventoryItems[this.Index] = this.Items;
|
|
|
|
await LocalStorage.SetItemAsync<Models.InventoryItem>("data" + this.Index, this.Items);
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
|
|
|
|
Parent.update();
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int total = Parent.CurrentDragItem.Stack + this.Items.Stack;
|
|
|
|
int total = Parent.CurrentDragItem.Stack + this.Items.Stack;
|
|
|
|
if (total >this.Items.item.StackSize)
|
|
|
|
if (total > this.Items.item.StackSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Items.Stack = this.Items.item.StackSize;
|
|
|
|
this.Items.Stack = this.Items.item.StackSize;
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,Items.item));
|
|
|
|
await LocalStorage.SetItemAsync<Models.InventoryItem>("data" + this.Index, this.Items);
|
|
|
|
Parent.inventory.inventoryItems[this.Index] = this.Items;
|
|
|
|
Parent.Actions.Add(new InventoryAction("On drag drop",this.Index,Items.item));
|
|
|
|
Parent.update();
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.Items.Stack = total;
|
|
|
|
this.Items.Stack = total;
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.CurrentDragItem = null;
|
|
|
|
Parent.inventory.inventoryItems[this.Index] = this.Items;
|
|
|
|
await LocalStorage.SetItemAsync<Models.InventoryItem>("data" + this.Index, this.Items);
|
|
|
|
Parent.update();
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -94,5 +95,19 @@ namespace Blazor.Components
|
|
|
|
if (this.Items == null) return;
|
|
|
|
if (this.Items == null) return;
|
|
|
|
Parent.Actions.Add(new InventoryAction("Drag Leave",this.Index,Items.item));
|
|
|
|
Parent.Actions.Add(new InventoryAction("Drag Leave",this.Index,Items.item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!firstRender)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Items = await LocalStorage.GetItemAsync<InventoryItem>("item" + this.Index);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|