associate weapon scenes with resources

wip-inventory
John Montagu, the 4th Earl of Sandvich 2023-12-29 17:45:36 -08:00
parent c1fcfcd398
commit 3230e487f2
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
12 changed files with 154 additions and 13 deletions

View File

@ -8,15 +8,12 @@ public abstract partial class Item : Node2D
[Signal] [Signal]
public delegate void UsedItemEventHandler(Item item); public delegate void UsedItemEventHandler(Item item);
[Export]
public string ItemName { get; set; }
[Export]
public string Description { get; set; }
[Export] [Export]
public bool CanStack { get; set; } = false; public bool CanStack { get; set; } = false;
[Export]
public ItemMetadata Metadata { get; set; }
public int Count { get; set; } = 1; public int Count { get; set; } = 1;
public bool IsOneHanded { get; set; } = false; public bool IsOneHanded { get; set; } = false;
@ -41,7 +38,7 @@ public abstract partial class Item : Node2D
return false; return false;
} }
if (ItemName != item.ItemName) if (Metadata.Name != item.Metadata.Name)
{ {
return false; return false;
} }

View File

@ -0,0 +1,16 @@
using Godot;
namespace SupaLidlGame.Items;
[GlobalClass]
public partial class ItemMetadata : Resource
{
[Export]
public Utils.ScenePath Instance { get; set; }
[Export]
public string Name { get; set; }
[Export(PropertyHint.MultilineText)]
public string Description { get; set; }
}

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="ItemMetadata" load_steps=4 format=3 uid="uid://cjsh0dcgbfn77"]
[ext_resource type="Script" path="res://Utils/ScenePath.cs" id="1_haiji"]
[ext_resource type="Script" path="res://Items/ItemMetadata.cs" id="2_hjbs0"]
[sub_resource type="Resource" id="Resource_mjj1w"]
script = ExtResource("1_haiji")
Path = "res://Items/Weapons/Bow.tscn"
[resource]
script = ExtResource("2_hjbs0")
Instance = SubResource("Resource_mjj1w")
Name = "Bow"
Description = "A bow and arrow."

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=16 format=3 uid="uid://cgg0sfm2qeiwn"] [gd_scene load_steps=17 format=3 uid="uid://cgg0sfm2qeiwn"]
[ext_resource type="Texture2D" uid="uid://dam6aigkw8xs" path="res://Assets/Sprites/Items/bow-and-arrow.png" id="1_1ghvv"] [ext_resource type="Texture2D" uid="uid://dam6aigkw8xs" path="res://Assets/Sprites/Items/bow-and-arrow.png" id="1_1ghvv"]
[ext_resource type="Script" path="res://Items/Weapons/ProjectileSpawner.cs" id="1_76bur"] [ext_resource type="Script" path="res://Items/Weapons/ProjectileSpawner.cs" id="1_76bur"]
[ext_resource type="PackedScene" uid="uid://cjiftn2suskla" path="res://Entities/Arrow.tscn" id="2_mvw0j"] [ext_resource type="PackedScene" uid="uid://cjiftn2suskla" path="res://Entities/Arrow.tscn" id="2_mvw0j"]
[ext_resource type="Resource" uid="uid://cjsh0dcgbfn77" path="res://Items/Weapons/Bow.tres" id="3_j7q7r"]
[ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="3_pg4gy"] [ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="3_pg4gy"]
[ext_resource type="Script" path="res://State/Weapon/RangedIdleState.cs" id="3_uxif8"] [ext_resource type="Script" path="res://State/Weapon/RangedIdleState.cs" id="3_uxif8"]
[ext_resource type="Script" path="res://State/Weapon/RangedFireState.cs" id="4_moo4d"] [ext_resource type="Script" path="res://State/Weapon/RangedFireState.cs" id="4_moo4d"]
@ -123,6 +124,7 @@ Knockback = 64.0
InitialVelocity = 200.0 InitialVelocity = 200.0
ShouldFreezeAngleOnUse = false ShouldFreezeAngleOnUse = false
PlayerLevelGain = 1.0 PlayerLevelGain = 1.0
Metadata = ExtResource("3_j7q7r")
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("3_pg4gy") script = ExtResource("3_pg4gy")

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="ItemMetadata" load_steps=4 format=3 uid="uid://cud7l7t0qsc65"]
[ext_resource type="Script" path="res://Utils/ScenePath.cs" id="1_2t2st"]
[ext_resource type="Script" path="res://Items/ItemMetadata.cs" id="1_fhdpj"]
[sub_resource type="Resource" id="Resource_clkv8"]
script = ExtResource("1_2t2st")
Path = "res://Items/Weapons/DocLance.tscn"
[resource]
script = ExtResource("1_fhdpj")
Instance = SubResource("Resource_clkv8")
Name = "Shungite Spear"
Description = "It's a billion year old lance, spear that protects against unwanted invaders."

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=22 format=3 uid="uid://p7oijq6dbvvk"] [gd_scene load_steps=23 format=3 uid="uid://p7oijq6dbvvk"]
[ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_1oyma"] [ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_1oyma"]
[ext_resource type="Resource" uid="uid://cud7l7t0qsc65" path="res://Items/Weapons/DocLance.tres" id="2_5r5mm"]
[ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_c41ov"] [ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_c41ov"]
[ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_sxffm"] [ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_sxffm"]
[ext_resource type="Script" path="res://State/Weapon/SwordAnticipateState.cs" id="4_t7af2"] [ext_resource type="Script" path="res://State/Weapon/SwordAnticipateState.cs" id="4_t7af2"]
@ -185,8 +186,7 @@ UseTime = 0.55
Knockback = 64.0 Knockback = 64.0
ShouldHideIdle = true ShouldHideIdle = true
HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand") HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand")
ItemName = "VSM-93" Metadata = ExtResource("2_5r5mm")
Description = "\"Violence. Speed. Momentum.\""
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_c41ov") script = ExtResource("2_c41ov")
@ -251,6 +251,7 @@ libraries = {
[node name="Hitbox" parent="." instance=ExtResource("9_buajm")] [node name="Hitbox" parent="." instance=ExtResource("9_buajm")]
position = Vector2(16, -4) position = Vector2(16, -4)
priority = 5
IsDisabled = true IsDisabled = true
[node name="CollisionShape2D" parent="Hitbox" index="0"] [node name="CollisionShape2D" parent="Hitbox" index="0"]

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="ItemMetadata" load_steps=4 format=3 uid="uid://iqe6rgnb3jur"]
[ext_resource type="Script" path="res://Utils/ScenePath.cs" id="1_o026a"]
[ext_resource type="Script" path="res://Items/ItemMetadata.cs" id="2_j4tmu"]
[sub_resource type="Resource" id="Resource_abrg1"]
script = ExtResource("1_o026a")
Path = "res://Items/Weapons/Pugio.tscn"
[resource]
script = ExtResource("2_j4tmu")
Instance = SubResource("Resource_abrg1")
Name = "Pugio"
Description = "A sidearm dagger."

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=29 format=3 uid="uid://5y1acxl4j4n7"] [gd_scene load_steps=30 format=3 uid="uid://5y1acxl4j4n7"]
[ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mai31"] [ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mai31"]
[ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_5ramr"] [ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_5ramr"]
[ext_resource type="Resource" uid="uid://iqe6rgnb3jur" path="res://Items/Weapons/Pugio.tres" id="2_ulca0"]
[ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_fwkit"] [ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_fwkit"]
[ext_resource type="Script" path="res://State/Weapon/SwordAnticipateState.cs" id="4_nsn1q"] [ext_resource type="Script" path="res://State/Weapon/SwordAnticipateState.cs" id="4_nsn1q"]
[ext_resource type="Script" path="res://State/Weapon/SwordAttackState.cs" id="5_g1en5"] [ext_resource type="Script" path="res://State/Weapon/SwordAttackState.cs" id="5_g1en5"]
@ -350,6 +351,7 @@ UseAltTime = 1.5
Knockback = 64.0 Knockback = 64.0
PlayerLevelGain = 1.0 PlayerLevelGain = 1.0
HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand") HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand")
Metadata = ExtResource("2_ulca0")
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_5ramr") script = ExtResource("2_5ramr")

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="ItemMetadata" load_steps=4 format=3 uid="uid://cl7jvdu2lnv2d"]
[ext_resource type="Script" path="res://Utils/ScenePath.cs" id="1_mh5y8"]
[ext_resource type="Script" path="res://Items/ItemMetadata.cs" id="2_asbkr"]
[sub_resource type="Resource" id="Resource_qqiwa"]
script = ExtResource("1_mh5y8")
Path = "res://Items/Weapons/Sword.tscn"
[resource]
script = ExtResource("2_asbkr")
Instance = SubResource("Resource_qqiwa")
Name = "Sword"
Description = "A basic sword."

View File

@ -1,6 +1,8 @@
[gd_scene load_steps=25 format=3 uid="uid://dvqap2uhcah63"] [gd_scene load_steps=29 format=3 uid="uid://dvqap2uhcah63"]
[ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mlo73"] [ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mlo73"]
[ext_resource type="Script" path="res://Utils/ScenePath.cs" id="2_g8hkw"]
[ext_resource type="Script" path="res://Items/ItemMetadata.cs" id="2_gy7e7"]
[ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_vwirq"] [ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_vwirq"]
[ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_nw6r0"] [ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_nw6r0"]
[ext_resource type="Texture2D" uid="uid://dp7osg05ip5oo" path="res://Assets/Sprites/sword.png" id="3_r75ni"] [ext_resource type="Texture2D" uid="uid://dp7osg05ip5oo" path="res://Assets/Sprites/sword.png" id="3_r75ni"]
@ -15,6 +17,16 @@
[ext_resource type="Texture2D" uid="uid://cmvh6pc71ir1m" path="res://Assets/Sprites/sword-swing-large.png" id="10_672jv"] [ext_resource type="Texture2D" uid="uid://cmvh6pc71ir1m" path="res://Assets/Sprites/sword-swing-large.png" id="10_672jv"]
[ext_resource type="AudioStream" uid="uid://qvthq6tppp63" path="res://Assets/Sounds/whoosh.wav" id="10_mfnl7"] [ext_resource type="AudioStream" uid="uid://qvthq6tppp63" path="res://Assets/Sounds/whoosh.wav" id="10_mfnl7"]
[sub_resource type="Resource" id="Resource_qqiwa"]
script = ExtResource("2_g8hkw")
Path = "res://Items/Weapons/Sword.tscn"
[sub_resource type="Resource" id="Resource_advps"]
script = ExtResource("2_gy7e7")
Instance = SubResource("Resource_qqiwa")
Name = "The Fool's Sword"
Description = "The Top Right's Sword"
[sub_resource type="Environment" id="Environment_72txp"] [sub_resource type="Environment" id="Environment_72txp"]
background_mode = 3 background_mode = 3
glow_enabled = true glow_enabled = true
@ -320,6 +332,7 @@ Knockback = 64.0
ShouldHideIdle = true ShouldHideIdle = true
PlayerLevelGain = 1.0 PlayerLevelGain = 1.0
HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand") HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand")
Metadata = SubResource("Resource_advps")
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_vwirq") script = ExtResource("2_vwirq")

View File

@ -0,0 +1,22 @@
using Godot;
namespace SupaLidlGame.Utils;
[GlobalClass]
public partial class ResourcePath : Resource
{
private static Godot.Collections.Dictionary<string, Resource> _loaded;
static ResourcePath()
{
_loaded = new();
}
[Export(Godot.PropertyHint.File)]
public string Path { get; set; }
public T Load<T>() where T : Resource
{
return GD.Load<T>(Path);
}
}

32
Utils/ScenePath.cs 100644
View File

@ -0,0 +1,32 @@
using Godot;
namespace SupaLidlGame.Utils;
[GlobalClass]
public partial class ScenePath : ResourcePath
{
private static Godot.Collections.Dictionary<string, PackedScene> _loaded;
static ScenePath()
{
_loaded = new();
}
public PackedScene Load(bool useCached = false)
{
if (useCached && _loaded.ContainsKey(Path))
{
return _loaded[Path];
}
// add scene to loaded to not have to reload scene when called again
var scene = base.Load<PackedScene>();
_loaded.Add(Path, scene);
return scene;
}
public T Instantiate<T>() where T : Node
{
return Load().Instantiate<T>();
}
}