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

@ -65,13 +65,13 @@ dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field
dotnet_naming_symbols.private_constants_symbols.required_modifiers = const dotnet_naming_symbols.private_constants_symbols.required_modifiers = const
dotnet_naming_symbols.private_instance_fields_symbols.applicable_accessibilities = private dotnet_naming_symbols.private_instance_fields_symbols.applicable_accessibilities = private
dotnet_naming_symbols.private_instance_fields_symbols.applicable_kinds = field dotnet_naming_symbols.private_instance_fields_symbols.applicable_kinds = field
dotnet_naming_symbols.private_static_fields_override_symbols.applicable_accessibilities = local,private dotnet_naming_symbols.private_static_fields_override_symbols.applicable_accessibilities = local, private
dotnet_naming_symbols.private_static_fields_override_symbols.applicable_kinds = field dotnet_naming_symbols.private_static_fields_override_symbols.applicable_kinds = field
dotnet_naming_symbols.private_static_fields_override_symbols.required_modifiers = const,static dotnet_naming_symbols.private_static_fields_override_symbols.required_modifiers = const, static
dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private
dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field
dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static
dotnet_naming_symbols.private_static_fields_symbols_1.applicable_accessibilities = local,private dotnet_naming_symbols.private_static_fields_symbols_1.applicable_accessibilities = local, private
dotnet_naming_symbols.private_static_fields_symbols_1.applicable_kinds = field dotnet_naming_symbols.private_static_fields_symbols_1.applicable_kinds = field
dotnet_naming_symbols.private_static_fields_symbols_1.required_modifiers = static dotnet_naming_symbols.private_static_fields_symbols_1.required_modifiers = static
dotnet_naming_symbols.private_static_fields_symbols_1.resharper_applicable_kinds = field dotnet_naming_symbols.private_static_fields_symbols_1.resharper_applicable_kinds = field

View file

@ -1,8 +1,9 @@
*~ *~
flake.* flake.*
*.cs
node_modules/ node_modules/
.direnv/ .direnv/
.config/ .config/
obj/ obj/
bin/ bin/

View file

@ -1,3 +1,3 @@
# Gallium CIL # Gallium CIL
A small Entity-Component-System (ECS) that is built around LINQ calls and `IEnumerable<Entity>` objects. A small Entity-Component-System (ECS) that is built around LINQ calls and `IEnumerable<Entity>` objects.

View file

@ -7,10 +7,7 @@ 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:
run: nixfmt flake.nix run: nixfmt flake.nix

View file

@ -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>());
} }

View file

@ -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)

View file

@ -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(

View file

@ -10,10 +10,10 @@
<Version>1.1.0</Version> <Version>1.1.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0"/>
<PackageReference Include="Serilog.Sinks.XUnit" Version="2.0.4" /> <PackageReference Include="Serilog.Sinks.XUnit" Version="2.0.4"/>
<PackageReference Include="JunitXml.TestLogger" Version="2.1.81" /> <PackageReference Include="JunitXml.TestLogger" Version="2.1.81"/>
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@ -24,6 +24,6 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Gallium\Gallium.csproj" /> <ProjectReference Include="..\..\src\Gallium\Gallium.csproj"/>
</ItemGroup> </ItemGroup>
</Project> </Project>