Skip to content

Commit

Permalink
IDE-198 Create class EndBrick and use in Composite Bricks instead of …
Browse files Browse the repository at this point in the history
…inner class (#4868)
  • Loading branch information
ma-zea authored Oct 9, 2023
1 parent af8dc0e commit 83e4db4
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 430 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ public static Iterable<Object[]> data() {

brickClasses = removeAbstractClasses(brickClasses);
brickClasses = removeInnerClasses(brickClasses);
brickClasses = removeEndBrick(brickClasses);
for (Class<?> brickClazz : brickClasses) {
parameters.add(new Object[] {brickClazz.getName(), brickClazz});
}
Expand Down Expand Up @@ -549,4 +550,15 @@ private static Set<Class> removeInnerClasses(Set<Class> classes) {
}
return filtered;
}

private static Set<Class> removeEndBrick(Set<Class> classes) {
Set<Class> filtered = new HashSet<>();

for (Class clazz : classes) {
if (!clazz.getName().contains("EndBrick")) {
filtered.add(clazz);
}
}
return filtered;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.content.bricks

import org.catrobat.catroid.R
import org.catrobat.catroid.content.Sprite
import org.catrobat.catroid.content.actions.ScriptSequenceAction
import java.util.UUID

class EndBrick @JvmOverloads constructor(
endBrickParent: BrickBaseType,
private val viewResource: Int = R.layout.brick_loop_end
) : BrickBaseType() {

init {
parent = endBrickParent
}

override fun getViewResource(): Int = viewResource

override fun addActionToSequence(sprite: Sprite?, sequence: ScriptSequenceAction?) {
// not needed for EndBricks, in case you need it for one, please be aware that changes
// here will affect multiple composite bricks
}

override fun isCommentedOut(): Boolean = parent.isCommentedOut

override fun consistsOfMultipleParts(): Boolean = true

override fun getAllParts(): List<Brick?>? = parent.allParts

override fun addToFlatList(bricks: List<Brick?>?) {
parent.addToFlatList(bricks)
}

override fun getDragAndDropTargetList(): List<Brick?>? =
parent.parent.dragAndDropTargetList

override fun getPositionInDragAndDropTargetList(): Int =
parent.parent.dragAndDropTargetList.indexOf(parent)

override fun getBrickID(): UUID? = parent.brickID
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,7 +36,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ForItemInUserListBrick extends UserDataBrick implements CompositeBrick {

Expand Down Expand Up @@ -165,55 +164,4 @@ public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {

sequence.addAction(action);
}

private static class EndBrick extends BrickBaseType {

EndBrick(ForItemInUserListBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
}

@Override
public int getViewResource() {
return R.layout.brick_loop_end;
}

@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,7 +36,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ForVariableFromToBrick extends UserVariableBrickWithFormula implements CompositeBrick {

Expand Down Expand Up @@ -184,55 +183,4 @@ public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {

sequence.addAction(action);
}

private static class EndBrick extends BrickBaseType {

EndBrick(ForVariableFromToBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
}

@Override
public int getViewResource() {
return R.layout.brick_loop_end;
}

@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,7 +33,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ForeverBrick extends BrickBaseType implements CompositeBrick {

Expand Down Expand Up @@ -158,55 +157,4 @@ public void addRequiredResources(final ResourcesSet requiredResourcesSet) {
brick.addRequiredResources(requiredResourcesSet);
}
}

private static class EndBrick extends BrickBaseType {

EndBrick(ForeverBrick parent) {
this.parent = parent;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
}

@Override
public int getViewResource() {
return R.layout.brick_loop_end;
}

@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -45,7 +45,7 @@ public class IfLogicBeginBrick extends FormulaBrick implements CompositeBrick {
private static final long serialVersionUID = 1L;

private transient ElseBrick elseBrick = new ElseBrick(this);
private transient EndBrick endBrick = new EndBrick(this);
private transient EndBrick endBrick = new EndBrick(this, R.layout.brick_if_end_if);

protected List<Brick> ifBranchBricks = new ArrayList<>();
protected List<Brick> elseBranchBricks = new ArrayList<>();
Expand Down Expand Up @@ -97,7 +97,7 @@ public void setCommentedOut(boolean commentedOut) {
public Brick clone() throws CloneNotSupportedException {
IfLogicBeginBrick clone = (IfLogicBeginBrick) super.clone();
clone.elseBrick = new ElseBrick(clone);
clone.endBrick = new EndBrick(clone);
clone.endBrick = new EndBrick(clone, R.layout.brick_if_end_if);
clone.ifBranchBricks = new ArrayList<>();
clone.elseBranchBricks = new ArrayList<>();

Expand Down Expand Up @@ -275,56 +275,4 @@ public UUID getBrickID() {
return parent.getBrickID();
}
}

@VisibleForTesting
public static class EndBrick extends BrickBaseType {

EndBrick(IfLogicBeginBrick ifBrick) {
parent = ifBrick;
}

@Override
public boolean isCommentedOut() {
return parent.isCommentedOut();
}

@Override
public boolean consistsOfMultipleParts() {
return true;
}

@Override
public List<Brick> getAllParts() {
return parent.getAllParts();
}

@Override
public void addToFlatList(List<Brick> bricks) {
parent.addToFlatList(bricks);
}

@Override
public List<Brick> getDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList();
}

@Override
public int getPositionInDragAndDropTargetList() {
return parent.getParent().getDragAndDropTargetList().indexOf(parent);
}

@Override
public int getViewResource() {
return R.layout.brick_if_end_if;
}

@Override
public void addActionToSequence(Sprite sprite, ScriptSequenceAction sequence) {
}

@Override
public UUID getBrickID() {
return parent.getBrickID();
}
}
}
Loading

0 comments on commit 83e4db4

Please sign in to comment.