Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Implement an extensible deserialization scheme that can work with tmx objects #20

Closed
thelukester92 opened this issue Jul 30, 2014 · 1 comment

Comments

@thelukester92
Copy link
Owner

So that entities can be stored and loaded from files, implement a deserialization scheme that component classes can implement. One possible way is to register component deserialization methods in the scene based on a unique string. For example, this JSON could represent an entity:

{ "position" : { x: 12, y: 24 } }

The LGPosition component could register for it like this in the scene:

registerDeserializer("position") { LGPosition.deserialize($0) }

And the result of deserialization would be this:

LGPosition(x: 12, y: 24)

Perhaps a Deserializable protocol could work, then registering is simply associating a string with a class. It would be nice if Swift let us use Types as Dictionary keys and values.

@thelukester92
Copy link
Owner Author

#26 implements #25, which will add the ability for the tmx parser to load tmx <object> elements into memory. These elements have a type attribute that could indicate some kind of template, as well as custom property key-value pairs that could indicate components like this (similar to the above example):

Key Value
position { x: 12, y: 24 }
sprite { spriteSheet: "Player" }

As proposed before, LGPosition and LGSprite would register to be deserializers for "position" and "sprite" respectively.

Better yet, with the possibility of using type as a template indicator, the game could define templates in a json object somewhere and just use the property values to override or add to the template-created entity.

@thelukester92 thelukester92 changed the title Implement an extensible deserialization scheme Implement an extensible deserialization scheme that can work with tmx objects Jul 31, 2014
@thelukester92 thelukester92 added this to the Beta Engine milestone Sep 5, 2014
@thelukester92 thelukester92 reopened this Sep 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant