Fix inventory menu, add armor as equippable item
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ArmorItem : InventoryItemInfo
|
||||
{
|
||||
[Export]
|
||||
public required int Defense { get; set; }
|
||||
}
|
||||
@@ -1,9 +1,27 @@
|
||||
using Godot;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public abstract partial class InventoryItem : Node3D
|
||||
public interface IInventoryItem : INode3D
|
||||
{
|
||||
public abstract InventoryItemInfo InventoryInfo { get; set; }
|
||||
|
||||
public IGameRepo GameRepo { get; }
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public abstract partial class InventoryItem : Node3D, IInventoryItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
public abstract InventoryItemInfo InventoryInfo { get; set; }
|
||||
|
||||
[Node] public Area3D Pickup { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Armor : InventoryItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export]
|
||||
public override InventoryItemInfo InventoryInfo { get; set; }
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
{
|
||||
var inventoryList = GameRepo.InventoryItems.Value.Append(InventoryInfo).ToList();
|
||||
GameRepo.InventoryItems.OnNext(inventoryList);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,33 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dorr7v1tkeiy0"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dorr7v1tkeiy0"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/armor/Armor.cs" id="1_cmjpq"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgoubcl86pib4" path="res://src/items/armor/armor.png" id="1_vpnem"]
|
||||
[ext_resource type="Resource" uid="uid://chjmkb3aiomvr" path="res://src/items/armor/resources/PatheticCoat.tres" id="2_eftit"]
|
||||
[ext_resource type="Script" path="res://src/items/armor/ArmorInfo.cs" id="2_cuhrp"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_o1cok"]
|
||||
script = ExtResource("2_cuhrp")
|
||||
Defense = 2
|
||||
Name = "Pathetic"
|
||||
Description = "A pathetic coat."
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1gpxo"]
|
||||
radius = 0.470016
|
||||
height = 0.940032
|
||||
|
||||
[node name="Armor" type="Node3D"]
|
||||
script = ExtResource("1_cmjpq")
|
||||
InventoryInfo = ExtResource("2_eftit")
|
||||
InventoryInfo = SubResource("Resource_o1cok")
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
billboard = 2
|
||||
alpha_cut = 1
|
||||
texture_filter = 0
|
||||
texture = ExtResource("1_vpnem")
|
||||
|
||||
[node name="Pickup" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Pickup"]
|
||||
shape = SubResource("CapsuleShape3D_1gpxo")
|
||||
|
||||
10
src/items/armor/ArmorInfo.cs
Normal file
10
src/items/armor/ArmorInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class ArmorInfo : InventoryItemInfo
|
||||
{
|
||||
[Export]
|
||||
public int Defense { get; set; }
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Weapon : InventoryItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
public Weapon()
|
||||
{
|
||||
_inventoryInfo = WeaponInfo.Default;
|
||||
@@ -12,4 +18,16 @@ public partial class Weapon : InventoryItem
|
||||
private WeaponInfo _inventoryInfo { get; set; }
|
||||
|
||||
public override InventoryItemInfo InventoryInfo { get => _inventoryInfo; set => _inventoryInfo = value as WeaponInfo; }
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
{
|
||||
var inventoryList = GameRepo.InventoryItems.Value.Append(InventoryInfo).ToList();
|
||||
GameRepo.InventoryItems.OnNext(inventoryList);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://b6atdgf2e6e2t"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b6atdgf2e6e2t"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/weapons/Weapon.cs" id="1_sr3bh"]
|
||||
[ext_resource type="Resource" uid="uid://dq8tdmjhrqsrh" path="res://src/items/weapons/resources/CommonSword.tres" id="2_krjts"]
|
||||
[ext_resource type="Texture2D" uid="uid://wd6jh5q51e4k" path="res://src/items/weapons/models/sword.png" id="3_ixjdd"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_j2it8"]
|
||||
radius = 0.470016
|
||||
height = 0.940032
|
||||
|
||||
[node name="CommonSword" type="Node3D"]
|
||||
script = ExtResource("1_sr3bh")
|
||||
_inventoryInfo = ExtResource("2_krjts")
|
||||
@@ -16,3 +20,11 @@ alpha_scissor_threshold = 0.511
|
||||
alpha_antialiasing_mode = 1
|
||||
texture_filter = 0
|
||||
texture = ExtResource("3_ixjdd")
|
||||
|
||||
[node name="Pickup" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Pickup"]
|
||||
shape = SubResource("CapsuleShape3D_j2it8")
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c10nhqq8su6pp"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c10nhqq8su6pp"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/weapons/Weapon.cs" id="1_f8v7v"]
|
||||
[ext_resource type="Resource" uid="uid://b4oxsf4k3nr43" path="res://src/items/weapons/resources/RareSword.tres" id="2_6nmyd"]
|
||||
[ext_resource type="Texture2D" uid="uid://wd6jh5q51e4k" path="res://src/items/weapons/models/sword.png" id="3_meaac"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4ic28"]
|
||||
radius = 0.470016
|
||||
height = 0.940032
|
||||
|
||||
[node name="RareSword" type="Node3D"]
|
||||
script = ExtResource("1_f8v7v")
|
||||
_inventoryInfo = ExtResource("2_6nmyd")
|
||||
@@ -16,3 +20,11 @@ alpha_scissor_threshold = 0.511
|
||||
alpha_antialiasing_mode = 1
|
||||
texture_filter = 0
|
||||
texture = ExtResource("3_meaac")
|
||||
|
||||
[node name="Pickup" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Pickup"]
|
||||
shape = SubResource("CapsuleShape3D_4ic28")
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cbb1fxllrnlyr"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cbb1fxllrnlyr"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/weapons/Weapon.cs" id="1_3o4dy"]
|
||||
[ext_resource type="Resource" uid="uid://e0t7swnl2sfd" path="res://src/items/weapons/resources/UncommonSword.tres" id="2_ga52m"]
|
||||
[ext_resource type="Texture2D" uid="uid://wd6jh5q51e4k" path="res://src/items/weapons/models/sword.png" id="3_r8wg3"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_cbafi"]
|
||||
radius = 0.470016
|
||||
height = 0.940032
|
||||
|
||||
[node name="UncommonSword" type="Node3D"]
|
||||
script = ExtResource("1_3o4dy")
|
||||
_inventoryInfo = ExtResource("2_ga52m")
|
||||
@@ -16,3 +20,11 @@ alpha_scissor_threshold = 0.511
|
||||
alpha_antialiasing_mode = 1
|
||||
texture_filter = 0
|
||||
texture = ExtResource("3_r8wg3")
|
||||
|
||||
[node name="Pickup" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Pickup"]
|
||||
shape = SubResource("CapsuleShape3D_cbafi")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="WeaponInfo" load_steps=2 format=3 uid="uid://dq8tdmjhrqsrh"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/WeaponInfo.cs" id="1_wc11x"]
|
||||
[ext_resource type="Script" path="res://src/items/weapons/WeaponInfo.cs" id="1_k7yyo"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_wc11x")
|
||||
Damage = 2
|
||||
Name = "Common Sword"
|
||||
Description = "This is just a regular sword."
|
||||
script = ExtResource("1_k7yyo")
|
||||
Damage = 3
|
||||
Name = "Common sword"
|
||||
Description = "Common"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="WeaponInfo" load_steps=2 format=3 uid="uid://b4oxsf4k3nr43"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/WeaponInfo.cs" id="1_ybm7s"]
|
||||
[ext_resource type="Script" path="res://src/items/weapons/WeaponInfo.cs" id="1_oqgv2"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ybm7s")
|
||||
script = ExtResource("1_oqgv2")
|
||||
Damage = 7
|
||||
Name = "Rare Sword"
|
||||
Description = "Wow. How did you get this one?"
|
||||
Name = "Rare sword"
|
||||
Description = "Rare"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="WeaponInfo" load_steps=2 format=3 uid="uid://e0t7swnl2sfd"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/WeaponInfo.cs" id="1_0u4lk"]
|
||||
[ext_resource type="Script" path="res://src/items/weapons/WeaponInfo.cs" id="1_8os8m"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_0u4lk")
|
||||
Damage = 4
|
||||
Name = "Uncommon Sword."
|
||||
Description = "This one is a little bit better."
|
||||
script = ExtResource("1_8os8m")
|
||||
Damage = 5
|
||||
Name = "Uncommon sword"
|
||||
Description = "Uncommon"
|
||||
|
||||
Reference in New Issue
Block a user