Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums as components #12

Open
Nertsal opened this issue Sep 23, 2024 · 0 comments
Open

Enums as components #12

Nertsal opened this issue Sep 23, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Nertsal
Copy link
Owner

Nertsal commented Sep 23, 2024

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.

@Nertsal Nertsal added the enhancement New feature or request label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant