Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 745f54b375 | |||
| 59d313d97d | |||
| 9032272599 | |||
| a2ef3bfaf0 | |||
| 1ab1071246 | |||
| e5b2b8b8ab | |||
| 2fa8aa9fbc | |||
| 6deb6e29fd | |||
| edc133749f | |||
| 2ed9dbbc52 | |||
| 6375383373 | |||
| 09f55d3aa7 | |||
| a736adaafb |
Generated
+1
@@ -0,0 +1 @@
|
|||||||
|
Babushka
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -14,5 +14,9 @@ position = Vector2(23, -96)
|
|||||||
scale = Vector2(0.547474, 0.547474)
|
scale = Vector2(0.547474, 0.547474)
|
||||||
texture = SubResource("AtlasTexture_ane0o")
|
texture = SubResource("AtlasTexture_ane0o")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" parent="TargetSelection/Click" index="0"]
|
||||||
|
position = Vector2(25.215, -195)
|
||||||
|
scale = Vector2(0.72370636, 1)
|
||||||
|
|
||||||
[node name="Sprite2D" parent="TargetSelection/HoverIndicator" index="0"]
|
[node name="Sprite2D" parent="TargetSelection/HoverIndicator" index="0"]
|
||||||
position = Vector2(1, -126)
|
position = Vector2(0.84, -126)
|
||||||
|
|||||||
+5
-3
@@ -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
|
||||||
@@ -186,8 +186,10 @@ directories/tres_directory={
|
|||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/viewport_width=1980
|
window/size/viewport_width=1920
|
||||||
window/size/viewport_height=1020
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class TargetSelectActionDetail : FighterAction.FighterActionDetail
|
|||||||
// settings
|
// settings
|
||||||
public required bool selectEnemy;
|
public required bool selectEnemy;
|
||||||
public required bool selectAlly;
|
public required bool selectAlly;
|
||||||
|
public required bool aliveOnly;
|
||||||
public VisualRange visualRange = VisualRange.Single;
|
public VisualRange visualRange = VisualRange.Single;
|
||||||
|
|
||||||
// result
|
// result
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ public class AllyAttackAction : FighterAction
|
|||||||
public TargetSelectActionDetail targetSelect = new()
|
public TargetSelectActionDetail targetSelect = new()
|
||||||
{
|
{
|
||||||
selectEnemy = true,
|
selectEnemy = true,
|
||||||
selectAlly = false
|
selectAlly = false,
|
||||||
|
aliveOnly = true
|
||||||
};
|
};
|
||||||
|
|
||||||
public MinigameActionDetail minigameDetail = new();
|
public MinigameActionDetail minigameDetail = new();
|
||||||
|
|||||||
@@ -117,11 +117,13 @@ public partial class AllFightersVisual : Node
|
|||||||
if (targetDetail.selectEnemy)
|
if (targetDetail.selectEnemy)
|
||||||
_fighterVisuals
|
_fighterVisuals
|
||||||
.Where(kv => kv.Key.IsInFormation(HappeningData.enemyFighterFormation))
|
.Where(kv => kv.Key.IsInFormation(HappeningData.enemyFighterFormation))
|
||||||
|
.Where(kv => !targetDetail.aliveOnly || kv.Key.IsAlive())// if aliveOnly: take where IsAlive
|
||||||
.ForEach(kv => kv.Value.SetTargetSelectionActive(true));
|
.ForEach(kv => kv.Value.SetTargetSelectionActive(true));
|
||||||
|
|
||||||
if (targetDetail.selectAlly)
|
if (targetDetail.selectAlly)
|
||||||
_fighterVisuals
|
_fighterVisuals
|
||||||
.Where(kv => kv.Key.IsInFormation(HappeningData.allyFighterFormation))
|
.Where(kv => kv.Key.IsInFormation(HappeningData.allyFighterFormation))
|
||||||
|
.Where(kv => !targetDetail.aliveOnly || kv.Key.IsAlive())// if aliveOnly: take where IsAlive
|
||||||
.ForEach(kv => kv.Value.SetTargetSelectionActive(true));
|
.ForEach(kv => kv.Value.SetTargetSelectionActive(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -307,6 +307,11 @@ public partial class FightHappening : Node
|
|||||||
HappeningData.enemyFighterFormation.SetFighterAtPosition(emptySlotIndex, fighter);
|
HappeningData.enemyFighterFormation.SetFighterAtPosition(emptySlotIndex, fighter);
|
||||||
HappeningData.fighterTurn.AddAsLast(fighter);
|
HappeningData.fighterTurn.AddAsLast(fighter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GD.RandRange(0, 2) != 0) // 2/3 chance for vesna to start
|
||||||
|
{
|
||||||
|
HappeningData.fighterTurn.SpinBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteNextFighter()
|
private void ExecuteNextFighter()
|
||||||
|
|||||||
@@ -99,6 +99,23 @@ public class FighterTurn : IEnumerable<FightWorld.Fighter>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the current one back
|
||||||
|
/// This is an expensive operation, because the entire data structure needs to be circled
|
||||||
|
/// </summary>
|
||||||
|
public void SpinBack()
|
||||||
|
{
|
||||||
|
if (_currentNode == null) return;
|
||||||
|
|
||||||
|
var node = _currentNode;
|
||||||
|
while (node.next != _currentNode)
|
||||||
|
{
|
||||||
|
node = node.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentNode = node;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerator<FightWorld.Fighter> GetEnumerator()
|
public IEnumerator<FightWorld.Fighter> GetEnumerator()
|
||||||
{
|
{
|
||||||
if (_currentNode == null) return Enumerable.Empty<FightWorld.Fighter>().GetEnumerator();
|
if (_currentNode == null) return Enumerable.Empty<FightWorld.Fighter>().GetEnumerator();
|
||||||
|
|||||||
@@ -9,9 +9,15 @@ public partial class SwitchSceneOnFightEnd : Node
|
|||||||
|
|
||||||
public void OnFightStateEnter(FightHappening.FightState to)
|
public void OnFightStateEnter(FightHappening.FightState to)
|
||||||
{
|
{
|
||||||
if (to is FightHappening.FightState.PlayerWin
|
if (to is FightHappening.FightState.PlayerWin )
|
||||||
or FightHappening.FightState.EnemyWin)
|
|
||||||
_ = SwitchSceneAfterTime(2.0f);
|
_ = SwitchSceneAfterTime(2.0f);
|
||||||
|
|
||||||
|
if (to is FightHappening.FightState.EnemyWin)
|
||||||
|
{
|
||||||
|
_fightSceneSwitcher.ExitFight();
|
||||||
|
_fightSceneSwitcher.ExitFightWorld();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SwitchSceneAfterTime(float seconds)
|
private async Task SwitchSceneAfterTime(float seconds)
|
||||||
|
|||||||
@@ -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,20 +1,16 @@
|
|||||||
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();
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user