Initial refactorin
This commit is contained in:
parent
89b059abfb
commit
5ce6580c6f
593 changed files with 52 additions and 78 deletions
38
Sledgemapper/ExtensionMethods.cs
Normal file
38
Sledgemapper/ExtensionMethods.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
// using MonoGame.Extended;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Linq;
|
||||
|
||||
namespace MyGame
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
public static Dictionary<string, T> LoadContentFolder<T>(this ContentManager contentManager, string contentFolder)
|
||||
{
|
||||
DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "/" + contentFolder);
|
||||
if (!dir.Exists)
|
||||
throw new DirectoryNotFoundException();
|
||||
Dictionary<string, T> result = new Dictionary<string, T>();
|
||||
|
||||
FileInfo[] files = dir.GetFiles("*.*");
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
result.Add(file.Name.Split('.')[0], contentManager.Load<T>(contentFolder + "/" + file.Name.Split('.')[0]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IEnumerable<string> Split(this string str, int chunkSize) => Enumerable.Range(0, str.Length / chunkSize)
|
||||
.Select(i => str.Substring(i * chunkSize, chunkSize));
|
||||
|
||||
public static Point AbsPoint(this Point point)
|
||||
{
|
||||
return new Point(System.Math.Abs(point.X), System.Math.Abs(point.Y));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue