Skip to content

Commit

Permalink
Renamed interface (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: ben_pollard <[email protected]>
  • Loading branch information
benpollarduk and ben_pollard authored Jan 26, 2024
1 parent e2bf5e1 commit f4d2fa1
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.github.benpollarduk.ktaf.assets

import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.assets.interaction.Interaction
import com.github.benpollarduk.ktaf.assets.interaction.InteractionEffect
import com.github.benpollarduk.ktaf.assets.interaction.InteractionResult
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget

/**
* Provides an item that can appear in a [Game]. The item must have a [identifier] and a [description].
* Optionally the item can be made takeable by setting [takeable] to true, and an interaction to define how this
* interacts with various [InteractionTarget] specified with [interaction].
* interacts with various [InteractWithItem] specified with [interaction].
*/
public class Item(
override var identifier: Identifier,
override var description: Description,
public var takeable: Boolean = false,
public var interaction: Interaction = defaultInteraction
) : ExaminableObject(), InteractionTarget {
) : ExaminableObject(), InteractWithItem {

/**
* Provides an item that can appear in a [Game]. The item must have a [identifier] and a [description].
* Optionally the item can be made takeable by setting [takeable] to true, and a interaction to define how this
* interacts with various [InteractionTarget] specified with [interaction].
* interacts with various [InteractWithItem] specified with [interaction].
*/
public constructor(
identifier: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.github.benpollarduk.ktaf.assets.characters

import com.github.benpollarduk.ktaf.assets.ExaminableObject
import com.github.benpollarduk.ktaf.assets.Item
import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.assets.interaction.Interaction
import com.github.benpollarduk.ktaf.assets.interaction.InteractionEffect
import com.github.benpollarduk.ktaf.assets.interaction.InteractionResult
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget

/**
* Provides a base for all Characters.
*/
public abstract class Character : ExaminableObject(), InteractionTarget {
public abstract class Character : ExaminableObject(), InteractWithItem {

/**
* Specifies how this [Character] interacts with various [Item].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.github.benpollarduk.ktaf.assets.characters
import com.github.benpollarduk.ktaf.assets.Description
import com.github.benpollarduk.ktaf.assets.Identifier
import com.github.benpollarduk.ktaf.assets.Item
import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.assets.interaction.InteractionEffect
import com.github.benpollarduk.ktaf.assets.interaction.InteractionResult
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget

/**
* A playable character with the specified [identifier] and [description] and [items].
Expand All @@ -23,7 +23,7 @@ public class PlayableCharacter(
/**
* Trigger this [Player] to use the specified [item] on the specified [target].
*/
public fun useItem(item: Item, target: InteractionTarget): InteractionResult {
public fun useItem(item: Item, target: InteractWithItem): InteractionResult {
val result = target.interact(item)

if (result.effect == InteractionEffect.FATAL_EFFECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.github.benpollarduk.ktaf.assets.interaction
import com.github.benpollarduk.ktaf.assets.Item

/**
* Provides a contract for any object that can be a target for an interaction.
* Provides a contract for any object that can be a target for an interaction with an [Item].
*/
public fun interface InteractionTarget {
public fun interface InteractWithItem {
/**
* Interact with the specified [item].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.github.benpollarduk.ktaf.assets.interaction
*/
public enum class InteractionEffect {
/**
* No effect to the interaction on either the [Item] or the [InteractionTarget].
* No effect to the interaction on either the [Item] or the [InteractWithItem].
*/
NO_EFFECT,

Expand All @@ -25,7 +25,7 @@ public enum class InteractionEffect {
FATAL_EFFECT,

/**
* The [InteractionTarget] was used up.
* The [InteractWithItem] was used up.
*/
TARGET_USED_UP,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.github.benpollarduk.ktaf.assets.Identifier
import com.github.benpollarduk.ktaf.assets.Item
import com.github.benpollarduk.ktaf.assets.characters.Character
import com.github.benpollarduk.ktaf.assets.characters.NonPlayableCharacter
import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.assets.interaction.Interaction
import com.github.benpollarduk.ktaf.assets.interaction.InteractionEffect
import com.github.benpollarduk.ktaf.assets.interaction.InteractionResult
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget
import com.github.benpollarduk.ktaf.extensions.equalsExaminable
import com.github.benpollarduk.ktaf.extensions.getObjectifier
import com.github.benpollarduk.ktaf.extensions.isPlural
Expand All @@ -26,7 +26,7 @@ public class Room(
override var description: Description,
exits: List<Exit> = emptyList(),
items: List<Item> = emptyList()
) : ExaminableObject(), InteractionTarget {
) : ExaminableObject(), InteractWithItem {
/**
* A room with a specified [identifier] and a [description].
*/
Expand Down Expand Up @@ -169,7 +169,7 @@ public class Room(
/**
* Remove a [target] from this [Room]. If the [target] exists in the [Room] true is returned else false.
*/
public fun removeInteractionTarget(target: InteractionTarget): Boolean {
public fun removeInteractionTarget(target: InteractWithItem): Boolean {
if (_items.contains(target)) {
removeItem(target as Item)
return true
Expand Down Expand Up @@ -239,7 +239,7 @@ public class Room(
}

/**
* Get if this [Room] contains an [InteractionTarget] specified by [target]. If [includeInvisibleExits] is true
* Get if this [Room] contains an [InteractWithItem] specified by [target]. If [includeInvisibleExits] is true
* then targets that aren't visible to the player are included.
*/
public fun containsInteractionTarget(target: String, includeInvisibleExits: Boolean = false): Boolean {
Expand All @@ -248,10 +248,10 @@ public class Room(
}

/**
* Find an [InteractionTarget] in this [Room], specified by [target]. If [includeInvisibleTargets] is true then
* Find an [InteractWithItem] in this [Room], specified by [target]. If [includeInvisibleTargets] is true then
* targets that aren't visible to the player are included.
*/
public fun findInteractionTarget(target: String, includeInvisibleTargets: Boolean = false): InteractionTarget? {
public fun findInteractionTarget(target: String, includeInvisibleTargets: Boolean = false): InteractWithItem? {
val item = items.firstOrNull { target.equalsExaminable(it) && (includeInvisibleTargets || it.isPlayerVisible) }
return item ?: characters.firstOrNull {
target.equalsExaminable(it) && (includeInvisibleTargets || it.isPlayerVisible)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.benpollarduk.ktaf.commands.game

import com.github.benpollarduk.ktaf.assets.Item
import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.assets.interaction.InteractionEffect
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget
import com.github.benpollarduk.ktaf.assets.interaction.Reaction
import com.github.benpollarduk.ktaf.assets.interaction.ReactionResult
import com.github.benpollarduk.ktaf.commands.Command
Expand All @@ -11,7 +11,7 @@ import com.github.benpollarduk.ktaf.logic.Game
/**
* Provides a command to use a specified [item] on a specified [target].
*/
internal class UseOn(private val item: Item?, private val target: InteractionTarget?) : Command {
internal class UseOn(private val item: Item?, private val target: InteractWithItem?) : Command {
override fun invoke(game: Game): Reaction {
if (item == null) {
return Reaction(ReactionResult.ERROR, "You must specify an item.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.benpollarduk.ktaf.interpretation

import com.github.benpollarduk.ktaf.assets.Item
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget
import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.commands.Command
import com.github.benpollarduk.ktaf.commands.game.Drop
import com.github.benpollarduk.ktaf.commands.game.Examine
Expand Down Expand Up @@ -125,7 +125,7 @@ public class ItemCommandInterpreter : Interpreter {
return null
}

val target: InteractionTarget?
val target: InteractWithItem?
var itemName: String
val onPadded = " $ON "

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.benpollarduk.ktaf.logic

import com.github.benpollarduk.ktaf.assets.Examinable
import com.github.benpollarduk.ktaf.assets.characters.PlayableCharacter
import com.github.benpollarduk.ktaf.assets.interaction.InteractionTarget
import com.github.benpollarduk.ktaf.assets.interaction.InteractWithItem
import com.github.benpollarduk.ktaf.assets.interaction.Reaction
import com.github.benpollarduk.ktaf.assets.interaction.ReactionResult
import com.github.benpollarduk.ktaf.assets.locations.Overworld
Expand Down Expand Up @@ -73,10 +73,10 @@ public class Game(
}

/**
* Find [InteractionTarget] within this [Game] from a specified [name]. If the target cannot be found null is
* Find an [InteractWithItem] within this [Game] from a specified [name]. If the target cannot be found null is
* returned.
*/
public fun findInteractionTarget(name: String): InteractionTarget? {
public fun findInteractionTarget(name: String): InteractWithItem? {
if (name.equalsExaminable(player)) {
return player
}
Expand Down

0 comments on commit f4d2fa1

Please sign in to comment.