@And("^this script has a change '(\\w+)' by (\\d+.?\\d*) brick$") public void script_has_change_var_by_val_brick(String name, String value) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); Project project = ProjectManager.getInstance().getCurrentProject(); UserVariable variable = project.getUserVariables().getUserVariable(name, object); if (variable == null) { variable = project.getUserVariables().addSpriteUserVariableToSprite(object, name); } FormulaElement elemValue = new FormulaElement(ElementType.NUMBER, value, null); Brick brick = new ChangeVariableBrick(new Formula(elemValue), variable); script.addBrick(brick); }
@And("^this script has a set '(\\w+)' to '(\\w+)' brick$") public void script_has_set_var_to_var_brick(String a, String b) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); Project project = ProjectManager.getInstance().getCurrentProject(); UserVariable varA = project.getUserVariables().getUserVariable(a, object); if (varA == null) { varA = project.getUserVariables().addSpriteUserVariableToSprite(object, a); } FormulaElement elemB = new FormulaElement(ElementType.USER_VARIABLE, b, null); Brick brick = new SetVariableBrick(new Formula(elemB), varA); script.addBrick(brick); }
@Then("^the variable '(\\w+)' should be equal (\\d+.?\\d*)$") public void var_should_equal_float(String name, float expected) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Project project = ProjectManager.getInstance().getCurrentProject(); UserVariable variable = project.getUserVariables().getUserVariable(name, object); assertNotNull("The variable does not exist.", variable); float actual = variable.getValue().floatValue(); assertThat("The variable is != the value.", actual, equalTo(expected)); }