public List<Brick> getListWithAllBricks() { List<Brick> allBricks = new ArrayList<>(); for (Script script : scriptList) { allBricks.add(script.getScriptBrick()); allBricks.addAll(script.getBrickList()); } for (UserBrick userBrick : userBricks) { allBricks.add(userBrick); Script userScript = userBrick.getDefinitionBrick().getUserScript(); if (userScript != null) { allBricks.addAll(userScript.getBrickList()); } } return allBricks; }
public int getNumberOfBricks() { int brickCount = 0; for (Script s : scriptList) { brickCount += s.getBrickList().size(); } return brickCount; }
public List<Brick> getAllBricks() { List<Brick> result = new ArrayList<>(); for (Script script : scriptList) { for (Brick brick : script.getBrickList()) { result.add(brick); } } for (UserBrick userBrick : userBricks) { result.add(userBrick); Script userScript = userBrick.getDefinitionBrick().getUserScript(); for (Brick brick : userScript.getBrickList()) { result.add(brick); } } return result; }
private void setDefinitionBrickReferences( Sprite cloneSprite, List<UserBrick> originalPrototypeUserBricks) { for (int scriptPosition = 0; scriptPosition < cloneSprite.getScriptList().size(); scriptPosition++) { Script clonedScript = cloneSprite.getScript(scriptPosition); for (int brickPosition = 0; brickPosition < clonedScript.getBrickList().size(); brickPosition++) { Brick clonedBrick = clonedScript.getBrick(brickPosition); if (!(clonedBrick instanceof UserBrick)) { continue; } UserBrick clonedUserBrick = ((UserBrick) clonedBrick); UserBrick originalUserBrick = ((UserBrick) getScript(scriptPosition).getBrick(brickPosition)); int originalIndexOfDefinitionBrick = 0; for (int prototypeUserBrickPosition = 0; prototypeUserBrickPosition < originalPrototypeUserBricks.size(); prototypeUserBrickPosition++) { UserBrick originalPrototypeUserBrick = originalPrototypeUserBricks.get(prototypeUserBrickPosition); if (originalPrototypeUserBrick .getDefinitionBrick() .equals(originalUserBrick.getDefinitionBrick())) { originalIndexOfDefinitionBrick = prototypeUserBrickPosition; break; } } UserBrick clonedPrototypeUserBrick = cloneSprite.getUserBrickList().get(originalIndexOfDefinitionBrick); UserScriptDefinitionBrick correctClonedDefinitionBrick = clonedPrototypeUserBrick.getDefinitionBrick(); clonedUserBrick.setDefinitionBrick(correctClonedDefinitionBrick); clonedPrototypeUserBrick.updateUserBrickParametersAndVariables(); clonedUserBrick.updateUserBrickParametersAndVariables(); } } }
public void removeUnusedBroadcastMessages() { List<String> usedMessages = new ArrayList<String>(); for (Sprite currentSprite : spriteList) { for (int scriptIndex = 0; scriptIndex < currentSprite.getNumberOfScripts(); scriptIndex++) { Script currentScript = currentSprite.getScript(scriptIndex); if (currentScript instanceof BroadcastMessage) { addBroadcastMessage( ((BroadcastMessage) currentScript).getBroadcastMessage(), usedMessages); } for (int brickIndex = 0; brickIndex < currentScript.getBrickList().size(); brickIndex++) { Brick currentBrick = currentScript.getBrick(brickIndex); if (currentBrick instanceof BroadcastMessage) { addBroadcastMessage( ((BroadcastMessage) currentBrick).getBroadcastMessage(), usedMessages); } } } } MessageContainer.removeUnusedMessages(usedMessages); }