Example #1
0
  public void testBehaviourWithoutBricks() {
    Project project = ProjectManager.getInstance().getCurrentProject();
    assertNotNull("current project was null", project);

    Sprite blueSprite = project.getSpriteList().get(4);
    while (blueSprite.getNumberOfScripts() > 0) {
      blueSprite.removeScript(blueSprite.getScript(0));
    }

    assertEquals("there shouldn't be any script left", 0, blueSprite.getNumberOfScripts());
    assertEquals("there shouldn't be any script left", 0, blueSprite.getNumberOfBricks());
    StorageHandler.getInstance().loadProject(project.getName());

    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1400);

    byte[] screenArray = StageActivity.stageListener.getPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, -19, -19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, -19, 19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 19, -19, SCREEN_WIDTH, SCREEN_HEIGHT);
    UiTestUtils.comparePixelArrayWithPixelScreenArray(
        BLUE_PIXEL, screenArray, 19, 19, SCREEN_WIDTH, SCREEN_HEIGHT);

    solo.sleep(2000);
  }
Example #2
0
 public void handleScriptDelete(Sprite spriteToEdit, Script scriptToDelete) {
   spriteToEdit.removeScript(scriptToDelete);
   if (spriteToEdit.getNumberOfScripts() == 0) {
     ProjectManager.getInstance().setCurrentScript(null);
     updateProjectBrickList();
   } else {
     int lastScriptIndex = spriteToEdit.getNumberOfScripts() - 1;
     Script lastScript = spriteToEdit.getScript(lastScriptIndex);
     ProjectManager.getInstance().setCurrentScript(lastScript);
     updateProjectBrickList();
   }
 }
Example #3
0
  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();
  }
Example #4
0
  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;
  }
Example #5
0
 private void addScriptEndCallbacks() {
   Project project = ProjectManager.getInstance().getCurrentProject();
   for (Sprite sprite : project.getSpriteList()) {
     for (int i = 0; i < sprite.getNumberOfScripts(); i++) {
       sprite
           .getScript(i)
           .addBrick(
               new CallbackBrick(
                   sprite,
                   new CallbackBrick.BrickCallback() {
                     @Override
                     public void onCallback() {
                       programWaitLock.release();
                     }
                   }));
     }
   }
 }
Example #6
0
  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);
      }
    }
  }
Example #7
0
  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);
  }