Functional Config!

This commit is contained in:
nelle 2023-10-30 01:39:50 -06:00
parent ad6d9ae228
commit e51ae92ce7
6 changed files with 56 additions and 15 deletions

View file

@ -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()
}

View file

@ -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()

View file

@ -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)
}}

View file

@ -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()

View file

@ -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
)

View file

@ -0,0 +1,22 @@
<configuration>
<!-- We only print to the console (stdout) by default using the following format -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- Logging is set to info by default for our console logger -->
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
<!-- You can either set logging level for whole packages -->
<!--<logger name="org.hexworks.zircon" level="warn"/>
<logger name="org.hexworks.cobalt" level="warn"/>-->
<!-- Or individual classes -->
<!--<logger name="org.hexworks.zircon.api.component.Button" level="debug"/>-->
</configuration>