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
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-2025 The Catrobat Team
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -20,36 +20,29 @@
* 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 android.util.Log;

import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction;

import org.catrobat.catroid.content.Scope;
import org.catrobat.catroid.formulaeditor.Formula;
import org.catrobat.catroid.formulaeditor.InterpretationException;

public class ChangeSizeByNAction extends TemporalAction {

private Scope scope;
private Formula size;

@Override
protected void update(float percent) {
try {
Float newSize = size == null ? Float.valueOf(0f) : size.interpretFloat(scope);
scope.getSprite().look.changeSizeInUserInterfaceDimensionUnit(newSize);
} catch (InterpretationException interpretationException) {
Log.d(getClass().getSimpleName(), "Formula interpretation for this specific Brick failed.", interpretationException);
}
}

public void setScope(Scope scope) {
this.scope = scope;
}

public void setSize(Formula size) {
this.size = size;
}
package org.catrobat.catroid.content.actions

import android.util.Log
import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction
import org.catrobat.catroid.content.Scope
import org.catrobat.catroid.formulaeditor.Formula
import org.catrobat.catroid.formulaeditor.InterpretationException

class ChangeSizeByNAction : TemporalAction() {
var scope: Scope? = null
var size: Formula? = null

override fun update(percent: Float) {
val notNullScope = scope ?: return
try {
val newSize = size?.interpretFloat(notNullScope) ?: 0f
notNullScope.sprite.look.changeSizeInUserInterfaceDimensionUnit(newSize)
} catch (interpretationException: InterpretationException) {
Log.d(
javaClass.simpleName,
"Formula interpretation for this specific Brick failed.",
interpretationException
)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.content.ActionFactory
import org.catrobat.catroid.content.Sprite
import org.catrobat.catroid.formulaeditor.Formula
import org.catrobat.catroid.test.StaticSingletonInitializer.Companion.initializeStaticSingletonMethods
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(JUnit4::class)
class ChangeSizeByNActionTest {

@Rule
@JvmField
val exception: ExpectedException = ExpectedException.none()

private lateinit var sprite: Sprite

@Before
@Throws(Exception::class)
fun setUp() {
initializeStaticSingletonMethods()
sprite = Sprite("testSprite")
}

@Test
fun testSize() {
assertEquals(INITIALIZED_VALUE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)

sprite.actionFactory.createChangeSizeByNAction(
sprite,
SequenceAction(), Formula(CHANGE_SIZE)
).act(1.0f)
assertEquals(INITIALIZED_VALUE + CHANGE_SIZE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)

sprite.actionFactory.createChangeSizeByNAction(
sprite, SequenceAction(),
Formula(-CHANGE_SIZE)
).act(1.0f)
assertEquals(INITIALIZED_VALUE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)
}

@Test(expected = NullPointerException::class)
fun testNullSprite() {
val factory = ActionFactory()
val action = factory.createChangeSizeByNAction(
null, SequenceAction(),
Formula(CHANGE_SIZE)
)
action.act(1.0f)
}

@Test
fun testBrickWithStringFormula() {
sprite.actionFactory.createChangeSizeByNAction(
sprite,
SequenceAction(),
Formula(CHANGE_VALUE.toString())
)
.act(1.0f)
assertEquals(INITIALIZED_VALUE + CHANGE_VALUE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)

sprite.actionFactory.createChangeSizeByNAction(
sprite,
SequenceAction(),
Formula(NOT_NUMERICAL_STRING)
).act(1.0f)
assertEquals(INITIALIZED_VALUE + CHANGE_VALUE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)
}

@Test
fun testNullFormula() {
sprite.actionFactory.createChangeSizeByNAction(sprite, SequenceAction(), null).act(1.0f)
assertEquals(INITIALIZED_VALUE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)
}

@Test
fun testNotANumberFormula() {
sprite.actionFactory.createChangeSizeByNAction(sprite, SequenceAction(), Formula(Double.NaN)).act(1.0f)
assertEquals(INITIALIZED_VALUE, sprite.look.getSizeInUserInterfaceDimensionUnit(), DELTA)
}

companion object {
private const val INITIALIZED_VALUE = 100f
private const val CHANGE_VALUE = 44.4f
private const val NOT_NUMERICAL_STRING = "size"
private const val CHANGE_SIZE = 20f
private const val DELTA = 0.0001f
}
}
Loading