|
2 | 2 | using static EZCodeLanguage.Interpreter; |
3 | 3 | using System.Data; |
4 | 4 | using System.Diagnostics; |
| 5 | +using System.Timers; |
| 6 | +using Timer = System.Timers.Timer; |
5 | 7 |
|
6 | 8 | namespace EZCodeLanguage |
7 | 9 | { |
@@ -251,7 +253,7 @@ public bool Expression(string expression) |
251 | 253 | } |
252 | 254 | continue; |
253 | 255 | } |
254 | | - if ((new[] { "&", "|", "and", "or", "&&", "||" }).Any(x => x == e)) |
| 256 | + if ((new[] { "&", "|", "and", "not", "or", "&&", "||" }).Any(x => x == e)) |
255 | 257 | { |
256 | 258 | allIsText = false; |
257 | 259 | continue; |
@@ -667,6 +669,11 @@ public int RandomNumber(object _min, object _max) |
667 | 669 | int max = IntParse(_max); |
668 | 670 | return random.Next(min, max); |
669 | 671 | } |
| 672 | + public int RoundToInt(object _num) |
| 673 | + { |
| 674 | + var num = FloatParse(_num); |
| 675 | + return (int)Math.Round(num); |
| 676 | + } |
670 | 677 | public string Trim(object text) => StringParse(text).Trim(); |
671 | 678 | public string ToLower(object text) => StringParse(text).ToLower(); |
672 | 679 | public string ToUpper(object text) => StringParse(text).ToUpper(); |
@@ -1139,15 +1146,34 @@ public void StopwatchEnd(object _stopwatch) |
1139 | 1146 | Stopwatch stopwatch = (Stopwatch)ObjectParse(_stopwatch, "stopwatch"); |
1140 | 1147 | stopwatch.Stop(); |
1141 | 1148 | } |
1142 | | - public float StopwatchElapsedSeconds(object _stopwatch) |
1143 | | - { |
1144 | | - Stopwatch stopwatch = (Stopwatch)ObjectParse(_stopwatch, "stopwatch"); |
1145 | | - return (float)stopwatch.Elapsed.TotalSeconds; |
| 1149 | + public float StopwatchElapsedNanoseconds(object _stopwatch) => (float)(ObjectParse(_stopwatch, "stopwatch") as Stopwatch).Elapsed.TotalNanoseconds; |
| 1150 | + public float StopwatchElapsedMiliseconds(object _stopwatch) => (float)(ObjectParse(_stopwatch, "stopwatch") as Stopwatch).Elapsed.TotalMilliseconds; |
| 1151 | + public float StopwatchElapsedSeconds(object _stopwatch) => (float)(ObjectParse(_stopwatch, "stopwatch") as Stopwatch).Elapsed.TotalSeconds; |
| 1152 | + public float StopwatchElapsedMinutes(object _stopwatch) => (float)(ObjectParse(_stopwatch, "stopwatch") as Stopwatch).Elapsed.TotalMinutes; |
| 1153 | + public float StopwatchElapsedHours(object _stopwatch) => (float)(ObjectParse(_stopwatch, "stopwatch") as Stopwatch).Elapsed.TotalHours; |
| 1154 | + public Timer TimerNewInstance(object _hours, object _minutes, object _seconds, object _milliseconds) |
| 1155 | + { |
| 1156 | + var hours = IntParse(_hours); |
| 1157 | + var minutes = IntParse(_minutes); |
| 1158 | + var seconds = IntParse(_seconds); |
| 1159 | + var miliseconds = IntParse(_milliseconds); |
| 1160 | + |
| 1161 | + var timespan = new TimeSpan(0, hours, minutes, seconds, miliseconds); |
| 1162 | + var timer = new Timer(timespan); |
| 1163 | + |
| 1164 | + timer.Elapsed += Timer_Elapsed; |
| 1165 | + _Timers.Add(timer, false); |
| 1166 | + |
| 1167 | + return timer; |
1146 | 1168 | } |
1147 | | - public float StopwatchElapsedMiliseconds(object _stopwatch) |
| 1169 | + public void TimerStart(object _timer) => (ObjectParse(_timer, "timer") as Timer).Start(); |
| 1170 | + public void TimerStop(object _timer) => (ObjectParse(_timer, "timer") as Timer).Stop(); |
| 1171 | + public bool TimerIsDone(object _timer) => _Timers[ObjectParse(_timer, "timer") as Timer]; |
| 1172 | + private void Timer_Elapsed(object? sender, ElapsedEventArgs e) |
1148 | 1173 | { |
1149 | | - Stopwatch stopwatch = (Stopwatch)ObjectParse(_stopwatch, "stopwatch"); |
1150 | | - return (float)stopwatch.Elapsed.TotalMilliseconds; |
| 1174 | + var timer = (Timer)sender; |
| 1175 | + _Timers[timer] = true; |
1151 | 1176 | } |
| 1177 | + public Dictionary<Timer, bool> _Timers = []; |
1152 | 1178 | } |
1153 | 1179 | } |
0 commit comments