CORE dashboard + a lot of changes
This commit is contained in:
@@ -11,13 +11,19 @@ using UnityEngine;
|
||||
namespace RPGCore.ObjectModules.ActionObjectModule
|
||||
{
|
||||
[Serializable]
|
||||
[ObjectModule(
|
||||
name: "[Core] Actions",
|
||||
description: "[Built-in module] Module that can be attached to <b>UnitObject</b>. " +
|
||||
"Can execute any implementations of <b>BaseAction</b> with queue and/or instant execution.",
|
||||
required: true
|
||||
)]
|
||||
public class ActionModule : ObjectModule<UnitObject>
|
||||
{
|
||||
private List<BaseActionParallel> _actionParallels = new();
|
||||
private List<BaseAction> _actionParallels = new();
|
||||
private readonly List<BaseAction> _actionQueue = new();
|
||||
private BaseAction _actionCurrent;
|
||||
|
||||
public List<BaseActionParallel> actionParallels => _actionParallels.ToList();
|
||||
public List<BaseAction> actionParallels => _actionParallels.ToList();
|
||||
public List<BaseAction> actionQueue => _actionQueue.ToList();
|
||||
public BaseAction actionCurrent => _actionCurrent;
|
||||
|
||||
@@ -30,7 +36,7 @@ namespace RPGCore.ObjectModules.ActionObjectModule
|
||||
/// 1. Checks if the action can be executed outside the queue.<br/>
|
||||
/// 2. If allowed, executes the action and handles potential errors.
|
||||
/// </summary>
|
||||
public void Execute(BaseActionParallel action)
|
||||
public void Execute(BaseAction action)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace RPGCore.ObjectModules.ActionObjectModule
|
||||
{
|
||||
public abstract class BaseActionParallel : BaseAction
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e46b8a02e3894ecb87b4455602287715
|
||||
timeCreated: 1762624491
|
||||
@@ -8,7 +8,7 @@ namespace RPGCore.ObjectModules.EventObjectModule.Data
|
||||
[Serializable]
|
||||
public class BaseObjectData : BaseData<BaseObject>
|
||||
{
|
||||
[Header("Uniqueness")]
|
||||
[field: Header("Uniqueness")]
|
||||
[field: SerializeField, ReadOnly] public string guid { get; private set; } = Guid.NewGuid().ToString();
|
||||
|
||||
[Header("Display")]
|
||||
|
||||
@@ -8,7 +8,12 @@ using UnityEngine;
|
||||
namespace RPGCore.ObjectModules.EventObjectModule
|
||||
{
|
||||
[Serializable]
|
||||
[RequireComponent(typeof(BaseObject))]
|
||||
[ObjectModule(
|
||||
name: "[Core] Data",
|
||||
description: "[Built-in module] Manages all implementations of <b>BaseData</b>. " +
|
||||
"Automatically adds matching data to attached implementation of <b>BaseObject</b>.",
|
||||
required: true
|
||||
)]
|
||||
public class DataModule : ObjectModule<BaseObject>
|
||||
{
|
||||
// SERIALIZED
|
||||
@@ -48,6 +53,9 @@ namespace RPGCore.ObjectModules.EventObjectModule
|
||||
|
||||
public T Get<T>() where T : BaseData
|
||||
{
|
||||
if (!_dataDict.ContainsKey(typeof(T)))
|
||||
_dataDict.Add(typeof(T), Activator.CreateInstance(typeof(T)) as T);
|
||||
|
||||
return (T)_dataDict[typeof(T)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,28 @@
|
||||
using System.Collections.Generic;
|
||||
using RPGCore.Core;
|
||||
using RPGCore.Core.Objects;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RPGCore.ObjectModules.EventObjectModule
|
||||
{
|
||||
[Serializable]
|
||||
[ObjectModule(
|
||||
name: "[Core] Data",
|
||||
description: "[Built-in module] Manages all implementations of <b>BaseEvent</b> and <b>BasePreventableEvent</b>. " +
|
||||
"Allows for registering and invoking events by its type.",
|
||||
required: true
|
||||
)]
|
||||
public class EventModule : ObjectModule<BaseObject>
|
||||
{
|
||||
// TODO: tutaj dodać serializowane eventy w postaci SerializableDictionary<SerializableType, UnityAction>
|
||||
// TODO: dodatkowo mozna zmienić preventableEvents na dwa osobne słowniki before i after
|
||||
// TODO: 1. tutaj dodać serializowane eventy w postaci SerializableDictionary<SerializableType, UnityAction>
|
||||
// TODO: w Awake() zrobić bridge to uruchamiania serializowanych eventów jak uruchamia się ten runtimeowy
|
||||
// TODO: 2. dodatkowo mozna zmienić preventableEvents na dwa osobne słowniki before i after
|
||||
|
||||
internal readonly Dictionary<Type, Delegate> events = new();
|
||||
internal readonly Dictionary<Type, Delegate[]> preventableEvents = new();
|
||||
|
||||
/***** INVOKE *****/
|
||||
|
||||
public void Invoke<T>(T baseEvent) where T : BaseEvent
|
||||
{
|
||||
events.TryAdd(typeof(T), null);
|
||||
@@ -23,19 +33,17 @@ namespace RPGCore.ObjectModules.EventObjectModule
|
||||
public void Register<T>(Action<T> action) where T : BaseEvent
|
||||
{
|
||||
events.TryAdd(typeof(T), null);
|
||||
var temp = (Action<T>)events[typeof(T)];
|
||||
temp += action;
|
||||
events[typeof(T)] = temp;
|
||||
events[typeof(T)] = (Action<T>)events[typeof(T)] + action;
|
||||
}
|
||||
|
||||
public void Unregister<T>(Action<T> action) where T : BaseEvent
|
||||
{
|
||||
events.TryAdd(typeof(T), null);
|
||||
var temp = (Action<T>)events[typeof(T)];
|
||||
temp -= action;
|
||||
events[typeof(T)] = temp;
|
||||
events[typeof(T)] = (Action<T>)events[typeof(T)] - action;
|
||||
}
|
||||
|
||||
|
||||
/***** INVOKE BEFORE *****/
|
||||
|
||||
public void InvokeBefore<T>(T basePreventableEvent) where T : BasePreventableEvent
|
||||
{
|
||||
preventableEvents.TryAdd(typeof(T), new Delegate[2]);
|
||||
@@ -45,22 +53,25 @@ namespace RPGCore.ObjectModules.EventObjectModule
|
||||
public void RegisterBefore<T>(Action<T> action) where T : BasePreventableEvent
|
||||
{
|
||||
preventableEvents.TryAdd(typeof(T), new Delegate[2]);
|
||||
var temp = (Action<T>)preventableEvents[typeof(T)][0];
|
||||
temp += action;
|
||||
preventableEvents[typeof(T)][0] = temp;
|
||||
preventableEvents[typeof(T)][0] = (Action<T>)preventableEvents[typeof(T)][0] + action;
|
||||
}
|
||||
|
||||
public void UnregisterBefore<T>(Action<T> action) where T : BasePreventableEvent
|
||||
{
|
||||
preventableEvents.TryAdd(typeof(T), new Delegate[2]);
|
||||
var temp = (Action<T>)preventableEvents[typeof(T)][0];
|
||||
temp -= action;
|
||||
preventableEvents[typeof(T)][0] = temp;
|
||||
preventableEvents[typeof(T)][0] = (Action<T>)preventableEvents[typeof(T)][0] - action;
|
||||
}
|
||||
|
||||
|
||||
/***** INVOKE AFTER *****/
|
||||
|
||||
public void InvokeAfter<T>(T basePreventableEvent) where T : BasePreventableEvent
|
||||
{
|
||||
if (basePreventableEvent.isPrevented) throw new EventPreventedException("Event is prevented and can't be invoked!");
|
||||
if (basePreventableEvent.isPrevented)
|
||||
{
|
||||
Debug.LogWarning("Event is prevented and can't be invoked!");
|
||||
return;
|
||||
}
|
||||
|
||||
preventableEvents.TryAdd(typeof(T), new Delegate[2]);
|
||||
(preventableEvents[typeof(T)][1] as Action<T>)?.Invoke(basePreventableEvent);
|
||||
}
|
||||
@@ -68,17 +79,13 @@ namespace RPGCore.ObjectModules.EventObjectModule
|
||||
public void RegisterAfter<T>(Action<T> action) where T : BasePreventableEvent
|
||||
{
|
||||
preventableEvents.TryAdd(typeof(T), new Delegate[2]);
|
||||
var temp = (Action<T>)preventableEvents[typeof(T)][1];
|
||||
temp += action;
|
||||
preventableEvents[typeof(T)][1] = temp;
|
||||
preventableEvents[typeof(T)][1] = (Action<T>)preventableEvents[typeof(T)][1] + action;
|
||||
}
|
||||
|
||||
public void UnregisterAfter<T>(Action<T> action) where T : BasePreventableEvent
|
||||
{
|
||||
preventableEvents.TryAdd(typeof(T), new Delegate[2]);
|
||||
var temp = (Action<T>)preventableEvents[typeof(T)][1];
|
||||
temp -= action;
|
||||
preventableEvents[typeof(T)][1] = temp;
|
||||
preventableEvents[typeof(T)][1] = (Action<T>)preventableEvents[typeof(T)][1] - action;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace RPGCore.ObjectModules.EventObjectModule
|
||||
{
|
||||
public class EventPreventedException : Exception
|
||||
{
|
||||
public EventPreventedException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a647e5d4d4ed44c28fd6961d60943fe4
|
||||
timeCreated: 1761917482
|
||||
@@ -0,0 +1,15 @@
|
||||
using RPGCore.Core;
|
||||
using RPGCore.Core.Objects;
|
||||
|
||||
namespace RPGCore.ObjectModules.EventObjectModule.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Executed when <see cref="BaseObject"/> forcefully exits <see cref="Trigger"/> by non-physics means, by default
|
||||
/// it is when object is <b>Disabled</b> or <b>Removed</b>.<br/><br/>
|
||||
/// Execute this if you want to object exit its trigger.
|
||||
/// </summary>
|
||||
public class TriggerClearEvent : BaseEvent<BaseObject>
|
||||
{
|
||||
public BaseObject obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b02fda53526495c88e8c59795782dec
|
||||
timeCreated: 1779650139
|
||||
@@ -3,9 +3,12 @@ using RPGCore.Core.Objects;
|
||||
|
||||
namespace RPGCore.ObjectModules.EventObjectModule.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Executed when <see cref="BaseObject"/> enters <see cref="Trigger"/>'s colliders.
|
||||
/// </summary>
|
||||
public class TriggerEnterEvent : BaseEvent<BaseObject>
|
||||
{
|
||||
public BaseObject target;
|
||||
public ITrigger trigger;
|
||||
public BaseObject obj;
|
||||
public Trigger trigger;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,12 @@ using RPGCore.Core.Objects;
|
||||
|
||||
namespace RPGCore.ObjectModules.EventObjectModule.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Executed when <see cref="BaseObject"/> exits <see cref="Trigger"/>'s colliders.
|
||||
/// </summary>
|
||||
public class TriggerExitEvent : BaseEvent<BaseObject>
|
||||
{
|
||||
public BaseObject target;
|
||||
public ITrigger trigger;
|
||||
public BaseObject obj;
|
||||
public Trigger trigger;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user