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

Improved updateRequirements on command so ConfigCommandStore should a… #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ public void createCommandsFromConfig(ObjectNode json) throws ConfigException {
JsonNode config = json.get(command.getName());
configureCommand(command, config);
}
for (int i = 0; i < 10; i++) {
boolean wasUpdated;
do {
wasUpdated = false;
for (Map.Entry<String, Command> commandEntry : commandsMapCopy.entrySet()) {
Command command = commandEntry.getValue();
command.updateRequirements();
wasUpdated = wasUpdated || command.updateRequirements();
}
}
} while (wasUpdated);
}

public void configureCommand(Command command, JsonNode config) throws ConfigException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public boolean doesRequire(Subsystem subsystem) {
return requirements != null && requirements.contains(subsystem);
}

public void updateRequirements() {

/**
* Updates any requirements on this command to require all child commands
* @return If any requirements had to be added
*/
public boolean updateRequirements() {
return false;
}

private boolean isRequiring(Subsystem subsystem, CommandRunContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ private void updateValidStates() {
}

@Override
public void updateRequirements() {
public boolean updateRequirements() {
// A sequential command requires all subsystems required by all child commands
sequence.forEach(run -> {
run.command.updateRequirements();
if (run.command.getRequirements() != null)
boolean wasUpdated = false;
for (SequentialCommandRun run : sequence) {
wasUpdated = wasUpdated || run.command.updateRequirements();
int lengthBefore = getRequirements().size();
if (run.command.getRequirements() != null && !run.parallel)
requiresAll(run.command.getRequirements());
});
wasUpdated = wasUpdated || (lengthBefore != getRequirements().size());
}
return wasUpdated;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public void configure(Config config) {
}

@Override
public void updateRequirements() {
public boolean updateRequirements() {
if (config == null) {
return;
return false;
}
List<String> commandNames = new ArrayList<>();
if (config.type == SelectorType.FIELD_CONFIGURATION) {
Expand All @@ -156,15 +156,19 @@ public void updateRequirements() {
} else {
logger.error("Invalid selector type: " + config.type);
}
boolean wasUpdated = false;
for (String commandName : commandNames) {
Command command;
try {
command = commandStore.getCommand(commandName);
} catch (IllegalArgumentException e) {
continue;
}
int lengthBefore = getRequirements().size();
requiresAll(command.getRequirements());
wasUpdated = wasUpdated || (lengthBefore != getRequirements().size());
}
return wasUpdated;
}

public enum SelectorType {
Expand Down