Skip to content

Commit

Permalink
Released v0.0.2
Browse files Browse the repository at this point in the history
Includes API improvements.
  • Loading branch information
saifkhichi96 committed Jun 30, 2022
1 parent b432b66 commit 3b86ad5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 46 deletions.
14 changes: 4 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
buildscript {
ext.kotlin_version = '1.7.0'
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4' // Gradle
Expand All @@ -21,11 +18,8 @@ plugins {

allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
mavenCentral()
google()
}

tasks.withType(Javadoc) {
Expand Down
4 changes: 2 additions & 2 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29
compileSdkVersion 31

defaultConfig {
applicationId "dev.aspirasoft.apis.tiled.demo"
minSdkVersion 15
targetSdkVersion 29
targetSdkVersion 31
versionCode 1
versionName "1.0.0"
}
Expand Down
14 changes: 8 additions & 6 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name=".MarioDemo">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".YoshiDemo"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
21 changes: 11 additions & 10 deletions tiles/src/main/java/dev/aspirasoft/apis/tiled/TiledView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class TiledView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :

private val lookupTable: HashMap<String, Int> = HashMap()

private lateinit var tileMap: TileMap
lateinit var map: TileMap
private set

var pixelWidth: Double = 0.0
var pixelHeight: Double = 0.0
Expand Down Expand Up @@ -114,7 +115,7 @@ class TiledView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
}

val tileSize = calculateTileSize(rowCount, columnCount)
this.tileMap = TileMap(columnCount, rowCount, tileSize.first, tileSize.second)
this.map = TileMap(columnCount, rowCount, tileSize.first, tileSize.second)

val grid = LinearLayout(context)
grid.layoutParams = LayoutParams(
Expand All @@ -127,7 +128,7 @@ class TiledView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
val row = LinearLayout(context)
row.layoutParams = LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
this.tileMap.tileHeight.roundToInt()
this.map.tileHeight.roundToInt()
)
row.orientation = HORIZONTAL

Expand All @@ -136,12 +137,12 @@ class TiledView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
val tileImage = ImageView(context)
tileImage.scaleType = ImageView.ScaleType.FIT_XY
tileImage.layoutParams = ViewGroup.LayoutParams(
ceil(this.tileMap.tileWidth).roundToInt(),
ceil(this.tileMap.tileHeight).roundToInt(),
ceil(this.map.tileWidth).roundToInt(),
ceil(this.map.tileHeight).roundToInt(),
)

row.addView(tileImage)
this.tileMap[c, r] = id
this.map[c, r] = id
lookupTable[id]?.let { tileImage.setImageResource(it) }

tileImage.setOnClickListener {
Expand Down Expand Up @@ -173,7 +174,7 @@ class TiledView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
@UiThread
@Throws(IllegalArgumentException::class, IndexOutOfBoundsException::class)
operator fun set(c: Int, r: Int, id: String) {
this.tileMap[c, r] = id
this.map[c, r] = id

val tileImage = getViewAt(c, r)
val resId = lookupTable[id]
Expand All @@ -191,21 +192,21 @@ class TiledView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
*/
@Throws(IndexOutOfBoundsException::class)
operator fun get(c: Int, r: Int): String {
return tileMap[c, r]
return map[c, r]
}

/**
* Column in which horizontal position [x] (in pixels) lies.
*/
fun getColumn(x: Double): Int {
return (x / tileMap.tileWidth).toInt()
return (x / map.tileWidth).toInt()
}

/**
* Row in which vertical position [y] (in pixels) lies.
*/
fun getRow(y: Double): Int {
return (y / tileMap.tileHeight).toInt()
return (y / map.tileHeight).toInt()
}

private fun calculateTileSize(rowCount: Int, columnCount: Int): Pair<Double, Double> {
Expand Down
36 changes: 18 additions & 18 deletions tiles/src/test/java/dev/aspirasoft/apis/tiled/TileMapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ internal class TileMapTest {
private val tilemap = TileMap(3, 3, 35.0, 25.0)

init {
tilemap[0, 0] = 'a'
tilemap[0, 1] = 'b'
tilemap[0, 2] = 'c'
tilemap[1, 0] = 'd'
tilemap[1, 1] = 'e'
tilemap[1, 2] = 'f'
tilemap[2, 0] = 'g'
tilemap[2, 1] = 'h'
tilemap[2, 2] = 'i'
tilemap[0, 0] = "a"
tilemap[0, 1] = "b"
tilemap[0, 2] = "c"
tilemap[1, 0] = "d"
tilemap[1, 1] = "e"
tilemap[1, 2] = "f"
tilemap[2, 0] = "g"
tilemap[2, 1] = "h"
tilemap[2, 2] = "i"
}

@Test
Expand All @@ -32,15 +32,15 @@ internal class TileMapTest {

@Test
fun testTileMapData() {
assertEquals('a', tilemap[0, 0])
assertEquals('b', tilemap[0, 1])
assertEquals('c', tilemap[0, 2])
assertEquals('d', tilemap[1, 0])
assertEquals('e', tilemap[1, 1])
assertEquals('f', tilemap[1, 2])
assertEquals('g', tilemap[2, 0])
assertEquals('h', tilemap[2, 1])
assertEquals('i', tilemap[2, 2])
assertEquals("a", tilemap[0, 0])
assertEquals("b", tilemap[0, 1])
assertEquals("c", tilemap[0, 2])
assertEquals("d", tilemap[1, 0])
assertEquals("e", tilemap[1, 1])
assertEquals("f", tilemap[1, 2])
assertEquals("g", tilemap[2, 0])
assertEquals("h", tilemap[2, 1])
assertEquals("i", tilemap[2, 2])

assertThrows(IndexOutOfBoundsException::class.java) { tilemap[-1, 0] }
assertThrows(IndexOutOfBoundsException::class.java) { tilemap[0, -1] }
Expand Down

0 comments on commit 3b86ad5

Please sign in to comment.