parent
1d4da585ed
commit
4d108068b3
@ -1,21 +1,33 @@
|
|||||||
package com.last.commit.inventory
|
package com.last.commit.inventory
|
||||||
|
|
||||||
class Inventory {
|
import com.last.commit.GameState
|
||||||
|
|
||||||
|
class Inventory() {
|
||||||
|
|
||||||
val items: MutableList<InventoryItem> = ArrayList()
|
val items: MutableList<InventoryItem> = ArrayList()
|
||||||
public var updated = false
|
public var updated = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name the name of the subtexture loaded from xml
|
* @param name the name of the subtexture loaded from xml
|
||||||
|
* @return wether the item was added
|
||||||
*/
|
*/
|
||||||
fun add(name: String) {
|
fun add(name: String, state: GameState): Boolean {
|
||||||
if (this.items.size < 8) {
|
if (this.items.find { it.name == name } == null) {
|
||||||
items.add(InventoryItem(name))
|
if (this.items.size < 8) {
|
||||||
this.updated = true
|
items.add(InventoryItem(name))
|
||||||
|
this.updated = true
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Item is already in inventory
|
||||||
|
state.dialogStage.setTexts("You already have this item.")
|
||||||
|
state.dialogStage.show()
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun remove(name: String) {
|
fun remove(name: String) {
|
||||||
items.removeIf() {item -> item.name == name}
|
items.removeIf() { item -> item.name == name }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue