Noah2610 / deathfloor

Work-in-progress Mega Man inspired game.
MIT License
2 stars 0 forks source link

EntityConfig variants #35

Closed Noah2610 closed 4 years ago

Noah2610 commented 4 years ago

Introduce variants for EntityConfig. Variants allow an EntityConfig to have optional groups of EntityConfigs.

Use-case example

Let's say we have an enemy, that just stands still. For some instances of that enemy type, we may want to make it move. We could have a variant called "Walker", that adds the Walker component.

Config mockup

// This could be in any config, that holds an `entity` field.
entity: (
    components: (
        /* ...snip... */
        walker: ( x: 100.0, ),
    ),
    /* ...snip... */

    variants: {
        // This "Faster" variant is another `EntityConfig`.
        "Faster": (
            components: (
                walker: ( x: 400.0, ),
                size: (16.0, 16.0),
            ),
            // We could add other fields, such as
            // `events` or `collision_tag` here as well.
        ),
    },
)

Using a variant

In code, editing an entity with its EntityConfig, we could pass an optional variant string.

For example for enemies, when placing an enemy within Tiled, they always get a type value. In addition to its type, we could give it an optional variant property.

Switching variants at runtime

Out of scope for this issue, but it would be cool to be able to switch variant type via an action or such.

Noah2610 commented 4 years ago

Configure entity variants like in the config mockup above. Example config for an enemy with variations MoveLeft and MoveRight.

Within tiled, set the variant property on an entity to a variant's name, to use that variant. image

Switch variants during runtime with the event action: EntityAction(SwitchVariant("VariantName")) Example. Note: Right now, switching variants like this only works for the components and the events fields. (TODO)

Noah2610 commented 4 years ago

Working, but not quite finished. Closing for now.