Skip to content

Commit

Permalink
GdxIdentityMap alias. #176
Browse files Browse the repository at this point in the history
  • Loading branch information
czyzby committed Sep 9, 2020
1 parent 214ad94 commit 1b738d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ _See also: [the official LibGDX changelog](https://github.com/libgdx/libgdx/blob
``
- **[UPDATE]** Updated to Kotlin 1.4.0.
- **[UPDATE]** Updated to Kotlin Coroutines 1.3.9.
- **[FEATURE]** (`ktx-collections`) Added `GdxIdentityMap` and `GdxArrayMap` aliases for LibGDX `IdentityMap` and `ArrayMap` collections.
- **[FEATURE]** (`ktx-collections`) Added `set` operator extension method to `ArrayMap` to support square brackets assignment.
- **[FEATURE]** (`ktx-scene2d`) Added `image` builders for `NinePatch`, `TextureRegion`, `Texture` and `Drawable`.
- **[FEATURE]** (`ktx-collections`) Added alias `GdxArrayMap` for gds ArrayMap and `set` operator function to use square brackets assignment.

#### 1.9.11-b1

Expand Down
8 changes: 6 additions & 2 deletions collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ remove elements from the map.
- Keys stored in the map can be quickly converted to an `ObjectSet` using `toGdxSet` method.
- Every iterable and array can be converted to `ObjectMap` using `toGdxMap` method. A lambda that converts values to keys
has to be provided - since the method is inlined, no new lambda object will be created at runtime.
- Type alias added for consistency with other collections: `GdxMap` - `com.badlogic.gdx.utils.ObjectMap`.
- All LibGDX maps now feature `component1()` and `component2()` operator extension methods, so they can be destructed.
- Type aliases were added for consistency with other collections:
- `GdxMap`: `com.badlogic.gdx.utils.ObjectMap`
- `GdxIdentityMap`: `com.badlogic.gdx.utils.IdentityMap`
- `GdxArrayMap`: `com.badlogic.gdx.utils.ArrayMap`
- All LibGDX map entries now feature `component1()` and `component2()` operator extension methods, so they can be
destructed into a key and a value.

#### Note

Expand Down
7 changes: 5 additions & 2 deletions collections/src/main/kotlin/ktx/collections/maps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import com.badlogic.gdx.utils.ObjectSet
/** Alias for [com.badlogic.gdx.utils.ObjectMap]. Added for consistency with other collections and factory methods. */
typealias GdxMap<Key, Value> = ObjectMap<Key, Value>

/** Alias for [com.badlogic.gdx.utils.IdentityMap]. Added for consistency with other collections and factory methods. */
typealias GdxIdentityMap<Key, Value> = IdentityMap<Key, Value>

/** Alias for [com.badlogic.gdx.utils.ArrayMap]. Added for consistency with other collections and factory methods. */
typealias GdxArrayMap<Key, Value> = ArrayMap<Key, Value>

Expand Down Expand Up @@ -173,7 +176,7 @@ inline fun <Type, Key, Value> Array<Type>.toGdxMap(
* @return a new [IdentityMap], which compares keys by references.
*/
fun <Key, Value> gdxIdentityMapOf(initialCapacity: Int = defaultMapSize, loadFactor: Float = defaultLoadFactor):
IdentityMap<Key, Value> = IdentityMap(initialCapacity, loadFactor)
GdxIdentityMap<Key, Value> = IdentityMap(initialCapacity, loadFactor)

/**
* @param keysToValues will be added to the map.
Expand All @@ -185,7 +188,7 @@ inline fun <Key, Value> gdxIdentityMapOf(
vararg keysToValues: Pair<Key, Value>,
initialCapacity: Int = defaultMapSize,
loadFactor: Float = defaultLoadFactor
): IdentityMap<Key, Value> {
): GdxIdentityMap<Key, Value> {
val map = IdentityMap<Key, Value>(initialCapacity, loadFactor)
keysToValues.forEach { map[it.first] = it.second }
return map
Expand Down

0 comments on commit 1b738d4

Please sign in to comment.