From e51ae92ce714737bb3263d63b617c1c142d1e3c9 Mon Sep 17 00:00:00 2001 From: LimePotato Date: Mon, 30 Oct 2023 01:39:50 -0600 Subject: [PATCH] Functional Config! --- .../ouroboros/potrogue/data/config/Config.kt | 18 ++++++++++----- .../potrogue/data/config/GameConfig.kt | 10 ++++----- .../ouroboros/potrogue/view/ConfigView.kt | 13 ++++++++++- .../group/ouroboros/potrogue/view/PlayView.kt | 4 ++-- .../ouroboros/potrogue/world/GameBuilder.kt | 4 ++-- src/main/resources/logback.xml | 22 +++++++++++++++++++ 6 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/logback.xml diff --git a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt index 17e952c..a869539 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt @@ -9,6 +9,10 @@ import java.nio.file.Path import java.nio.file.Paths import java.util.* +//SET ALL PROPERTIES +val prop = Properties() +val winWS = prop.getProperty("WINDOW_HEIGHT") +//val WINDOW_WIDTH = 80 //TODO: make them variables work :( @@ -35,13 +39,17 @@ class Config { prop.setProperty("WINDOW_WIDTH", "80") prop.setProperty("WINDOW_HEIGHT", "50") + val out: OutputStream = FileOutputStream(file) prop.store(out, "some comment") } - // Print all properties - prop.stringPropertyNames() - .associateWith {prop.getProperty(it)} - .forEach { println(it) } - } + //SET ALL PROPERTIES + //val winWS = prop.getProperty("WINDOW_WIDTH") + //val WINDOW_WIDTH = winWS.filter { it.isDigit() } + + //println(WINDOW_WIDTH) +} + val winWS = prop.getProperty("WINDOW_WIDTH") + val WINDOW_WIDTH: Int = winWS.toInt() } \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/data/config/GameConfig.kt b/src/main/kotlin/group/ouroboros/potrogue/data/config/GameConfig.kt index 0b02431..d91541a 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/data/config/GameConfig.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/data/config/GameConfig.kt @@ -13,7 +13,7 @@ object GameConfig { const val DUNGEON_LEVELS = 2 // look & feel - val TILESET = CP437TilesetResources.rogueYun16x16() + var TILESET = CP437TilesetResources.rogueYun16x16() val THEME = ColorThemes.cyberpunk() const val SIDEBAR_WIDTH = 18 const val LOG_AREA_HEIGHT = 12 @@ -21,19 +21,19 @@ object GameConfig { // sizing const val BORDERLESS_WINDOW_WIDTH = 120 const val BORDERLESS_WINDOW_HEIGHT = 65 - const val WINDOW_WIDTH = 80 + //const val WINDOW_WIDTH = 80 const val WINDOW_HEIGHT = 50 - val WORLD_SIZE = Size3D.create(WINDOW_WIDTH * 3, WINDOW_HEIGHT * 3 , DUNGEON_LEVELS) + val WORLD_SIZE = Size3D.create(Config().WINDOW_WIDTH * 3, WINDOW_HEIGHT * 3 , DUNGEON_LEVELS) val GAME_AREA_SIZE = Size3D.create( - xLength = WINDOW_WIDTH - SIDEBAR_WIDTH, + xLength = Config().WINDOW_WIDTH - SIDEBAR_WIDTH, yLength = WINDOW_HEIGHT - LOG_AREA_HEIGHT, zLength = DUNGEON_LEVELS ) fun buildAppConfig() = AppConfig.newBuilder() .withDefaultTileset(TILESET) - .withSize(WINDOW_WIDTH, WINDOW_HEIGHT) + .withSize(Config().WINDOW_WIDTH, WINDOW_HEIGHT) .withTitle("$GAME_ID | $GAME_VER") .withIcon("assets/icon.png") .build() diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/ConfigView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/ConfigView.kt index d44a576..ec0003e 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/ConfigView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/ConfigView.kt @@ -1,6 +1,7 @@ package group.ouroboros.potrogue.view import group.ouroboros.potrogue.data.config.GameConfig +import org.hexworks.zircon.api.CP437TilesetResources import org.hexworks.zircon.api.ComponentDecorations import org.hexworks.zircon.api.Components import org.hexworks.zircon.api.component.ColorTheme @@ -28,12 +29,22 @@ class ConfigView (private val grid: TileGrid, theme: ColorTheme = GameConfig.TH //TODO: Options: world size, character tile (smiley, @, &), character customizations (class, looks, stats, start), + val tilesetButton = Components.button() + .withAlignmentWithin(screen, ComponentAlignment.CENTER) + .withText("CHANGE TILESET") + .withDecorations(ComponentDecorations.box(), ComponentDecorations.shadow()) + .build() + val backButton = Components.button() .withAlignmentWithin(screen, ComponentAlignment.BOTTOM_CENTER) .withText("BACK") .withDecorations(ComponentDecorations.box(), ComponentDecorations.shadow()) .build() + tilesetButton.onActivated { + GameConfig.TILESET = CP437TilesetResources.anikki16x16() + } + //Once the back button is activated go back to startView backButton.onActivated { replaceWith(StartView(grid)) @@ -41,5 +52,5 @@ class ConfigView (private val grid: TileGrid, theme: ColorTheme = GameConfig.TH // We can add multiple components at once //Bake The Cake - screen.addComponents(header,backButton) + screen.addComponents(header,backButton,tilesetButton) }} \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt index 9f1b5ea..9db43a2 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt @@ -1,9 +1,9 @@ package group.ouroboros.potrogue.view import group.ouroboros.potrogue.builders.GameTileRepository +import group.ouroboros.potrogue.data.config.Config import group.ouroboros.potrogue.data.config.GameConfig import group.ouroboros.potrogue.data.config.GameConfig.LOG_AREA_HEIGHT -import group.ouroboros.potrogue.data.config.GameConfig.WINDOW_WIDTH import group.ouroboros.potrogue.world.Game import group.ouroboros.potrogue.world.GameBuilder import org.hexworks.cobalt.databinding.api.extension.toProperty @@ -29,7 +29,7 @@ class PlayView (private val grid: TileGrid, private val game: Game = GameBuilder //Create area for logging val logArea = Components.logArea() .withDecorations(box(title = "Log")) - .withSize(WINDOW_WIDTH, LOG_AREA_HEIGHT) + .withSize(Config().WINDOW_WIDTH, LOG_AREA_HEIGHT) .withAlignmentWithin(screen, ComponentAlignment.BOTTOM_RIGHT) .build() diff --git a/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt b/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt index 553fed7..8aa121a 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt @@ -2,11 +2,11 @@ package group.ouroboros.potrogue.world import group.ouroboros.potrogue.builders.EntityFactory import group.ouroboros.potrogue.builders.WorldBuilder +import group.ouroboros.potrogue.data.config.Config import group.ouroboros.potrogue.data.config.GameConfig import group.ouroboros.potrogue.data.config.GameConfig.LOG_AREA_HEIGHT import group.ouroboros.potrogue.data.config.GameConfig.SIDEBAR_WIDTH import group.ouroboros.potrogue.data.config.GameConfig.WINDOW_HEIGHT -import group.ouroboros.potrogue.data.config.GameConfig.WINDOW_WIDTH import group.ouroboros.potrogue.data.config.GameConfig.WORLD_SIZE import group.ouroboros.potrogue.entity.attributes.types.Player import group.ouroboros.potrogue.extensions.GameEntity @@ -18,7 +18,7 @@ class GameBuilder (val worldSize: Size3D) { // We define the visible size which is our viewport of the world private val visibleSize = Size3D.create( - xLength = WINDOW_WIDTH - SIDEBAR_WIDTH, + xLength = Config().WINDOW_WIDTH - SIDEBAR_WIDTH, yLength = WINDOW_HEIGHT - LOG_AREA_HEIGHT, zLength = 1 ) diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..8e16f8f --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,22 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + +