Project A Part 5: The Entity Editor

Today I started playing with a front-end to modify entities outside of the game proper. Pretty screenshot first:

A screenshot of the Entity Editor, showing a list of game entities on the left, and a hierarchal display of entity values on the right.

Doing this properly involved discovering even more tight couplings between components that the Kryo serializer seemed to have problems with. The long and short of it seems to be: if a Component is referenced as a bog-standard field on other components, the serializer gets confused and fails to reify that component when it’s meant to for a given entity.

Each of the individual components has its own way of displaying itself in the table, all of which are rather crude right now. Some of the raw data exists as protobuf messages, making it fairly painless to iterate over them and display all of the keys and values (as seen here). However, Artemis’ components must extend a sentinel class with no methods or fields. This makes it impossible to have a proto message which is also a component. The one place I do this is for items called ‘raws’, which are any items which need to be created from a template (e.g. bottles of water, guns, etc.). And this is kind of a kludge:

public class Raws extends Component {
  public GeneratedMessageV3 raws; 

This also means that I can’t have systems subscribe to any of those raw keys, so even if I could make all components protos, there would also need to be an implementation on top of Artemis’ systems to allow them to subscribe to only the proto “aspects” they are interested in.

So what I have to do for now is, for every field on a component, I need a separate line of code with a ton of duplication within the editor UI. So for the field Stats.currentHealth, I have the line

    new QStandardItem("currentHealth"),
    new QStandardItem(String.valueOf(stats.currentHealth)),

in the list of rows being added to the table view. And this sucks. I guess the most resilient way to handle this would be to use Java reflection on all of the components. It wouldn’t be too bad; just checking to see which fields have primitives or Strings and add them to the UI. So I guess that’s the next step.

After that, I want to be able to modify in-game values using this editor, and then load the save back up. I mean, I’m still conflating saved games with pre-stored game data, but right now they’re using the same mechanism. After a while I can imagine saved games simply being a delta of what the player changed against the pre-stored game data, but that seems a little like overkill.