"Inventory ended"

aurian
Aurian JAULT 2 years ago
parent f1cfce9fe6
commit 413a6f2db3

@ -15,4 +15,9 @@
} }
} }
</div> </div>
<div class="col-12">
<div>Actions</div>
<div class="actions" id="actions">
</div>
</div>
</CascadingValue> </CascadingValue>

@ -17,61 +17,11 @@ namespace Blazor.Components
public void update() public void update()
{ {
this.StateHasChanged(); this.StateHasChanged();
return;
} }
[Parameter] [Parameter]
public InventoryList inventory { get; set; } public InventoryList inventory { get; set; }
public void Add(Item item)
/*peut être useless*/
{
if (item == null) return;
foreach(InventoryItem element in inventory.inventoryItems)
{
if(item.Id == element.item.Id)
{
if(element.Stack == element.item.StackSize)
{
addEnd(item);
this.StateHasChanged();
return;
}
else
{
element.Stack += 1;
this.StateHasChanged();
return;
}
}
if(element == null)
{
element.item = item;
element.Stack = 1;
this.StateHasChanged();
return;
}
}
/*Si c'est ici c'est que l'inventaire est plein jsais pas si il faut avertir le user*/
}
public void addEnd(Item item)
/*peut être useless*/
{
int i = 0;
while (inventory.inventoryItems[i]!=null)
{
i += 1;
}
if(i < InventoryList.size)
{
inventory.inventoryItems[i].item = item;
inventory.inventoryItems[i].Stack = 1;
}
else
{
/*Inventaire plein même cas que la fonction add*/
}
}
} }
} }

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

@ -8,17 +8,15 @@
{ {
@if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64)) @if(!string.IsNullOrWhiteSpace(Items.item.ImageBase64))
{ {
<img src="data:image/png;base64, @(Items.item.ImageBase64)" class="img-thumbnail" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="min-width: 50px;" /> <img src="data:image/png;base64, @(Items.item.ImageBase64)" class="img-thumbnail" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="width: 50px;" />
} }
else else
{ {
<img src="images/default.png" class="img-thumbnail" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="fill" /> <img src="images/default.png" class="img-thumbnail" title="@Items.item.DisplayName" alt="@Items.item.DisplayName" style="width: 50px; height: 50px" />
} }
} }
else else
{ {
<div> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAINJREFUeF7t18ENACAMAzE6OuLD1jDImREiGitz9n0r/EYAfoAT0AHhDlxKkAIUoAAFKBBOAIMYxCAGMRhGwBjCIAYxiEEMYjCcAAYxiEEMYjCMgDWIQQxiEIMYxGA4AQxiEIMYxGAYAWsQgxjEIAYxiMFwAhjEIAYxiMEwAtYgBusMfuMLowEYJcXzAAAAAElFTkSuQmCC" class="img-thumbnail" title="empty" alt="empty slot" style="width: 50px; height: 50px" />
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAZElEQVR42u3QAQ0AAAQAMAppJz85zB/h2VUTj6UAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBBw3wKq0HRBv18xwgAAAABJRU5ErkJggg==" class="img-thumbnail" title="Empty" style="width: 64px; height: 64px" />
</div>
} }
</div> </div>

@ -22,10 +22,13 @@ namespace Blazor.Components
{ {
if(!NoDrop) if(!NoDrop)
{ {
Parent.CurrentDragItem = null;
return; return;
} }
Parent.CurrentDragItem = this.Items; Parent.CurrentDragItem = this.Items;
Parent.inventory.inventoryItems[Index] = null; Parent.inventory.inventoryItems[this.Index] = null;
this.NoDrop = false;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this));
Parent.update(); Parent.update();
} }
@ -37,14 +40,20 @@ namespace Blazor.Components
this.Items = Parent.CurrentDragItem; this.Items = Parent.CurrentDragItem;
NoDrop = true; NoDrop = true;
Parent.CurrentDragItem = null; Parent.CurrentDragItem = null;
Parent.Actions.Add(new InventoryAction("On Drop",this.Index,this));
return; return;
} }
if(Parent.CurrentDragItem == null)
if (Parent.CurrentDragItem != this.Items) {
return;
}
if (Parent.CurrentDragItem.item.Id != this.Items.item.Id)
{ {
InventoryItem tmp = Parent.CurrentDragItem; this.Items = Parent.CurrentDragItem;
Parent.CurrentDragItem = this.Items; this.NoDrop= true;
this.Items = tmp; Parent.CurrentDragItem = null;
Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this));
return;
} }
else else
{ {
@ -52,22 +61,24 @@ namespace Blazor.Components
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.Stack=total - this.Items.item.StackSize; Parent.Actions.Add(new InventoryAction("On drag start",this.Index,this));
return;
} }
else else
{ {
this.Items.Stack = total; this.Items.Stack = total;
return;
} }
} }
} }
internal void OnDragEnter() internal void OnDragEnter()
{ {
Parent.Actions.Add(new InventoryAction { Action = "Drag Enter", Item = this, Index = this.Index }); Parent.Actions.Add(new InventoryAction("Drag Enter",this.Index,this));
} }
internal void OnDragLeave() internal void OnDragLeave()
{ {
Parent.Actions.Add(new InventoryAction { Action = "Drag Leave", Item = this, Index = this.Index }); Parent.Actions.Add(new InventoryAction("Drag Leave",this.Index,this));
} }
} }
} }

Loading…
Cancel
Save