Compare commits
No commits in common. "6af8540bac7f6349ab2af806818156240b0efb2b" and "97cdf2675102be29142ac5d70b5b23348392342a" have entirely different histories.
6af8540bac
...
97cdf26751
|
@ -838,6 +838,11 @@ y_sort_enabled = true
|
|||
script = ExtResource("30_y2wmw")
|
||||
Hotbar = [null, null, null]
|
||||
Items = Array[Object]([ExtResource("33_3qyfl"), ExtResource("34_70ron"), ExtResource("35_4pap1")])
|
||||
InventoryMap = {
|
||||
"equip_1": 0,
|
||||
"equip_2": 1,
|
||||
"equip_3": 2
|
||||
}
|
||||
|
||||
[node name="Hurtbox" parent="." node_paths=PackedStringArray("InvincibilityTimer") instance=ExtResource("9_avyu4")]
|
||||
visible = false
|
||||
|
|
|
@ -11,10 +11,11 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
|
|||
[Export]
|
||||
public Array<Item> Hotbar { get; private set; }
|
||||
|
||||
public Array<int> HotbarToItemIndexMap { get; set; } = new();
|
||||
[Export]
|
||||
public Array<ItemMetadata> Items { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Array<ItemMetadata> Items { get; set; }
|
||||
public Dictionary<string, int> InventoryMap { get; set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void UsedItemEventHandler(Item item);
|
||||
|
@ -61,12 +62,6 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
|
|||
|
||||
public bool IsUsingItem => SelectedItem?.IsUsing ?? false;
|
||||
|
||||
public Inventory()
|
||||
{
|
||||
HotbarToItemIndexMap.Resize(HotbarCapacity);
|
||||
HotbarToItemIndexMap.Fill(-1);
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Hotbar is null)
|
||||
|
@ -135,6 +130,21 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
|
|||
return EquipIndex(index);
|
||||
}
|
||||
|
||||
[System.Obsolete]
|
||||
public Item GetItemByMap(string keymap)
|
||||
{
|
||||
if (InventoryMap.ContainsKey(keymap))
|
||||
{
|
||||
int idx = InventoryMap[keymap];
|
||||
if (idx < Hotbar.Count)
|
||||
{
|
||||
return Hotbar[InventoryMap[keymap]];
|
||||
}
|
||||
}
|
||||
else GD.Print(keymap + " does not exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
public Item AddToHotbar(ItemMetadata metadata)
|
||||
{
|
||||
//AddItemMetadata(metadata);
|
||||
|
@ -145,19 +155,7 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
|
|||
return item;
|
||||
}
|
||||
|
||||
public Item SetHotbarIndexToItemIndex(int hotbarIndex, int itemIndex)
|
||||
{
|
||||
HotbarToItemIndexMap[hotbarIndex] = itemIndex;
|
||||
|
||||
if (itemIndex >= 0)
|
||||
{
|
||||
return SetHotbarIndexToItem(hotbarIndex, Items[itemIndex]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Item SetHotbarIndexToItem(int index, ItemMetadata metadata)
|
||||
public Item SetHotbarIndexToItem(int index, ItemMetadata metadata)
|
||||
{
|
||||
var oldItem = Hotbar[index];
|
||||
Item newItem = null;
|
||||
|
|
|
@ -76,19 +76,6 @@ public partial class GlobalState : Node
|
|||
Progression = save.Progression;
|
||||
MapState = save.MapState;
|
||||
Stats = save.Stats;
|
||||
|
||||
var inventory = World.Instance.CurrentPlayer.Inventory;
|
||||
inventory.Items = Stats.Items;
|
||||
|
||||
for (int i = 0; i < Stats.HotbarToItemIndexMap.Count; i++)
|
||||
{
|
||||
int itemIndex = Stats.HotbarToItemIndexMap[i];
|
||||
|
||||
if (itemIndex >= 0)
|
||||
{
|
||||
inventory.SetHotbarIndexToItemIndex(i, itemIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ExportToSave(Save save)
|
||||
|
@ -96,9 +83,5 @@ public partial class GlobalState : Node
|
|||
save.Progression = Progression;
|
||||
save.MapState = MapState;
|
||||
save.Stats = Stats;
|
||||
|
||||
var inventory = World.Instance.CurrentPlayer.Inventory;
|
||||
Stats.Items = inventory.Items;
|
||||
Stats.HotbarToItemIndexMap = inventory.HotbarToItemIndexMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace SupaLidlGame.State.Global;
|
||||
|
||||
|
@ -14,10 +13,4 @@ public partial class Stats : Resource
|
|||
|
||||
[Export]
|
||||
public int DeathCount { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
public Array<Items.ItemMetadata> Items { get; set; } = new();
|
||||
|
||||
[Export]
|
||||
public Array<int> HotbarToItemIndexMap { get; set; } = new();
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ public partial class InventoryGrid : GridContainer
|
|||
|
||||
ItemMetadata item = items.Current;
|
||||
slot.Item = item;
|
||||
slot.Index = i;
|
||||
}
|
||||
|
||||
// make remaining slots display empty
|
||||
|
@ -81,7 +80,6 @@ public partial class InventoryGrid : GridContainer
|
|||
InventorySlot slot = children[i] as InventorySlot;
|
||||
|
||||
slot.Item = null;
|
||||
slot.Index = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,6 @@ public partial class InventoryMenu : BaseMenu, IModal
|
|||
{
|
||||
int slot = button.GetMeta("slot").AsInt32();
|
||||
GD.Print("Equipping item at slot " + slot);
|
||||
Source.SetHotbarIndexToItemIndex(slot, _selected.Index);
|
||||
Source.SetHotbarIndexToItem(slot, _selected.Item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ public partial class InventorySlot : Button
|
|||
|
||||
private static Texture2D _placeholderTexture;
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
private Items.ItemMetadata _item;
|
||||
|
||||
public Items.ItemMetadata Item
|
||||
|
|
|
@ -21,12 +21,7 @@ public partial class ScenePath : ResourcePath
|
|||
|
||||
// add scene to loaded to not have to reload scene when called again
|
||||
var scene = base.Load<PackedScene>();
|
||||
|
||||
if (useCached)
|
||||
{
|
||||
_loaded.Add(Path, scene);
|
||||
}
|
||||
|
||||
_loaded.Add(Path, scene);
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,13 +84,6 @@ public partial class World : Node
|
|||
{
|
||||
throw new System.Exception("Another World instance is running.");
|
||||
}
|
||||
|
||||
Debug = new DebugCommands(this);
|
||||
}
|
||||
|
||||
~World()
|
||||
{
|
||||
Debug.Free();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
|
@ -342,23 +335,4 @@ public partial class World : Node
|
|||
}
|
||||
|
||||
public Node FindEntity(string name) => CurrentMap.Entities.GetNode(name);
|
||||
|
||||
internal DebugCommands Debug { get; set; }
|
||||
}
|
||||
|
||||
internal partial class DebugCommands : GodotObject
|
||||
{
|
||||
private World _world;
|
||||
|
||||
internal DebugCommands(World world)
|
||||
{
|
||||
_world = world;
|
||||
}
|
||||
|
||||
internal void GiveItem(string item)
|
||||
{
|
||||
var itemMetadata = ResourceLoader
|
||||
.Load<Items.ItemMetadata>($"res://Items/{item}.tres");
|
||||
_world.CurrentPlayer.Inventory.Items.Add(itemMetadata);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue