示例#1
0
文件: Events.cs 项目: Bagoum/danmokou
 /// <summary>
 /// An event that will only trigger once.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static EventDeclaration <Event0> Once(string name)
 {
     if (storedEvents.ContainsKey(name))
     {
         throw new Exception($"Event already declared: {name}");
     }
     return(storedEvents[name] = new Event0(true));
 }
示例#2
0
文件: Events.cs 项目: Bagoum/danmokou
            /// <summary>
            /// An event that will trigger once, but may be reset when another event is triggered.
            /// </summary>
            /// <param name="name"></param>
            /// <param name="reactivator"></param>
            /// <returns></returns>
            public static EventDeclaration <Event0> Refract(string name, string reactivator)
            {
                if (storedEvents.ContainsKey(name))
                {
                    throw new Exception($"Event already declared: {name}");
                }
                var ev = storedEvents[name] = new Event0(true);

                ev.ListenForReactivation(reactivator);
                if (waitingToResolve.TryGetValue(name, out var waiters))
                {
                    for (int ii = 0; ii < waiters.Count; ++ii)
                    {
                        waiters[ii].ListenForReactivation(name);
                    }
                    waitingToResolve.Remove(name);
                }
                return(ev);
            }