refactor: formatting code

This commit is contained in:
Dylan R. E. Moonfire 2022-07-08 23:35:43 -05:00
parent 148e0c149e
commit f95cef20c6
8 changed files with 96 additions and 51 deletions

View file

@ -1,5 +1,6 @@
*~
flake.*
*.cs
node_modules/
.direnv/

View file

@ -7,9 +7,6 @@ pre-push:
pre-commit:
parallel: true
commands:
dotnet-format-style:
glob: "*.cs"
run: dotnet format
prettier:
run: prettier . --write --loglevel warn
nixfmt:

View file

@ -5,26 +5,22 @@ namespace Gallium
{
public static class WhereEntityHasExtensions
{
public static IEnumerable<Entity> WhereEntityHas<T1>(
this IEnumerable<Entity> entities)
public static IEnumerable<Entity> WhereEntityHas<T1>(this IEnumerable<Entity> entities)
{
return entities.Where(x => x.Has<T1>());
}
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2>(
this IEnumerable<Entity> entities)
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2>(this IEnumerable<Entity> entities)
{
return entities.Where(x => x.HasAll<T1, T2>());
}
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3>(
this IEnumerable<Entity> entities)
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3>(this IEnumerable<Entity> entities)
{
return entities.Where(x => x.HasAll<T1, T2, T3>());
}
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3, T4>(
this IEnumerable<Entity> entities)
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3, T4>(this IEnumerable<Entity> entities)
{
return entities.Where(x => x.HasAll<T1, T2, T3, T4>());
}

View file

@ -39,6 +39,7 @@ namespace Gallium.Tests
public void AddingTwiceThrowsException()
{
var component1 = new TestComponent1();
Exception exception = Assert.Throws<ArgumentException>(
() => new Entity()
.Add(component1)
@ -153,6 +154,7 @@ namespace Gallium.Tests
{
var component1 = new TestComponent3a();
var component2 = new TestComponent3b();
Entity entity1 = new Entity()
.Set<ITestComponent3>(component1)
.Set<ITestComponent3>(component1)

View file

@ -11,14 +11,20 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()),
new Entity().Add("3").Add(new TestComponent1()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2()),
new Entity().Add("3")
.Add(new TestComponent1()),
};
Assert.Equal(
new[] { "1!", "2", "3!" },
entities.SelectEntity<TestComponent1>((e, _) => e.Set(e.Get<string>() + "!"))
entities.SelectEntity<TestComponent1>(
(
e,
_) => e.Set(e.Get<string>() + "!"))
.Select(x => x.Get<string>())
.ToArray());
}
@ -28,14 +34,22 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()),
new Entity().Add("3").Add(new TestComponent1()).Add(new TestComponent2()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2()),
new Entity().Add("3")
.Add(new TestComponent1())
.Add(new TestComponent2()),
};
Assert.Equal(
new[] { "1", "2", "3!" },
entities.SelectEntity<TestComponent1, TestComponent2>((e, _, _) => e.Set(e.Get<string>() + "!"))
entities.SelectEntity<TestComponent1, TestComponent2>(
(
e,
_,
_) => e.Set(e.Get<string>() + "!"))
.Select(x => x.Get<string>())
.ToArray());
}
@ -45,8 +59,11 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()).Add<ITestComponent3>(new TestComponent3b()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2())
.Add<ITestComponent3>(new TestComponent3b()),
new Entity().Add("3")
.Add<ITestComponent3>(new TestComponent3a())
.Add(new TestComponent1())
@ -56,7 +73,15 @@ namespace Gallium.Tests
Assert.Equal(
new[] { "1", "2", "3-TestComponent3a" },
entities.SelectEntity<TestComponent1, TestComponent2, ITestComponent3>(
(e, _, _, t) => e.Set(e.Get<string>() + "-" + t.GetType().Name))
(
e,
_,
_,
t) => e.Set(
e.Get<string>()
+ "-"
+ t.GetType()
.Name))
.Select(x => x.Get<string>())
.ToArray());
}
@ -66,14 +91,19 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()),
new Entity().Add("3").Add(new TestComponent1()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2()),
new Entity().Add("3")
.Add(new TestComponent1()),
};
Assert.Equal(
new[] { "1", "3" },
entities.WhereEntityHas<TestComponent1>().Select(x => x.Get<string>()).ToArray());
entities.WhereEntityHas<TestComponent1>()
.Select(x => x.Get<string>())
.ToArray());
}
[Fact]
@ -81,14 +111,20 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()).Add(new TestComponent1()),
new Entity().Add("3").Add(new TestComponent1()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2())
.Add(new TestComponent1()),
new Entity().Add("3")
.Add(new TestComponent1()),
};
Assert.Equal(
new[] { "2" },
entities.WhereEntityHasAll<TestComponent1, TestComponent2>().Select(x => x.Get<string>()).ToArray());
entities.WhereEntityHasAll<TestComponent1, TestComponent2>()
.Select(x => x.Get<string>())
.ToArray());
}
[Fact]
@ -100,8 +136,11 @@ namespace Gallium.Tests
.Add(new TestComponent1())
.Add<ITestComponent3>(new TestComponent3b())
.Add(new TestComponent2()),
new Entity().Add("2").Add(new TestComponent2()).Add(new TestComponent1()),
new Entity().Add("3").Add<ITestComponent3>(new TestComponent3a()),
new Entity().Add("2")
.Add(new TestComponent2())
.Add(new TestComponent1()),
new Entity().Add("3")
.Add<ITestComponent3>(new TestComponent3a()),
};
Assert.Equal(
@ -116,14 +155,19 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()),
new Entity().Add("3").Add(new TestComponent1()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2()),
new Entity().Add("3")
.Add(new TestComponent1()),
};
Assert.Equal(
new[] { "2" },
entities.WhereEntityNotHas<TestComponent1>().Select(x => x.Get<string>()).ToArray());
entities.WhereEntityNotHas<TestComponent1>()
.Select(x => x.Get<string>())
.ToArray());
}
[Fact]
@ -131,8 +175,11 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("2").Add(new TestComponent2()).Add(new TestComponent1()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent2())
.Add(new TestComponent1()),
new Entity().Add("3"),
};
@ -148,12 +195,14 @@ namespace Gallium.Tests
{
Entity[] entities =
{
new Entity().Add("1").Add(new TestComponent1()),
new Entity().Add("1")
.Add(new TestComponent1()),
new Entity().Add("2")
.Add(new TestComponent1())
.Add(new TestComponent2())
.Add<ITestComponent3>(new TestComponent3b()),
new Entity().Add("3").Add<ITestComponent3>(new TestComponent3a()),
new Entity().Add("3")
.Add<ITestComponent3>(new TestComponent3a()),
};
Assert.Equal(