DS-Pokemon-Rom-Editor/DS_Map/Extensions.cs
2021-08-10 14:20:10 +02:00

55 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DSPRE {
public static class Extensions {
public static int IndexOfNumber(this string str) {
return str.IndexOfAny("0123456789".ToCharArray());
}
public static bool ContainsNumber(this string str) {
return str.IndexOfNumber() > 0;
}
public static Dictionary<string, ushort> Reverse (this Dictionary<ushort, string> source) {
var dictionary = new Dictionary<string, ushort>(StringComparer.InvariantCultureIgnoreCase);
foreach (var entry in source) {
string newKey = entry.Value;
if (!dictionary.ContainsKey(newKey)) {
dictionary.Add(newKey, entry.Key);
}
}
return dictionary;
}
public static void FadeIn(this Form o, int framelength = 16, int frames = 10) {
//Object is not fully invisible. Fade it in
while (o != null && !o.IsDisposed && o.Opacity < 1.0) {
Thread.Sleep(framelength);
o.Opacity += (1.0 / frames);
}
o.Opacity = 1; //make fully visible
}
public static void FadeOut(this Form o, int framelength = 16, int frames = 10) {
//Object is fully visible. Fade it out
while (o != null && o.Opacity > 0.0) {
Thread.Sleep(framelength);
o.Opacity -= (1.0 / frames);
}
o.Opacity = 0; //make fully invisible
Console.WriteLine("Fadeout done");
}
//public static Dictionary<TValue, TKey> Reverse<TKey, TValue>(this IDictionary<TKey, TValue> source) {
// var dictionary = new Dictionary<TValue, TKey>();
// foreach (var entry in source) {
// if (!dictionary.ContainsKey(entry.Value)) {
// dictionary.Add(entry.Value, entry.Key);
// }
// }
// return dictionary;
//}
}
}