JECSu
JECSu copied to clipboard
Templating/blueprinting
Task:
- Have a way to store entity composition and its data in a simple extremely readable and editable format.
- Have a serializer/deserializer that constructs entity from template
Example: The way how Dwarf Fortress stores game data/definitions is perfect example:
[OBJECT:CREATURE]
[CREATURE:WORM]
[DESCRIPTION:A tiny burrowing creature, found in moist soil. It is legless, long and thin.]
[NAME:worm:worms:worm]
[CASTE_NAME:worm:worms:worm]
[CREATURE_TILE:'~'][COLOR:7:0:0]
[PETVALUE:10]
[VERMIN_SOIL][FREQUENCY:100][VERMIN_HATEABLE]
[SMALL_REMAINS][VERMIN_NOTRAP][NOBONES]
[NATURAL][PET]
[NOT_BUTCHERABLE]
Idea: Have a mechanism allowing to read text files in game directory and load data from them as entities on demand.
Benefits:
- example: will allow to have composition root logic depend on dynamically loaded data/entities instead of hardcoded.
- allows for dynamic replacement of an entity/component with updated one
- human readable format, with emphasis on editability outside of editor, modding
Proposal:
- first step would be to have a "database" like system, that scans some root directory for all files of template format, builds a database from them.
- the database itself must be configurable outside of editor through yaml file.
- templates will use yaml as its a reliable serialization.
- we will use YamlDotNet, and not unity serialization, because YamlDotNet comes with open source.
- When system is established, expose request calls by database id
public Entity Template.LoadByName(string name) // LoadById(string id)
- work out entity construction from template/factory
- make sure mechanism for dynamic replacement is provided
< chicken
name = "Chicken"
[Position]
[Creature]
max_hp = 90000
attack_dmg = 1
attack = "meelee"
range = 1
speed = 1
run_speed = 3
[Animal]
type = "Chicken"
[ColorComponent]
color = #ffffff
[WorldView]
prefab = "animals/chicken";
[Loot]
loot_table{
"chicken", 1, 10
"feather", 3, 6
}
>
< chicken_brown
parent = chicken
[ColorComponent]
color = #ffffff
>
< feather
name = "Feather"
[Position]
[Item]
mass = 0.01
>
an example of a template document, several in one, parenting, custom serialization