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

Add task verifier display to ui and all related interfaces #155

Merged
merged 4 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -42,6 +42,7 @@ public static void main(final String[] args) {
TestEntity.TEXTURE_HANDLE = ManualStartSimulation.animated;

final SimulationBuilder sb = new SimulationBuilder();
sb.setTaskVerifier(new TestTaskVerifier());
sb.buildSimulation();
final Simulation sim = sb.getBuiltSimulation();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* This source file is part of the FIUS ICGE project.
* For more information see github.com/FIUS/ICGE2
*
* Copyright (c) 2019 the ICGE project authors.
*
* This software is available under the MIT license.
* SPDX-License-Identifier: MIT
*/
package de.unistuttgart.informatik.fius.icge.manualstart;

import java.util.List;

import de.unistuttgart.informatik.fius.icge.simulation.Simulation;
import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier;
import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog;
import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityMoveAction;
import de.unistuttgart.informatik.fius.icge.ui.TaskInformation;
import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus;


/**
* Example task verifier.
*
* @author Fabian Bühler
*/
public class TestTaskVerifier implements TaskVerifier, TaskInformation {

private ActionLog log;
private TaskVerificationStatus taskIsValid = TaskVerificationStatus.UNDECIDED;
private int stepsToWalk = 4;

@Override
public void attachToSimulation(Simulation sim) {
// get the log to verify if the required events did happen later
this.log = sim.getActionLog();
}

@Override
public void verify() {
if (this.log == null) {
return;
}
// check the number of steps/moves all entity have taken together
int steps = this.log.getActionsOfType(EntityMoveAction.class, true).size();
if (steps > 3) {
this.stepsToWalk = 0;
this.taskIsValid = TaskVerificationStatus.SUCCESSFUL;
} else {
this.stepsToWalk = 4 - steps;
this.taskIsValid = TaskVerificationStatus.FAILED;
neumantm marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public TaskInformation getTaskInformation() {
return this;
}

@Override
public String getTaskTitle() {
return "Test Task";
}

@Override
public String getTaskDescription() {
String description = "Just a demo task to test the UI and the Backend.";
if (this.stepsToWalk > 1) {
description += " (" + this.stepsToWalk + " steps to walk)";
}
if (this.stepsToWalk == 1) {
description += " (1 step to walk)";
}
return description;
}

@Override
public TaskVerificationStatus getTaskStatus() {
return this.taskIsValid;
}

@Override
public List<TaskInformation> getChildTasks() {
return null;
neumantm marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public interface Simulation {
*/
Playfield getPlayfield();

/**
* Get the task verifier set for this simulation.
*
* @return The task verifier set for this simulation
*/
TaskVerifier getTaskVerifier();

/**
* Get the simulation clock for this simulation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
public class SimulationBuilder {

private TaskVerifier taskVerifier;

private Simulation simulation;

/**
Expand All @@ -39,12 +41,13 @@ public class SimulationBuilder {
* @param taskVerifier
* The task verifier to use
*/
public void setTaskVerifier(final Object taskVerifier) {
public void setTaskVerifier(final TaskVerifier taskVerifier) {
if (
this.hasBuiltSimulation()
) throw new IllegalStateException(
"The simulation was already built! Use the methods of the Simulation Object to change its properties."
);
this.taskVerifier = taskVerifier;
}

/**
Expand All @@ -71,7 +74,8 @@ public void buildSimulation() {
final InspectionManager inspectionManager = new InspectionManager();

this.simulation = new StandardSimulation(
playfield, simulationClock, entityTypeRegistry, entityProgramRegistry, entityProgramRunner, actionLog, inspectionManager
playfield, simulationClock, entityTypeRegistry, entityProgramRegistry, entityProgramRunner, actionLog, inspectionManager,
this.taskVerifier
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This source file is part of the FIUS ICGE project.
* For more information see github.com/FIUS/ICGE2
*
* Copyright (c) 2019 the ICGE project authors.
*
* This software is available under the MIT license.
* SPDX-License-Identifier: MIT
*/
package de.unistuttgart.informatik.fius.icge.simulation;

import de.unistuttgart.informatik.fius.icge.ui.TaskInformation;


/**
* The interface for a verifier of a task.
*
* @author Fabian Bühler
*/
public interface TaskVerifier {
/**
* Attach the verifier to a simulation.
* <p>
* Must be called by the simulation or the simulation builder.
*
* @param sim
* the simulation to verify
*/
void attachToSimulation(Simulation sim);

/**
* Verify if the current state of the simulation matches the requirements for the successful completion of the task.
* <p>
* This method should update the task information returned by {@link #getTaskInformation}.
*/
void verify();

/**
* Get the current task information.
* <p>
* The information returned by this method should not change unless {@link #verify} is called.
*
* @return the task information
*/
TaskInformation getTaskInformation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.unistuttgart.informatik.fius.icge.simulation.Playfield;
import de.unistuttgart.informatik.fius.icge.simulation.Simulation;
import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock;
import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier;
import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog;
import de.unistuttgart.informatik.fius.icge.simulation.entity.EntityTypeRegistry;
import de.unistuttgart.informatik.fius.icge.simulation.entity.program.EntityProgramRegistry;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class StandardSimulation implements Simulation {
private final StandardEntityProgramRunner entityProgramRunner;
private final StandardActionLog actionLog;
private final StandardEntityTypeRegistry entityTypeRegistry;
private final TaskVerifier taskVerifier;
private final StandardSimulationProxy simulationProxy;

/**
Expand All @@ -60,24 +62,29 @@ public class StandardSimulation implements Simulation {
* The actionLog to use
* @param inspectionManager
* The inspection manager to use
* @param taskVerifier
* the task verifier to use to verify the task completion status
*/
public StandardSimulation(
final StandardPlayfield playfield, final StandardSimulationClock simulationClock,
final StandardEntityTypeRegistry entityTypeRegistry, final StandardEntityProgramRegistry entityProgramRegistry,
final StandardEntityProgramRunner entityProgramRunner, final StandardActionLog actionLog,
final InspectionManager inspectionManager
final InspectionManager inspectionManager, final TaskVerifier taskVerifier
) {
this.playfield = playfield;
this.simulationClock = simulationClock;
this.entityProgramRegistry = entityProgramRegistry;
this.entityProgramRunner = entityProgramRunner;
this.actionLog = actionLog;
this.entityTypeRegistry = entityTypeRegistry;
this.taskVerifier = taskVerifier;

this.playfield.initialize(this);

taskVerifier.attachToSimulation(this);

this.simulationProxy = new StandardSimulationProxy(
simulationClock, inspectionManager, entityTypeRegistry, playfield, entityProgramRegistry
simulationClock, inspectionManager, entityTypeRegistry, playfield, entityProgramRegistry, taskVerifier
);
}

Expand All @@ -86,6 +93,11 @@ public Playfield getPlayfield() {
return this.playfield;
}

@Override
public TaskVerifier getTaskVerifier() {
return this.taskVerifier;
}

@Override
public SimulationClock getSimulationClock() {
return this.simulationClock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.function.Consumer;

import de.unistuttgart.informatik.fius.icge.simulation.Position;
import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier;
import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;
import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotRunProgramException;
import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException;
Expand All @@ -31,6 +32,7 @@
import de.unistuttgart.informatik.fius.icge.ui.GameWindow;
import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy;
import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode;
import de.unistuttgart.informatik.fius.icge.ui.TaskInformation;
import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ClockButtonState;
import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;

Expand Down Expand Up @@ -63,6 +65,7 @@ public class StandardSimulationProxy implements SimulationProxy {
private final StandardSimulationClock simulationClock;
private final StandardPlayfield playfield;
private final StandardEntityProgramRegistry entityProgramRegistry;
private final TaskVerifier taskVerifier;
private final Map<SimulationTreeNode, Entity> simualtionSidebarMap;

private Entity entityToInspect;
Expand All @@ -80,17 +83,20 @@ public class StandardSimulationProxy implements SimulationProxy {
* The playfield to use
* @param entityProgramRegistry
* the entity program registry
* @param taskVerifier
* the task verifier to use to verify the task completion status
*/
public StandardSimulationProxy(
final StandardSimulationClock simulationClock, final InspectionManager inspectionManager,
final StandardEntityTypeRegistry entityTypeRegistry, final StandardPlayfield playfield,
final StandardEntityProgramRegistry entityProgramRegistry
final StandardEntityProgramRegistry entityProgramRegistry, final TaskVerifier taskVerifier
) {
this.simulationClock = simulationClock;
this.inspectionManager = inspectionManager;
this.entityTypeRegistry = entityTypeRegistry;
this.playfield = playfield;
this.entityProgramRegistry = entityProgramRegistry;
this.taskVerifier = taskVerifier;
this.simualtionSidebarMap = new ConcurrentHashMap<>();
}

Expand Down Expand Up @@ -171,6 +177,13 @@ public void accept(final List<Drawable> drawables) {
return true;
});

// taskState
TaskInformation task = null;
if (this.taskVerifier != null) {
task = this.taskVerifier.getTaskInformation();
}
this.gameWindow.getTaskStatusDisplay().setTaskInformation(task);

this.gameWindow.setSimulationProxy(this);
}

Expand Down Expand Up @@ -234,6 +247,16 @@ public void selectedEntityChanged(final String name) {
this.gameWindow.getPlayfieldDrawer().setSelectedEntityType(name, textureHandle);
}

@Override
public void refreshTaskInformation() {
this.taskVerifier.verify();
TaskInformation task = null;
if (this.taskVerifier != null) {
task = this.taskVerifier.getTaskInformation();
}
this.gameWindow.getTaskStatusDisplay().setTaskInformation(task);
}

@Override
public Set<String> getAvailableProgramsForEntityType(final String typeName) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ public interface GameWindow {
/**
* Get the console for this game window
*
* @return The console used by thsi window
* @return The console used by this window
*/
Console getConsole();

/**
* Get the task status display for this game window.
*
* @return The task status display used by this window
*/
TaskStatusDisplay getTaskStatusDisplay();

/**
* Set the title of the window, in which the ICGE is displayed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

/**
* The SimulationProxy interface. This is used for communication most between the UI and the simulation.
*
* <p>
* First the {@link #attachToGameWindow(GameWindow)} needs to be called to establish the connection. This should set up
* all communication channels from the Simulation to the UI.
*
* <p>
* The other methods are communication channels from the UI the Simulation.
*
* @author Tobias Wältken, Tim Neumann
Expand Down Expand Up @@ -79,6 +79,13 @@ public enum ButtonType {
*/
void selectedEntityChanged(String name);

/**
* This gets called by the user to refresh task status information.
* <p>
* Calling this must verify the task.
*/
void refreshTaskInformation();

//
// Entity placing
//
Expand Down
Loading