mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
added Gamerules to the GameWorld
This commit is contained in:
@@ -27,7 +27,9 @@ object CommandDict {
|
|||||||
"SetLocale",
|
"SetLocale",
|
||||||
"TakeScreenshot",
|
"TakeScreenshot",
|
||||||
"Unpause",
|
"Unpause",
|
||||||
"Version"
|
"Version",
|
||||||
|
"SetGR",
|
||||||
|
"GetGR",
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
58
src/net/torvald/terrarum/console/GetGR.kt
Normal file
58
src/net/torvald/terrarum/console/GetGR.kt
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package net.torvald.terrarum.console
|
||||||
|
|
||||||
|
import net.torvald.terrarum.*
|
||||||
|
import net.torvald.terrarum.modulebasegame.console.GetAV.isNum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2022-06-03.
|
||||||
|
*/
|
||||||
|
internal object GetGR : ConsoleCommand {
|
||||||
|
override fun execute(args: Array<String>) {
|
||||||
|
val gameRules = INGAME.world.gameRules
|
||||||
|
|
||||||
|
// check if args[1] is number or not
|
||||||
|
if (args.size > 1 && !args[1].isNum()) { // args[1] is Gamerule name
|
||||||
|
gameRules[args[1]].let {
|
||||||
|
if (it != null) {
|
||||||
|
Echo("${ccW}Gamerule $ccM${args[1]} $ccW= " +
|
||||||
|
ccG +
|
||||||
|
it +
|
||||||
|
" $ccO" +
|
||||||
|
it.javaClass.simpleName
|
||||||
|
)
|
||||||
|
println("[GetGR] Gamerule ${args[1]} = " +
|
||||||
|
it +
|
||||||
|
" " +
|
||||||
|
it.javaClass.simpleName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EchoError("No such Gamerule defined: ${args[1]}")
|
||||||
|
println("[GetGR] No such Gamerule defined: ${args[1]}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// args[1] is actor ID
|
||||||
|
val keyset = gameRules.keySet
|
||||||
|
|
||||||
|
Echo("$ccW== List of$ccY Gamerules $ccW==")
|
||||||
|
println("[GetGR] == List of Gamerules ==")
|
||||||
|
if (keyset.isEmpty()) {
|
||||||
|
Echo("$ccK(nothing)")
|
||||||
|
println("[GetGR] (nothing)")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keyset.forEach { elem ->
|
||||||
|
Echo("$ccM$elem $ccW= $ccG${gameRules[elem as String]}")
|
||||||
|
println("[GetGR] $elem = ${gameRules[elem]}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun printUsage() {
|
||||||
|
Echo("Usage: getgr <gamerule>")
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/net/torvald/terrarum/console/SetGR.kt
Normal file
64
src/net/torvald/terrarum/console/SetGR.kt
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package net.torvald.terrarum.console
|
||||||
|
|
||||||
|
import net.torvald.terrarum.INGAME
|
||||||
|
import net.torvald.terrarum.ccG
|
||||||
|
import net.torvald.terrarum.ccM
|
||||||
|
import net.torvald.terrarum.ccW
|
||||||
|
import net.torvald.terrarum.modulebasegame.console.SetAV.isNum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2022-06-03.
|
||||||
|
*/
|
||||||
|
internal object SetGR : ConsoleCommand {
|
||||||
|
override fun execute(args: Array<String>) {
|
||||||
|
fun parseAVInput(arg: String): Any {
|
||||||
|
var inputval: Any
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputval = Integer(arg) // try for integer
|
||||||
|
}
|
||||||
|
catch (e: NumberFormatException) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputval = arg.toDouble() // try for double
|
||||||
|
}
|
||||||
|
catch (ee: NumberFormatException) {
|
||||||
|
if (arg.equals("__true", ignoreCase = true)) {
|
||||||
|
inputval = true
|
||||||
|
}
|
||||||
|
else if (arg.equals("__false", ignoreCase = true)) {
|
||||||
|
inputval = false
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
inputval = arg // string if not number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputval
|
||||||
|
}
|
||||||
|
|
||||||
|
// setav <id, or blank for player> <av> <val>
|
||||||
|
if (args.size != 3) {
|
||||||
|
printUsage()
|
||||||
|
}
|
||||||
|
else if (args.size == 3) {
|
||||||
|
val newValue = parseAVInput(args[2])
|
||||||
|
|
||||||
|
// check if av is number
|
||||||
|
if (args[1].isNum()) {
|
||||||
|
EchoError("Illegal Gamerule ${args[1]}: Gamerule cannot be a number.")
|
||||||
|
System.err.println("[SetGR] Illegal Gamerule ${args[1]}: Gamerule cannot be a number.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
INGAME.world.gameRules[args[1]] = newValue
|
||||||
|
Echo("${ccW}Set Gamerule $ccM${args[1]} ${ccW}to $ccG$newValue")
|
||||||
|
println("[SetGR] set Gamerule '${args[1]}' to '$newValue'.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun printUsage() {
|
||||||
|
Echo("Usage: setgr <gamerule> <value>")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,4 +36,4 @@ class ActorValue : KVHashMap {
|
|||||||
fun clone(newActor: Actor): ActorValue {
|
fun clone(newActor: Actor): ActorValue {
|
||||||
return ActorValue(newActor, hashMap)
|
return ActorValue(newActor, hashMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ open class GameWorld() : Disposable {
|
|||||||
/** Creation time for this world, NOT the entire savegame */
|
/** Creation time for this world, NOT the entire savegame */
|
||||||
internal var totalPlayTime = 0L // cumulative value for this very world
|
internal var totalPlayTime = 0L // cumulative value for this very world
|
||||||
|
|
||||||
|
val gameRules = KVHashMap() // spawn points, creation/lastplay/totalplaytimes are NOT stored to gameRules
|
||||||
|
|
||||||
init {
|
init {
|
||||||
creationTime = App.getTIME_T()
|
creationTime = App.getTIME_T()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user