Skip to content

Enums as components #12

@Nertsal

Description

@Nertsal

Can something like this be allowed?

#[derive(SplitFields)]
enum AiType {
    Crawler,
    Shooter { some_data: i64 },
}

#[derive(SplitFields)]
struct Unit {
    #[split(nested)]
    ai_type: AiType,
    // other fields
}

Perhaps it could be represented as:

#[derive(SplitFields)]
struct AiTypeCrawler {}

#[derive(SplitFields)]
struct AiTypeShooter {
    some_data: i64,
}

struct AiTypeStructOf<F: StorageFamily> {
    Crawler: F::Storage<Option<AiTypeCrawler::StructOf<F>>>,
    Shooter: F::Storage<Option<AiTypeShooter::StructOf<F>>>,
}

And then queries could look like:

for (pos, crawler_ai) in query!(world.units, (&position, &ai_type.Crawler.Get.Some)) { }

Thought, ideally, .Get.Some could be omitted since it is already implied by the enum.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions