Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/abilities/cards/explotionCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/cards/firetrailCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/cards/guardCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/cards/mirrorCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/cards/shieldCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/explosion-card-temp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/explosion-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/mirror-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/new_movement-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/shield-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/abilities/swap-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions assets/skin/plain-james-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ com.badlogic.gdx.scenes.scene2d.ui.ImageButton$ImageButtonStyle: {
over: round-light-gray
checked: round-dark-gray
checkedOver: round-light-gray
}
},

}
com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton$ImageTextButtonStyle: {
default: {
Expand Down Expand Up @@ -255,4 +256,4 @@ com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
stageBackground: white
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.chessevolved.components
import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.ComponentMapper

private object CurrentCardIdCounter {
var count = 0
}

class AbilityCardComponent : Component {
companion object {
val mapper: ComponentMapper<AbilityCardComponent> =
ComponentMapper.getFor(AbilityCardComponent::class.java)
}

val id = CurrentCardIdCounter.count++
var isInInventory = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.github.chessevolved.entities

import com.badlogic.ashley.core.Engine
import com.badlogic.ashley.core.Entity
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureRegion
import io.github.chessevolved.components.AbilityCardComponent
import io.github.chessevolved.components.AbilityComponent
import io.github.chessevolved.components.TextureRegionComponent
import io.github.chessevolved.enums.AbilityType

class AbilityItemFactory(
private val engine: Engine,
private val assetManager: AssetManager,
) {
private fun getAbilityItemTexture(abilityType: AbilityType): TextureRegion =
when (abilityType) {
AbilityType.SHIELD -> TextureRegion(assetManager.get("abilities/cards/shieldCard.png", Texture::class.java))
AbilityType.EXPLOSION -> TextureRegion(assetManager.get("abilities/cards/explosionCard.png", Texture::class.java))
// TODO: update all cards
AbilityType.SWAP -> TextureRegion(assetManager.get("abilities/swap-card.png", Texture::class.java))
AbilityType.MIRROR -> TextureRegion(assetManager.get("abilities/cards/mirrorCard.png", Texture::class.java))
AbilityType.NEW_MOVEMENT -> TextureRegion(assetManager.get("abilities/new_movement-card.png", Texture::class.java))
}

fun createAbilityItem(abilityType: AbilityType): Entity {
var cooldown: Int = 3

when (abilityType) {
AbilityType.SHIELD -> {
cooldown = 3
}
AbilityType.EXPLOSION -> {
cooldown = 2
}
AbilityType.SWAP -> {
cooldown = 2
}
AbilityType.MIRROR -> {
cooldown = 3
}
AbilityType.NEW_MOVEMENT -> {
cooldown = 0
}
}

return Entity().apply {
add(AbilityComponent(abilityType, cooldown, 0))
add(AbilityCardComponent())
add(TextureRegionComponent(getAbilityItemTexture(abilityType)))
engine.addEntity(this)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package io.github.chessevolved.systems
import com.badlogic.ashley.core.Entity
import com.badlogic.ashley.core.Family
import com.badlogic.ashley.systems.IteratingSystem
import io.github.chessevolved.components.AbilityCardComponent
import io.github.chessevolved.components.AbilityComponent
import io.github.chessevolved.components.CanBeCapturedComponent
import io.github.chessevolved.components.CapturedComponent
import io.github.chessevolved.components.ClickEventComponent
Expand All @@ -26,23 +28,49 @@ class InputSystem :
handlePieceClicked(entity)
} else if (entity?.getComponent(WeatherEventComponent::class.java) != null) {
handleBoardSquareClicked(entity)
} else if (entity?.getComponent(AbilityCardComponent::class.java) != null) {
handleAbilityCardClicked(entity)
}

entity?.remove(ClickEventComponent::class.java)
}

private fun handlePieceClicked(piece: Entity) {
val selectionComponent = piece.getComponent(SelectionComponent::class.java)
val selectedPiece = engine.getEntitiesFor(Family.all(SelectionComponent::class.java).get()).firstOrNull()
val selectedEntity = engine.getEntitiesFor(Family.all(SelectionComponent::class.java).get()).firstOrNull()
val canBeCapturedComponent = piece.getComponent(CanBeCapturedComponent::class.java)

if (selectionComponent != null) {
piece.remove(SelectionComponent::class.java)
} else if (selectedPiece != null && canBeCapturedComponent != null) {
} else if (selectedEntity != null && canBeCapturedComponent != null) {
piece.add(CapturedComponent())
} else {
selectedPiece?.remove(SelectionComponent::class.java)
piece.add(SelectionComponent())
if (selectedEntity != null &&
AbilityCardComponent.mapper.get(selectedEntity) != null &&
AbilityCardComponent.mapper.get(selectedEntity).isInInventory
) {
if (AbilityComponent.mapper.get(piece) != null) {
println("Already has ability")
} else {
val abilityComponent = AbilityComponent.mapper.get(selectedEntity)

if (abilityComponent != null) {
piece.add(
AbilityComponent(
abilityComponent.ability,
abilityComponent.abilityCooldownTime,
abilityComponent.currentAbilityCDTime,
),
)
}

println("Ability got applied to piece!")
selectedEntity.removeAll() // Remove abilityCard-entity from the game.
}
} else {
selectedEntity?.remove(SelectionComponent::class.java)
piece.add(SelectionComponent())
}
}
}

Expand All @@ -54,6 +82,18 @@ class InputSystem :
.firstOrNull()
?.add(MovementIntentComponent(position))
}

private fun handleAbilityCardClicked(abilityCard: Entity) {
val selectionComponent = SelectionComponent.mapper.get(abilityCard)
val alreadySelectedEntity = engine.getEntitiesFor(Family.all(SelectionComponent::class.java).get()).firstOrNull()

if (selectionComponent != null) {
abilityCard.remove(SelectionComponent::class.java)
} else {
alreadySelectedEntity?.remove(SelectionComponent::class.java)
abilityCard.add(SelectionComponent())
}
}
}

class InputService {
Expand All @@ -74,4 +114,32 @@ class InputService {

entity?.add(ClickEventComponent())
}

fun clickAbilityCardWithId(abilityCardId: Int) {
val entity =
EcsEngine
.getEntitiesFor(Family.all(AbilityCardComponent::class.java).get())
.find { AbilityCardComponent.mapper.get(it).id == abilityCardId }

entity?.add(ClickEventComponent())
}

fun confirmAbilityChoice() {
val entityWithSelectionComponent =
EcsEngine.getEntitiesFor(Family.all(SelectionComponent::class.java).get()).firstOrNull() ?: return
val abilityCardComponent = AbilityCardComponent.mapper.get(entityWithSelectionComponent) ?: return
if (abilityCardComponent.isInInventory) return

abilityCardComponent.isInInventory = true
entityWithSelectionComponent.remove(SelectionComponent::class.java)

// Remove all other not-in-inventory cards
EcsEngine
.getEntitiesFor(Family.all(AbilityCardComponent::class.java).get())
.filter {
!AbilityCardComponent.mapper.get(it).isInInventory
}.forEach {
it.removeAll()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.chessevolved.systems
import com.badlogic.ashley.core.Entity
import com.badlogic.ashley.core.Family
import com.badlogic.ashley.systems.IteratingSystem
import io.github.chessevolved.components.AbilityTriggerComponent
import io.github.chessevolved.components.ActorComponent
import io.github.chessevolved.components.FowComponent
import io.github.chessevolved.components.MovementIntentComponent
Expand Down Expand Up @@ -45,6 +46,8 @@ class MovementSystem(
val pieceActorComponent = ActorComponent.mapper.get(entity)
val pieceMovementRuleComponent = MovementRuleComponent.mapper.get(entity)

entity?.add(AbilityTriggerComponent(targetPosition, piecePositionComponent.position))

piecePositionComponent.position = targetPosition
pieceActorComponent.actor.setPosition(targetPosition.x.toFloat(), targetPosition.y.toFloat())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.badlogic.ashley.core.Entity
import com.badlogic.ashley.core.EntityListener
import com.badlogic.ashley.core.Family
import com.badlogic.gdx.graphics.Color
import io.github.chessevolved.components.AbilityCardComponent
import io.github.chessevolved.components.CanBeCapturedComponent
import io.github.chessevolved.components.HighlightComponent
import io.github.chessevolved.components.MovementRuleComponent
Expand All @@ -14,7 +15,9 @@ import io.github.chessevolved.components.ValidMovesComponent
import io.github.chessevolved.components.WeatherEventComponent
import io.github.chessevolved.singletons.EcsEngine

class SelectionEntityListener(private val boardSize: Int) : EntityListener {
class SelectionEntityListener(
private val boardSize: Int,
) : EntityListener {
private val moveValidator = MoveValidator()

private val capturableFamily = Family.all(CanBeCapturedComponent::class.java).get()
Expand All @@ -27,6 +30,7 @@ class SelectionEntityListener(private val boardSize: Int) : EntityListener {
.get()

override fun entityAdded(entity: Entity?) {
if (AbilityCardComponent.mapper.get(entity) != null) return
for (piece in EcsEngine.getEntitiesFor(capturableFamily)) {
piece.remove(CanBeCapturedComponent::class.java)
}
Expand All @@ -51,6 +55,7 @@ class SelectionEntityListener(private val boardSize: Int) : EntityListener {
}

override fun entityRemoved(entity: Entity?) {
if (AbilityCardComponent.mapper.get(entity) != null) return
entity?.remove(ValidMovesComponent::class.java)

for (piece in EcsEngine.getEntitiesFor(capturableFamily)) {
Expand Down
Loading