More inventory menu improvements

This commit is contained in:
2024-09-13 16:43:10 -07:00
parent f0e75703f6
commit 1d7d70e033
41 changed files with 995 additions and 275 deletions

View File

@@ -2,7 +2,9 @@
using Chickensoft.GodotNodeInterfaces;
using Godot;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace GameJamDungeon;
@@ -31,6 +33,8 @@ public interface IInventory : INode
public void Drop(IInventoryItem inventoryItem);
public void Sort();
event Inventory.InventoryAtCapacityEventHandler InventoryAtCapacity;
event Inventory.AccessoryUnequippedEventHandler AccessoryUnequipped;
@@ -137,4 +141,67 @@ public partial class Inventory : Node, IInventory
{
Remove(item);
}
public void Sort()
{
var equippedWeapon = Items.OfType<Weapon>().Where(IsEquipped);
var equippedArmor = Items.OfType<Armor>().Where(IsEquipped);
var equippedAccessory = Items.OfType<Accessory>().Where(IsEquipped);
var equippedItems = new List<IInventoryItem>();
equippedItems.AddRange(equippedWeapon);
equippedItems.AddRange(equippedArmor);
equippedItems.AddRange(equippedAccessory);
var listToSort = Items.Except(equippedItems);
var weapons = listToSort.Where(x => x is Weapon).OrderBy(x => x as Weapon, new WeaponComparer());
var armor = listToSort.Where(x => x is Armor).OrderBy(x => x as Armor, new ArmorComparer());
var accessories = listToSort.Where(x => x is Accessory).OrderBy(x => x as Accessory, new AccessoryComparer());
var consumables = listToSort.Where(x => x is ConsumableItem).OrderBy(x => x as ConsumableItem, new ConsumableComparer());
var throwables = listToSort.Where(x => x is ThrowableItem).OrderBy(x => x as ThrowableItem, new ThrowableComparer());
Items = [.. consumables, .. equippedItems, .. weapons, .. armor, .. accessories, .. throwables];
}
public class WeaponComparer : IComparer<Weapon>
{
public int Compare(Weapon x, Weapon y)
{
if (x.WeaponStats.Damage == y.WeaponStats.Damage)
return x.WeaponStats.Name.CompareTo(y.WeaponStats.Name);
return x.WeaponStats.Damage < y.WeaponStats.Damage ? 1 : -1;
}
}
public class ArmorComparer : IComparer<Armor>
{
public int Compare(Armor x, Armor y)
{
if (x.ArmorStats.Defense == y.ArmorStats.Defense)
return x.ArmorStats.Name.CompareTo(y.ArmorStats.Name);
return x.ArmorStats.Defense < y.ArmorStats.Defense ? 1 : -1;
}
}
public class AccessoryComparer : IComparer<Accessory>
{
public int Compare(Accessory x, Accessory y)
{
return x.AccessoryStats.Name.CompareTo(y.AccessoryStats.Name);
}
}
public class ConsumableComparer : IComparer<ConsumableItem>
{
public int Compare(ConsumableItem x, ConsumableItem y)
{
return x.ConsumableItemInfo.Name.CompareTo(y.ConsumableItemInfo.Name);
}
}
public class ThrowableComparer : IComparer<ThrowableItem>
{
public int Compare(ThrowableItem x, ThrowableItem y)
{
return x.ThrowableItemInfo.Name.CompareTo(y.ThrowableItemInfo.Name);
}
}
}

View File

@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="WeaponInfo" load_steps=3 format=3 uid="uid://cfr100khjkloh"]
[gd_resource type="Resource" script_class="WeaponStats" load_steps=3 format=3 uid="uid://cfr100khjkloh"]
[ext_resource type="Texture2D" uid="uid://blq3nnyostunl" path="res://src/items/weapons/textures/LOVE JUDGEMENT.PNG" id="1_ivlxj"]
[ext_resource type="Script" path="res://src/items/weapons/WeaponStats.cs" id="1_vroib"]
@@ -15,7 +15,7 @@ IgneousDamageBonus = 0.0
FerrumDamageBonus = 0.0
WeaponTags = []
Name = "Love Judgement"
Description = "+12 DEF
Description = "+12 ATK
A mace only wieldable by the strong of heart."
Texture = ExtResource("1_ivlxj")
SpawnRate = 0.5