-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fdac9f
commit 2db3a39
Showing
23 changed files
with
386 additions
and
6 deletions.
There are no files selected for viewing
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
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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/org/hexworks/cavesofzircon/attributes/Inventory.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,34 @@ | ||
package org.hexworks.cavesofzircon.attributes | ||
|
||
import org.hexworks.amethyst.api.Attribute | ||
import org.hexworks.cavesofzircon.extensions.GameItem | ||
import org.hexworks.cobalt.datatypes.Identifier | ||
import org.hexworks.cobalt.datatypes.Maybe | ||
|
||
class Inventory(val size: Int) : Attribute { | ||
|
||
private val currentItems = mutableListOf<GameItem>() | ||
|
||
val items: List<GameItem> | ||
get() = currentItems.toList() | ||
|
||
val isEmpty: Boolean | ||
get() = currentItems.isEmpty() | ||
|
||
val isFull: Boolean | ||
get() = currentItems.size >= size | ||
|
||
fun findItemBy(id: Identifier): Maybe<GameItem> { | ||
return Maybe.ofNullable(items.firstOrNull { it.id == id }) | ||
} | ||
|
||
fun addItem(item: GameItem): Boolean { | ||
return if (isFull.not()) { | ||
currentItems.add(item) | ||
} else false | ||
} | ||
|
||
fun removeItem(entity: GameItem): Boolean { | ||
return currentItems.remove(entity) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/org/hexworks/cavesofzircon/attributes/ItemIcon.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,6 @@ | ||
package org.hexworks.cavesofzircon.attributes | ||
|
||
import org.hexworks.amethyst.api.Attribute | ||
import org.hexworks.zircon.api.data.GraphicalTile | ||
|
||
data class ItemIcon(val iconTile: GraphicalTile) : Attribute |
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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/org/hexworks/cavesofzircon/attributes/types/Item.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,16 @@ | ||
package org.hexworks.cavesofzircon.attributes.types | ||
|
||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.attributes.EntityTile | ||
import org.hexworks.cavesofzircon.attributes.ItemIcon | ||
import org.hexworks.cavesofzircon.extensions.GameEntity | ||
import org.hexworks.zircon.api.data.GraphicalTile | ||
import org.hexworks.zircon.api.data.Tile | ||
|
||
interface Item : EntityType | ||
|
||
val GameEntity<Item>.tile: Tile | ||
get() = findAttribute(EntityTile::class).get().tile | ||
|
||
val GameEntity<Item>.iconTile: GraphicalTile | ||
get() = findAttribute(ItemIcon::class).get().iconTile |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/org/hexworks/cavesofzircon/attributes/types/ItemHolder.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,15 @@ | ||
package org.hexworks.cavesofzircon.attributes.types | ||
|
||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.attributes.Inventory | ||
import org.hexworks.cavesofzircon.extensions.GameItem | ||
import org.hexworks.cavesofzircon.extensions.GameItemHolder | ||
|
||
interface ItemHolder : EntityType | ||
|
||
fun GameItemHolder.addItem(item: GameItem) = inventory.addItem(item) | ||
|
||
fun GameItemHolder.removeItem(item: GameItem) = inventory.removeItem(item) | ||
|
||
val GameItemHolder.inventory: Inventory | ||
get() = findAttribute(Inventory::class).get() |
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
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
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
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/org/hexworks/cavesofzircon/commands/DropItem.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,13 @@ | ||
package org.hexworks.cavesofzircon.commands | ||
|
||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.GameItem | ||
import org.hexworks.cavesofzircon.extensions.GameItemHolder | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
import org.hexworks.zircon.api.data.impl.Position3D | ||
|
||
data class DropItem(override val context: GameContext, | ||
override val source: GameItemHolder, | ||
val item: GameItem, | ||
val position: Position3D) : GameCommand<EntityType> |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/org/hexworks/cavesofzircon/commands/InspectInventory.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,11 @@ | ||
package org.hexworks.cavesofzircon.commands | ||
|
||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.GameItemHolder | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
import org.hexworks.zircon.api.data.impl.Position3D | ||
|
||
data class InspectInventory(override val context: GameContext, | ||
override val source: GameItemHolder, | ||
val position: Position3D) : GameCommand<EntityType> |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/org/hexworks/cavesofzircon/commands/PickItemUp.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,14 @@ | ||
package org.hexworks.cavesofzircon.commands | ||
|
||
import org.hexworks.cavesofzircon.attributes.types.ItemHolder | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.GameItemHolder | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
import org.hexworks.zircon.api.data.impl.Position3D | ||
|
||
/** | ||
* A [GameCommand] representing [source] picking up an item at [position]. | ||
*/ | ||
data class PickItemUp(override val context: GameContext, | ||
override val source: GameItemHolder, | ||
val position: Position3D) : GameCommand<ItemHolder> |
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
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
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
64 changes: 64 additions & 0 deletions
64
src/main/kotlin/org/hexworks/cavesofzircon/systems/InventoryInspector.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,64 @@ | ||
package org.hexworks.cavesofzircon.systems | ||
|
||
import org.hexworks.amethyst.api.Consumed | ||
import org.hexworks.amethyst.api.base.BaseFacet | ||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.GameConfig | ||
import org.hexworks.cavesofzircon.attributes.types.inventory | ||
import org.hexworks.cavesofzircon.commands.DropItem | ||
import org.hexworks.cavesofzircon.commands.InspectInventory | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.view.fragment.InventoryFragment | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
import org.hexworks.zircon.api.Components | ||
import org.hexworks.zircon.api.Sizes | ||
import org.hexworks.zircon.api.builder.component.ModalBuilder | ||
import org.hexworks.zircon.api.component.ComponentAlignment.BOTTOM_LEFT | ||
import org.hexworks.zircon.api.extensions.onComponentEvent | ||
import org.hexworks.zircon.api.uievent.ComponentEventType.ACTIVATED | ||
import org.hexworks.zircon.api.uievent.Processed | ||
import org.hexworks.zircon.internal.component.modal.EmptyModalResult | ||
|
||
object InventoryInspector : BaseFacet<GameContext>() { | ||
|
||
val DIALOG_SIZE = Sizes.create(33, 14) | ||
|
||
override fun executeCommand(command: GameCommand<out EntityType>) = command | ||
.responseWhenCommandIs(InspectInventory::class) { (context, itemHolder, position) -> | ||
|
||
val screen = context.screen | ||
|
||
val fragment = InventoryFragment(itemHolder.inventory, DIALOG_SIZE.width - 3) { item -> | ||
itemHolder.executeCommand(DropItem(context, itemHolder, item, position)) | ||
} | ||
|
||
val panel = Components.panel() | ||
.withSize(DIALOG_SIZE) | ||
.wrapWithBox(true) | ||
.wrapWithShadow(true) | ||
.withTitle("Inventory") | ||
.build() | ||
|
||
panel.addFragment(fragment) | ||
|
||
val modal = ModalBuilder.newBuilder<EmptyModalResult>() | ||
.withParentSize(screen.size) | ||
.withComponent(panel) | ||
.build() | ||
|
||
panel.addComponent(Components.button() | ||
.withText("Close") | ||
.withAlignmentWithin(panel, BOTTOM_LEFT) | ||
.build().apply { | ||
onComponentEvent(ACTIVATED) { | ||
modal.close(EmptyModalResult) | ||
Processed | ||
} | ||
}) | ||
|
||
modal.applyColorTheme(GameConfig.THEME) | ||
screen.openModal(modal) | ||
Consumed | ||
} | ||
|
||
} |
Oops, something went wrong.