64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
public class DirtyMarkSubmodule : SubmoduleBase
|
|
{
|
|
public bool isAnyDirty { get; private set; }
|
|
public Dictionary<string, bool> dirtyFlags;
|
|
|
|
public DirtyMarkSubmodule(GameElement attachedGameElement) : base(attachedGameElement)
|
|
{
|
|
isAnyDirty = false;
|
|
dirtyFlags = new Dictionary<string, bool>();
|
|
|
|
if (!HaveSameSubmodule && attachedGameElement is IHaveDirtyMarkSubmodule host)
|
|
{
|
|
host.dirtyMarkSubmodule = this;
|
|
}
|
|
}
|
|
|
|
public void MarkDirty(string flagKey = "All")
|
|
{
|
|
isAnyDirty = true;
|
|
if (!string.IsNullOrEmpty(flagKey))
|
|
{
|
|
dirtyFlags[flagKey] = true;
|
|
}
|
|
}
|
|
|
|
public void ExecuteDeferredRefresh()
|
|
{
|
|
if (isAnyDirty && attachedGameElement is IHaveDirtyMarkSubmodule host)
|
|
{
|
|
host.OnDirtyRefresh(dirtyFlags);
|
|
ClearDirty();
|
|
}
|
|
}
|
|
|
|
public void ClearDirty()
|
|
{
|
|
isAnyDirty = false;
|
|
dirtyFlags.Clear();
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
MarkDirty("All");
|
|
}
|
|
|
|
public override void CheckAndRemoveObservers() { }
|
|
}
|
|
|
|
public interface IHaveDirtyMarkSubmodule
|
|
{
|
|
DirtyMarkSubmodule dirtyMarkSubmodule { get; set; }
|
|
|
|
/// <summary>
|
|
/// 当有一帧收到来自于动画或者其它管理器的脏标记篡改时,在此方法中处理推送至具体表现层的工作。
|
|
/// </summary>
|
|
void OnDirtyRefresh(Dictionary<string, bool> flags);
|
|
}
|
|
}
|