Compare commits
8 Commits
2c8a024528
...
628da80ed3
| Author | SHA1 | Date |
|---|---|---|
|
|
628da80ed3 | 2 months ago |
|
|
0dfbd73978 | 2 months ago |
|
|
8a93b00e72 | 2 months ago |
|
|
ba7d550c3f | 2 months ago |
|
|
b65a3bbd6d | 2 months ago |
|
|
bcbc074c86 | 2 months ago |
|
|
745f54b375 | 2 months ago |
|
|
59d313d97d | 4 months ago |
@ -0,0 +1,15 @@
|
|||||||
|
[gd_scene load_steps=4 format=3 uid="uid://hdfejdnmp8sl"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://umop2b1m1qm8" path="res://scripts/CSharp/GameEntity/Management/EntityManager.cs" id="1_2bwns"]
|
||||||
|
[ext_resource type="Script" uid="uid://bogqp274y1pgr" path="res://scripts/CSharp/GameEntity/Management/EntityNodeCreator.cs" id="2_8m173"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://sbf12hin4kes" path="res://prefabs/Interactables/trash_object.tscn" id="3_v3vdc"]
|
||||||
|
|
||||||
|
[node name="EntityManager" type="Node" node_paths=PackedStringArray("_nodeCreator")]
|
||||||
|
script = ExtResource("1_2bwns")
|
||||||
|
_nodeCreator = NodePath("EntityCreator")
|
||||||
|
|
||||||
|
[node name="EntityCreator" type="Node" parent="."]
|
||||||
|
script = ExtResource("2_8m173")
|
||||||
|
_entityPrefabs = Dictionary[String, PackedScene]({
|
||||||
|
"TrashEntity": ExtResource("3_v3vdc")
|
||||||
|
})
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.LoadSave;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
|
||||||
|
public class Entity
|
||||||
|
{
|
||||||
|
public long id;
|
||||||
|
public virtual string EntityType => "";
|
||||||
|
|
||||||
|
public Entity()
|
||||||
|
{
|
||||||
|
id = new Random().NextInt64();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void SaveEntity(JObject json)
|
||||||
|
{
|
||||||
|
json["id"] = id;
|
||||||
|
json["type"] = EntityType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void LoadEntity(JObject json)
|
||||||
|
{
|
||||||
|
id = json.GetLongValue("id");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://hnmpt23ovfgl
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Transactions;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
|
||||||
|
public class LoadedScenesEntity : Entity
|
||||||
|
{
|
||||||
|
private HashSet<string> _loadedScenes = new();
|
||||||
|
public override string EntityType => OWN_TYPE_NAME;
|
||||||
|
public const string OWN_TYPE_NAME = "LoadedScenesEntity";
|
||||||
|
|
||||||
|
public void AddScene(string sceneName) => _loadedScenes.Add(sceneName);
|
||||||
|
|
||||||
|
public bool WasSceneLoaded(string sceneName) => _loadedScenes.Contains(sceneName);
|
||||||
|
|
||||||
|
public override void SaveEntity(JObject json)
|
||||||
|
{
|
||||||
|
base.SaveEntity(json);
|
||||||
|
json["scenes"] = new JArray(_loadedScenes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadEntity(JObject json)
|
||||||
|
{
|
||||||
|
base.LoadEntity(json);
|
||||||
|
JArray array = (JArray?) json["scenes"] ?? throw new Exception("No scenes found in LoadedScenesEntity.");
|
||||||
|
|
||||||
|
_loadedScenes = array.ToObject<HashSet<string>>()!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://rabb1y637cm5
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://bs38dulqv7sop
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
|
||||||
|
public class TrashEntity : PositionalEntity
|
||||||
|
{
|
||||||
|
public override string EntityType => OWN_TYPE_NAME;
|
||||||
|
public const string OWN_TYPE_NAME = "TrashEntity";
|
||||||
|
private EntityNodeCreator _creator;
|
||||||
|
|
||||||
|
public TrashEntity()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void InstantiateEntityNode(Node2D parent)
|
||||||
|
{
|
||||||
|
if(_creator == null) _creator = EntityManager.Instance.NodeCreator;
|
||||||
|
var entityNode = _creator.InstantiateNode(EntityType);
|
||||||
|
parent.AddChild(entityNode);
|
||||||
|
entityNode.GlobalPosition = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://c31k34epunk5t
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.EntityNodes;
|
||||||
|
|
||||||
|
public partial class TrashEntityNode : Node2D
|
||||||
|
{
|
||||||
|
private TrashEntity _trashEntity;
|
||||||
|
|
||||||
|
public void Initialize(TrashEntity trashEntity)
|
||||||
|
{
|
||||||
|
_trashEntity = trashEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://d3n8kwva4pxx5
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
using Babushka.scripts.CSharp.GameEntity.Entities;
|
||||||
|
using Babushka.scripts.CSharp.GameEntity.Management;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.GameEntity.EntityPlacer;
|
||||||
|
|
||||||
|
public partial class TrashEntityPlacer : Node2D
|
||||||
|
{
|
||||||
|
private string _trashEntityType = TrashEntity.OWN_TYPE_NAME;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
string sceneName = EntityManager.Instance.CurrentEntitySceneContainer!.sceneName;
|
||||||
|
var loadedScenesEntity = EntityManager.Instance.GetUniqueEntity<LoadedScenesEntity>();
|
||||||
|
|
||||||
|
if (!loadedScenesEntity.WasSceneLoaded(sceneName))
|
||||||
|
{
|
||||||
|
TrashEntity entity = new TrashEntity();
|
||||||
|
entity.sceneName = sceneName;
|
||||||
|
entity.position = GlobalPosition;
|
||||||
|
EntityManager.Instance.AddEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://bilg7e33usxuv
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://ccu6p418viliu
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://cuma3347l55mb
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://d1o066hh84ow
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://umop2b1m1qm8
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://dc3283h7sx4cl
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://bogqp274y1pgr
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://ca1pg6k3gn47y
|
||||||
Loading…
Reference in new issue