/*** Events ***/ public EasyBlock AddEvent(Func <EasyBlock, bool> evnt, Func <EasyBlock, bool> action, bool onChange = false) { EasyEvent.add(new EasyEvent(this, evnt, action, onChange)); return(this); }
public void AddEvent(EasyEvent e) { EasyEvent.add(e); }
public static void add(EasyEvent e) { events.Add(e); }
/*** Execute one tick of the program (interval is the minimum time between ticks) ***/ public void Tick(long interval = 0, string argument = "") { /*** Handle Arguments ***/ if (argument != "") { if (this.ArgumentActions.ContainsKey(argument)) { for (int n = 0; n < this.ArgumentActions[argument].Count; n++) { this.ArgumentActions[argument][n](); } } else if (this.CommandActions.Count > 0) { int argc = 0; var matches = System.Text.RegularExpressions.Regex.Matches(argument, @"(?<match>[^\s""]+)|""(?<match>[^""]*)"""); string[] argv = new string[matches.Count]; for (int n = 0; n < matches.Count; n++) { argv[n] = matches[n].Groups["match"].Value; } argc = argv.Length; if (argc > 0 && this.CommandActions.ContainsKey(argv[0])) { for (int n = 0; n < this.CommandActions[argv[0]].Count; n++) { this.CommandActions[argv[0]][n](argc, argv); } } } else if (argument.Length > 12 && argument.Substring(0, 12) == "EasyCommand ") { this.commands.handle(argument.Substring(12)); } } long now = DateTime.Now.Ticks; if (this.clock > this.start && now - this.clock < interval) { InterTickRunCount++; float transpiredPercentage = ((float)((double)(now - this.clock) / interval)); onRunThrottled(transpiredPercentage); return; // Don't run until the minimum time between ticks } if (InterTickRunCount == 1) { if (onSingleTap()) { return; // Override has postponed this Tick to next Run } } else if (InterTickRunCount > 1) { if (onDoubleTap()) { return; // Override has postponed this Tick to next Run } } InterTickRunCount = 0; onTickStart(); long lastClock = this.clock; this.clock = now; this.delta = this.clock - lastClock; /*** Handle Events ***/ EasyEvent.handle(); /*** Handle Intervals ***/ for (int n = 0; n < this.Intervals.Count; n++) { if (this.clock >= this.Intervals[n].time) { long time = this.clock + this.Intervals[n].interval - (this.clock - this.Intervals[n].time); (this.Intervals[n].action)(); this.Intervals[n] = new EasyInterval(time, this.Intervals[n].interval, this.Intervals[n].action); // reset time interval } } /*** Handle Schedule ***/ for (int n = 0; n < this.Schedule.Count; n++) { if (this.clock >= this.Schedule[n].time) { (this.Schedule[n].action)(); Schedule.Remove(this.Schedule[n]); } } onTickComplete(); }