private void createTestProject(String projectName) { double size = 0.8; Project project = new Project(null, projectName); Sprite firstSprite = new Sprite("cat"); Script testScript = new StartScript(); brickListToCheck = new ArrayList<Brick>(); brickListToCheck.add(new HideBrick()); brickListToCheck.add(new ShowBrick()); brickListToCheck.add(new SetSizeToBrick(size)); for (Brick brick : brickListToCheck) { testScript.addBrick(brick); } firstSprite.addScript(testScript); project.addSprite(firstSprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(firstSprite); ProjectManager.getInstance().setCurrentScript(testScript); }
public void testBroadcastWait() { Sprite sprite = new Sprite("spriteOne"); Script scriptWait = new StartScript(sprite); String message = "waitTest"; BroadcastWaitBrick broadcastWaitBrick = new BroadcastWaitBrick(sprite, message); int testPosition = 100; SetXBrick setXBrick = new SetXBrick(sprite, testPosition); scriptWait.addBrick(broadcastWaitBrick); scriptWait.addBrick(setXBrick); sprite.addScript(scriptWait); BroadcastScript broadcastScript = new BroadcastScript(sprite, message); WaitBrick waitBrick = new WaitBrick(sprite, 500); int setTestPosition = 20; SetXBrick setXBrick2 = new SetXBrick(sprite, setTestPosition); broadcastScript.addBrick(waitBrick); broadcastScript.addBrick(setXBrick2); sprite.addScript(broadcastScript); Project project = new Project(getContext(), "testProject"); project.addSprite(sprite); ProjectManager.getInstance().setProject(project); sprite.createStartScriptActionSequence(); while (!sprite.look.getAllActionsAreFinished()) { sprite.look.act(1.0f); } assertEquals( "Broadcast and wait failed", testPosition, (int) sprite.look.getXInUserInterfaceDimensionUnit()); }
public void testBroadcastWait() { Sprite sprite = new Sprite("spriteOne"); Script scriptWait = new StartScript(sprite); BroadcastWaitBrick broadcastWaitBrick = new BroadcastWaitBrick(sprite); String message = "waitTest"; broadcastWaitBrick.setSelectedMessage(message); int testPosition = 100; SetXBrick setXBrick = new SetXBrick(sprite, testPosition); scriptWait.addBrick(broadcastWaitBrick); scriptWait.addBrick(setXBrick); sprite.addScript(scriptWait); BroadcastScript broadcastScript = new BroadcastScript(sprite); WaitBrick waitBrick = new WaitBrick(sprite, 500); int setTestPosition = 20; SetXBrick setXBrick2 = new SetXBrick(sprite, setTestPosition); broadcastScript.setBroadcastMessage(message); broadcastScript.addBrick(waitBrick); broadcastScript.addBrick(setXBrick2); sprite.addScript(broadcastScript); sprite.startStartScripts(); try { Thread.sleep(1000); } catch (InterruptedException ignored) { } assertEquals("Broadcast and wait failed", testPosition, (int) sprite.costume.getXPosition()); }
public void testBroadcast() { Sprite sprite = new SingleSprite("testSprite"); Script script = new StartScript(); String message = "simpleTest"; BroadcastBrick broadcastBrick = new BroadcastBrick(message); script.addBrick(broadcastBrick); sprite.addScript(script); BroadcastScript broadcastScript = new BroadcastScript(message); int testPosition = 100; SetXBrick testBrick = new SetXBrick(testPosition); broadcastScript.addBrick(testBrick); sprite.addScript(broadcastScript); Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME); Scene scene = project.getDefaultScene(); scene.addSprite(sprite); ProjectManager.getInstance().setProject(project); sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>()); while (!allActionsOfAllSpritesAreFinished()) { for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) { spriteOfList.look.act(1.0f); } } assertEquals( "Simple broadcast failed", testPosition, (int) sprite.look.getXInUserInterfaceDimensionUnit()); }
private void addBrickToPositionInProject(int position, Brick brick) { Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite(); int[] temp = getScriptAndBrickIndexFromProject(position); int scriptPosition = temp[0]; int brickPosition = temp[1]; Script script = currentSprite.getScript(scriptPosition); if (brick instanceof NestingBrick) { ((NestingBrick) draggedBrick).initialize(); List<NestingBrick> nestingBrickList = ((NestingBrick) draggedBrick).getAllNestingBrickParts(true); for (int i = 0; i < nestingBrickList.size(); i++) { if (nestingBrickList.get(i) instanceof DeadEndBrick) { if (i < nestingBrickList.size() - 1) { Log.w(TAG, "Adding a DeadEndBrick in the middle of the NestingBricks"); } position = getPositionForDeadEndBrick(position); temp = getScriptAndBrickIndexFromProject(position); script.addBrick(temp[1], (Brick) nestingBrickList.get(i)); } else { script.addBrick(brickPosition + i, (Brick) nestingBrickList.get(i)); } } } else { script.addBrick(brickPosition, brick); } }
@And("^this script has a BroadcastWait '(\\w+)' brick$") public void script_has_broadcast_wait_brick(String message) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); BroadcastWaitBrick brick = new BroadcastWaitBrick(message); script.addBrick(brick); }
@And("^this script has a Wait (\\d+) milliseconds brick$") public void script_has_wait_ms_brick(int millis) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); WaitBrick brick = new WaitBrick(millis); script.addBrick(brick); }
@And("^this script has a Wait (\\d+.?\\d*) seconds? brick$") public void script_has_wait_s_brick(int seconds) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); WaitBrick brick = new WaitBrick(seconds * 1000); script.addBrick(brick); }
@And("^this script has a Repeat (\\d+) times brick$") public void script_has_repeat_times_brick(int iterations) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); Brick brick = new RepeatBrick(new Formula(iterations)); Cucumber.put(Cucumber.KEY_LOOP_BEGIN_BRICK, brick); script.addBrick(brick); }
@And("^this script has a Repeat end brick$") public void script_has_repeat_end_brick() { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); LoopBeginBrick loopBeginBrick = (LoopBeginBrick) Cucumber.get(Cucumber.KEY_LOOP_BEGIN_BRICK); Brick brick = new LoopEndBrick(loopBeginBrick); script.addBrick(brick); }
private void createProject() { Project project = new Project(null, UiTestUtils.PROJECTNAME1); Sprite spriteCat = new Sprite(backgroundName); Script startScriptCat = new StartScript(); Script scriptTappedCat = new WhenScript(); Brick setXBrick = new SetXBrick(50); Brick setYBrick = new SetYBrick(50); Brick changeXBrick = new ChangeXByNBrick(50); startScriptCat.addBrick(setYBrick); startScriptCat.addBrick(setXBrick); scriptTappedCat.addBrick(changeXBrick); spriteCat.addScript(startScriptCat); spriteCat.addScript(scriptTappedCat); project.addSprite(spriteCat); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(spriteCat); ProjectManager.getInstance().setCurrentScript(startScriptCat); File imageFile = UiTestUtils.saveFileToProject( project.getName(), "catroid_sunglasses.png", org.catrobat.catroid.test.R.drawable.catroid_sunglasses, getInstrumentation().getContext(), UiTestUtils.FileTypes.IMAGE); ProjectManager projectManager = ProjectManager.getInstance(); List<LookData> lookDataList = projectManager.getCurrentSprite().getLookDataList(); LookData lookData = new LookData(); lookData.setLookFilename(imageFile.getName()); lookData.setLookName("Catroid sun"); lookDataList.add(lookData); projectManager .getFileChecksumContainer() .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath()); File soundFile = UiTestUtils.saveFileToProject( project.getName(), "longsound.mp3", org.catrobat.catroid.test.R.raw.longsound, getInstrumentation().getContext(), UiTestUtils.FileTypes.SOUND); SoundInfo soundInfo = new SoundInfo(); soundInfo.setSoundFileName(soundFile.getName()); soundInfo.setTitle("longsound"); List<SoundInfo> soundInfoList = ProjectManager.getInstance().getCurrentSprite().getSoundList(); soundInfoList.add(soundInfo); ProjectManager.getInstance() .getFileChecksumContainer() .addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath()); }
public void testAliasesAndXmlHeader() { String projectName = "myProject"; File projectFile = new File(Constants.DEFAULT_ROOT + "/" + projectName); if (projectFile.exists()) { UtilFile.deleteDirectory(projectFile); } Project project = new Project(getContext(), projectName); Sprite sprite = new Sprite("testSprite"); Script startScript = new StartScript(sprite); Script whenScript = new WhenScript(sprite); sprite.addScript(startScript); sprite.addScript(whenScript); project.addSprite(sprite); ArrayList<Brick> startScriptBrickList = new ArrayList<Brick>(); ArrayList<Brick> whenScriptBrickList = new ArrayList<Brick>(); startScriptBrickList.add(new ChangeXByNBrick(sprite, 4)); startScriptBrickList.add(new ChangeYByNBrick(sprite, 5)); startScriptBrickList.add(new ComeToFrontBrick(sprite)); startScriptBrickList.add(new GoNStepsBackBrick(sprite, 5)); startScriptBrickList.add(new HideBrick(sprite)); startScriptBrickList.add(new WhenStartedBrick(sprite, startScript)); whenScriptBrickList.add(new PlaySoundBrick(sprite)); whenScriptBrickList.add(new SetSizeToBrick(sprite, 50)); whenScriptBrickList.add(new SetCostumeBrick(sprite)); whenScriptBrickList.add(new SetXBrick(sprite, 50)); whenScriptBrickList.add(new SetYBrick(sprite, 50)); whenScriptBrickList.add(new ShowBrick(sprite)); whenScriptBrickList.add(new WaitBrick(sprite, 1000)); for (Brick b : startScriptBrickList) { startScript.addBrick(b); } for (Brick b : whenScriptBrickList) { whenScript.addBrick(b); } storageHandler.saveProject(project); String projectString = TestUtils.getProjectfileAsString(projectName); assertFalse("project contains package information", projectString.contains("org.catrobat")); String xmlHeader = (String) TestUtils.getPrivateField("XML_HEADER", new XmlSerializer(), false); assertTrue( "Project file did not contain correct XML header.", projectString.startsWith(xmlHeader)); projectFile = new File(Constants.DEFAULT_ROOT + "/" + projectName); if (projectFile.exists()) { UtilFile.deleteDirectory(projectFile); } }
@And("^this script has a Print brick with$") public void script_has_a_print_brick(String text) { Sprite object = (Sprite) Cucumber.get(Cucumber.KEY_CURRENT_OBJECT); Script script = (Script) Cucumber.get(Cucumber.KEY_CURRENT_SCRIPT); if (outputStream == null) { outputStream = new ByteArrayOutputStream(); } PrintBrick brick = new PrintBrick(object, text); brick.setOutputStream(outputStream); script.addBrick(brick); }
public void addNewBrick(int position, Brick brickToBeAdded, boolean initInsertedBrick) { if (draggedBrick != null) { Log.w(TAG, "Want to add Brick while there is another one currently dragged."); return; } Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite(); int scriptCount = currentSprite.getNumberOfScripts(); if (scriptCount == 0 && brickToBeAdded instanceof ScriptBrick) { currentSprite.addScript(((ScriptBrick) brickToBeAdded).getScriptSafe()); initBrickList(); notifyDataSetChanged(); return; } if (position < 0) { position = 0; } else if (position > brickList.size()) { position = brickList.size(); } if (brickToBeAdded instanceof ScriptBrick) { brickList.add(position, brickToBeAdded); position = getNewPositionForScriptBrick(position, brickToBeAdded); brickList.remove(brickToBeAdded); brickList.add(position, brickToBeAdded); scrollToPosition(position); } else { position = getNewPositionIfEndingBrickIsThere(position, brickToBeAdded); position = position <= 0 ? 1 : position; position = position > brickList.size() ? brickList.size() : position; brickList.add(position, brickToBeAdded); } this.initInsertedBrick = initInsertedBrick; this.positionOfInsertedBrick = position; if (scriptCount == 0 && userBrick == null) { Script script = new StartScript(); currentSprite.addScript(script); brickList.add(0, script.getScriptBrick()); ProjectManager.getInstance().setCurrentScript(script); clearCheckedItems(); positionOfInsertedBrick = 1; } notifyDataSetChanged(); }
private int[] getScriptAndBrickIndexFromProject(int position) { int[] returnValue = new int[2]; if (position >= brickList.size()) { returnValue[0] = sprite.getNumberOfScripts() - 1; if (returnValue[0] < 0) { returnValue[0] = 0; returnValue[1] = 0; } else { Script script = sprite.getScript(returnValue[0]); if (script != null) { returnValue[1] = script.getBrickList().size(); } else { returnValue[1] = 0; } } return returnValue; } int scriptPosition = 0; int scriptOffset; for (scriptOffset = 0; scriptOffset < position; ) { scriptOffset += sprite.getScript(scriptPosition).getBrickList().size() + 1; if (scriptOffset < position) { scriptPosition++; } } scriptOffset -= sprite.getScript(scriptPosition).getBrickList().size(); returnValue[0] = scriptPosition; List<Brick> brickListFromProject = sprite.getScript(scriptPosition).getBrickList(); int brickPosition = position; if (scriptOffset > 0) { brickPosition -= scriptOffset; } Brick brickFromProject; if (brickListFromProject.size() != 0 && brickPosition < brickListFromProject.size()) { brickFromProject = brickListFromProject.get(brickPosition); } else { brickFromProject = null; } returnValue[1] = sprite.getScript(scriptPosition).getBrickList().indexOf(brickFromProject); if (returnValue[1] < 0) { returnValue[1] = sprite.getScript(scriptPosition).getBrickList().size(); } return returnValue; }
private void createProject() { project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME); Sprite sprite = new Sprite("cat"); Script script = new StartScript(sprite); script.addBrick(new StopAllSoundsBrick(sprite)); sprite.addScript(script); project.addSprite(sprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(sprite); ProjectManager.getInstance().setCurrentScript(script); }
private void addBrickToPositionInUserScript(int position, Brick brick) { position = getPositionInUserScript(position); if (brick instanceof NestingBrick) { ((NestingBrick) draggedBrick).initialize(); List<NestingBrick> nestingBrickList = ((NestingBrick) draggedBrick).getAllNestingBrickParts(true); for (int i = 0; i < nestingBrickList.size(); i++) { script.addBrick(position + i, (Brick) nestingBrickList.get(i)); } } else { script.addBrick(position, brick); } }
private void createProject() { project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME); sprite = new Sprite("cat"); Script script = new StartScript(sprite); placeAtBrick = new PlaceAtBrick(sprite, INITIAL_X, INITIAL_Y); script.addBrick(placeAtBrick); sprite.addScript(script); project.addSprite(sprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(sprite); ProjectManager.getInstance().setCurrentScript(script); }
private void createProject() { ProjectManager projectManager = ProjectManager.getInstance(); Project project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME); Sprite firstSprite = new Sprite("cat"); Script testScript = new StartScript(firstSprite); SetLookBrick setLookBrick = new SetLookBrick(firstSprite); testScript.addBrick(setLookBrick); firstSprite.addScript(testScript); project.addSprite(firstSprite); projectManager.setProject(project); projectManager.setCurrentSprite(firstSprite); projectManager.setCurrentScript(testScript); lookDataList = projectManager.getCurrentSprite().getLookDataList(); lookFile = UiTestUtils.saveFileToProject( UiTestUtils.DEFAULT_TEST_PROJECT_NAME, "image.png", RESOURCE_LOOK, getInstrumentation().getContext(), UiTestUtils.FileTypes.IMAGE); LookData lookData = new LookData(); lookData.setLookFilename(lookFile.getName()); lookData.setLookName(lookName); lookFile2 = UiTestUtils.saveFileToProject( UiTestUtils.DEFAULT_TEST_PROJECT_NAME, "image2.png", RESOURCE_LOOK2, getInstrumentation().getContext(), UiTestUtils.FileTypes.IMAGE); LookData lookData2 = new LookData(); lookData2.setLookFilename(lookFile2.getName()); lookData2.setLookName(lookName2); lookDataList.add(lookData); lookDataList.add(lookData2); ProjectManager.getInstance() .getFileChecksumContainer() .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath()); ProjectManager.getInstance() .getFileChecksumContainer() .addChecksum(lookData2.getChecksum(), lookData2.getAbsolutePath()); }
@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); }
private void createProject() { project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME); Sprite sprite = new Sprite("cat"); Script script = new StartScript(); motorBrick = new LegoNxtMotorMoveBrick(LegoNxtMotorMoveBrick.Motor.MOTOR_A, SET_SPEED_INITIALLY); script.addBrick(motorBrick); sprite.addScript(script); project.addSprite(sprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(sprite); ProjectManager.getInstance().setCurrentScript(script); }
public void launchAddBrickAndSelectBrickAt(Context context, int index) { int[] temp = getScriptAndBrickIndexFromProject(index); Script script = ProjectManager.getInstance().getCurrentSprite().getScript(temp[0]); if (script != null) { Brick brick = script.getBrick(temp[1]); if (!viewSwitchLock.tryLock()) { return; } if (brick instanceof UserBrick) { AddBrickFragment.setBrickFocus(((UserBrick) brick)); } ScriptFragment theScriptFragment = ((ScriptFragment) scriptFragment); theScriptFragment.onCategorySelected(context.getString(R.string.category_user_bricks)); } }
private void initBrickListUserScript() { script = getUserScript(); brickList = new ArrayList<Brick>(); brickList.add(script.getScriptBrick()); script.getScriptBrick().setBrickAdapter(this); for (Brick brick : script.getBrickList()) { if (brick.getClass().equals(ChangeVariableBrick.class)) { ChangeVariableBrick changeVariableBrick = (ChangeVariableBrick) brick; changeVariableBrick.setInUserBrick(true); } else if (brick.getClass().equals(SetVariableBrick.class)) { SetVariableBrick setVariableBrick = (SetVariableBrick) brick; setVariableBrick.setInUserBrick(true); } brickList.add(brick); brick.setBrickAdapter(this); } }
public void testRestartingOfWhenScriptWithBroadcastWaitBrick() { String messageOne = "messageOne"; String messageTwo = "messageTwo"; final int xMovement = 1; Sprite sprite = new SingleSprite("cat"); Script startScript = new StartScript(); BroadcastBrick startBroadcastBrick = new BroadcastBrick(messageOne); startScript.addBrick(startBroadcastBrick); sprite.addScript(startScript); BroadcastScript broadcastScriptMessageOne = new BroadcastScript(messageOne); ChangeXByNBrick changeXByNBrickOne = new ChangeXByNBrick(xMovement); BroadcastWaitBrick broadcastWaitBrickOne = new BroadcastWaitBrick(messageTwo); broadcastScriptMessageOne.addBrick(changeXByNBrickOne); broadcastScriptMessageOne.addBrick(broadcastWaitBrickOne); sprite.addScript(broadcastScriptMessageOne); BroadcastScript broadcastScriptMessageTwo = new BroadcastScript(messageTwo); ChangeXByNBrick changeXByNBrickTwo = new ChangeXByNBrick(xMovement); BroadcastWaitBrick broadcastWaitBrickTwo = new BroadcastWaitBrick(messageOne); broadcastScriptMessageTwo.addBrick(changeXByNBrickTwo); broadcastScriptMessageTwo.addBrick(broadcastWaitBrickTwo); sprite.addScript(broadcastScriptMessageTwo); Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME); project.getDefaultScene().addSprite(sprite); ProjectManager.getInstance().setProject(project); sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>()); int loopCounter = 0; while (!allActionsOfAllSpritesAreFinished() && loopCounter++ < 20) { for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) { spriteOfList.look.act(1.0f); } } assertTrue( "When script does not restart itself when a BroadcastWait is sent! ", (int) sprite.look.getXInUserInterfaceDimensionUnit() > 5 * xMovement); }
public void initBrickList() { brickList = new ArrayList<Brick>(); if (userBrick != null) { initBrickListUserScript(); return; } Sprite sprite = ProjectManager.getInstance().getCurrentSprite(); int numberOfScripts = sprite.getNumberOfScripts(); for (int scriptPosition = 0; scriptPosition < numberOfScripts; scriptPosition++) { Script script = sprite.getScript(scriptPosition); brickList.add(script.getScriptBrick()); script.getScriptBrick().setBrickAdapter(this); for (Brick brick : script.getBrickList()) { brickList.add(brick); brick.setBrickAdapter(this); } } }
public void testWhenScriptRestartingItself() { Sprite sprite = new SingleSprite("testSprite"); Script script = new StartScript(); String message = "simpleTest"; BroadcastBrick broadcastBrick = new BroadcastBrick(message); script.addBrick(broadcastBrick); sprite.addScript(script); BroadcastScript broadcastScript = new BroadcastScript(message); final int xMovement = 1; ChangeXByNBrick changeXByNBrick = new ChangeXByNBrick(xMovement); broadcastScript.addBrick(changeXByNBrick); BroadcastBrick broadcastBrickLoop = new BroadcastBrick(message); broadcastScript.addBrick(broadcastBrickLoop); WaitBrick wb = new WaitBrick(5); broadcastScript.addBrick(wb); sprite.addScript(broadcastScript); Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME); project.getDefaultScene().addSprite(sprite); ProjectManager.getInstance().setProject(project); sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>()); int loopCounter = 0; while (!allActionsOfAllSpritesAreFinished() && loopCounter++ < 20) { for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) { spriteOfList.look.act(1.0f); } } assertTrue( "When script does not restart itself!", (int) sprite.look.getXInUserInterfaceDimensionUnit() > xMovement); }
private void addScriptToProject(int position, ScriptBrick scriptBrick) { Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite(); int[] temp = getScriptAndBrickIndexFromProject(position); int scriptPosition = temp[0]; int brickPosition = temp[1]; Script newScript = scriptBrick.getScriptSafe(); if (currentSprite.getNumberOfBricks() > 0) { int addScriptTo = position == 0 ? 0 : scriptPosition + 1; currentSprite.addScript(addScriptTo, newScript); } else { currentSprite.addScript(newScript); } Script previousScript = currentSprite.getScript(scriptPosition); if (previousScript != null) { Brick brick; int size = previousScript.getBrickList().size(); for (int i = brickPosition; i < size; i++) { brick = previousScript.getBrick(brickPosition); previousScript.removeBrick(brick); newScript.addBrick(brick); } } ProjectManager.getInstance().setCurrentScript(newScript); }
private void createProject() { project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME); sprite = new Sprite("cat"); Script script = new StartScript(sprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(sprite); ProjectManager.getInstance().setCurrentScript(script); userVariablesContainer = project.getUserVariables(); userVariablesContainer.addProjectUserVariable("p1"); userVariablesContainer.addProjectUserVariable("p2"); userVariablesContainer.addSpriteUserVariable("sprite_var1"); userVariablesContainer.addSpriteUserVariable("sprite_var2"); setVariableBrick = new SetVariableBrick(sprite, 0.0); script.addBrick(setVariableBrick); changeVariableBrick = new ChangeVariableBrick(sprite, 1.1); script.addBrick(changeVariableBrick); sprite.addScript(script); project.addSprite(sprite); }
private int getScriptIndexFromProject(int index) { int scriptIndex = 0; Script temporaryScript = null; for (int i = 0; i < index; ) { temporaryScript = sprite.getScript(scriptIndex); if (temporaryScript == null) { Log.e( TAG, "getScriptIndexFromProject() tmpScript was null. Index was " + index + " scriptIndex was " + scriptIndex); return -1; } i += temporaryScript.getBrickList().size() + 1; if (i <= index) { scriptIndex++; } } return scriptIndex; }