refactor: formatting code
This commit is contained in:
parent
148e0c149e
commit
f95cef20c6
8 changed files with 96 additions and 51 deletions
|
@ -1,5 +1,6 @@
|
||||||
*~
|
*~
|
||||||
flake.*
|
flake.*
|
||||||
|
*.cs
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
.direnv/
|
.direnv/
|
||||||
|
|
|
@ -7,9 +7,6 @@ pre-push:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
parallel: true
|
parallel: true
|
||||||
commands:
|
commands:
|
||||||
dotnet-format-style:
|
|
||||||
glob: "*.cs"
|
|
||||||
run: dotnet format
|
|
||||||
prettier:
|
prettier:
|
||||||
run: prettier . --write --loglevel warn
|
run: prettier . --write --loglevel warn
|
||||||
nixfmt:
|
nixfmt:
|
||||||
|
|
|
@ -5,26 +5,22 @@ namespace Gallium
|
||||||
{
|
{
|
||||||
public static class WhereEntityHasExtensions
|
public static class WhereEntityHasExtensions
|
||||||
{
|
{
|
||||||
public static IEnumerable<Entity> WhereEntityHas<T1>(
|
public static IEnumerable<Entity> WhereEntityHas<T1>(this IEnumerable<Entity> entities)
|
||||||
this IEnumerable<Entity> entities)
|
|
||||||
{
|
{
|
||||||
return entities.Where(x => x.Has<T1>());
|
return entities.Where(x => x.Has<T1>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2>(
|
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2>(this IEnumerable<Entity> entities)
|
||||||
this IEnumerable<Entity> entities)
|
|
||||||
{
|
{
|
||||||
return entities.Where(x => x.HasAll<T1, T2>());
|
return entities.Where(x => x.HasAll<T1, T2>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3>(
|
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3>(this IEnumerable<Entity> entities)
|
||||||
this IEnumerable<Entity> entities)
|
|
||||||
{
|
{
|
||||||
return entities.Where(x => x.HasAll<T1, T2, T3>());
|
return entities.Where(x => x.HasAll<T1, T2, T3>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3, T4>(
|
public static IEnumerable<Entity> WhereEntityHasAll<T1, T2, T3, T4>(this IEnumerable<Entity> entities)
|
||||||
this IEnumerable<Entity> entities)
|
|
||||||
{
|
{
|
||||||
return entities.Where(x => x.HasAll<T1, T2, T3, T4>());
|
return entities.Where(x => x.HasAll<T1, T2, T3, T4>());
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace Gallium.Tests
|
||||||
public void AddingTwiceThrowsException()
|
public void AddingTwiceThrowsException()
|
||||||
{
|
{
|
||||||
var component1 = new TestComponent1();
|
var component1 = new TestComponent1();
|
||||||
|
|
||||||
Exception exception = Assert.Throws<ArgumentException>(
|
Exception exception = Assert.Throws<ArgumentException>(
|
||||||
() => new Entity()
|
() => new Entity()
|
||||||
.Add(component1)
|
.Add(component1)
|
||||||
|
@ -153,6 +154,7 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
var component1 = new TestComponent3a();
|
var component1 = new TestComponent3a();
|
||||||
var component2 = new TestComponent3b();
|
var component2 = new TestComponent3b();
|
||||||
|
|
||||||
Entity entity1 = new Entity()
|
Entity entity1 = new Entity()
|
||||||
.Set<ITestComponent3>(component1)
|
.Set<ITestComponent3>(component1)
|
||||||
.Set<ITestComponent3>(component1)
|
.Set<ITestComponent3>(component1)
|
||||||
|
|
|
@ -11,14 +11,20 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()),
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("3").Add(new TestComponent1()),
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2()),
|
||||||
|
new Entity().Add("3")
|
||||||
|
.Add(new TestComponent1()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new[] { "1!", "2", "3!" },
|
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>())
|
.Select(x => x.Get<string>())
|
||||||
.ToArray());
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
@ -28,14 +34,22 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()),
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("3").Add(new TestComponent1()).Add(new TestComponent2()),
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2()),
|
||||||
|
new Entity().Add("3")
|
||||||
|
.Add(new TestComponent1())
|
||||||
|
.Add(new TestComponent2()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new[] { "1", "2", "3!" },
|
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>())
|
.Select(x => x.Get<string>())
|
||||||
.ToArray());
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
@ -45,8 +59,11 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()).Add<ITestComponent3>(new TestComponent3b()),
|
.Add(new TestComponent1()),
|
||||||
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2())
|
||||||
|
.Add<ITestComponent3>(new TestComponent3b()),
|
||||||
new Entity().Add("3")
|
new Entity().Add("3")
|
||||||
.Add<ITestComponent3>(new TestComponent3a())
|
.Add<ITestComponent3>(new TestComponent3a())
|
||||||
.Add(new TestComponent1())
|
.Add(new TestComponent1())
|
||||||
|
@ -56,7 +73,15 @@ namespace Gallium.Tests
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new[] { "1", "2", "3-TestComponent3a" },
|
new[] { "1", "2", "3-TestComponent3a" },
|
||||||
entities.SelectEntity<TestComponent1, TestComponent2, ITestComponent3>(
|
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>())
|
.Select(x => x.Get<string>())
|
||||||
.ToArray());
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
@ -66,14 +91,19 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()),
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("3").Add(new TestComponent1()),
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2()),
|
||||||
|
new Entity().Add("3")
|
||||||
|
.Add(new TestComponent1()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new[] { "1", "3" },
|
new[] { "1", "3" },
|
||||||
entities.WhereEntityHas<TestComponent1>().Select(x => x.Get<string>()).ToArray());
|
entities.WhereEntityHas<TestComponent1>()
|
||||||
|
.Select(x => x.Get<string>())
|
||||||
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -81,14 +111,20 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()).Add(new TestComponent1()),
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("3").Add(new TestComponent1()),
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2())
|
||||||
|
.Add(new TestComponent1()),
|
||||||
|
new Entity().Add("3")
|
||||||
|
.Add(new TestComponent1()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new[] { "2" },
|
new[] { "2" },
|
||||||
entities.WhereEntityHasAll<TestComponent1, TestComponent2>().Select(x => x.Get<string>()).ToArray());
|
entities.WhereEntityHasAll<TestComponent1, TestComponent2>()
|
||||||
|
.Select(x => x.Get<string>())
|
||||||
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -100,8 +136,11 @@ namespace Gallium.Tests
|
||||||
.Add(new TestComponent1())
|
.Add(new TestComponent1())
|
||||||
.Add<ITestComponent3>(new TestComponent3b())
|
.Add<ITestComponent3>(new TestComponent3b())
|
||||||
.Add(new TestComponent2()),
|
.Add(new TestComponent2()),
|
||||||
new Entity().Add("2").Add(new TestComponent2()).Add(new TestComponent1()),
|
new Entity().Add("2")
|
||||||
new Entity().Add("3").Add<ITestComponent3>(new TestComponent3a()),
|
.Add(new TestComponent2())
|
||||||
|
.Add(new TestComponent1()),
|
||||||
|
new Entity().Add("3")
|
||||||
|
.Add<ITestComponent3>(new TestComponent3a()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
|
@ -116,14 +155,19 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()),
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("3").Add(new TestComponent1()),
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2()),
|
||||||
|
new Entity().Add("3")
|
||||||
|
.Add(new TestComponent1()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
new[] { "2" },
|
new[] { "2" },
|
||||||
entities.WhereEntityNotHas<TestComponent1>().Select(x => x.Get<string>()).ToArray());
|
entities.WhereEntityNotHas<TestComponent1>()
|
||||||
|
.Select(x => x.Get<string>())
|
||||||
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -131,8 +175,11 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
new Entity().Add("2").Add(new TestComponent2()).Add(new TestComponent1()),
|
.Add(new TestComponent1()),
|
||||||
|
new Entity().Add("2")
|
||||||
|
.Add(new TestComponent2())
|
||||||
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("3"),
|
new Entity().Add("3"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -148,12 +195,14 @@ namespace Gallium.Tests
|
||||||
{
|
{
|
||||||
Entity[] entities =
|
Entity[] entities =
|
||||||
{
|
{
|
||||||
new Entity().Add("1").Add(new TestComponent1()),
|
new Entity().Add("1")
|
||||||
|
.Add(new TestComponent1()),
|
||||||
new Entity().Add("2")
|
new Entity().Add("2")
|
||||||
.Add(new TestComponent1())
|
.Add(new TestComponent1())
|
||||||
.Add(new TestComponent2())
|
.Add(new TestComponent2())
|
||||||
.Add<ITestComponent3>(new TestComponent3b()),
|
.Add<ITestComponent3>(new TestComponent3b()),
|
||||||
new Entity().Add("3").Add<ITestComponent3>(new TestComponent3a()),
|
new Entity().Add("3")
|
||||||
|
.Add<ITestComponent3>(new TestComponent3a()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(
|
Assert.Equal(
|
||||||
|
|
Reference in a new issue