junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
769 stars 109 forks source link

TransientProperties on Components [FEATURE] #643

Closed bryanbrunt closed 2 years ago

bryanbrunt commented 2 years ago

I have been assigning controller classes to my Components like this:

public Object npcController;

These controller classes separate the game logic from the Components which are purely data.

Is there anyway with artemis to not serialize these Objects without writing a custom serializer?

It seems like Artemis should have a @Transient tag that applies to just properties of Components.

DaanVanYperen commented 2 years ago

Are you sure @Transient doesn't work on fields? Glancing over the Json code it does check for it.

Alternatively, there is a pattern used for non-serialized state that you want to populate after loading: https://github.com/junkdog/artemis-odb/wiki/Model-for-Serialization

bryanbrunt commented 2 years ago

Are you sure @Transient doesn't work on fields? Glancing over the Json code it does check for it.

@Transient
public Object controller;

There is a compile error when using the Transient tag inside of a class.

error: annotation type not applicable to this kind of declaration @Transient

DaanVanYperen commented 2 years ago

The @Transient I'm thinking of is javax.persistence.Transient which doesn't apply in odb, oops.

Try the java modifier. public transient Object controller;

DaanVanYperen commented 2 years ago

Added wiki page. Thanks for the question. https://github.com/junkdog/artemis-odb/wiki/How-to-avoid-serializing-specific-components-or-fields

bryanbrunt commented 2 years ago

Added wiki page. Thanks for the question. https://github.com/junkdog/artemis-odb/wiki/How-to-avoid-serializing-specific-components-or-fields

Nice! I was about to ask where this is documented.

bryanbrunt commented 2 years ago

Daan, it would be great if you could put a load and save game system into one of your games.

As far as I know, there is no simple existing example for Artemis ODB in the entire universe.

On the libgdx discord, I like to point people to your games, but there's nothing on loading and saving games to point people to.

DaanVanYperen commented 2 years ago

Daan, it would be great if you could put a load and save game system into one of your games.

I'll see if I can fit it in somewhere.