Skip to content

Commit

Permalink
Add program argument parsing, add dev and test mode idea confs
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvinas01 committed May 12, 2017
1 parent 28b489e commit 659b015
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
!gradle-wrapper.jar
.gradle/

# IntelliJ
.idea/
# IntelliJ stuff.
.idea/*

# Useful run config files fo IntelliJ
!.idea/
!.idea/runConfigurations/
.idea/runConfigurations/*
!.idea/runConfigurations/test.xml
!.idea/runConfigurations/dev.xml

# General
classes/
Expand Down
15 changes: 15 additions & 0 deletions .idea/runConfigurations/dev.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/runConfigurations/test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ buildscript {
}

repositories {
mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
mavenLocal()
jcenter()

maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}

dependencies {
Expand All @@ -22,8 +23,10 @@ buildscript {
}

repositories {
mavenLocal()
mavenCentral()
mavenLocal()
jcenter()

maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
maven { url 'http://dl.bintray.com/arturbosch/code-analysis' }
Expand Down Expand Up @@ -112,6 +115,7 @@ dependencies {
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.0.pr1'
compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.0.pr1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0.pr1'
compile 'com.xenomachina:kotlin-argparser:2.0.0'
compile 'commons-io:commons-io:2.5'

// JBox2d + Liquid fun dependencies.
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/edd/jelly/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.edd.jelly.game.JellyGame
import com.edd.jelly.core.configuration.Configurations
import com.edd.jelly.util.UncaughtExceptionLogger
import com.xenomachina.argparser.ArgParser

class Launcher : ApplicationAdapter() {

Expand All @@ -15,7 +16,7 @@ class Launcher : ApplicationAdapter() {
fun main(args: Array<String>) {
Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionLogger())

val configurations = Configurations()
val configurations = Configurations(ArgParser(args))
LwjglApplication(JellyGame(configurations), LwjglApplicationConfiguration().apply {
val video = configurations.config.video
foregroundFPS = video.fpsLimit
Expand Down
17 changes: 12 additions & 5 deletions src/main/kotlin/com/edd/jelly/core/configuration/Configurations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.xenomachina.argparser.ArgParser
import java.io.File

class Configurations {
class Configurations(argParser: ArgParser) {

companion object {
private const val CONFIG_FILE = "config.yml"
Expand All @@ -25,13 +26,19 @@ class Configurations {
// Configurations have to be loaded before Guice, so can't use DI here.
val mapper = ObjectMapper(YAMLFactory()).apply {
registerModule(KotlinModule())

// enable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES)
enable(JsonParser.Feature.ALLOW_YAML_COMMENTS)
}

// Is dev mode enabled.
private val dev by argParser.flagging(
"-d",
"--dev",
help = "developer mode"
)

private var messaging: Messaging? = null
val config: Config = load()

val config = load(dev)

/**
* Setup configuration settings for the game.
Expand All @@ -58,7 +65,7 @@ class Configurations {
/**
* Load config file from classpath resources.
*/
private fun load(internal: Boolean = true): Config {
private fun load(internal: Boolean): Config {
if (internal) {
return mapper.readValue(ClassLoader.getSystemResourceAsStream(CONFIG_FILE), Config::class.java)
}
Expand Down

0 comments on commit 659b015

Please sign in to comment.