Open danprince opened 4 years ago
This could also be useful for partial overrides if sprite became an object:
"human": {
"sprite.texture": "sprites.png",
"sprite.x": 50,
"sprite.y": 50,
"sprite.w": 16,
"sprite.h": 16,
},
"player": {
"extends": ["human"],
"sprite.x": 20,
"sprite.y": 0
}
The main problem with this technique is type safety. It makes it much more difficult to validate a data file because the flattened form of the types is time consuming to create.
interface GameObject {
sprite: Sprite
}
interface GameObjectTemplate {
"sprite.x": Sprite["x"],
"sprite.y": Sprite["y"],
// and so on
}
What if the flattened interfaces could be generated as part of the validation step instead?
There are some problems with the JSON format inheritance causing property overwrites.
In this example all inherited effects would be clobbered. There could be a few ways to get around this, one would be running the effects for every inherited type (e.g.
player.effects.rest
would also triggerhuman.effects.rest
).Another would be allowing keys to be unflattened at build time:
This would unflatten to the structure above, but could also support merging with keys in ancestors.