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
@@ -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;
}
}