Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2026 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.test.content.actions

import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction
import org.catrobat.catroid.ProjectManager
import org.catrobat.catroid.common.BrickValues
import org.catrobat.catroid.common.ScreenValues
import org.catrobat.catroid.content.Project
import org.catrobat.catroid.content.Scene
import org.catrobat.catroid.content.Sprite
import org.catrobat.catroid.content.actions.GlideToTouchPositionAction
import org.catrobat.catroid.formulaeditor.Formula
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith


import androidx.test.ext.junit.runners.AndroidJUnit4;

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning test

Needless blank line(s)

Check warning

Code scanning / detekt

Detects semicolons Warning test

Unnecessary semicolon
import org.catrobat.catroid.utils.TouchUtil
import org.koin.java.KoinJavaComponent

@RunWith(AndroidJUnit4::class)
class GlideToTouchPositionActionTest {

private lateinit var sprite: Sprite
private lateinit var action: GlideToTouchPositionAction
private val EXPECTED_X_POSITION =20f;

Check warning

Code scanning / detekt

Reports multiple space usages Warning test

Unnecessary long whitespace

Check warning

Code scanning / detekt

Reports spaces around operators Warning test

Missing spacing after "="

Check warning

Code scanning / detekt

Detects semicolons Warning test

Unnecessary semicolon
private val EXPECTED_Y_POSITION =40f;

Check warning

Code scanning / detekt

Reports multiple space usages Warning test

Unnecessary long whitespace

Check warning

Code scanning / detekt

Reports spaces around operators Warning test

Missing spacing after "="

Check warning

Code scanning / detekt

Detects semicolons Warning test

Unnecessary semicolon
private val projectManager: ProjectManager by KoinJavaComponent.inject(ProjectManager::class.java)

@Before
@Throws(Exception::class)
fun SetUp() {


val project = Project()

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning test

Needless blank line(s)
projectManager.currentProject = project
val scene = Scene()
project.addScene(scene)
projectManager.currentlyPlayingScene = scene
sprite = Sprite("testSprite")
scene.addSprite(sprite)
ScreenValues.setToDefaultScreenSize()
action = sprite.actionFactory.createGlideToPositionAction(
sprite, null, SequenceAction(), Formula(2.0),
BrickValues.GLIDE_TO_TOUCH_POSITION
)
as GlideToTouchPositionAction
}

@Test
public fun testGlideToTouchPositionDestination() {

Check warning

Code scanning / detekt

Redundant visibility modifiers detected, which can be safely removed. Warning test

testGlideToTouchPositionDestination is explicitly marked as public. Functions are public by default so this modifier is redundant.

sprite.look.xInUserInterfaceDimensionUnit = 0f
sprite.look.yInUserInterfaceDimensionUnit = 0f

assertEquals(0f, sprite.look.xInUserInterfaceDimensionUnit)
assertEquals(0f, sprite.look.yInUserInterfaceDimensionUnit)

TouchUtil.touchDown(EXPECTED_X_POSITION, EXPECTED_Y_POSITION, 0)

action.act(2.0F)

assertEquals(EXPECTED_Y_POSITION, sprite.look.yInUserInterfaceDimensionUnit)
assertEquals(EXPECTED_X_POSITION, sprite.look.xInUserInterfaceDimensionUnit)
}

@Test
public fun testGlideToBehavior(){

Check warning

Code scanning / detekt

Redundant visibility modifiers detected, which can be safely removed. Warning test

testGlideToBehavior is explicitly marked as public. Functions are public by default so this modifier is redundant.

Check warning

Code scanning / detekt

Reports spaces around curly braces Warning test

Missing spacing before "{"
sprite.look.xInUserInterfaceDimensionUnit = 0f
sprite.look.yInUserInterfaceDimensionUnit = 0f

assertEquals(0f, sprite.look.xInUserInterfaceDimensionUnit)
assertEquals(0f, sprite.look.yInUserInterfaceDimensionUnit)

TouchUtil.touchDown(EXPECTED_X_POSITION, EXPECTED_Y_POSITION, 0)
action.act(1.0f)

assertNotEquals(0f, sprite.look.xInUserInterfaceDimensionUnit)
assertNotEquals(0f, sprite.look.yInUserInterfaceDimensionUnit)
assertNotEquals(EXPECTED_X_POSITION, sprite.look.xInUserInterfaceDimensionUnit)
assertNotEquals(EXPECTED_Y_POSITION, sprite.look.yInUserInterfaceDimensionUnit)
assertEquals(action.currentXPosition, sprite.look.xInUserInterfaceDimensionUnit)
assertEquals(action.currentYPosition, sprite.look.yInUserInterfaceDimensionUnit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public final class BrickValues {
public static final int GO_TO_TOUCH_POSITION = 80;
public static final int GO_TO_RANDOM_POSITION = 81;
public static final int GO_TO_OTHER_SPRITE_POSITION = 82;
public static final int GLIDE_TO_TOUCH_POSITION = 1;
public static final int GLIDE_TO_RANDOM_POSITION = 0;
public static final int GLIDE_TO_OTHER_SPRITE_POSITION = 2;

public static final int SET_LOOK_BY_INDEX = 1;
public static final String PARTICLE_COLOR = "#ff0000";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
import org.catrobat.catroid.content.actions.FlashAction;
import org.catrobat.catroid.content.actions.ForItemInUserListAction;
import org.catrobat.catroid.content.actions.ForVariableFromToAction;
import org.catrobat.catroid.content.actions.GlideToOtherSpritePositionAction;
import org.catrobat.catroid.content.actions.GlideToPhysicsAction;
import org.catrobat.catroid.content.actions.GlideToRandomPositionAction;
import org.catrobat.catroid.content.actions.GlideToTouchPositionAction;
import org.catrobat.catroid.content.actions.GoNStepsBackAction;
import org.catrobat.catroid.content.actions.GoThroughAction;
import org.catrobat.catroid.content.actions.GoToOtherSpritePositionAction;
Expand Down Expand Up @@ -206,6 +209,7 @@
import org.catrobat.catroid.content.bricks.brickspinner.PickableDrum;
import org.catrobat.catroid.content.bricks.brickspinner.PickableMusicalInstrument;
import org.catrobat.catroid.formulaeditor.Formula;
import org.catrobat.catroid.formulaeditor.InterpretationException;
import org.catrobat.catroid.formulaeditor.UserData;
import org.catrobat.catroid.formulaeditor.UserList;
import org.catrobat.catroid.formulaeditor.UserVariable;
Expand Down Expand Up @@ -375,6 +379,35 @@
return action;
}

public Action createGlideToPositionAction(Sprite sprite,
Sprite destinationSprite, SequenceAction sequence,
Formula duration, int spinnerSelection) throws InterpretationException {
Scope scope = new Scope(ProjectManager.getInstance().getCurrentProject(), sprite, sequence);
switch (spinnerSelection) {
case BrickValues.GLIDE_TO_RANDOM_POSITION:
GlideToRandomPositionAction randomAction =
action(GlideToRandomPositionAction.class);
randomAction.setScope(scope);
randomAction.setDuration(duration.interpretFloat(scope));
return randomAction;
case BrickValues.GLIDE_TO_TOUCH_POSITION:
GlideToTouchPositionAction touchAction =
action(GlideToTouchPositionAction.class);
touchAction.setScope(scope);
touchAction.setDuration(duration.interpretFloat(scope));
return touchAction;
case BrickValues.GLIDE_TO_OTHER_SPRITE_POSITION:
GlideToOtherSpritePositionAction otherSpritePositionAction =
action(GlideToOtherSpritePositionAction.class);
otherSpritePositionAction.setScope(scope);
otherSpritePositionAction.setDuration(duration.interpretFloat(scope));
otherSpritePositionAction.setDestinationSprite(destinationSprite);
return otherSpritePositionAction;
default:
return null;
}
}

public Action createPlaceAtAction(Sprite sprite, SequenceAction sequence, Formula x, Formula y) {
GlideToAction action = Actions.action(GlideToAction.class);
action.setPosition(x, y);
Expand Down Expand Up @@ -609,7 +642,6 @@
return action;
}


public Action createStartCutAction(Sprite sprite) {
StartCutAction action = Actions.action(StartCutAction.class);
action.setSprite(sprite);
Expand Down Expand Up @@ -1232,29 +1264,31 @@
return action;
}

public Action createSavePlotAction(Sprite sprite, SequenceAction sequence, Formula fileName){
public Action createSavePlotAction(Sprite sprite, SequenceAction sequence, Formula fileName) {
SavePlotAction action = Actions.action(SavePlotAction.class);
Scope scope = new Scope(ProjectManager.getInstance().getCurrentProject(), sprite, sequence);
action.setScope(scope);
action.setFormula(fileName);
return action;
}
public Action createSaveLaserAction(Sprite sprite, SequenceAction sequence, Formula fileName){

public Action createSaveLaserAction(Sprite sprite, SequenceAction sequence, Formula fileName) {
SaveLaserAction action = Actions.action(SaveLaserAction.class);
Scope scope = new Scope(ProjectManager.getInstance().getCurrentProject(), sprite, sequence);
action.setScope(scope);
action.setFormula(fileName);
return action;
}

public Action createSharePlotAction(Sprite sprite, SequenceAction sequence, Formula fileName){
public Action createSharePlotAction(Sprite sprite, SequenceAction sequence, Formula fileName) {
SharePlotAction action = Actions.action(SharePlotAction.class);
Scope scope = new Scope(ProjectManager.getInstance().getCurrentProject(), sprite, sequence);
action.setScope(scope);
action.setFormula(fileName);
return action;
}
public Action createShareLaserAction(Sprite sprite, SequenceAction sequence, Formula fileName){

public Action createShareLaserAction(Sprite sprite, SequenceAction sequence, Formula fileName) {
ShareLaserAction action = Actions.action(ShareLaserAction.class);
Scope scope = new Scope(ProjectManager.getInstance().getCurrentProject(), sprite, sequence);
action.setScope(scope);
Expand Down Expand Up @@ -1341,7 +1375,7 @@
return action;
}

public Action createShowVariableColorAndSizeAction(Sprite sprite, SequenceAction sequence,

Check warning on line 1378 in catroid/src/main/java/org/catrobat/catroid/content/ActionFactory.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Method has 9 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=Catrobat_Catroid&issues=AaB_UTg0-1tmkEbxmFn_&open=AaB_UTg0-1tmkEbxmFn_&pullRequest=5239
Formula xPosition, Formula yPosition, Formula relativeTextSize, Formula color,
UserVariable userVariable, int alignment, AndroidStringProvider androidStringProvider) {
ShowTextColorSizeAlignmentAction action = action(ShowTextColorSizeAlignmentAction.class);
Expand Down Expand Up @@ -1540,7 +1574,7 @@
}

public Action createRepeatParameterizedAction(Sprite sprite, ParameterizedData data,
List<? extends Pair<UserList, UserVariable>> parameters,
List<Pair<UserList, UserVariable>> parameters,
String position, Action repeatedAction, boolean isLoopDelay) {
RepeatParameterizedAction action = action(RepeatParameterizedAction.class);
action.setParameterizedData(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction

data class Scope(
val project: Project?,
val sprite: Sprite,
var sprite: Sprite,
val sequence: SequenceAction?
)
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-2025 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.actions

import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction
import org.catrobat.catroid.content.Scope
import org.catrobat.catroid.content.Sprite

class GlideToOtherSpritePositionAction : TemporalAction() {
lateinit var scope: Scope
var destinationSprite: Sprite? = null
private var startXPosition: Float = 0f
private var startYPosition: Float = 0f
var destinationXPosition: Float = 0f
var destinationYPosition: Float = 0f
var currentXPosition: Float = 0f
var currentYPosition: Float = 0f


override fun begin() {

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning

Needless blank line(s)
super.begin()
scope.sprite.isGliding = true
startXPosition = scope.sprite.look.xInUserInterfaceDimensionUnit
startYPosition = scope.sprite.look.yInUserInterfaceDimensionUnit
}

override fun act(delta: Float): Boolean {
return super.act(delta)

Check warning

Code scanning / detekt

Functions with exact one statement, the return statement, can be rewritten with ExpressionBodySyntax. Warning

Functions with exact one statement, the return statement, can be rewritten with ExpressionBodySyntax.

}

Check warning

Code scanning / detekt

Detects blank lines before rbraces Warning

Unexpected blank line(s) before "}"
override fun update(percent: Float) {
val destinationLook = destinationSprite?.look?:return

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "?:"
destinationXPosition = destinationLook.xInUserInterfaceDimensionUnit
destinationYPosition = destinationLook.yInUserInterfaceDimensionUnit
currentXPosition = startXPosition + (destinationXPosition-startXPosition)*percent

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "-"

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "*"
currentYPosition = startYPosition + (destinationYPosition-startYPosition)*percent

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "-"

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "*"
scope.sprite.look?.setPositionInUserInterfaceDimensionUnit(currentXPosition,currentYPosition)

Check warning

Code scanning / detekt

Reports spaces around commas Warning

Missing spacing after ","
}
override fun end(){

Check warning

Code scanning / detekt

Reports spaces around curly braces Warning

Missing spacing before "{"
super.end()
scope.sprite.isGliding = false
}

}

Check warning

Code scanning / detekt

Detects blank lines before rbraces Warning

Unexpected blank line(s) before "}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 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.actions

import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction
import org.catrobat.catroid.common.ScreenValues
import org.catrobat.catroid.content.Scope


class GlideToRandomPositionAction : TemporalAction() {

Check warning

Code scanning / detekt

Violation of the package declaration style detected. Warning

There should be exactly one empty line in between the list of imports and the declaration of GlideToRandomPositionAction.

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning

Needless blank line(s)
lateinit var scope: Scope
private var startXPosition: Float = 0f
private var startYPosition: Float = 0f
var randomXPosition: Float = 0f
var randomYPosition: Float = 0f
var currentXPosition: Float = 0f
var currentYPosition: Float = 0f


override fun begin() {

Check warning

Code scanning / detekt

Reports consecutive blank lines Warning

Needless blank line(s)
super.begin()
scope.sprite.isGliding = true
startXPosition = scope.sprite.look.xInUserInterfaceDimensionUnit
startYPosition = scope.sprite.look.yInUserInterfaceDimensionUnit
randomXPosition = Math.random().toFloat() * (ScreenValues.currentScreenResolution.width +
1) - (ScreenValues.currentScreenResolution.width / 2)
randomYPosition = Math.random().toFloat() * (ScreenValues.currentScreenResolution.height +
1) - (ScreenValues.currentScreenResolution.height / 2)
}

override fun update(percent: Float) {

currentXPosition = startXPosition + (randomXPosition-startXPosition)*percent

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "-"

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "*"
currentYPosition = startYPosition + (randomYPosition-startYPosition)*percent

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "-"

Check warning

Code scanning / detekt

Reports spaces around operators Warning

Missing spacing around "*"
scope.sprite.look?.setPositionInUserInterfaceDimensionUnit(currentXPosition,currentYPosition)

Check warning

Code scanning / detekt

Reports mis-indented code Warning

Unexpected indentation (7) (should be 8)

Check warning

Code scanning / detekt

Reports spaces around commas Warning

Missing spacing after ","
}
override fun end(){

Check warning

Code scanning / detekt

Reports spaces around curly braces Warning

Missing spacing before "{"
super.end()
scope.sprite.isGliding = false
}

}

Check warning

Code scanning / detekt

Detects blank lines before rbraces Warning

Unexpected blank line(s) before "}"
Loading
Loading