-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CATROID-1071 GoToRandomPositionAction refactor
Refactor GoToRandomPositionAction.java and GoToRandomPositionActionTest.java to Kotlin
- Loading branch information
1 parent
f073a63
commit cfe0765
Showing
4 changed files
with
125 additions
and
137 deletions.
There are no files selected for viewing
58 changes: 0 additions & 58 deletions
58
catroid/src/main/java/org/catrobat/catroid/content/actions/GoToRandomPositionAction.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
catroid/src/main/java/org/catrobat/catroid/content/actions/GoToRandomPositionAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Catroid: An on-device visual programming system for Android devices | ||
* Copyright (C) 2010-2024 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.Sprite | ||
|
||
class GoToRandomPositionAction : TemporalAction() { | ||
private var sprite: Sprite? = null | ||
var randomXPosition: Float = 0f | ||
private set | ||
var randomYPosition: Float = 0f | ||
private set | ||
|
||
override fun update(percent: Float) { | ||
randomXPosition = Math.random() | ||
.toFloat() * (ScreenValues.currentScreenResolution.width + 1) - (ScreenValues.currentScreenResolution.width / 2) | ||
randomYPosition = Math.random() | ||
.toFloat() * (ScreenValues.currentScreenResolution.height + 1) - (ScreenValues.currentScreenResolution.height / 2) | ||
|
||
sprite!!.look.setPositionInUserInterfaceDimensionUnit(randomXPosition, randomYPosition) | ||
} | ||
|
||
fun setSprite(sprite: Sprite?) { | ||
this.sprite = sprite | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
...src/test/java/org/catrobat/catroid/test/content/actions/GoToRandomPositionActionTest.java
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
...d/src/test/java/org/catrobat/catroid/test/content/actions/GoToRandomPositionActionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Catroid: An on-device visual programming system for Android devices | ||
* Copyright (C) 2010-2024 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 junit.framework.TestCase.assertEquals | ||
import org.catrobat.catroid.common.BrickValues | ||
import org.catrobat.catroid.common.ScreenValues | ||
import org.catrobat.catroid.content.ActionFactory | ||
import org.catrobat.catroid.content.Sprite | ||
import org.catrobat.catroid.content.actions.GoToRandomPositionAction | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
|
||
@RunWith(JUnit4::class) | ||
class GoToRandomPositionActionTest { | ||
|
||
private lateinit var sprite: Sprite | ||
private lateinit var dummySprite: Sprite | ||
private lateinit var action: GoToRandomPositionAction | ||
|
||
@Before | ||
@Throws(Exception::class) | ||
fun setUp() { | ||
sprite = Sprite("testSprite") | ||
dummySprite = Sprite("dummySprite") | ||
ScreenValues.setToDefaultScreenSize() | ||
action = sprite.actionFactory.createGoToAction( | ||
sprite, dummySprite, BrickValues.GO_TO_RANDOM_POSITION | ||
) as GoToRandomPositionAction | ||
} | ||
|
||
@Test | ||
fun testGoToOtherSpriteAction() { | ||
sprite.look.xInUserInterfaceDimensionUnit = 0f | ||
sprite.look.yInUserInterfaceDimensionUnit = 0f | ||
|
||
assertEquals(0f, sprite.look.xInUserInterfaceDimensionUnit) | ||
assertEquals(0f, sprite.look.yInUserInterfaceDimensionUnit) | ||
|
||
action.act(1f) | ||
|
||
assertEquals(action.randomXPosition, sprite.look.xInUserInterfaceDimensionUnit) | ||
assertEquals(action.randomYPosition, sprite.look.yInUserInterfaceDimensionUnit) | ||
} | ||
|
||
@Test | ||
fun testNullActor() { | ||
val factory = ActionFactory() | ||
Assert.assertThrows(NullPointerException::class.java) { | ||
val action = factory.createGoToAction(null, dummySprite, BrickValues.GO_TO_RANDOM_POSITION) | ||
action.act(1.0f) | ||
} | ||
} | ||
} |