Skip to content

Commit

Permalink
Add logback config, update amethyst and cobalt versions
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-arold committed Jan 30, 2019
1 parent 91b463e commit f2c80e7
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 50 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ org.gradle.jvmargs=-Xmx2048M
org.gradle.daemon=true

group=org.hexworks.cavesofzircon
version=2019.1.0-PREVIEW
version=2019.2.0

kotlin_version=1.3.11
kotlin_version=1.3.20

cobalt_version=2018.1.0-PREVIEW
amethyst_version=2019.0.1-PREVIEW
zircon_version=2019.0.9-PREVIEW
amethyst_version=2019.0.2-PREVIEW
zircon_version=2019.0.10-PREVIEW
junit_version=4.12
mockito_version=1.10.19
assertj_version=3.6.2
Expand Down
3 changes: 0 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
rootProject.name = "caves-of-zircon"

include "caves-of-zircon.java"
include "caves-of-zircon.kotlin"
1 change: 1 addition & 0 deletions src/main/kotlin/org/hexworks/cavesofzircon/GameConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object GameConfig {

fun buildAppConfig() = AppConfigs.newConfig()
.enableBetaFeatures()
.withDebugMode(false)
.withDefaultTileset(TILESET)
.withSize(Sizes.create(WINDOW_WIDTH, WINDOW_HEIGHT))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package org.hexworks.cavesofzircon.attributes.types

import org.hexworks.amethyst.api.entity.Entity
import org.hexworks.cavesofzircon.attributes.ItemCombatStats
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute
import org.hexworks.cavesofzircon.world.GameContext

interface Armor : Item

val Entity<Armor, GameContext>.attackValue: Int
get() = attribute<ItemCombatStats>().attackValue
get() = findAttribute<ItemCombatStats>().attackValue

val Entity<Armor, GameContext>.defenseValue: Int
get() = attribute<ItemCombatStats>().defenseValue
get() = findAttribute<ItemCombatStats>().defenseValue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.CombatStats
import org.hexworks.cavesofzircon.attributes.Equipment
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute
import org.hexworks.cobalt.datatypes.Maybe

interface Combatant : EntityType

val GameEntity<Combatant>.combatStats: CombatStats
get() = attribute()
get() = findAttribute()

val GameEntity<Combatant>.equipment: Maybe<Equipment>
get() = attribute(Equipment::class)
get() = findAttribute(Equipment::class)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.hexworks.amethyst.api.base.BaseEntityType
import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.ZirconCounter
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute

object Player : BaseEntityType(
name = "player"), ItemHolder, ExperienceGainer

val GameEntity<Player>.zirconCounter: ZirconCounter
get() = attribute()
get() = findAttribute()

object StairsDown : BaseEntityType(
name = "stairs down")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.CombatStats
import org.hexworks.cavesofzircon.attributes.Experience
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute

interface ExperienceGainer : EntityType

val GameEntity<ExperienceGainer>.experience: Experience
get() = attribute()
get() = findAttribute()

val GameEntity<ExperienceGainer>.combatStats: CombatStats
get() = attribute()
get() = findAttribute()

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package org.hexworks.cavesofzircon.attributes.types

import org.hexworks.cavesofzircon.attributes.NutritionalValue
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute

interface Food : Item

val GameEntity<Food>.nutritionalValue: NutritionalValue
get() = attribute()
get() = findAttribute()
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute
import org.hexworks.zircon.api.data.GraphicTile
import org.hexworks.zircon.api.data.Tile

interface Item : EntityType

val GameEntity<Item>.tile: Tile
get() = attribute<EntityTile>().tile
get() = findAttribute<EntityTile>().tile

val GameEntity<Item>.iconTile: GraphicTile
get() = attribute<ItemIcon>().iconTile
get() = findAttribute<ItemIcon>().iconTile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.hexworks.cavesofzircon.attributes.types
import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.Inventory
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute

interface ItemHolder : EntityType

val GameEntity<ItemHolder>.inventory: Inventory
get() = attribute()
get() = findAttribute()
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.hexworks.cavesofzircon.attributes.types

import org.hexworks.cavesofzircon.attributes.ItemCombatStats
import org.hexworks.cavesofzircon.extensions.AnyGameEntity
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.hasAttribute
import org.hexworks.cavesofzircon.extensions.findAttribute

interface Weapon : Item

val GameEntity<Weapon>.attackValue: Int
get() = attribute<ItemCombatStats>().attackValue
get() = findAttribute<ItemCombatStats>().attackValue

val GameEntity<Weapon>.defenseValue: Int
get() = attribute<ItemCombatStats>().defenseValue
get() = findAttribute<ItemCombatStats>().defenseValue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.hexworks.cavesofzircon.blocks
import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.builders.GameTileRepository
import org.hexworks.cavesofzircon.extensions.*
import org.hexworks.zircon.api.data.Block
import org.hexworks.zircon.api.data.BlockSide
import org.hexworks.zircon.api.data.Tile
import org.hexworks.zircon.api.data.base.BlockBase
Expand Down Expand Up @@ -59,6 +60,14 @@ class GameBlock private constructor(private var defaultTile: Tile = GameTileRepo
return GameTileRepository.EMPTY
}

override fun createCopy(): Block<Tile> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun setSide(side: BlockSide, tile: Tile) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

companion object {

fun create(): GameBlock = GameBlock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import kotlin.reflect.full.isSubclassOf
import kotlin.reflect.full.isSuperclassOf

var AnyGameEntity.position
get() = attribute(EntityPosition::class).orElseThrow {
get() = findAttribute(EntityPosition::class).orElseThrow {
IllegalArgumentException("This Entity has no EntityPosition")
}.position
set(value) {
attribute(EntityPosition::class).map {
findAttribute(EntityPosition::class).map {
it.position = value
}
}

val AnyGameEntity.tile: Tile
get() = this.attribute<EntityTile>().tile
get() = this.findAttribute<EntityTile>().tile

val AnyGameEntity.occupiesBlock: Boolean
get() = hasAttribute<BlockOccupier>()
Expand All @@ -52,13 +52,13 @@ val AnyGameEntity.isExit: Boolean
val AnyGameEntity.isStairsDown: Boolean
get() = this.type is StairsDown

inline fun <reified T : Attribute> AnyGameEntity.attribute(): T = attribute(T::class).orElseThrow {
inline fun <reified T : Attribute> AnyGameEntity.findAttribute(): T = findAttribute(T::class).orElseThrow {
NoSuchElementException("Entity '$this' has no property with type '${T::class.simpleName}'.")
}

inline fun <reified T : Attribute> AnyGameEntity.hasAttribute() = attribute(T::class).isPresent
inline fun <reified T : Attribute> AnyGameEntity.hasAttribute() = findAttribute(T::class).isPresent

inline fun <reified T : Attribute> AnyGameEntity.whenHasAttribute(crossinline fn: (T) -> Unit) = attribute(T::class).map(fn)
inline fun <reified T : Attribute> AnyGameEntity.whenHasAttribute(crossinline fn: (T) -> Unit) = findAttribute(T::class).map(fn)

@Suppress("UNCHECKED_CAST")
inline fun <reified T : EntityType> Iterable<AnyGameEntity>.filterType(): List<Entity<T, GameContext>> {
Expand All @@ -69,11 +69,11 @@ fun AnyGameEntity.hasPosition() = position.isUnknown().not()

@Suppress("UNCHECKED_CAST")
inline fun <reified T : Attribute> AnyGameEntity.attributesOfType(): List<T> {
return fetchAttributes().filter { T::class.isSuperclassOf(it::class) }.toList() as List<T>
return attributes.filter { T::class.isSuperclassOf(it::class) }.toList() as List<T>
}

fun AnyGameEntity.tryActionsOn(context: GameContext, target: AnyGameEntity) {
attribute<EntityActions>()
findAttribute<EntityActions>()
.createActionsFor(context, this, target)
.forEach { action ->
if (target.executeCommand(action) is Consumed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.hexworks.cavesofzircon.attributes.Hunger
import org.hexworks.cavesofzircon.attributes.types.Player

val GameEntity<Player>.hunger: Hunger
get() = attribute()
get() = findAttribute()

val GameEntity<Player>.equipment: Equipment
get() = attribute()
get() = findAttribute()
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import org.hexworks.cavesofzircon.world.GameContext
object DigestiveSystem : BaseActor<GameContext>(Hunger::class) {

override fun executeCommand(command: GameCommand<out EntityType>): Response {
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER")
var response: Response = command.responseWhenCommandIs<Eat> { (_, entity, food) ->
entity.attribute<Hunger>().currentValue += food.nutritionalValue.value
entity.findAttribute<Hunger>().currentValue += food.nutritionalValue.value
Consumed
}
response = command.responseWhenCommandIs<Exert> { (context, entity, force) ->
val hunger = entity.attribute<Hunger>()
val hunger = entity.findAttribute<Hunger>()
hunger.currentValue -= force
checkStarvation(context, entity, hunger)
Consumed
Expand All @@ -29,7 +30,7 @@ object DigestiveSystem : BaseActor<GameContext>(Hunger::class) {
}

override fun update(entity: GameEntity<out EntityType>, context: GameContext): Boolean {
val hunger = entity.attribute<Hunger>()
val hunger = entity.findAttribute<Hunger>()
hunger.currentValue -= 2
checkStarvation(context, entity, hunger)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.FungusSpread
import org.hexworks.cavesofzircon.builders.EntityFactory
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute
import org.hexworks.cavesofzircon.extensions.position
import org.hexworks.cavesofzircon.world.GameContext
import org.hexworks.cobalt.datatypes.extensions.map
Expand All @@ -15,7 +15,7 @@ object FungusGrower : BaseBehavior<GameContext>(FungusSpread::class) {

override fun update(entity: GameEntity<out EntityType>, context: GameContext): Boolean {
val world = context.world
val fungusSpread = entity.attribute<FungusSpread>()
val fungusSpread = entity.findAttribute<FungusSpread>()
val (spreadcount) = fungusSpread
return if (spreadcount < 4 && Math.random() < 0.015) {
val spreadSize = Sizes.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ object PlayerInputHandler : BaseBehavior<GameContext>() {
.firstOrNull { entity ->
entity.hasInventory()
}?.let { lootable ->
@Suppress("UNCHECKED_CAST")
openLootDialog(context, player, lootable as GameEntity<ItemHolder>)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.hexworks.cavesofzircon.attributes.Inventory
import org.hexworks.cavesofzircon.attributes.types.Food
import org.hexworks.cavesofzircon.commands.DropItem
import org.hexworks.cavesofzircon.commands.Eat
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute
import org.hexworks.cavesofzircon.extensions.position
import org.hexworks.cavesofzircon.extensions.whenTypeIs
import org.hexworks.cavesofzircon.view.fragment.ItemInfoFragment
Expand All @@ -28,7 +28,7 @@ class InventoryDialog(context: GameContext) : Dialog(context.screen) {
.build().also { inventoryPanel ->
val player = context.player
val playerPosition = player.position
val inventory = player.attribute<Inventory>()
val inventory = player.findAttribute<Inventory>()
val itemListFragment = ItemListFragment(inventory, 20)
inventoryPanel.addFragment(itemListFragment)
inventoryPanel.addFragment(ItemInfoFragment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.CombatStats
import org.hexworks.cavesofzircon.attributes.VisionAttributes
import org.hexworks.cavesofzircon.extensions.GameEntity
import org.hexworks.cavesofzircon.extensions.attribute
import org.hexworks.cavesofzircon.extensions.findAttribute
import org.hexworks.cavesofzircon.extensions.logGameEvent
import org.hexworks.zircon.api.Components
import org.hexworks.zircon.api.graphics.BoxType
Expand All @@ -26,8 +26,8 @@ class LevelUpDialog(screen: Screen, player: GameEntity<EntityType>) : Dialog(scr
.addHeader("Congratulations, you levelled up!")
.addParagraph("Pick an improvement from the options below:"))

val stats = player.attribute<CombatStats>()
val vision = player.attribute<VisionAttributes>()
val stats = player.findAttribute<CombatStats>()
val vision = player.findAttribute<VisionAttributes>()

modalPanel.addComponent(Components.button()
.withText("Max HP")
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="debug">
<appender-ref ref="STDOUT" />
</root>

<logger name="org.hexworks.cobalt" level="INFO" />
<logger name="org.hexworks.amethyst" level="INFO" />
<logger name="org.hexworks.cavesofzircon" level="INFO" />

</configuration>

0 comments on commit f2c80e7

Please sign in to comment.