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 removed assets/ability/effects/fow/fow.png
Binary file not shown.
Binary file added assets/board/fow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.chessevolved.components

import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.ComponentMapper

class FowComponent(
var showFog: Boolean,
) : Component {
companion object {
val mapper: ComponentMapper<FowComponent> =
ComponentMapper.getFor(FowComponent::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Image
import io.github.chessevolved.components.ActorComponent
import io.github.chessevolved.components.FowComponent
import io.github.chessevolved.components.HighlightComponent
import io.github.chessevolved.components.PlayerColorComponent
import io.github.chessevolved.components.PositionComponent
Expand All @@ -17,6 +18,7 @@ import io.github.chessevolved.components.WeatherEventComponent
import io.github.chessevolved.data.Position
import io.github.chessevolved.enums.PlayerColor
import io.github.chessevolved.enums.WeatherEvent
import io.github.chessevolved.singletons.GameSettings
import io.github.chessevolved.systems.InputService
import ktx.actors.onClick

Expand All @@ -25,6 +27,7 @@ class BoardSquareFactory(
private val assetManager: AssetManager,
) {
private val inputService: InputService = InputService()
private val isFowEnabled = GameSettings.isFOWEnabled()

private fun getBoardSquareTextureRegion(playerColor: PlayerColor): TextureRegion {
val colorStr = playerColor.name.lowercase()
Expand Down Expand Up @@ -65,6 +68,7 @@ class BoardSquareFactory(
add(PlayerColorComponent(playerColor))
add(TextureRegionComponent(getBoardSquareTextureRegion(playerColor)))
add(HighlightComponent(Color.WHITE))
add(FowComponent(isFowEnabled))
add(
ActorComponent(
getBoardActor(position, stage) { clickedPosition -> inputService.clickBoardSquareAtPosition(clickedPosition) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.github.chessevolved.systems

import com.badlogic.ashley.core.Entity
import com.badlogic.ashley.core.Family
import com.badlogic.ashley.systems.IteratingSystem
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import io.github.chessevolved.components.FowComponent
import io.github.chessevolved.components.PositionComponent
import io.github.chessevolved.singletons.GameSettings

class FowRenderingSystem(
private val batch: SpriteBatch,
private val assetManager: AssetManager,
) : IteratingSystem(
Family.all(PositionComponent::class.java, FowComponent::class.java).get(),
) {
private val isFowEnabled = GameSettings.isFOWEnabled()
private val fowTexture = assetManager.get("board/fow.png", Texture::class.java)

override fun processEntity(
entity: Entity,
deltaTime: Float,
) {
if (!isFowEnabled) return

val position = PositionComponent.mapper.get(entity)
val fow = FowComponent.mapper.get(entity)

if (position != null && fow != null) {
if (fow.showFog && (position.position.y >= (GameSettings.getBoardSize() + 1) / 2)) {
batch.draw(
fowTexture,
position.position.x.toFloat(),
position.position.y.toFloat(),
1f,
1f,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import com.badlogic.ashley.core.Entity
import com.badlogic.ashley.core.Family
import com.badlogic.ashley.systems.IteratingSystem
import io.github.chessevolved.components.ActorComponent
import io.github.chessevolved.components.FowComponent
import io.github.chessevolved.components.MovementIntentComponent
import io.github.chessevolved.components.MovementRuleComponent
import io.github.chessevolved.components.PositionComponent
import io.github.chessevolved.components.SelectionComponent
import io.github.chessevolved.components.ValidMovesComponent
import io.github.chessevolved.data.Position
import io.github.chessevolved.singletons.EcsEngine

class MovementSystem(
private val onTurnComplete: () -> Unit,
Expand All @@ -20,6 +23,8 @@ class MovementSystem(
MovementIntentComponent::class.java,
).get(),
) {
private val boardFamily = Family.all(PositionComponent::class.java, FowComponent::class.java).get()

override fun processEntity(
entity: Entity?,
deltaTime: Float,
Expand Down Expand Up @@ -49,10 +54,30 @@ class MovementSystem(
}
}

clearFow(targetPosition)

entity?.remove(SelectionComponent::class.java)
entity?.remove(ValidMovesComponent::class.java)
entity?.remove(MovementIntentComponent::class.java)

onTurnComplete()
}

private fun clearFow(center: Position) {
for (x in -1..1) {
for (y in -1..1) {
val currentPosition = Position(center.x + x, center.y + y)

val boardSquare =
EcsEngine.getEntitiesFor(boardFamily).firstOrNull {
PositionComponent.mapper.get(it).position == currentPosition
}

boardSquare?.let {
val fow = FowComponent.mapper.get(it)
if (fow.showFog) fow.showFog = false
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import io.github.chessevolved.singletons.EcsEntityMapper
import io.github.chessevolved.singletons.Game
import io.github.chessevolved.singletons.Game.subscribeToGameUpdates
import io.github.chessevolved.singletons.Game.unsubscribeFromGameUpdates
import io.github.chessevolved.singletons.GameSettings
import io.github.chessevolved.singletons.Lobby
import io.github.chessevolved.systems.AbilitySystem
import io.github.chessevolved.systems.CaptureSystem
import io.github.chessevolved.systems.FowRenderingSystem
import io.github.chessevolved.systems.InputSystem
import io.github.chessevolved.systems.MovementSystem
import io.github.chessevolved.systems.RenderingSystem
Expand Down Expand Up @@ -57,13 +59,15 @@ class GamePresenter(

private val movementSystem: MovementSystem
private val renderingSystem: RenderingSystem
private val fowRenderingSystem: FowRenderingSystem
private val selectionListener: SelectionEntityListener
private val captureSystem: CaptureSystem
private val inputSystem: InputSystem
private val abilitySystem: AbilitySystem
private val visualEffectSystem: VisualEffectSystem

private var navigatingToEndGame = false
private val isFowEnabled = GameSettings.isFOWEnabled()
Comment thread
ChrisKrane marked this conversation as resolved.

init {
setupGameView()
Expand Down Expand Up @@ -92,6 +96,9 @@ class GamePresenter(
loadRequiredAssets()
assetManager.finishLoading()

fowRenderingSystem = FowRenderingSystem(gameBatch, assetManager)
engine.addSystem(fowRenderingSystem)

visualEffectSystem.initializeAnimations()

setupBoard()
Expand All @@ -103,6 +110,7 @@ class GamePresenter(
private fun loadRequiredAssets() {
assetManager.load("board/black-tile.png", Texture::class.java)
assetManager.load("board/white-tile.png", Texture::class.java)
assetManager.load("board/fow.png", Texture::class.java)

PlayerColor.entries.forEach { color ->
PieceType.entries.forEach { type ->
Expand Down