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

Exclusive input mode for edit systems #22

Open
idanarye opened this issue Apr 13, 2023 · 2 comments
Open

Exclusive input mode for edit systems #22

idanarye opened this issue Apr 13, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@idanarye
Copy link
Owner

Example usecase - #21. When an entity refers to another entity, we want the first entity to click the second entity, we want to be able to do this by editing the target entity, doing something to indicate that we want to pick an entity to refer to, and then click on the other entity.

For this, we need to be able to send an edit system to an "exclusive input mode". In that mode:

  • Other edit systems don't run.
  • Yoleck ignores directives.
    • Actually, there is one directive it won't ignore - a directive for cancelling the exclusive mode.
    • Vpeol should send that directive when Escape is pressed.
  • The exclusive edit system handles the clicks (how? should it get the directives themselves?)
@idanarye idanarye added the enhancement New feature or request label Apr 13, 2023
@idanarye
Copy link
Owner Author

I imagine the syntax as something like this:

fn edit_system_with_exclusive_mode(
    mut ui: ResMut<YoleckUi>,
    mut edit: YoleckEdit<&mut OtherEntityUuid>,
    mut exclusive: YoleckExclusive, // this captures the system (like `YoleckMarking` does)
    uuid_query: Query<&VpeolUuid>,
) {
    let Ok(mut other_entity_uuid) = edit.get_single_mut() else { return };

    if let Some(exclusive) = exclusive.exclusive() {
        // Or maybe this should use passed-data?
        if let Some(clicked_entity) = exclusive.get_clicked() {
            if let Ok(uuid) = uuid_query.get(clicked_entity) {
                other_entity_uuid.0 = uuid.0;
                exclusive.finish();
            }
        }
    } else {
        if ui.button("Pick Other Entity").clicked() {
            exclusive.start();
        }
    }
}

@idanarye
Copy link
Owner Author

idanarye commented Jun 6, 2023

Alternatively, maybe this can be combined with #20's mechanism?

fn edit_system_that_initiates_the_exclusive_mode(
    mut ui: ResMut<YoleckUi>,
    mut edit: YoleckEdit<With<&OtherEntityUuid>>,
    mut exclusive: YoleckExclusive,
    uuid_query: Query<&VpeolUuid>,
) {
    let Ok(_) = edit.get_single_mut() else { return };

    if ui.button("Pick Other Entity").clicked() {
        exclusive.enqueue(edit_system_for_the_exclusive_mode);
    }
}

fn edit_system_for_the_exclusive_mode(
    mut exclusive_input: Res<YoleckExclusiveInput>,
    mut edit: YoleckEdit<&mut OtherEntityUuid>,
) -> Option<YoleckExclusiveVeredict> {
    let mut other_entity_uuid = edit.get_single_mut()?;
    if let Some(clicked_entity) = exclusive_input.get_clicked() {
        if let Ok(uuid) = uuid_query.get(clicked_entity) {
            other_entity_uuid.0 = uuid.0;
            return Some(YoleckExclusiveVeredict::Done);
        }
    }
    None
}

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