Compare commits

...

2 Commits

Author SHA1 Message Date
John Montagu, the 4th Earl of Sandvich cfb8527a42 Fix broken WorldEnvironment for maps 2024-10-05 15:52:31 -07:00
HumanoidSandvichDispenser c85aeb6b5b
Implement saving and loading hotbar state (#45) 2024-10-05 15:46:40 -07:00
13 changed files with 104 additions and 52 deletions

View File

@ -11,10 +11,11 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
[Export] [Export]
public Array<Item> Hotbar { get; private set; } public Array<Item> Hotbar { get; private set; }
[Export] public Array<int> HotbarToItemIndexMap { get; set; } = new();
public Array<ItemMetadata> Items { get; private set; }
[Export] [Export]
public Array<ItemMetadata> Items { get; set; }
public Dictionary<string, int> InventoryMap { get; set; } public Dictionary<string, int> InventoryMap { get; set; }
[Signal] [Signal]
@ -62,6 +63,12 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
public bool IsUsingItem => SelectedItem?.IsUsing ?? false; public bool IsUsingItem => SelectedItem?.IsUsing ?? false;
public Inventory()
{
HotbarToItemIndexMap.Resize(HotbarCapacity);
HotbarToItemIndexMap.Fill(-1);
}
public override void _Ready() public override void _Ready()
{ {
if (Hotbar is null) if (Hotbar is null)
@ -155,7 +162,19 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
return item; return item;
} }
public Item SetHotbarIndexToItem(int index, ItemMetadata metadata) 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)
{ {
var oldItem = Hotbar[index]; var oldItem = Hotbar[index];
Item newItem = null; Item newItem = null;

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=30 format=3 uid="uid://5y1acxl4j4n7"] [gd_scene load_steps=29 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"]
@ -19,11 +19,6 @@
[ext_resource type="AudioStream" uid="uid://qvthq6tppp63" path="res://Assets/Sounds/whoosh.wav" id="12_a8o3x"] [ext_resource type="AudioStream" uid="uid://qvthq6tppp63" path="res://Assets/Sounds/whoosh.wav" id="12_a8o3x"]
[ext_resource type="AudioStream" uid="uid://c4n7ioxpukdwi" path="res://Assets/Sounds/parry.wav" id="13_t5wmj"] [ext_resource type="AudioStream" uid="uid://c4n7ioxpukdwi" path="res://Assets/Sounds/parry.wav" id="13_t5wmj"]
[sub_resource type="Environment" id="Environment_72txp"]
background_mode = 3
glow_enabled = true
glow_hdr_threshold = 1.42
[sub_resource type="Animation" id="Animation_b7327"] [sub_resource type="Animation" id="Animation_b7327"]
length = 0.001 length = 0.001
tracks/0/type = "value" tracks/0/type = "value"
@ -382,9 +377,6 @@ IdleState = NodePath("../Idle")
UseState = NodePath("../Anticipate") UseState = NodePath("../Anticipate")
BlockAnimKey = "block" BlockAnimKey = "block"
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_72txp")
[node name="Anchor" type="Node2D" parent="."] [node name="Anchor" type="Node2D" parent="."]
y_sort_enabled = true y_sort_enabled = true
rotation = 3.14159 rotation = 3.14159

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://dvqap2uhcah63"] [gd_scene load_steps=25 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="Resource" uid="uid://cl7jvdu2lnv2d" path="res://Items/Weapons/Sword.tres" id="2_atd4f"] [ext_resource type="Resource" uid="uid://cl7jvdu2lnv2d" path="res://Items/Weapons/Sword.tres" id="2_atd4f"]
@ -16,11 +16,6 @@
[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="Environment" id="Environment_72txp"]
background_mode = 3
glow_enabled = true
glow_hdr_threshold = 1.42
[sub_resource type="Curve" id="Curve_4cxtp"] [sub_resource type="Curve" id="Curve_4cxtp"]
_data = [Vector2(0.00687286, 1), 0.0, 0.0, 0, 0, Vector2(0.879725, 0.190909), -2.93145, -2.93145, 0, 0, Vector2(1, 0.0454545), 0.0483926, 0.0, 0, 0] _data = [Vector2(0.00687286, 1), 0.0, 0.0, 0, 0, Vector2(0.879725, 0.190909), -2.93145, -2.93145, 0, 0, Vector2(1, 0.0454545), 0.0483926, 0.0, 0, 0]
point_count = 3 point_count = 3
@ -380,9 +375,6 @@ script = ExtResource("5_hmisb")
Sword = NodePath("../..") Sword = NodePath("../..")
IdleState = NodePath("../Idle") IdleState = NodePath("../Idle")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_72txp")
[node name="Anchor" type="Node2D" parent="."] [node name="Anchor" type="Node2D" parent="."]
y_sort_enabled = true y_sort_enabled = true
rotation = -1.5708 rotation = -1.5708

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=49 format=4 uid="uid://b2x17su05ou5w"] [gd_scene load_steps=50 format=4 uid="uid://b2x17su05ou5w"]
[ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_ifiic"] [ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_ifiic"]
[ext_resource type="TileSet" uid="uid://l61kbx31ug4p" path="res://Scenes/Maps/ArenaTileset.tres" id="2_x0mh7"] [ext_resource type="TileSet" uid="uid://l61kbx31ug4p" path="res://Scenes/Maps/ArenaTileset.tres" id="2_x0mh7"]
@ -17,6 +17,7 @@
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd" id="11_q01ik"] [ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd" id="11_q01ik"]
[ext_resource type="Texture2D" uid="uid://c1a7lvb4uuwfy" path="res://Assets/Sprites/Particles/circle-16.png" id="11_yjp7m"] [ext_resource type="Texture2D" uid="uid://c1a7lvb4uuwfy" path="res://Assets/Sprites/Particles/circle-16.png" id="11_yjp7m"]
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="12_ca3oh"] [ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="12_ca3oh"]
[ext_resource type="Environment" uid="uid://bl15544uvuppq" path="res://Scenes/Maps/ArenaEnvironment.tres" id="18_m6btu"]
[sub_resource type="AtlasTexture" id="AtlasTexture_7aiot"] [sub_resource type="AtlasTexture" id="AtlasTexture_7aiot"]
atlas = ExtResource("5_5ley7") atlas = ExtResource("5_5ley7")
@ -409,6 +410,9 @@ visible = false
[node name="Entrance" type="Marker2D" parent="Markers" index="0"] [node name="Entrance" type="Marker2D" parent="Markers" index="0"]
position = Vector2(0, 352) position = Vector2(0, 352)
[node name="WorldEnvironment" parent="." index="7"]
environment = ExtResource("18_m6btu")
[node name="CanvasLayer" type="CanvasLayer" parent="." index="8"] [node name="CanvasLayer" type="CanvasLayer" parent="." index="8"]
layer = -99 layer = -99

View File

@ -0,0 +1,16 @@
[gd_resource type="Environment" load_steps=3 format=3 uid="uid://bl15544uvuppq"]
[sub_resource type="Gradient" id="Gradient_u5tnr"]
offsets = PackedFloat32Array(0, 0.933649, 1)
colors = PackedColorArray(0, 0, 0, 1, 0.938186, 0.874428, 0.818076, 1, 1, 1, 1, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_ri0vy"]
gradient = SubResource("Gradient_u5tnr")
[resource]
background_mode = 3
glow_enabled = true
glow_intensity = 4.0
adjustment_enabled = true
adjustment_saturation = 0.75
adjustment_color_correction = SubResource("GradientTexture1D_ri0vy")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=96 format=4 uid="uid://dr3bcvql7burk"] [gd_scene load_steps=94 format=4 uid="uid://dr3bcvql7burk"]
[ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_ci4ij"] [ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_ci4ij"]
[ext_resource type="TileSet" uid="uid://l61kbx31ug4p" path="res://Scenes/Maps/ArenaTileset.tres" id="2_m6h7j"] [ext_resource type="TileSet" uid="uid://l61kbx31ug4p" path="res://Scenes/Maps/ArenaTileset.tres" id="2_m6h7j"]
@ -42,6 +42,7 @@
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd" id="39_48cwk"] [ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2d.gd" id="39_48cwk"]
[ext_resource type="Script" path="res://BoundingBoxes/CameraTrigger.cs" id="39_50gr5"] [ext_resource type="Script" path="res://BoundingBoxes/CameraTrigger.cs" id="39_50gr5"]
[ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="40_h1ykh"] [ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="40_h1ykh"]
[ext_resource type="Environment" uid="uid://bl15544uvuppq" path="res://Scenes/Maps/ArenaEnvironment.tres" id="44_kuply"]
[ext_resource type="Script" path="res://BoundingBoxes/OcclusionTrigger.cs" id="44_oj3d3"] [ext_resource type="Script" path="res://BoundingBoxes/OcclusionTrigger.cs" id="44_oj3d3"]
[sub_resource type="Gradient" id="Gradient_jupxw"] [sub_resource type="Gradient" id="Gradient_jupxw"]
@ -363,21 +364,6 @@ agent_radius = 8.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_te7jt"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_te7jt"]
size = Vector2(112, 64) size = Vector2(112, 64)
[sub_resource type="Gradient" id="Gradient_u5tnr"]
offsets = PackedFloat32Array(0.455224, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_ri0vy"]
gradient = SubResource("Gradient_u5tnr")
[sub_resource type="Environment" id="Environment_6j53s"]
background_mode = 3
tonemap_mode = 3
glow_enabled = true
glow_intensity = 4.0
adjustment_enabled = true
adjustment_saturation = 0.01
adjustment_color_correction = SubResource("GradientTexture1D_ri0vy")
[sub_resource type="Gradient" id="Gradient_yn44d"] [sub_resource type="Gradient" id="Gradient_yn44d"]
offsets = PackedFloat32Array(0) offsets = PackedFloat32Array(0)
colors = PackedColorArray(0.105882, 0.0470588, 0.117647, 1) colors = PackedColorArray(0.105882, 0.0470588, 0.117647, 1)
@ -1134,7 +1120,7 @@ shape = SubResource("RectangleShape2D_te7jt")
position = Vector2(576, 431) position = Vector2(576, 431)
[node name="WorldEnvironment" parent="." index="7"] [node name="WorldEnvironment" parent="." index="7"]
environment = SubResource("Environment_6j53s") environment = ExtResource("44_kuply")
[node name="CanvasLayer" type="CanvasLayer" parent="." index="8"] [node name="CanvasLayer" type="CanvasLayer" parent="." index="8"]
layer = -99 layer = -99

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=4 uid="uid://cumi1cbg6xfdd"] [gd_scene load_steps=20 format=4 uid="uid://cumi1cbg6xfdd"]
[ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_oy3cp"] [ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_oy3cp"]
[ext_resource type="TileSet" uid="uid://dkis3rb4n62cu" path="res://Scenes/Maps/ForestTileset.tres" id="2_q0kvn"] [ext_resource type="TileSet" uid="uid://dkis3rb4n62cu" path="res://Scenes/Maps/ForestTileset.tres" id="2_q0kvn"]
@ -41,11 +41,22 @@ source_geometry_group_name = &"navigation"
cell_size = 16.0 cell_size = 16.0
agent_radius = 8.0 agent_radius = 8.0
[node name="TileMap" node_paths=PackedStringArray("Entities", "Areas", "Spawners", "Markers") groups=["navigation"] instance=ExtResource("1_oy3cp")] [sub_resource type="Gradient" id="Gradient_pc2cc"]
Entities = NodePath("Entities") offsets = PackedFloat32Array(0, 0.962085, 1)
Areas = NodePath("Areas") colors = PackedColorArray(0, 0, 0, 1, 1, 0.911833, 0.77, 1, 1, 1, 1, 1)
Spawners = NodePath("Spawners")
Markers = NodePath("Markers") [sub_resource type="GradientTexture1D" id="GradientTexture1D_s5jwl"]
gradient = SubResource("Gradient_pc2cc")
[sub_resource type="Environment" id="Environment_usobl"]
background_mode = 3
glow_enabled = true
glow_hdr_threshold = 1.2
adjustment_enabled = true
adjustment_saturation = 0.7
adjustment_color_correction = SubResource("GradientTexture1D_s5jwl")
[node name="TileMap" groups=["navigation"] instance=ExtResource("1_oy3cp")]
AreaName = "Forest" AreaName = "Forest"
MapName = "Forest" MapName = "Forest"
@ -441,12 +452,8 @@ position = Vector2(1272, 0)
[node name="Campfire" parent="Entities" index="0" instance=ExtResource("3_ve4i2")] [node name="Campfire" parent="Entities" index="0" instance=ExtResource("3_ve4i2")]
position = Vector2(-24, -8) position = Vector2(-24, -8)
[node name="SnusDealer" parent="Entities" index="1" node_paths=PackedStringArray("ThinkerStateMachine", "Sprite", "Inventory", "StateMachine") instance=ExtResource("12_eyny2")] [node name="SnusDealer" parent="Entities" index="1" instance=ExtResource("12_eyny2")]
position = Vector2(79, -6) position = Vector2(79, -6)
ThinkerStateMachine = NodePath("Thinker")
Sprite = NodePath("Sprites/Sprite")
Inventory = NodePath("Inventory")
StateMachine = NodePath("StateMachine")
[node name="Areas" parent="." index="4"] [node name="Areas" parent="." index="4"]
visible = false visible = false
@ -456,3 +463,6 @@ navigation_polygon = SubResource("NavigationPolygon_al0u7")
[node name="House" type="NavigationRegion2D" parent="Areas" index="1"] [node name="House" type="NavigationRegion2D" parent="Areas" index="1"]
navigation_polygon = SubResource("NavigationPolygon_8xwo5") navigation_polygon = SubResource("NavigationPolygon_8xwo5")
[node name="WorldEnvironment" parent="." index="7"]
environment = SubResource("Environment_usobl")

View File

@ -76,6 +76,19 @@ public partial class GlobalState : Node
Progression = save.Progression; Progression = save.Progression;
MapState = save.MapState; MapState = save.MapState;
Stats = save.Stats; 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) public void ExportToSave(Save save)
@ -83,5 +96,9 @@ public partial class GlobalState : Node
save.Progression = Progression; save.Progression = Progression;
save.MapState = MapState; save.MapState = MapState;
save.Stats = Stats; save.Stats = Stats;
var inventory = World.Instance.CurrentPlayer.Inventory;
Stats.Items = inventory.Items;
Stats.HotbarToItemIndexMap = inventory.HotbarToItemIndexMap;
} }
} }

View File

@ -1,4 +1,5 @@
using Godot; using Godot;
using Godot.Collections;
namespace SupaLidlGame.State.Global; namespace SupaLidlGame.State.Global;
@ -13,4 +14,10 @@ public partial class Stats : Resource
[Export] [Export]
public int DeathCount { get; set; } = 0; public int DeathCount { get; set; } = 0;
[Export]
public Array<Items.ItemMetadata> Items { get; set; } = new();
[Export]
public Array<int> HotbarToItemIndexMap { get; set; } = new();
} }

View File

@ -72,6 +72,7 @@ public partial class InventoryGrid : GridContainer
ItemMetadata item = items.Current; ItemMetadata item = items.Current;
slot.Item = item; slot.Item = item;
slot.Index = i;
} }
// make remaining slots display empty // make remaining slots display empty
@ -80,6 +81,7 @@ public partial class InventoryGrid : GridContainer
InventorySlot slot = children[i] as InventorySlot; InventorySlot slot = children[i] as InventorySlot;
slot.Item = null; slot.Item = null;
slot.Index = i;
} }
} }

View File

@ -76,6 +76,6 @@ public partial class InventoryMenu : BaseMenu, IModal
{ {
int slot = button.GetMeta("slot").AsInt32(); int slot = button.GetMeta("slot").AsInt32();
GD.Print("Equipping item at slot " + slot); GD.Print("Equipping item at slot " + slot);
Source.SetHotbarIndexToItem(slot, _selected.Item); Source.SetHotbarIndexToItemIndex(slot, _selected.Index);
} }
} }

View File

@ -33,6 +33,8 @@ public partial class InventorySlot : Button
private static Texture2D _placeholderTexture; private static Texture2D _placeholderTexture;
public int Index { get; set; }
private Items.ItemMetadata _item; private Items.ItemMetadata _item;
public Items.ItemMetadata Item public Items.ItemMetadata Item

View File

@ -21,7 +21,12 @@ public partial class ScenePath : ResourcePath
// add scene to loaded to not have to reload scene when called again // add scene to loaded to not have to reload scene when called again
var scene = base.Load<PackedScene>(); var scene = base.Load<PackedScene>();
if (useCached)
{
_loaded.Add(Path, scene); _loaded.Add(Path, scene);
}
return scene; return scene;
} }