JECSu icon indicating copy to clipboard operation
JECSu copied to clipboard

Templating/blueprinting

Open pointcache opened this issue 8 years ago • 2 comments

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]

pointcache avatar Sep 07 '16 09:09 pointcache

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:

  1. 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.
  2. the database itself must be configurable outside of editor through yaml file.
  3. templates will use yaml as its a reliable serialization.
  4. we will use YamlDotNet, and not unity serialization, because YamlDotNet comes with open source.
  5. When system is established, expose request calls by database id
  public Entity Template.LoadByName(string name) // LoadById(string id) 
  1. work out entity construction from template/factory
  2. make sure mechanism for dynamic replacement is provided

pointcache avatar Sep 08 '16 08:09 pointcache

< 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

pointcache avatar Sep 10 '16 14:09 pointcache