Skip to content

Commit

Permalink
Add simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-arold committed Jan 3, 2019
1 parent 43b7bde commit d4694ba
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 44 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=2018.3.0-PREVIEW
version=2019.1.0-PREVIEW

kotlin_version=1.3.11

cobalt_version=2018.1.0-BETA
amethyst_version=2018.1.1-PREVIEW
zircon_version=2019.0.6-PREVIEW
cobalt_version=2018.1.0-PREVIEW
amethyst_version=2019.0.1-PREVIEW
zircon_version=2019.0.7-PREVIEW
junit_version=4.12
mockito_version=1.10.19
assertj_version=3.6.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hexworks.cavesofzircon.builders

import org.hexworks.cavesofzircon.extensions.lightenByPercent
import org.hexworks.zircon.api.Tiles
import org.hexworks.zircon.api.color.ANSITileColor
import org.hexworks.zircon.api.data.CharacterTile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.hexworks.amethyst.api.Response
import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.world.GameContext

inline fun <reified T : Command<out EntityType, GameContext>> Command<out EntityType, GameContext>.whenCommandIs(
inline fun <reified T : Command<out EntityType, GameContext>> Command<out EntityType, GameContext>.responseWhenCommandIs(
noinline fn: (T) -> Response): Response {
return whenCommandIs(T::class, fn)
return responseWhenCommandIs(T::class, fn)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.hexworks.cobalt.datatypes.extensions.fold

object Attackable : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<Attack> { (context, attacker, target) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<Attack> { (context, attacker, target) ->
if (attacker.isPlayer || target.isPlayer) {
val attackerEquipment = attacker.equipment
val attackerStats = attacker.combatStats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.hexworks.cavesofzircon.world.GameContext

object BlockInspector : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<LookAt> { (context, source, position) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<LookAt> { (context, source, position) ->
if (source.isPlayer) {
context.world.withBlockAt(position) { block ->
block.withTopNonPlayerEntity { entity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import org.hexworks.cavesofzircon.commands.CameraMoveDirection.*
import org.hexworks.cavesofzircon.commands.MoveCamera
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.position
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.world.GameContext

object CameraMover : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<MoveCamera> { cmd ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<MoveCamera> { cmd ->
val world = cmd.context.world
val player = cmd.context.player
val screenPos = player.position - world.visibleOffset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.hexworks.zircon.internal.Zircon

object Destroyable : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<Destroy> { (context, entity, cause) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<Destroy> { (context, entity, cause) ->
val world = context.world
entity.whenHasInventory { inventory ->
world.addEntity(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hexworks.cavesofzircon.systems

import org.hexworks.amethyst.api.Consumed
import org.hexworks.amethyst.api.Pass
import org.hexworks.amethyst.api.Response
import org.hexworks.amethyst.api.base.BaseActor
import org.hexworks.amethyst.api.entity.EntityType
Expand All @@ -16,11 +15,11 @@ import org.hexworks.cavesofzircon.world.GameContext
object DigestiveSystem : BaseActor<GameContext>(Hunger::class) {

override fun executeCommand(command: GameCommand<out EntityType>): Response {
var response: Response = command.whenCommandIs<Eat> { (_, entity, food) ->
var response: Response = command.responseWhenCommandIs<Eat> { (_, entity, food) ->
entity.attribute<Hunger>().currentValue += food.nutritionalValue.value
Consumed
}
response = command.whenCommandIs<Exert> { (context, entity, force) ->
response = command.responseWhenCommandIs<Exert> { (context, entity, force) ->
val hunger = entity.attribute<Hunger>()
hunger.currentValue -= force
checkStarvation(context, entity, hunger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.hexworks.cavesofzircon.commands.Dig
import org.hexworks.cavesofzircon.events.EntityDiggedOut
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.position
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.world.GameContext
import org.hexworks.cobalt.logging.api.LoggerFactory
import org.hexworks.zircon.internal.Zircon
Expand All @@ -16,7 +16,7 @@ object Diggable : BaseFacet<GameContext>() {

private val logger = LoggerFactory.getLogger(javaClass)

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<Dig> { (context, _, target) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<Dig> { (context, _, target) ->
logger.debug("Digging out ${target.name}.")
Zircon.eventBus.publish(EntityDiggedOut(target.position))
context.world.removeEntity(target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import org.hexworks.cavesofzircon.events.PlayerGainedLevel
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.isPlayer
import org.hexworks.cavesofzircon.extensions.logGameEvent
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.world.GameContext
import org.hexworks.zircon.internal.Zircon
import kotlin.math.min


object ExperienceSystem : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<GainXpFrom> { (_, source, gainer) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<GainXpFrom> { (_, source, gainer) ->
val sourceStats = source.combatStats
val gainerXp = gainer.experience
val gainerStats = gainer.combatStats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.cavesofzircon.attributes.types.inventory
import org.hexworks.cavesofzircon.commands.DropItem
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.world.GameContext

object ItemDropper : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<DropItem> { (context, itemHolder, item, position) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<DropItem> { (context, itemHolder, item, position) ->
if (itemHolder.inventory.removeItem(item)) {
context.world.addEntity(item, position)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.hexworks.cavesofzircon.world.GameContext

object ItemPicker : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<PickItemUp> { (context, itemHolder, position) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<PickItemUp> { (context, itemHolder, position) ->
val world = context.world
world.findItemsAt(position).whenHasItems { items ->
val item = items.last()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/hexworks/cavesofzircon/systems/Movable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import org.hexworks.cavesofzircon.commands.LookAt
import org.hexworks.cavesofzircon.commands.MoveTo
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.tryActionsOn
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.extensions.whenHasBlockAt
import org.hexworks.cavesofzircon.world.GameContext

object Movable : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>) = command.whenCommandIs<MoveTo> { (context, entity, position) ->
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs<MoveTo> { (context, entity, position) ->
val world = context.world
var result: Response = Pass
world.whenHasBlockAt(position) { block ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import org.hexworks.cavesofzircon.commands.MoveUp
import org.hexworks.cavesofzircon.events.PlayerWonTheGame
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.logGameEvent
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.world.GameContext
import org.hexworks.zircon.internal.Zircon

object StairClimber : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>): Response {
val world = command.context.world
return command.whenCommandIs<MoveUp> { (_, player, position) ->
return command.responseWhenCommandIs<MoveUp> { (_, player, position) ->
world.withBlockAt(position) { block ->
when {
block.hasStairsUp -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import org.hexworks.cavesofzircon.commands.MoveDown
import org.hexworks.cavesofzircon.events.PlayerWonTheGame
import org.hexworks.cavesofzircon.extensions.GameCommand
import org.hexworks.cavesofzircon.extensions.logGameEvent
import org.hexworks.cavesofzircon.extensions.whenCommandIs
import org.hexworks.cavesofzircon.extensions.responseWhenCommandIs
import org.hexworks.cavesofzircon.world.GameContext
import org.hexworks.zircon.internal.Zircon

object StairDescender : BaseFacet<GameContext>() {

override fun executeCommand(command: GameCommand<out EntityType>): Response {
val world = command.context.world
return command.whenCommandIs<MoveDown> { (_, player, position) ->
return command.responseWhenCommandIs<MoveDown> { (_, player, position) ->
world.withBlockAt(position) { block ->
when {
block.hasStairsDown -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.hexworks.cavesofzircon.world.GameContext

object ZirconGatherer : BaseFacet<GameContext>(ZirconCounter::class) {

override fun executeCommand(command: Command<out EntityType, GameContext>) = command.whenCommandIs<PickItemUp> { (context, source, position) ->
override fun executeCommand(command: Command<out EntityType, GameContext>) = command.responseWhenCommandIs<PickItemUp> { (context, source, position) ->
var response: Response = Pass
val world = context.world
world.findItemsAt(position).whenHasItems { items ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PlayerStats(player: GameEntity<Player>) : Fragment {
addComponent(combatStats)
addComponent(hunger)
addComponent(equipment)
addComponent(zircons)
addComponent(zircons)
}
}
}

0 comments on commit d4694ba

Please sign in to comment.