[Add] Dice & Refactor private names

This commit is contained in:
2026-03-02 11:22:01 +07:00
parent 4890fa946e
commit f65976796d
36 changed files with 883 additions and 489 deletions
@@ -9,13 +9,13 @@ namespace YachtDice.Modifiers.Pipeline
{
public class ModifierPipeline
{
private readonly ModifierRegistry registry;
private readonly List<EffectEntry> effectBuffer = new();
private bool isExecuting;
private readonly Queue<(TriggerType trigger, ModifierContext context)> deferredQueue = new();
private readonly ModifierRegistry _registry;
private readonly List<EffectEntry> _effectBuffer = new();
private bool _isExecuting;
private readonly Queue<(TriggerType trigger, ModifierContext context)> _deferredQueue = new();
private const int MaxRecursionDepth = 1;
private int currentDepth;
private int _currentDepth;
public bool TracingEnabled { get; set; }
#if UNITY_EDITOR || DEVELOPMENT_BUILD
@@ -24,23 +24,23 @@ namespace YachtDice.Modifiers.Pipeline
public ModifierPipeline(ModifierRegistry registry)
{
this.registry = registry;
this._registry = registry;
}
public async UniTask<ModifierContext> Execute(TriggerType trigger, ModifierContext context)
{
if (isExecuting)
if (_isExecuting)
{
if (currentDepth >= MaxRecursionDepth)
if (_currentDepth >= MaxRecursionDepth)
{
Debug.LogWarning($"[ModifierPipeline] Max recursion depth reached for trigger {trigger}. Dropping.");
return context;
}
currentDepth++;
_currentDepth++;
}
isExecuting = true;
_isExecuting = true;
context.Trigger = trigger;
PipelineTrace trace = null;
@@ -50,10 +50,10 @@ namespace YachtDice.Modifiers.Pipeline
context.DebugLog ??= new List<string>();
}
effectBuffer.Clear();
_effectBuffer.Clear();
// Snapshot active modifiers to avoid modification during iteration
var activeSnapshot = registry.Active;
var activeSnapshot = _registry.Active;
// Gather eligible effects
for (int i = 0; i < activeSnapshot.Count; i++)
@@ -93,7 +93,7 @@ namespace YachtDice.Modifiers.Pipeline
for (int e = 0; e < effects.Count; e++)
{
if (effects[e] == null) continue;
effectBuffer.Add(new EffectEntry
_effectBuffer.Add(new EffectEntry
{
Effect = effects[e],
Instance = inst,
@@ -103,12 +103,12 @@ namespace YachtDice.Modifiers.Pipeline
}
// Sort by Phase -> Priority -> Id
effectBuffer.Sort(ModifierComparer.Default);
_effectBuffer.Sort(ModifierComparer.Default);
// Execute sequentially
for (int i = 0; i < effectBuffer.Count; i++)
for (int i = 0; i < _effectBuffer.Count; i++)
{
var entry = effectBuffer[i];
var entry = _effectBuffer[i];
await entry.Effect.Apply(context, entry.Instance);
if (trace != null)
@@ -122,8 +122,8 @@ namespace YachtDice.Modifiers.Pipeline
Debug.Log(traceStr);
}
isExecuting = false;
currentDepth = 0;
_isExecuting = false;
_currentDepth = 0;
return context;
}