Comments (5)
I will resist and try not to change too much :D
I will keep the familiar api with Add / Replace / Remove for now. I would also research if I can overwrite default analyzer behaviour for nullable checks before I would attempt to migrate to nullable. E.g. in reactive system + Filter() we're guaranteed that entities have components, but the compiler doesn't know that and warns about possible null.
@OctopBP Yes! I'll definitely do the fluent api!
Thanks for your feedback! Will close
from entitas.
Personally, I would rename ReplaceComponent()
to SetComponent()
. To me, replace implied I should not use it if the component is not already added. Set doesn't have that connotation.
I don't feel like there is a huge downside to keeping AddComponent()
around.
It can help uncover some issues that would otherwise be hard to diagnose.
While being part of #1046, I feel similarly about generating additional TryGetComponent(out component)
methods.
I don't see a huge downside to having them - and situationally it might be the nicest solution.
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.
from entitas.
@rubenwe Right, using settings sounds good. I tried adding a test value using .editorconfig
, but it doesn't seem to work. fb7f45f
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 .editorconfig
from the root folder.
Any ideas why?
from entitas.
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 Select()
.
var options = initContext.AnalyzerConfigOptionsProvider;
and later before generating the code, I retrieve options like this by providing the component SyntaxTree
, which I had to add to the ComponentDeclaration
.
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
from entitas.
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 chain
I rewrote the methods so that they return an entity so that I can call the next method as a chain.
Here's how I use it:
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 null
I use LanguageExt library in my project and I also added it to my Entitas generator.
It has the type Option<T>
, and it is an alternative to nullable types. But this forces devs to handle None (null) values, and also has many useful methods, as in LINQ.
For example this component, will generate two new properties for me: maybePosition
and maybePosition_value
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.
from entitas.
Related Issues (20)
- [SOLVED] Unity 2022.3.4f1: Exceptions + broken inspector when looking at any entity HOT 16
- Boolean in setttings for unique components to actually be unique
- A component with multiple contexts +events, only make event listeners for 1 context
- Could not resolve type with token ... expected class System.Threading.CancellationToken HOT 10
- How to generate codes in a project which has several csproj files? HOT 1
- Update on Entitas 2.0-beta and my situation HOT 4
- [1.14.1]code gen twice and compile error HOT 1
- there is a Error, on click Tools/Jenny/Gennerate, how can I do? HOT 4
- _group.GetEntities().AsParallel().ForAll(Execute);这段语句有GC HOT 2
- Is it feasible to use Entitas in the backend? HOT 7
- Entity Behaviour in Unity inspector not visible HOT 2
- Removal of crucial SearchPaths when executing the wiz command
- How to get all group in some context, without reflection。
- GUI Null ref when trying to view entity in inspector HOT 1
- generator issues HOT 1
- Error running dotnet Jenny/Jenny.Generator.Cli.dll gen -v command - System.IO.FileNotFoundException HOT 1
- Bro i want remove this how i remove
- Generate error
- Visual debugging. Coloring components not working properly.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entitas.