WIP
This commit is contained in:
Generated
+1
@@ -0,0 +1 @@
|
||||
Babushka
|
||||
@@ -4,19 +4,22 @@ importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://b3kyrsoobmkhp"
|
||||
valid=false
|
||||
path="res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://art/mockups/3d/best_house_blender.blend"
|
||||
dest_files=["res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"]
|
||||
|
||||
[params]
|
||||
|
||||
nodes/root_type=""
|
||||
nodes/root_name=""
|
||||
nodes/root_script=null
|
||||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=1.0
|
||||
nodes/import_as_skeleton_bones=false
|
||||
nodes/use_name_suffixes=true
|
||||
nodes/use_node_type_suffixes=true
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
@@ -31,6 +34,9 @@ animation/trimming=false
|
||||
animation/remove_immutable_tracks=true
|
||||
animation/import_rest_as_RESET=false
|
||||
import_script/path=""
|
||||
materials/extract=0
|
||||
materials/extract_format=0
|
||||
materials/extract_path=""
|
||||
_subresources={}
|
||||
blender/nodes/visible=0
|
||||
blender/nodes/active_collection_only=false
|
||||
@@ -50,3 +56,4 @@ blender/materials/export_materials=1
|
||||
blender/animation/limit_playback=true
|
||||
blender/animation/always_sample=true
|
||||
blender/animation/group_tracks=true
|
||||
gltf/naming_version=0
|
||||
|
||||
+3
-1
@@ -11,7 +11,7 @@ config_version=5
|
||||
[application]
|
||||
|
||||
config/name="Babushka"
|
||||
run/main_scene="uid://bopv10dqm1knc"
|
||||
run/main_scene="uid://66pmq4efjip8"
|
||||
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
|
||||
run/max_fps=120
|
||||
boot_splash/fullsize=false
|
||||
@@ -188,6 +188,8 @@ directories/tres_directory={
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/size/window_width_override=1200
|
||||
window/size/window_height_override=720
|
||||
window/stretch/mode="viewport"
|
||||
window/stretch/aspect="keep_height"
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -186,7 +186,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
|
||||
private void SetActiveHarvestablePlant(bool active)
|
||||
{
|
||||
_harvestablePlant.IsActive = active;
|
||||
//_harvestablePlant.IsActive = active;
|
||||
_harvestablePlant.UpdateVisuals();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||
using Godot;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
// Do not instantiate this resource
|
||||
// But it has to be a resource because Godot
|
||||
[GlobalClass]
|
||||
public partial class ItemInstance: Resource
|
||||
public partial class ItemInstance : Resource, IJsonSerializable
|
||||
{
|
||||
[Export] public required ItemResource blueprint;
|
||||
[Export] public int amount = 1;
|
||||
@@ -17,4 +20,18 @@ public partial class ItemInstance: Resource
|
||||
amount = amount
|
||||
};
|
||||
}
|
||||
|
||||
public void LoadFromJson(JObject json)
|
||||
{
|
||||
var blueprintPath = json.GetStringValue("blueprint");
|
||||
blueprint = GD.Load<ItemResource>(blueprintPath);
|
||||
amount = json.GetIntValue("amount");
|
||||
}
|
||||
|
||||
public JObject SaveToJson()
|
||||
{
|
||||
return new(
|
||||
new JProperty("blueprint", blueprint.ResourcePath),
|
||||
new JProperty("amount", amount));
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,16 @@
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGround2D : Node, ISaveable
|
||||
public partial class ItemOnGround2D : PositionalEntity
|
||||
{
|
||||
private ItemInstance _itemInstance;
|
||||
|
||||
[Export] public bool IsActive = true;
|
||||
[Export] private bool _infiniteSupply = false;
|
||||
[Export] private int _finiteSupply = 1;
|
||||
[Export] private bool _saveToDisk = true;
|
||||
|
||||
private int pickUpCounter = 0;
|
||||
|
||||
[Signal] public delegate void SuccessfulPickUpEventHandler();
|
||||
|
||||
|
||||
@@ -34,16 +30,12 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LoadFromSaveData();
|
||||
UpdateVisuals();
|
||||
_pickupErrorLabel.Text = "";
|
||||
}
|
||||
|
||||
public void TryPickUp()
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
||||
EmitSignal(SignalName.SuccessfulPickUp);
|
||||
if (result == InventoryActionResult.Success)
|
||||
@@ -58,16 +50,7 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
|
||||
private void Pickup()
|
||||
{
|
||||
if (!_infiniteSupply)
|
||||
{
|
||||
pickUpCounter++;
|
||||
if (pickUpCounter >= _finiteSupply)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
UpdateSaveData();
|
||||
}
|
||||
// remove from entity manager
|
||||
}
|
||||
|
||||
private void FailToPickup()
|
||||
@@ -80,9 +63,6 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
|
||||
public void UpdateVisuals()
|
||||
{
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
_iconSprite.Texture = itemInstance?.blueprint?.icon;
|
||||
if (_iconSprite.Texture == null)
|
||||
{
|
||||
@@ -94,7 +74,20 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
}
|
||||
}
|
||||
|
||||
// todo: What do we do with instances that are created at runtime?
|
||||
protected override void LoadEntity(JObject json)
|
||||
{
|
||||
base.LoadEntity(json);
|
||||
_itemInstance.LoadFromJson(json.GetObject("item"));
|
||||
}
|
||||
|
||||
protected override void SaveEntity(JObject json)
|
||||
{
|
||||
base.SaveEntity(json);
|
||||
json["item"] = _itemInstance.SaveToJson();
|
||||
}
|
||||
|
||||
// old save
|
||||
/*
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
if (!_saveToDisk)
|
||||
@@ -157,5 +150,5 @@ public partial class ItemOnGround2D : Node, ISaveable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Godot;
|
||||
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||
using Godot;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
|
||||
@@ -18,12 +18,24 @@ public static class EntityLoadSaveUtil
|
||||
return json.Value<long>(key);
|
||||
}
|
||||
|
||||
public static int GetIntValue(this JObject json, string key)
|
||||
{
|
||||
AssertTokenType(json, key, JTokenType.Integer);
|
||||
return json.Value<int>(key);
|
||||
}
|
||||
|
||||
public static float GetFloatValue(this JObject json, string key)
|
||||
{
|
||||
AssertTokenType(json, key, JTokenType.Float);
|
||||
return json.Value<float>(key);
|
||||
}
|
||||
|
||||
public static JObject GetObject(this JObject json, string key)
|
||||
{
|
||||
AssertTokenType(json, key, JTokenType.Object);
|
||||
return json.Value<JObject>(key)!;
|
||||
}
|
||||
|
||||
public static string GetStringValue(this JObject json, string key)
|
||||
{
|
||||
AssertTokenType(json, key, JTokenType.String);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||
|
||||
public interface IJsonSerializable
|
||||
{
|
||||
public void LoadFromJson(JObject json);
|
||||
public JObject SaveToJson();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cuma3347l55mb
|
||||
Reference in New Issue
Block a user