コード例 #1
0
ファイル: Sprite.java プロジェクト: paggerbua/Catroid
  private void setVariableReferencesOfClonedSprite(Sprite cloneSprite) {
    DataContainer dataContainer =
        ProjectManager.getInstance().getCurrentProject().getDataContainer();
    List<UserVariable> clonedSpriteVariables =
        dataContainer.getOrCreateVariableListForSprite(cloneSprite);
    cloneSprite.updateUserVariableReferencesInUserVariableBricks(clonedSpriteVariables);

    List<UserVariable> clonedProjectVariables = dataContainer.getProjectVariables();
    cloneSprite.updateUserVariableReferencesInUserVariableBricks(clonedProjectVariables);
  }
コード例 #2
0
ファイル: Sprite.java プロジェクト: paggerbua/Catroid
 private void cloneSpriteVariables(Project currentProject, Sprite cloneSprite) {
   DataContainer userVariables = currentProject.getDataContainer();
   List<UserVariable> originalSpriteVariables =
       userVariables.getOrCreateVariableListForSprite(this);
   List<UserVariable> clonedSpriteVariables =
       userVariables.getOrCreateVariableListForSprite(cloneSprite);
   for (UserVariable variable : originalSpriteVariables) {
     clonedSpriteVariables.add(new UserVariable(variable.getName(), variable.getValue()));
   }
 }
コード例 #3
0
  @Override
  protected void setUp() {
    Project project = new Project(null, "testProject");
    firstSprite = new SingleSprite("firstSprite");
    StartScript startScript = new StartScript();
    ChangeSizeByNBrick changeBrick = new ChangeSizeByNBrick(10);
    firstSprite.addScript(startScript);
    startScript.addBrick(changeBrick);
    project.getDefaultScene().addSprite(firstSprite);
    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(firstSprite);

    dataContainer = ProjectManager.getInstance().getCurrentScene().getDataContainer();
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME);
    dataContainer.addSpriteUserListToSprite(firstSprite, SPRITE_USER_LIST_NAME);
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME_2);
  }
コード例 #4
0
  public void testFunctionLength() {
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME);
    dataContainer.getUserList(PROJECT_USER_LIST_NAME, firstSprite).setList(new ArrayList<Object>());

    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        (double) 0,
        firstSprite);

    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_STRINGS);
    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        (double) USER_LIST_VALUES_STRINGS_LENGTH_INTERPRETATION_VALUE,
        firstSprite);

    ArrayList<Object> userList = new ArrayList<Object>();
    userList.add("0");
    dataContainer.getUserList(PROJECT_USER_LIST_NAME, firstSprite).setList(userList);
    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        (double) 1,
        firstSprite);

    userList.clear();
    userList.add("0.0");
    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        (double) 3,
        firstSprite);

    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH, InternTokenType.NUMBER, "0", (double) 1, firstSprite);

    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH, InternTokenType.NUMBER, "0.0", (double) 3, firstSprite);
  }
コード例 #5
0
  public void testUserListReset() {
    dataContainer.addSpriteUserList(SPRITE_USER_LIST_NAME);
    dataContainer.addSpriteUserList(PROJECT_USER_LIST_NAME_2);
    dataContainer.addSpriteUserList(PROJECT_USER_LIST_NAME);

    dataContainer
        .getUserList(SPRITE_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS);
    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS);
    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME_2, firstSprite)
        .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS);

    dataContainer.resetAllDataObjects();

    assertEquals(
        "Sprite UserList did not reset",
        EMPTY_USER_LIST_INTERPRETATION_VALUE,
        interpretUserList(SPRITE_USER_LIST_NAME));
    assertEquals(
        "Project UserList did not reset",
        EMPTY_USER_LIST_INTERPRETATION_VALUE,
        interpretUserList(PROJECT_USER_LIST_NAME));
    assertEquals(
        "Project UserList 2 did not reset",
        EMPTY_USER_LIST_INTERPRETATION_VALUE,
        interpretUserList(PROJECT_USER_LIST_NAME_2));
  }
コード例 #6
0
  public void testUserListInterpretationEmptyList() {
    dataContainer.getUserList(PROJECT_USER_LIST_NAME, firstSprite).getList().clear();

    assertEquals(
        "Formula interpretation of List is not as expected",
        EMPTY_USER_LIST_INTERPRETATION_VALUE,
        (Double) interpretUserList(PROJECT_USER_LIST_NAME),
        DELTA);
  }
コード例 #7
0
 public void testUserListInterpretationStringsAndNumbers() {
   dataContainer
       .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
       .setList(USER_LIST_VALUES_STRINGS_AND_NUMBERS);
   assertEquals(
       "Formula interpretation of List is not as expected",
       USER_LIST_VALUES_STRINGS_AND_NUMBERS_INTERPRETATION_VALUE,
       interpretUserList(PROJECT_USER_LIST_NAME));
 }
コード例 #8
0
 public void testUserListInterpretationMultipleNumberString() {
   dataContainer
       .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
       .setList(USER_LIST_VALUES_MULTIPLE_NUMBER_STRING);
   assertEquals(
       "Formula interpretation of List is not as expected",
       USER_LIST_VALUES_MULTIPLE_NUMBER_STRING_INTERPRETATION_VALUE,
       interpretUserList(PROJECT_USER_LIST_NAME));
 }
コード例 #9
0
  public void testFunctionNumberOfItems() {
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME);

    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.NUMBER_OF_ITEMS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        (double) 0,
        firstSprite);

    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_STRINGS);
    FormulaEditorTestUtil.testSingleParameterFunction(
        Functions.LENGTH,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        (double) USER_LIST_VALUES_STRINGS_LENGTH_INTERPRETATION_VALUE,
        firstSprite);
  }
コード例 #10
0
ファイル: HideTextAction.java プロジェクト: paggerbua/Catroid
  @Override
  protected void begin() {
    DataContainer dataContainer =
        ProjectManager.getInstance().getCurrentProject().getDataContainer();
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    List<UserVariable> variableList = dataContainer.getProjectVariables();
    Map<Sprite, List<UserVariable>> spriteVariableMap = dataContainer.getSpriteVariableMap();

    setVariablesVisible(variableList);

    if (currentSprite != null) {
      List<UserVariable> spriteVariableList = spriteVariableMap.get(currentSprite);
      setVariablesVisible(spriteVariableList);
    }
    if (userBrick != null) {
      List<UserVariable> userBrickVariableList =
          dataContainer.getOrCreateVariableListForUserBrick(userBrick);
      setVariablesVisible(userBrickVariableList);
    }
  }
コード例 #11
0
  public void testFunctionContains() {
    dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME);
    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS);
    dataContainer.addProjectUserVariable(PROJECT_USER_VARIABLE);

    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.CONTAINS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        InternTokenType.NUMBER,
        "1",
        1d,
        firstSprite);

    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.CONTAINS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        InternTokenType.STRING,
        "1",
        1d,
        firstSprite);

    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.CONTAINS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        InternTokenType.STRING,
        "1.00",
        1d,
        firstSprite);

    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.CONTAINS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        InternTokenType.NUMBER,
        "0",
        0d,
        firstSprite);

    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_STRINGS_AND_NUMBERS);

    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.CONTAINS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        InternTokenType.STRING,
        "Hello",
        1d,
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("Hello");
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.CONTAINS,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        1d,
        firstSprite);
  }
コード例 #12
0
  public void testFunctionListItem() {
    dataContainer.addSpriteUserList(PROJECT_USER_LIST_NAME);
    dataContainer
        .getUserList(PROJECT_USER_LIST_NAME, firstSprite)
        .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS);
    dataContainer.addProjectUserVariable(PROJECT_USER_VARIABLE);

    String index = "1";
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.NUMBER,
        index,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        1.0,
        firstSprite);

    index = "0";
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.NUMBER,
        index,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        "",
        firstSprite);

    index = "4";
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.NUMBER,
        index,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        "",
        firstSprite);

    index = "1.4";
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.NUMBER,
        index,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        1.0,
        firstSprite);

    index = "1.0";
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.STRING,
        index,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        1.0,
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("1");
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        1.0,
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("0");
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        "",
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("4");
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        "",
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue(1d);
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        1.0,
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue(0d);
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        "",
        firstSprite);

    dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue(4d);
    FormulaEditorTestUtil.testDoubleParameterFunction(
        Functions.LIST_ITEM,
        InternTokenType.USER_VARIABLE,
        PROJECT_USER_VARIABLE,
        InternTokenType.USER_LIST,
        PROJECT_USER_LIST_NAME,
        "",
        firstSprite);
  }