-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve settings and properties (#577)
* Fix xp rate modifier * Fix music unlock command * Fix tests for experience rate * Add Settings closes #576 * Add settings reload event * Convert properties to load via Settings * Fix incorrect inject() usages * Convert properties to Settings * Fix left-over state effecting other tests * Convert World variables to Settings * Convert missed property loading * Refactor game.properties * Add shooting star respawn time settings and command * Add global event message * Add toggle for esse pouch degrading * Add infinite run energy toggle * Add bots random walk setting * Add networked bots as dev setting * Add lumbridge safe zone setting * More organising and add a few startup configs * Make home tile and exp rate settings dynamic * Replace Main.name with server.name setting
- Loading branch information
Showing
151 changed files
with
1,009 additions
and
634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
engine/src/main/kotlin/world/gregs/voidps/engine/data/Settings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package world.gregs.voidps.engine.data | ||
|
||
import com.github.michaelbull.logging.InlineLogger | ||
import java.io.File | ||
import java.io.InputStream | ||
import java.util.* | ||
|
||
/** | ||
* Class to load and reload game settings from .property files | ||
*/ | ||
open class Settings { | ||
|
||
protected val properties = Properties() | ||
|
||
fun load(stream: InputStream): Properties { | ||
properties.load(stream) | ||
return properties | ||
} | ||
|
||
fun load(map: Map<String, String>): Properties { | ||
properties.putAll(map) | ||
return properties | ||
} | ||
|
||
fun load(properties: Properties): Properties { | ||
this.properties.putAll(properties) | ||
return this.properties | ||
} | ||
|
||
fun getOrNull(name: String): String? = properties.getProperty(name) | ||
|
||
operator fun get(name: String): String = properties.getProperty(name) | ||
|
||
operator fun get(name: String, default: String): String = properties.getProperty(name, default) | ||
|
||
operator fun get(name: String, default: Int): Int = getOrNull(name)?.toIntOrNull() ?: default | ||
|
||
operator fun get(name: String, default: Double): Double = getOrNull(name)?.toDoubleOrNull() ?: default | ||
|
||
operator fun get(name: String, default: Boolean): Boolean = getOrNull(name)?.toBooleanStrictOrNull() ?: default | ||
|
||
fun clear() { | ||
properties.clear() | ||
} | ||
|
||
companion object : Settings() { | ||
private const val PROPERTY_FILE_NAME = "game.properties" | ||
private val logger = InlineLogger() | ||
|
||
fun load(fileName: String = PROPERTY_FILE_NAME): Properties { | ||
val file = File("./$fileName") | ||
return if (file.exists()) { | ||
Settings.load(file.inputStream()) | ||
} else { | ||
logger.debug { "Property file not found; defaulting to internal." } | ||
Settings.load(Settings::class.java.getResourceAsStream("/$fileName")!!) | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
engine/src/main/kotlin/world/gregs/voidps/engine/data/SettingsReload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package world.gregs.voidps.engine.data | ||
|
||
import world.gregs.voidps.engine.entity.character.player.Player | ||
import world.gregs.voidps.engine.event.Event | ||
import world.gregs.voidps.engine.event.EventDispatcher | ||
import world.gregs.voidps.engine.event.Events | ||
|
||
object SettingsReload : Event { | ||
|
||
override val notification: Boolean = true | ||
|
||
override val size = 1 | ||
|
||
override fun parameter(dispatcher: EventDispatcher, index: Int) = when (index) { | ||
0 -> "settings_reload" | ||
else -> null | ||
} | ||
} | ||
|
||
fun settingsReload(handler: suspend SettingsReload.(Player) -> Unit) { | ||
Events.handle("settings_reload", handler = handler) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.