-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add/Replace/Remove vs Set/Unset #1069
Comments
Personally, I would rename I don't feel like there is a huge downside to keeping While being part of #1046, I feel similarly about generating additional Of course, there is some bloat that can slow down the compiler a bit. But it may also be plausible to have some of these things be generated based on settings? I haven't tested this yet, especially not in Unity. They haven't upgraded their build system and switched to user-defined MSBuild projects yet, but afaik that's still part of their plan for the future. But for now, some things (like AdditionalFiles) seem to be broken, so I'm not sure if this part is viable. |
@rubenwe Right, using settings sounds good. I tried adding a test value using I updated the TestHelper.cs to feed the unit tests with a test value, and that worked well and the tests successfully reads the value. But generated code in the integration test project doesn't seem to read the Any ideas why? |
Ok, I found a solution, but not sure if I'm happy. Instead of converting the global options to a custom options struct like this: var options = initContext.AnalyzerConfigOptionsProvider
.Select((provider, _) => new EntitasAnalyzerConfigOptions(provider.GlobalOptions)); and later trying to retrieve the value from it (which did not work), I'm now using a slightly different approach, by using the AnalyzerConfigOptionsProvider without var options = initContext.AnalyzerConfigOptionsProvider; and later before generating the code, I retrieve options like this by providing the component var entitasOptions = new EntitasAnalyzerConfigOptions(options.GetOptions(component.Syntax!.SyntaxTree)); Why do I need to provide the SyntaxTree?!? This should not affect global options, or does it? I'm slightly confused. see commit: 9f06a26 |
Hey @sschmid ! Since you're rewriting this, I have two points that I think you might be interested in. I use this in my project and it makes my life much easier. 1. Method chainI rewrote the methods so that they return an entity so that I can call the next method as a chain. entity
.SetPlayer(true)
.SetMovable(true)
.AddView(backing.gameObject)
.AddPosition(backing.transform.position)
.AddMoveComplete(true)
.AddPositionListener(backing); This reduces the number of code and helps to group it better. 2. Option instead of nullI use LanguageExt library in my project and I also added it to my Entitas generator. For example this component, will generate two new properties for me: public class PositionComponent : IComponent
{
public Vector2 value;
} public Option<PositionComponent> maybePosition;
public Option<Vector2> maybePosition_value; Thanks to this, I can safely use position later in my code entity.maybePosition_value.IfSome(position =>
{
// Its guaranteed here that this entity have position
}); Or we can do some calculations, as in this fictional example entity.maybePosition_value
.Map(position => position.normalized)
.Filter(normal => normal.x > 0)
.IfSome(positiveNormals =>
{
// ...
}
); Or like here: var hasFinished = entity.maybePosition_value.Match(
Some: position => position.x > 10,
None: () => false
); And a lot more :) I will be happy to help if you find any of this useful for Entitas. |
I will resist and try not to change too much :D @OctopBP Yes! I'll definitely do the fluent api! Thanks for your feedback! Will close |
Overview
vs
The code generator currently produces methods like this:
As we know in Entitas exceptions are thrown when
You will get nice exception description like
While working on the new code generator using C# source generators #1005, I started using C# nullables and I was wondering if we should get rid of the exceptions and move the responsibility to the dev.
This would mean adding components even if they already exists will result in overwriting them, basically exactly what
ReplaceComponent()
does right now. Attempting to remove a component that doesn't exist would also NOT fail.To communicate this fact, we can rename the methods to
Set
andUnset
, see examples in unit tests:https://github.com/sschmid/Entitas/blob/set-unset/tests/Entitas.Generators.IntegrationTests/ComponentTests.cs#L18-L55
Entitas won't throw exception and communicates that using nullables.
Example:
Keep in mind that removing exceptions also mean no more
Cannot add component 'Health' to Entity_123!
What do you think?
The text was updated successfully, but these errors were encountered: