diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/actions/StitchActionTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/actions/StitchActionTest.java deleted file mode 100644 index a17ac4f238d..00000000000 --- a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/actions/StitchActionTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2025 The Catrobat Team - * () - * - * 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 . - */ - -package org.catrobat.catroid.test.content.actions; - -import android.graphics.PointF; - -import com.badlogic.gdx.graphics.Color; - -import org.catrobat.catroid.ProjectManager; -import org.catrobat.catroid.content.ActionFactory; -import org.catrobat.catroid.content.Project; -import org.catrobat.catroid.content.Sprite; -import org.catrobat.catroid.embroidery.DSTPatternManager; -import org.catrobat.catroid.embroidery.DSTStitchCommand; -import org.catrobat.catroid.stage.StageActivity; -import org.catrobat.catroid.stage.StageListener; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; - -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -@RunWith(AndroidJUnit4.class) -public class StitchActionTest { - private Sprite testSprite1; - private Sprite testSprite2; - private PointF spriteCoords1; - private PointF spriteCoords2; - - @Before - public void setUp() throws Exception { - Project project; - float xCoord = 50.0f; - float yCoord = 160.0f; - - testSprite1 = new Sprite("testSprite1"); - testSprite1.look.setX(xCoord); - testSprite1.look.setY(yCoord); - spriteCoords1 = new PointF(xCoord, yCoord); - - testSprite2 = new Sprite("testSprite2"); - spriteCoords2 = new PointF(0, 0); - - project = new Project(ApplicationProvider.getApplicationContext(), "testProject"); - ProjectManager.getInstance().setCurrentProject(project); - StageActivity.stageListener = Mockito.mock(StageListener.class); - StageActivity.stageListener.embroideryPatternManager = Mockito.mock(DSTPatternManager.class); - } - - @After - public void tearDown() { - StageActivity.stageListener = null; - } - - @Test - public void testAddSingleStitchPoint() { - ActionFactory.createStitchAction(testSprite1).act(1f); - Mockito.verify(StageActivity.stageListener.embroideryPatternManager, Mockito.times(1)).addStitchCommand( - Mockito.eq(new DSTStitchCommand(spriteCoords1.x, spriteCoords1.y, - testSprite1.look.getZIndex(), testSprite1, Color.BLACK))); - } - - @Test - public void testAddPointsTwoSprites() { - ActionFactory.createStitchAction(testSprite1).act(1f); - ActionFactory.createStitchAction(testSprite2).act(1f); - Mockito.verify(StageActivity.stageListener.embroideryPatternManager, Mockito.times(1)).addStitchCommand(new DSTStitchCommand(spriteCoords1.x, spriteCoords1.y, testSprite1.look.getZIndex(), testSprite1, Color.BLACK)); - Mockito.verify(StageActivity.stageListener.embroideryPatternManager, Mockito.times(1)).addStitchCommand(new DSTStitchCommand(spriteCoords2.x, spriteCoords2.y, testSprite2.look.getZIndex(), testSprite2, Color.BLACK)); - } -} diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/content/actions/StitchActionTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/actions/StitchActionTest.kt new file mode 100644 index 00000000000..ee637a845f9 --- /dev/null +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/content/actions/StitchActionTest.kt @@ -0,0 +1,123 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2026 The Catrobat Team + * () + * + * 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 . + */ + +package org.catrobat.catroid.test.content.actions + +import android.graphics.PointF +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.badlogic.gdx.graphics.Color +import org.catrobat.catroid.ProjectManager +import org.catrobat.catroid.content.ActionFactory +import org.catrobat.catroid.content.Project +import org.catrobat.catroid.content.Sprite +import org.catrobat.catroid.embroidery.DSTPatternManager +import org.catrobat.catroid.embroidery.DSTStitchCommand +import org.catrobat.catroid.stage.StageActivity +import org.catrobat.catroid.stage.StageListener +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mockito.mock +import org.mockito.Mockito.times +import org.mockito.Mockito.verify + +@RunWith(AndroidJUnit4::class) +class StitchActionTest { + private lateinit var testSprite1: Sprite + private lateinit var testSprite2: Sprite + private lateinit var spriteCoords1: PointF + private lateinit var spriteCoords2: PointF + private lateinit var embroideryPatternManagerMock: DSTPatternManager + + @Before + fun setUp() { + val xCoord = 50.0f + val yCoord = 160.0f + + testSprite1 = Sprite("testSprite1").apply { + look.setX(xCoord) + look.setY(yCoord) + } + spriteCoords1 = PointF(xCoord, yCoord) + + testSprite2 = Sprite("testSprite2") + spriteCoords2 = PointF(0f, 0f) + + val project = Project(ApplicationProvider.getApplicationContext(), "testProject") + ProjectManager.getInstance().currentProject = project + + embroideryPatternManagerMock = mock(DSTPatternManager::class.java) + val stageListenerMock = mock(StageListener::class.java) + stageListenerMock.embroideryPatternManager = embroideryPatternManagerMock + StageActivity.stageListener = stageListenerMock + } + + @After + fun tearDown() { + StageActivity.stageListener = null + } + + @Test + fun testAddSingleStitchPoint() { + ActionFactory.createStitchAction(testSprite1).act(1f) + verify(embroideryPatternManagerMock, times(1)).addStitchCommand( + eq( + DSTStitchCommand( + spriteCoords1.x, + spriteCoords1.y, + testSprite1.look.zIndex, + testSprite1, + Color.BLACK + ) + ) + ) + } + + @Test + fun testAddPointsTwoSprites() { + ActionFactory.createStitchAction(testSprite1).act(1f) + ActionFactory.createStitchAction(testSprite2).act(1f) + + verify(embroideryPatternManagerMock, times(1)).addStitchCommand( + DSTStitchCommand( + spriteCoords1.x, + spriteCoords1.y, + testSprite1.look.zIndex, + testSprite1, + Color.BLACK + ) + ) + verify(embroideryPatternManagerMock, times(1)).addStitchCommand( + DSTStitchCommand( + spriteCoords2.x, + spriteCoords2.y, + testSprite2.look.zIndex, + testSprite2, + Color.BLACK + ) + ) + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/StitchAction.java b/catroid/src/main/java/org/catrobat/catroid/content/actions/StitchAction.java deleted file mode 100644 index 8bc28cc04a1..00000000000 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/StitchAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2025 The Catrobat Team - * () - * - * 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 . - */ -package org.catrobat.catroid.content.actions; - -import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction; - -import org.catrobat.catroid.content.Sprite; -import org.catrobat.catroid.embroidery.DSTStitchCommand; -import org.catrobat.catroid.stage.StageActivity; - -public class StitchAction extends TemporalAction { - - private Sprite sprite; - - @Override - protected void update(float delta) { - sprite.runningStitch.pause(); - float x = sprite.look.getXInUserInterfaceDimensionUnit(); - float y = sprite.look.getYInUserInterfaceDimensionUnit(); - StageActivity.stageListener.embroideryPatternManager.addStitchCommand(new DSTStitchCommand(x, y, - sprite.look.getZIndex(), sprite, sprite.getEmbroideryThreadColor())); - sprite.runningStitch.setStartCoordinates(x, y); - sprite.runningStitch.resume(); - } - - public void setSprite(Sprite sprite) { - this.sprite = sprite; - } -} diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/StitchAction.kt b/catroid/src/main/java/org/catrobat/catroid/content/actions/StitchAction.kt new file mode 100644 index 00000000000..0913e11ab10 --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/StitchAction.kt @@ -0,0 +1,61 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2026 The Catrobat Team + * () + * + * 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 . + */ +package org.catrobat.catroid.content.actions + +import com.badlogic.gdx.scenes.scene2d.actions.TemporalAction +import org.catrobat.catroid.content.Sprite +import org.catrobat.catroid.embroidery.DSTStitchCommand +import org.catrobat.catroid.stage.StageActivity + +/** + * An action that adds a stitch command to the embroidery pattern manager. + * It pauses the running stitch, adds the current coordinates, and then resumes it. + */ +class StitchAction : TemporalAction() { + var sprite: Sprite? = null + + override fun update(delta: Float) { + sprite?.let { currentSprite -> + val runningStitch = currentSprite.runningStitch + val look = currentSprite.look + + runningStitch.pause() + + val x = look.getXInUserInterfaceDimensionUnit() + val y = look.getYInUserInterfaceDimensionUnit() + + StageActivity.stageListener?.embroideryPatternManager?.addStitchCommand( + DSTStitchCommand( + x, + y, + look.zIndex, + currentSprite, + currentSprite.embroideryThreadColor + ) + ) + + runningStitch.setStartCoordinates(x, y) + runningStitch.resume() + } + } +}