From 602787a181b5a1a05b0862d078561ed6d03ffdf1 Mon Sep 17 00:00:00 2001 From: LimePotato Date: Sat, 28 Oct 2023 15:18:28 -0600 Subject: [PATCH] Game Config and sidebar Signed-off-by: LimePotato --- .../group/ouroboros/potrogue/GameConfig.kt | 36 +++++++++++++++++++ .../kotlin/group/ouroboros/potrogue/main.kt | 25 +------------ .../group/ouroboros/potrogue/view/LoseView.kt | 5 +-- .../group/ouroboros/potrogue/view/PlayView.kt | 34 +++++------------- .../ouroboros/potrogue/view/StartView.kt | 5 +-- .../group/ouroboros/potrogue/view/WinView.kt | 5 +-- 6 files changed, 54 insertions(+), 56 deletions(-) create mode 100644 src/main/kotlin/group/ouroboros/potrogue/GameConfig.kt diff --git a/src/main/kotlin/group/ouroboros/potrogue/GameConfig.kt b/src/main/kotlin/group/ouroboros/potrogue/GameConfig.kt new file mode 100644 index 0000000..4fac9c7 --- /dev/null +++ b/src/main/kotlin/group/ouroboros/potrogue/GameConfig.kt @@ -0,0 +1,36 @@ +package group.ouroboros.potrogue + +import org.hexworks.zircon.api.CP437TilesetResources +import org.hexworks.zircon.api.ColorThemes +import org.hexworks.zircon.api.application.AppConfig +import org.hexworks.zircon.api.data.Size3D + +object GameConfig { + + // game + const val DUNGEON_LEVELS = 2 + + // look & feel + val TILESET = CP437TilesetResources.rogueYun16x16() + val THEME = ColorThemes.cyberpunk() + const val SIDEBAR_WIDTH = 18 + const val LOG_AREA_HEIGHT = 8 + + // sizing + const val WINDOW_WIDTH = 80 + const val WINDOW_HEIGHT = 50 + + val WORLD_SIZE = Size3D.create(WINDOW_WIDTH, WINDOW_HEIGHT, DUNGEON_LEVELS) + val GAME_AREA_SIZE = Size3D.create( + xLength = WINDOW_WIDTH - SIDEBAR_WIDTH, + yLength = WINDOW_HEIGHT - LOG_AREA_HEIGHT, + zLength = DUNGEON_LEVELS + ) + + fun buildAppConfig() = AppConfig.newBuilder() + .withDefaultTileset(TILESET) + .withSize(WINDOW_WIDTH, WINDOW_HEIGHT) + .withTitle("$GAME_ID | $GAME_VER") + .build() + +} \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/main.kt b/src/main/kotlin/group/ouroboros/potrogue/main.kt index e31fab1..a2086c7 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/main.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/main.kt @@ -11,31 +11,8 @@ import org.hexworks.zircon.api.screen.Screen //Important Values public val GAME_ID = "potrogue"; public val GAME_VER = "0.1.0-DEV"; -public val GAME_THEME = cyberpunk() fun main(args: Array) { - - //Start the tilegrid and screen - val grid = SwingApplications.startTileGrid( - AppConfig.newBuilder() - .withTitle("$GAME_ID | $GAME_VER") - .withDefaultTileset(CP437TilesetResources.rogueYun16x16()) - .build() - ) - val screen = Screen.create(grid) - - //TODO - //Create Custom Color Theme - /* - val GAME_THEME = ColorThemeBuilder.newBuilder() - .withName("potcolor") - .withAccentColor(TileColor.transparent()) - .withPrimaryForegroundColor(TileColor.transparent()) - .withSecondaryForegroundColor(TileColor.transparent()) - .withPrimaryBackgroundColor(TileColor.transparent()) - .withSecondaryBackgroundColor(TileColor.transparent()) - .build()) - */ - + val grid = SwingApplications.startTileGrid(GameConfig.buildAppConfig()) StartView(grid).dock() } \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/LoseView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/LoseView.kt index a62171b..f34c7b3 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/LoseView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/LoseView.kt @@ -1,15 +1,16 @@ package group.ouroboros.potrogue.view -import group.ouroboros.potrogue.GAME_THEME +import group.ouroboros.potrogue.GameConfig import org.hexworks.zircon.api.ComponentDecorations.box import org.hexworks.zircon.api.Components +import org.hexworks.zircon.api.component.ColorTheme import org.hexworks.zircon.api.component.ComponentAlignment import org.hexworks.zircon.api.grid.TileGrid import org.hexworks.zircon.api.view.base.BaseView import kotlin.system.exitProcess -class LoseView (private val grid: TileGrid) : BaseView(grid, GAME_THEME) { +class LoseView (private val grid: TileGrid, theme: ColorTheme = GameConfig.THEME) : BaseView(grid, theme) { init { //Title diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt index a5deba2..b7ffa75 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt @@ -1,38 +1,20 @@ package group.ouroboros.potrogue.view -import group.ouroboros.potrogue.GAME_THEME +import group.ouroboros.potrogue.GameConfig import org.hexworks.zircon.api.ComponentDecorations.box -import org.hexworks.zircon.api.ComponentDecorations.shadow import org.hexworks.zircon.api.Components -import org.hexworks.zircon.api.component.ComponentAlignment.LEFT_CENTER -import org.hexworks.zircon.api.component.ComponentAlignment.RIGHT_CENTER +import org.hexworks.zircon.api.component.ColorTheme import org.hexworks.zircon.api.grid.TileGrid import org.hexworks.zircon.api.view.base.BaseView -class PlayView (private val grid: TileGrid) : BaseView(grid, GAME_THEME) { + +class PlayView (private val grid: TileGrid, theme: ColorTheme = GameConfig.THEME) : BaseView(grid, theme) { init { - //Create Lose Button - val loseButton = Components.button() - // constants like LEFT_CENTER can also be imported for brevity - .withAlignmentWithin(screen, LEFT_CENTER) - .withText("Lose!") - .withDecorations(box(), shadow()) + val sidebar = Components.panel() + .withSize(GameConfig.SIDEBAR_WIDTH, GameConfig.WINDOW_HEIGHT) + .withDecorations(box()) .build() - //Create Win BUtton - val winButton = Components.button() - .withAlignmentWithin(screen, RIGHT_CENTER) - .withText("Win!") - .withDecorations(box(), shadow()) - .build() - - //On Win Button activated, move to WinView - winButton.onActivated { replaceWith(WinView(grid)) } - //On Lose Button activated, move to LoseView - loseButton.onActivated { replaceWith(LoseView(grid)) } - - // multiple components can be added once - // Bake The Cake - screen.addComponents(loseButton, winButton) + screen.addComponent(sidebar) } } \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/StartView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/StartView.kt index c2abedf..eddaea6 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/StartView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/StartView.kt @@ -1,15 +1,16 @@ package group.ouroboros.potrogue.view import group.ouroboros.potrogue.GAME_ID -import group.ouroboros.potrogue.GAME_THEME +import group.ouroboros.potrogue.GameConfig import org.hexworks.zircon.api.ComponentDecorations.box import org.hexworks.zircon.api.ComponentDecorations.shadow import org.hexworks.zircon.api.Components +import org.hexworks.zircon.api.component.ColorTheme import org.hexworks.zircon.api.component.ComponentAlignment import org.hexworks.zircon.api.grid.TileGrid import org.hexworks.zircon.api.view.base.BaseView -class StartView (private val grid: TileGrid) : BaseView(grid, GAME_THEME) { +class StartView (private val grid: TileGrid, theme: ColorTheme = GameConfig.THEME) : BaseView(grid, theme) { init { val msg = "Welcome to $GAME_ID." diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/WinView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/WinView.kt index 6ed819d..9f7ed89 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/WinView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/WinView.kt @@ -1,16 +1,17 @@ package group.ouroboros.potrogue.view -import group.ouroboros.potrogue.GAME_THEME +import group.ouroboros.potrogue.GameConfig import org.hexworks.zircon.api.ColorThemes import org.hexworks.zircon.api.ComponentDecorations.box import org.hexworks.zircon.api.Components +import org.hexworks.zircon.api.component.ColorTheme import org.hexworks.zircon.api.component.ComponentAlignment import org.hexworks.zircon.api.grid.TileGrid import org.hexworks.zircon.api.view.base.BaseView import kotlin.system.exitProcess // For if winning.... obviously just a test. -class WinView (private val grid: TileGrid) : BaseView(grid, GAME_THEME) { +class WinView (private val grid: TileGrid, theme: ColorTheme = GameConfig.THEME) : BaseView(grid, theme) { init { //Title