CORE dashboard + a lot of changes

This commit is contained in:
2026-06-22 20:09:15 +02:00
parent 19d6bd934a
commit 89fa0b23b2
101 changed files with 1525 additions and 177 deletions
@@ -5,7 +5,7 @@ using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.Actions
{
public class UseUsableAction : BaseActionParallel
public class UseUsableAction : BaseAction
{
private readonly UsableObject _usable;
@@ -19,12 +19,12 @@ namespace RPGCore.BackpackEquipment.ObjectModules.Content.Actions
protected override void OnDoIt()
{
var dropEvent = new DropEvent { unit = unit, item = _item };
var dropEvent = new ActionDropEvent { unit = unit, item = _item };
unit.events.InvokeBefore(dropEvent);
Check(!dropEvent.isPrevented, string.Format(ActionWasPreventedMessage, nameof(DropAction)));
unit.events.InvokeAfter(dropEvent);
unit.GetComponent<ContentModule>().Remove(_item);
unit.GetComponent<ContentModule>().Drop(_item);
}
protected override void OnEndIt()
@@ -19,18 +19,21 @@ namespace RPGCore.BackpackEquipment.ObjectModules.Content.Actions
public override void CanDoIt()
{
_contentOwner.CanAdd(_item, _index);
Check(
_contentOwner.CanAdd(_item, _index),
"This unit can't take that"
);
}
protected override void OnDoIt()
{
var takeEvent = new TakeEvent { unit = unit, item = _item };
var takeEvent = new ActionTakeEvent { unit = unit, item = _item };
unit.events.InvokeBefore(takeEvent);
Check(!takeEvent.isPrevented, string.Format(ActionWasPreventedMessage, nameof(TakeAction)));
unit.events.InvokeAfter(takeEvent);
var content = unit.GetComponent<ContentModule>();
content.Add(_item);
content.Take(_item);
content.TransferTo(_contentOwner, _item, _index);
}
@@ -11,14 +11,26 @@ using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.Content
{
[Serializable]
[RequireComponent(typeof(BaseObject))]
[ObjectModule(
name: "[Inventory] Content",
description: "Simple content managing attached to any implementation of <b>BaseObject</b>. " +
"By itself allows only: taking, dropping and deciding who manages items. " +
"Attach implementation of <b>"+nameof(IContentOwner)+"</b> to manage content's items."
)]
public sealed class ContentModule : ObjectModule<BaseObject>
{
// TODO: tutaj jakiś domyślny owner?
// RUNTIME
private GameObject _contentGameObject;
private Dictionary<ItemObject, IContentOwner> _items = new();
public bool Add(ItemObject item)
private void Awake()
{
_contentGameObject = new GameObject("-- CONTENT --");
_contentGameObject.transform.SetParent(transform);
_contentGameObject.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
}
public bool Take(ItemObject item)
{
if (item.data.Get<ItemObjectData>().carriedBy) return false;
if (_items.ContainsKey(item)) return false;
@@ -27,26 +39,33 @@ namespace RPGCore.BackpackEquipment.ObjectModules.Content
item.data.Get<ItemObjectData>().carriedBy = parent;
parent.events.Invoke(new ContentAddEvent{obj = parent, item = item});
item.events.Register<RemoveEvent>(OnItemRemove);
item.gameObject.SetActive(false);
item.transform.SetParent(_contentGameObject.transform);
item.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
return true;
}
public bool Remove(ItemObject item)
public bool Drop(ItemObject item)
{
if (!_items.ContainsKey(item)) return false;
_items[item]?.Remove_Internal(item);
_items.Remove(item);
item.data.Get<ItemObjectData>().carriedBy = null;
parent.events.Invoke(new ContentAddEvent{obj = parent, item = item});
parent.events.Invoke(new ContentRemoveEvent { obj = parent, item = item });
item.events.Unregister<RemoveEvent>(OnItemRemove);
item.gameObject.SetActive(true);
item.transform.SetParent(null);
return true;
}
public bool TransferTo(IContentOwner newOwner, ItemObject item, int index = -1)
{
if (parent.data.Get<ItemObjectData>().carriedBy != parent) return false;
if (item.data.Get<ItemObjectData>().carriedBy != parent) return false;
if (!newOwner.CanAdd(item, index)) return false;
@@ -58,9 +77,14 @@ namespace RPGCore.BackpackEquipment.ObjectModules.Content
return true;
}
public bool TransferFrom(ItemObject item)
{
return _items[item]?.Remove_Internal(item) ?? false;
}
private void OnItemRemove(RemoveEvent removeEvent)
{
Remove(removeEvent.obj as ItemObject);
Drop(removeEvent.obj as ItemObject);
}
}
}
@@ -4,7 +4,7 @@ using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Events
{
public class DropEvent : BasePreventableEvent<UnitObject>
public class ActionDropEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public ItemObject item;
@@ -4,7 +4,7 @@ using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.Content.Events
{
public class TakeEvent : BasePreventableEvent<UnitObject>
public class ActionTakeEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public ItemObject item;
@@ -5,14 +5,16 @@ using RPGCore.BackpackEquipment.ObjectModules.UnitBackpack.Events;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core;
using RPGCore.Core.Objects;
using RPGCoreCommon.Helpers.PropertyAttributeDrawers;
using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack
{
[RequireComponent(typeof(UnitObject))]
[RequireComponent(typeof(ContentModule))]
[DisallowMultipleComponent]
[ObjectModule(
name: "[Inventory] Backpack",
description: "Requires <b>ContentModule</b> to work. Simple backpack that can be attached to <b>UnitObject</b>."
)]
public sealed class UnitBackpackModule : ObjectModule<UnitObject>, IContentOwner
{
// TODO: implementacja stackowania tutaj
@@ -53,7 +55,7 @@ namespace RPGCore.BackpackEquipment.ObjectModules.UnitBackpack
bool IContentOwner.Add(ItemObject item, int index)
{
if (index < 0) index = Array.IndexOf(_items, false);
if (index < 0) index = Array.IndexOf(_items, null);
if (index < 0) return false;
if (isLimited && index >= itemsLimit) return false;
@@ -1,3 +1,5 @@
using RPGCore.BackpackEquipment.ObjectModules.Content;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.ObjectModules.ActionObjectModule;
@@ -16,10 +18,22 @@ namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Actions
public override void CanDoIt()
{
Check(
unit.GetComponent<UnitEquipmentModule>().CanAdd(_wearable, _index),
"This unit can't equip that"
);
}
protected override void OnDoIt()
{
var takeEvent = new ActionEquipEvent { unit = unit, wearable = _wearable };
unit.events.InvokeBefore(takeEvent);
Check(!takeEvent.isPrevented, string.Format(ActionWasPreventedMessage, nameof(EquipAction)));
unit.events.InvokeAfter(takeEvent);
var content = unit.GetComponent<ContentModule>();
var equipment = unit.GetComponent<UnitEquipmentModule>();
content.TransferTo(equipment, _wearable, _index);
}
protected override void OnEndIt() { }
@@ -1,27 +1,40 @@
using RPGCore.BackpackEquipment.ObjectModules.Content;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events;
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.ObjectModules.ActionObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Actions
{
public class UnEquipAction : BaseAction
{
private readonly WearableObject _wearable;
private readonly int _index;
public UnEquipAction(WearableObject wearable)
{
_wearable = wearable;
}
public override void CanDoIt()
{
throw new System.NotImplementedException();
}
protected override void OnDoIt()
{
throw new System.NotImplementedException();
var takeEvent = new ActionUnEquipEvent { unit = unit, wearable = _wearable };
unit.events.InvokeBefore(takeEvent);
Check(!takeEvent.isPrevented, string.Format(ActionWasPreventedMessage, nameof(UnEquipAction)));
unit.events.InvokeAfter(takeEvent);
unit.GetComponent<ContentModule>().TransferFrom(_wearable);
}
protected override void OnEndIt()
{
throw new System.NotImplementedException();
}
protected override void OnCancelIt()
{
throw new System.NotImplementedException();
}
}
}
@@ -0,0 +1,14 @@
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events
{
public class ActionEquipEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public WearableObject wearable;
public int index;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4de9db105bf64cd98dce43e3ec414e98
timeCreated: 1780567832
@@ -0,0 +1,14 @@
using RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Objects;
using RPGCore.BackpackEquipment.Objects;
using RPGCore.Core.Objects;
using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events
{
public class ActionUnEquipEvent : BasePreventableEvent<UnitObject>
{
public UnitObject unit;
public WearableObject wearable;
public int index;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 74199cbcfe30426aa9191ea3f9ab0f9c
timeCreated: 1780567872
@@ -5,7 +5,7 @@ using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events
{
public class EquipEvent : BaseEvent<UnitObject>
public class EquipmentEquipEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public WearableObject wearable;
@@ -5,7 +5,7 @@ using RPGCore.ObjectModules.EventObjectModule;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment.Events
{
public class UnEquipEvent : BaseEvent<UnitObject>
public class EquipmentUnEquipEvent : BaseEvent<UnitObject>
{
public UnitObject unit;
public WearableObject wearable;
@@ -11,9 +11,13 @@ using UnityEngine;
namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
{
[RequireComponent(typeof(UnitObject))]
[RequireComponent(typeof(ContentModule))]
[DisallowMultipleComponent]
[ObjectModule(
name: "[Inventory] Equipment",
description: "Requires <b>ContentModule</b> to work. Attached to <b>UnitObject</b>. " +
"Allows to define equipment schema which further allows to equip those wearable items."
)]
public class UnitEquipmentModule : ObjectModule<UnitObject>, IContentOwner
{
[SerializeField] private EquipmentSchemaSO _schema;
@@ -56,7 +60,7 @@ namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
{
var wearable = (WearableObject)item;
parent.events.Invoke(new EquipEvent { unit = parent, wearable = wearable, index = index });
parent.events.Invoke(new EquipmentEquipEvent { unit = parent, wearable = wearable, index = index });
_items[index] = wearable;
return true;
@@ -67,7 +71,7 @@ namespace RPGCore.BackpackEquipment.ObjectModules.UnitEquipment
var wearable = (WearableObject)item;
var index = Array.IndexOf(_items, wearable);
parent.events.Invoke(new UnEquipEvent { unit = parent, wearable = wearable, index = index });
parent.events.Invoke(new EquipmentUnEquipEvent { unit = parent, wearable = wearable, index = index });
_items[index] = null;
return true;
@@ -3,7 +3,6 @@
"rootNamespace": "RPGCore.BackpackEquipment",
"references": [
"RPGCore",
"RPGCore.StatusEffect",
"RPGCoreCommon.Settings",
"RPGCoreCommon.Helpers",
"RPGCoreCommon.DynamicValues"