Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bfe1be0145 | |||
| 745f54b375 | |||
| 59d313d97d |
Generated
+1
@@ -0,0 +1 @@
|
|||||||
|
Babushka
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="project" />
|
||||||
|
</component>
|
||||||
@@ -8,4 +8,7 @@
|
|||||||
<Folder Include="prefabs\UI\Inventory\" />
|
<Folder Include="prefabs\UI\Inventory\" />
|
||||||
<Folder Include="scripts\CSharp\Low Code\Randomizer\" />
|
<Folder Include="scripts\CSharp\Low Code\Randomizer\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -4,19 +4,22 @@ importer="scene"
|
|||||||
importer_version=1
|
importer_version=1
|
||||||
type="PackedScene"
|
type="PackedScene"
|
||||||
uid="uid://b3kyrsoobmkhp"
|
uid="uid://b3kyrsoobmkhp"
|
||||||
valid=false
|
path="res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://art/mockups/3d/best_house_blender.blend"
|
source_file="res://art/mockups/3d/best_house_blender.blend"
|
||||||
|
dest_files=["res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
nodes/root_type=""
|
nodes/root_type=""
|
||||||
nodes/root_name=""
|
nodes/root_name=""
|
||||||
|
nodes/root_script=null
|
||||||
nodes/apply_root_scale=true
|
nodes/apply_root_scale=true
|
||||||
nodes/root_scale=1.0
|
nodes/root_scale=1.0
|
||||||
nodes/import_as_skeleton_bones=false
|
nodes/import_as_skeleton_bones=false
|
||||||
|
nodes/use_name_suffixes=true
|
||||||
nodes/use_node_type_suffixes=true
|
nodes/use_node_type_suffixes=true
|
||||||
meshes/ensure_tangents=true
|
meshes/ensure_tangents=true
|
||||||
meshes/generate_lods=true
|
meshes/generate_lods=true
|
||||||
@@ -31,6 +34,9 @@ animation/trimming=false
|
|||||||
animation/remove_immutable_tracks=true
|
animation/remove_immutable_tracks=true
|
||||||
animation/import_rest_as_RESET=false
|
animation/import_rest_as_RESET=false
|
||||||
import_script/path=""
|
import_script/path=""
|
||||||
|
materials/extract=0
|
||||||
|
materials/extract_format=0
|
||||||
|
materials/extract_path=""
|
||||||
_subresources={}
|
_subresources={}
|
||||||
blender/nodes/visible=0
|
blender/nodes/visible=0
|
||||||
blender/nodes/active_collection_only=false
|
blender/nodes/active_collection_only=false
|
||||||
@@ -50,3 +56,4 @@ blender/materials/export_materials=1
|
|||||||
blender/animation/limit_playback=true
|
blender/animation/limit_playback=true
|
||||||
blender/animation/always_sample=true
|
blender/animation/always_sample=true
|
||||||
blender/animation/group_tracks=true
|
blender/animation/group_tracks=true
|
||||||
|
gltf/naming_version=0
|
||||||
|
|||||||
+3
-1
@@ -11,7 +11,7 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Babushka"
|
config/name="Babushka"
|
||||||
run/main_scene="uid://bopv10dqm1knc"
|
run/main_scene="uid://66pmq4efjip8"
|
||||||
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
|
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
|
||||||
run/max_fps=120
|
run/max_fps=120
|
||||||
boot_splash/fullsize=false
|
boot_splash/fullsize=false
|
||||||
@@ -188,6 +188,8 @@ directories/tres_directory={
|
|||||||
|
|
||||||
window/size/viewport_width=1920
|
window/size/viewport_width=1920
|
||||||
window/size/viewport_height=1080
|
window/size/viewport_height=1080
|
||||||
|
window/size/window_width_override=1200
|
||||||
|
window/size/window_height_override=720
|
||||||
window/stretch/mode="viewport"
|
window/stretch/mode="viewport"
|
||||||
window/stretch/aspect="keep_height"
|
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)
|
private void SetActiveHarvestablePlant(bool active)
|
||||||
{
|
{
|
||||||
_harvestablePlant.IsActive = active;
|
//_harvestablePlant.IsActive = active;
|
||||||
_harvestablePlant.UpdateVisuals();
|
_harvestablePlant.UpdateVisuals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
// Do not instantiate this resource
|
// Do not instantiate this resource
|
||||||
// But it has to be a resource because Godot
|
// But it has to be a resource because Godot
|
||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class ItemInstance: Resource
|
public partial class ItemInstance : Resource, IJsonSerializable
|
||||||
{
|
{
|
||||||
[Export] public required ItemResource blueprint;
|
[Export] public required ItemResource blueprint;
|
||||||
[Export] public int amount = 1;
|
[Export] public int amount = 1;
|
||||||
@@ -17,4 +20,18 @@ public partial class ItemInstance: Resource
|
|||||||
amount = amount
|
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,23 +1,19 @@
|
|||||||
using Babushka.scripts.CSharp.Common.Savegame;
|
using Babushka.scripts.CSharp.Common.Savegame;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
public partial class ItemOnGround2D : Node, ISaveable
|
public partial class ItemOnGround2D : PositionalEntity
|
||||||
{
|
{
|
||||||
private ItemInstance _itemInstance;
|
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();
|
[Signal] public delegate void SuccessfulPickUpEventHandler();
|
||||||
|
|
||||||
|
|
||||||
private Label _itemLabel => GetNode<Label>("ItemLabel");
|
private Label _itemLabel => GetNode<Label>("ItemLabel");
|
||||||
private Label _pickupErrorLabel => GetNode<Label>("PickupErrorLabel");
|
private Label _pickupErrorLabel => GetNode<Label>("PickupErrorLabel");
|
||||||
private Sprite2D _iconSprite => GetNode<Sprite2D>("Icon");
|
private Sprite2D _iconSprite => GetNode<Sprite2D>("Icon");
|
||||||
@@ -34,16 +30,12 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
LoadFromSaveData();
|
|
||||||
UpdateVisuals();
|
UpdateVisuals();
|
||||||
_pickupErrorLabel.Text = "";
|
_pickupErrorLabel.Text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TryPickUp()
|
public void TryPickUp()
|
||||||
{
|
{
|
||||||
if (!IsActive)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
||||||
EmitSignal(SignalName.SuccessfulPickUp);
|
EmitSignal(SignalName.SuccessfulPickUp);
|
||||||
if (result == InventoryActionResult.Success)
|
if (result == InventoryActionResult.Success)
|
||||||
@@ -58,16 +50,7 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
|
|
||||||
private void Pickup()
|
private void Pickup()
|
||||||
{
|
{
|
||||||
if (!_infiniteSupply)
|
// remove from entity manager
|
||||||
{
|
|
||||||
pickUpCounter++;
|
|
||||||
if (pickUpCounter >= _finiteSupply)
|
|
||||||
{
|
|
||||||
QueueFree();
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateSaveData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FailToPickup()
|
private void FailToPickup()
|
||||||
@@ -80,9 +63,6 @@ public partial class ItemOnGround2D : Node, ISaveable
|
|||||||
|
|
||||||
public void UpdateVisuals()
|
public void UpdateVisuals()
|
||||||
{
|
{
|
||||||
if (!IsActive)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_iconSprite.Texture = itemInstance?.blueprint?.icon;
|
_iconSprite.Texture = itemInstance?.blueprint?.icon;
|
||||||
if (_iconSprite.Texture == null)
|
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()
|
public void UpdateSaveData()
|
||||||
{
|
{
|
||||||
if (!_saveToDisk)
|
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;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.Types;
|
||||||
|
using Godot;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
|
||||||
|
public partial class Entity : Node2D
|
||||||
|
{
|
||||||
|
private long _id;
|
||||||
|
protected virtual EntityType Type => EntityType.None;
|
||||||
|
|
||||||
|
protected virtual void SaveEntity(JObject json)
|
||||||
|
{
|
||||||
|
json["id"] = _id;
|
||||||
|
json["type"] = (int)Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void LoadEntity(JObject json)
|
||||||
|
{
|
||||||
|
_id = json.GetLongValue("id");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://hnmpt23ovfgl
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
|
using Godot;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
|
||||||
|
public partial class PositionalEntity : Entity
|
||||||
|
{
|
||||||
|
public string sceneName = "none";
|
||||||
|
|
||||||
|
protected override void SaveEntity(JObject json)
|
||||||
|
{
|
||||||
|
base.SaveEntity(json);
|
||||||
|
json["posx"] = Position.X;
|
||||||
|
json["posy"] = Position.Y;
|
||||||
|
json["scene"] = sceneName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadEntity(JObject json)
|
||||||
|
{
|
||||||
|
base.LoadEntity(json);
|
||||||
|
Position = new Vector2(
|
||||||
|
json.GetFloatValue("posx"),
|
||||||
|
json.GetFloatValue("posy"));
|
||||||
|
sceneName = json.GetStringValue("scene");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://bs38dulqv7sop
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
|
|
||||||
|
public static class EntityLoadSaveUtil
|
||||||
|
{
|
||||||
|
private static void AssertTokenType(this JObject json, string key, JTokenType type)
|
||||||
|
{
|
||||||
|
var token = json[key];
|
||||||
|
if (token == null) throw new MalformedJsonException(json, key, "does not exist");
|
||||||
|
if (!token.HasValues) throw new MalformedJsonException(json, key, "has no value");
|
||||||
|
if (token.Type != type) throw new MalformedJsonException(json, key, $"is not of type {type}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long GetLongValue(this JObject json, string key)
|
||||||
|
{
|
||||||
|
AssertTokenType(json, key, JTokenType.Integer);
|
||||||
|
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);
|
||||||
|
return json.Value<string>(key)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://ccu6p418viliu
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
|
|
||||||
|
public class MalformedJsonException(JObject actualJson, string key, string problem) : Exception
|
||||||
|
{
|
||||||
|
public override string Message => $"JsonObject was malformed: {key} {problem}";
|
||||||
|
public override IDictionary Data => new Dictionary<string, JObject> { { "json", actualJson } };
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://d1o066hh84ow
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.Types;
|
||||||
|
using Godot;
|
||||||
|
using Entity = Babushka.scripts.CSharp.GameEntity.Entities.Entity;
|
||||||
|
using PositionalEntity = Babushka.scripts.CSharp.GameEntity.Entities.PositionalEntity;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Management;
|
||||||
|
|
||||||
|
public partial class EntityManager : Node
|
||||||
|
{
|
||||||
|
[Export] private EntityNodeCreator _nodeCreator = null!;
|
||||||
|
|
||||||
|
private EntitySceneManager? _currentEntitySceneManager;
|
||||||
|
|
||||||
|
|
||||||
|
private readonly List<Entity> _allEntities = new();
|
||||||
|
|
||||||
|
public IEnumerable<Entity> AllEntities => _allEntities;
|
||||||
|
|
||||||
|
public IEnumerable<PositionalEntity> AllPositionalEntities => _allEntities.OfType<PositionalEntity>();
|
||||||
|
|
||||||
|
public T NewPositionalEntity<T>(EntityType type, Vector2 position, string? scene = null) where T : PositionalEntity
|
||||||
|
{
|
||||||
|
if (scene == null)
|
||||||
|
{
|
||||||
|
if (_currentEntitySceneManager == null)
|
||||||
|
throw new Exception("No current scene. Specify scene to spawn an entity");
|
||||||
|
|
||||||
|
scene = _currentEntitySceneManager.sceneName;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newEntity = _nodeCreator.Create<T>(type);
|
||||||
|
newEntity.Position = position;
|
||||||
|
newEntity.sceneName = scene;
|
||||||
|
_allEntities.Add(newEntity);
|
||||||
|
|
||||||
|
_currentEntitySceneManager.AddIfNeeded(newEntity);
|
||||||
|
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnloadScene()
|
||||||
|
{
|
||||||
|
if (_currentEntitySceneManager == null) return;
|
||||||
|
_currentEntitySceneManager.RemoveAllEntities();
|
||||||
|
_currentEntitySceneManager = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadScene(EntitySceneManager sceneManager)
|
||||||
|
{
|
||||||
|
_currentEntitySceneManager = sceneManager;
|
||||||
|
foreach (var entity in AllPositionalEntities)
|
||||||
|
{
|
||||||
|
_currentEntitySceneManager.AddIfNeeded(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://umop2b1m1qm8
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using PositionalEntity = Babushka.scripts.CSharp.GameEntity.Entities.PositionalEntity;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Management;
|
||||||
|
|
||||||
|
public static class EntityManagerUtil
|
||||||
|
{
|
||||||
|
public static void AddIfNeeded(this EntitySceneManager? self, PositionalEntity entity)
|
||||||
|
{
|
||||||
|
if(self == null) return;
|
||||||
|
if(self.sceneName != entity.sceneName) return;
|
||||||
|
|
||||||
|
self.AddEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dc3283h7sx4cl
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.Types;
|
||||||
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
using Entity = Babushka.scripts.CSharp.GameEntity.Entities.Entity;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Management;
|
||||||
|
|
||||||
|
public partial class EntityNodeCreator : Node
|
||||||
|
{
|
||||||
|
[Export] private Dictionary<EntityType, PackedScene> _entityPrefabs;
|
||||||
|
|
||||||
|
public T Create<T>(EntityType type) where T:Entity
|
||||||
|
{
|
||||||
|
return _entityPrefabs[type].Instantiate<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://bogqp274y1pgr
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Godot;
|
||||||
|
using PositionalEntity = Babushka.scripts.CSharp.GameEntity.Entities.PositionalEntity;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Management;
|
||||||
|
|
||||||
|
public partial class EntitySceneManager : Node2D
|
||||||
|
{
|
||||||
|
[Export] public string sceneName = "none";
|
||||||
|
|
||||||
|
public void AddEntity(PositionalEntity entity)
|
||||||
|
{
|
||||||
|
AddChild(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveAllEntities()
|
||||||
|
{
|
||||||
|
foreach (var entity in GetChildren())
|
||||||
|
{
|
||||||
|
if (entity is PositionalEntity positionalEntity)
|
||||||
|
{
|
||||||
|
RemoveChild(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://ca1pg6k3gn47y
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Types;
|
||||||
|
|
||||||
|
public enum EntityType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Yeli = 1,
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cjygyr4lc224m
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.mock;
|
||||||
|
|
||||||
|
public static class DialogicStarter
|
||||||
|
{
|
||||||
|
public static async Task Dialog(string dialog)
|
||||||
|
{
|
||||||
|
// implement
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetValue(string key, int value)
|
||||||
|
{
|
||||||
|
// implement
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Babushka.scripts.CSharp.mock;
|
||||||
|
|
||||||
|
public static class ObjectLookup
|
||||||
|
{
|
||||||
|
// Referenzen werden bei startup gesetzt
|
||||||
|
|
||||||
|
// Quests
|
||||||
|
public static PotatoQuest potatoQuest;
|
||||||
|
|
||||||
|
// NPCs
|
||||||
|
public static YeliNpc yeliNpc;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.mock;
|
||||||
|
|
||||||
|
public partial class PotatoQuest:Node
|
||||||
|
{
|
||||||
|
// Yeli will 5 kartoffeln haben.
|
||||||
|
// Man kann Yeli auch erstmal weniger geben.
|
||||||
|
// Yeli sagt dir dann, wie viele kartoffeln noch fehlen.
|
||||||
|
|
||||||
|
public enum State
|
||||||
|
{
|
||||||
|
Unavailable, // bevor die quest verfügbar ist
|
||||||
|
YeliRequest, // Yeli fragt nach kartoffeln
|
||||||
|
BringPotato, // Vesna soll kartoffeln bringen
|
||||||
|
Done // kartoffeln abgegeben
|
||||||
|
}
|
||||||
|
|
||||||
|
public State state = State.Unavailable;
|
||||||
|
public int potatoesWanted = 5;
|
||||||
|
public int potatoesBrought = 0;
|
||||||
|
public ItemResource itemBlueprint; // potato item
|
||||||
|
|
||||||
|
public void Activate() // wird von woanders aufgerufen
|
||||||
|
{
|
||||||
|
if (state == State.Unavailable)
|
||||||
|
state = State.YeliRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dpl5xeuiu7cwg
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
using Babushka.scripts.CSharp.Common.NPC;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.mock;
|
||||||
|
|
||||||
|
// Dieses script enthält ALLE möglichen dialogoptionen die Yeli in der gesamten Demo hat.
|
||||||
|
// Das script ist dafür verantwortlich den richtigen Dialog zu starten.
|
||||||
|
public partial class YeliDialog : Node
|
||||||
|
{
|
||||||
|
public async void StartDialog() // kann zu jedem zeitpunkt vom spieler getriggert werden
|
||||||
|
{
|
||||||
|
var potato = ObjectLookup.potatoQuest;
|
||||||
|
var yeli = ObjectLookup.yeliNpc;
|
||||||
|
var inventory = InventoryManager.Instance.playerInventory!;
|
||||||
|
|
||||||
|
if (yeli.isSleeping) // wenn yeli schläft kann keine quest von ihr angenommen werden, auch wenn die quest verfügbar ist
|
||||||
|
{
|
||||||
|
await DialogicStarter.Dialog("YeliSleep"); // "ZZZ"
|
||||||
|
}
|
||||||
|
else if (potato.state == PotatoQuest.State.YeliRequest)
|
||||||
|
{
|
||||||
|
await DialogicStarter.Dialog("YeliAskForPotato"); // "Can you bring me 5 potatoes?"
|
||||||
|
potato.state = PotatoQuest.State.BringPotato;
|
||||||
|
}
|
||||||
|
else if (potato.state == PotatoQuest.State.BringPotato)
|
||||||
|
{
|
||||||
|
var potatoesTodo = potato.potatoesWanted - potato.potatoesBrought;
|
||||||
|
var potatoesAvailable = inventory.TotalItemsOfBlueprint(potato.itemBlueprint);
|
||||||
|
var takePotatoes = Math.Min(potatoesTodo, potatoesAvailable);
|
||||||
|
|
||||||
|
inventory.TryRemoveAllItems(new ItemInstance
|
||||||
|
{ blueprint = potato.itemBlueprint, amount = takePotatoes }); // should not fail
|
||||||
|
potato.potatoesWanted -= takePotatoes;
|
||||||
|
|
||||||
|
potatoesTodo = potato.potatoesWanted - potato.potatoesBrought;
|
||||||
|
|
||||||
|
var isComplete = potatoesTodo <= 0;
|
||||||
|
var wasSomeDelivered = takePotatoes > 0;
|
||||||
|
|
||||||
|
if (isComplete)
|
||||||
|
{
|
||||||
|
await DialogicStarter.Dialog("YeliPotatoThankYou"); // "thanks for bringing me all the potatoes"
|
||||||
|
potato.state = PotatoQuest.State.Done;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DialogicStarter.SetValue("potatoes", potatoesTodo); // setzt die Dialogic variable
|
||||||
|
|
||||||
|
if (wasSomeDelivered)
|
||||||
|
{
|
||||||
|
await DialogicStarter.Dialog("YeliPotatoThanksButMore"); // "thank you but i need {potatoes} more potatoes"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await DialogicStarter.Dialog("YeliPotatoMore"); // "I still need {potatoes} more potatoes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await DialogicStarter.Dialog("YeliDefault"); // "I'm happy to have you around" oder so
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://ssob0ssvbskx
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.mock;
|
||||||
|
|
||||||
|
public partial class YeliNpc : Entity
|
||||||
|
{
|
||||||
|
public bool isSleeping = false;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user