Draft: Archetype invariant#23658
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨ |
|
Looks good so far. However there are a some of edgecases that aren't documented from what I can tell. RecursionWhat happens to recursive #[derive(Component)]
#[constraint(only(Armour))]
pub struct Knight;
#[derive(Component)]
#[constraint(only(Cost))]
pub struct Armour;
#[derive(Component)]
pub struct Cost;Can knight only exist with EnforcementWhat happens when you attempt to break an archetype invariant? Does the order matter? For example, if you had #[derive(Component)]
#[constraint(forbid(Dead))]
pub struct Alive;
#[derive(Component)]
#[constraint(forbid(Alive))]
pub struct Dead;And tried to insert I think both have their uses, it's probably a good idea to allow users specify the behaviour. /// Inserting `Alive` into an entity with `Dead` will "bounce" and `Dead` will remain.
/// Unfortunately death is quite permanent.
#[derive(Component)]
#[constraint(forbid(Dead))]
pub struct Alive;
/// Inserting `Dead` into an entity with `Alive` will overwrite it and `Dead` will remain.
#[derive(Component)]
#[constraint(forbid(Alive, overwrite))]
pub struct Dead;A similar system could also be extended to |
i.e.
Ohh, the current circumstance seems to lack transactional functionality. But, this problem can be easily solved without using transaction, using XOR. #[drive(Component)]
#[constraint(or(and(require(Alive), forbid(Dead)), and(require(Dead), forbid(Alive))))] // i.e #[constraint(xor(Alive, Dead))]
struct State;
What if I think it is better to use Observer to make it more explicit: Or a new hook? That is to say, why does the existing This is some of my thought! |
Objective
Testing
constraint.rscomponent_constraints.rsBenches
Notes