mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-12 06:41:51 +09:00
Make package names comply with the naming conventions, new player tester "Cynthia", creature-making factories now use CreatureRawInjector to create their ActorValues.
Former-commit-id: f924467637c8e34ecc9b2ffd00b343253c40aaf7 Former-commit-id: 7779de4420c27e06ee17e8576b643c366d434ef8
This commit is contained in:
13
src/com/torvald/random/Fudge3.kt
Normal file
13
src/com/torvald/random/Fudge3.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.torvald.random
|
||||
|
||||
import java.util.Random
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-03.
|
||||
*/
|
||||
class Fudge3
|
||||
/**
|
||||
* Define new set of fudge dice with three dice.
|
||||
* @param randfunc java.util.Random or its extension
|
||||
*/
|
||||
(randfunc: Random) : FudgeDice(randfunc, 3)
|
||||
47
src/com/torvald/random/FudgeDice.kt
Normal file
47
src/com/torvald/random/FudgeDice.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.torvald.random
|
||||
|
||||
import java.util.Random
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-03.
|
||||
*/
|
||||
open class FudgeDice
|
||||
/**
|
||||
* Define new set of fudge dice with given counts.
|
||||
* @param randfunc java.util.Random or its extension
|
||||
* *
|
||||
* @param counts amount of die
|
||||
*/
|
||||
(private val randfunc: Random, val diceCounts: Int) {
|
||||
|
||||
/**
|
||||
* Roll dice and get result.
|
||||
* @return Normal distributed integer [-N , N] for diceCount of N. 0 is the most frequent return.
|
||||
*/
|
||||
fun roll(): Int {
|
||||
var diceResult = 0
|
||||
for (c in 0..diceCounts - 1) {
|
||||
diceResult += rollSingleDie()
|
||||
}
|
||||
|
||||
return diceResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Roll dice and get result, for array index
|
||||
* @return Normal distributed integer [0 , N] for N = 2 × DiceCounts + 1. 0 is the most frequent return.
|
||||
*/
|
||||
fun rollForArray(): Int {
|
||||
return roll() + diceCounts
|
||||
}
|
||||
|
||||
val sizeOfProbabilityRange: Int
|
||||
get() = 2 * diceCounts + 1
|
||||
|
||||
/**
|
||||
* @return integer randomly picked from {-1, 0, 1}
|
||||
*/
|
||||
private fun rollSingleDie(): Int {
|
||||
return randfunc.nextInt(3) - 1
|
||||
}
|
||||
}
|
||||
59
src/com/torvald/random/HQRNG.java
Normal file
59
src/com/torvald/random/HQRNG.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.torvald.random;
|
||||
|
||||
import java.util.Random;
|
||||
//import java.util.concurrent.locks.*;
|
||||
|
||||
/**
|
||||
* This class implements a better random number generator than the standard LCG that is implemented in java.util.Random.
|
||||
* It is based on <a href="http://www.amazon.com/gp/product/0521880688?ie=UTF8&tag=javamex-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0521880688">Numerical Recipes: The Art of Scientific Computing</a>,
|
||||
* and gives a good compromise between quality and speed. It is a combined generator: two XORShift generators are combined with an LCG and a multiply with carry generator.
|
||||
* (Without going into all the details here, notice the two blocks of three shifts each, which are the XORShifts; the first line which is the LCG, similar to the standard
|
||||
* Java Random algorithm, and the line between the two XORShifts, which is a multiply with carry generator.)
|
||||
* Note that this version is <b>not</b> thread-safe. In order to make it thread-safe, uncomment the lock-related lines. It is also <b>not</b> cryptographically secure, like the java.security.SecureRandom class.
|
||||
* @author Numerical Recipes
|
||||
*/
|
||||
|
||||
public class HQRNG extends Random {
|
||||
|
||||
//private Lock l = new ReentrantLock();
|
||||
private long u;
|
||||
private long v = 4101842887655102017L;
|
||||
private long w = 1;
|
||||
|
||||
public HQRNG() {
|
||||
this(System.nanoTime());
|
||||
}
|
||||
public HQRNG(long seed) {
|
||||
//l.lock();
|
||||
u = seed ^ v;
|
||||
nextLong();
|
||||
v = u;
|
||||
nextLong();
|
||||
w = v;
|
||||
nextLong();
|
||||
//l.unlock();
|
||||
}
|
||||
|
||||
public long nextLong() {
|
||||
// l.lock();
|
||||
try {
|
||||
u = u * 2862933555777941757L + 7046029254386353087L;
|
||||
v ^= v >>> 17;
|
||||
v ^= v << 31;
|
||||
v ^= v >>> 8;
|
||||
w = 4294957665L * (w & 0xffffffff) + (w >>> 32);
|
||||
long x = u ^ (u << 21);
|
||||
x ^= x >>> 35;
|
||||
x ^= x << 4;
|
||||
long ret = (x + v) ^ w;
|
||||
return ret;
|
||||
} finally {
|
||||
//l.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected int next(int bits) {
|
||||
return (int) (nextLong() >>> (64-bits));
|
||||
}
|
||||
|
||||
}
|
||||
1440
src/com/torvald/random/MTRandom.java
Normal file
1440
src/com/torvald/random/MTRandom.java
Normal file
File diff suppressed because it is too large
Load Diff
46
src/com/torvald/terrarum/console/Authenticator.kt
Normal file
46
src/com/torvald/terrarum/console/Authenticator.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.torvald.terrarum.ui.ConsoleWindow
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-19.
|
||||
*/
|
||||
class Authenticator : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val pwd = args[1]
|
||||
val hashedPwd = DigestUtils.sha256Hex(pwd)
|
||||
|
||||
if ("54c5b3dd459d5ef778bb2fa1e23a5fb0e1b62ae66970bcb436e8f81a1a1a8e41".equals(hashedPwd, ignoreCase = true)) {
|
||||
// alpine
|
||||
val msg = if (a) "Locked" else "Authenticated"
|
||||
Echo().execute(msg)
|
||||
println("[Authenticator] " + msg)
|
||||
a = !a
|
||||
(Terrarum.game.consoleHandler.UI as ConsoleWindow).reset()
|
||||
}
|
||||
else {
|
||||
printUsage() // thou shalt not pass!
|
||||
}
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
fun b(): Boolean {
|
||||
return a
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
CommandInterpreter.echoUnknownCmd("auth")
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private var a = false
|
||||
}
|
||||
}
|
||||
24
src/com/torvald/terrarum/console/Batch.kt
Normal file
24
src/com/torvald/terrarum/console/Batch.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-07.
|
||||
*/
|
||||
class Batch : ConsoleCommand {
|
||||
@Throws(Exception::class)
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
Files.lines(FileSystems.getDefault().getPath(args[1])).forEach(
|
||||
{ CommandInterpreter.execute(it) })
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("batch path/to/batch.txt")
|
||||
}
|
||||
}
|
||||
32
src/com/torvald/terrarum/console/CatStdout.kt
Normal file
32
src/com/torvald/terrarum/console/CatStdout.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import java.io.IOException
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-10.
|
||||
*/
|
||||
class CatStdout : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
|
||||
val echo = Echo()
|
||||
|
||||
if (args.size == 1) {
|
||||
printUsage()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
Files.lines(FileSystems.getDefault().getPath(args[1])).forEach({ echo.execute(it) })
|
||||
}
|
||||
catch (e: IOException) {
|
||||
echo.execute("CatStdout: could not read file -- IOException")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("usage: cat 'path/to/text/file")
|
||||
}
|
||||
}
|
||||
45
src/com/torvald/terrarum/console/CodexEdictis.kt
Normal file
45
src/com/torvald/terrarum/console/CodexEdictis.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Game
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.ui.ConsoleWindow
|
||||
|
||||
import java.util.Formatter
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-16.
|
||||
*/
|
||||
class CodexEdictis : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 1) {
|
||||
printList()
|
||||
}
|
||||
else {
|
||||
try {
|
||||
val commandObj = CommandDict.getCommand(args[1].toLowerCase())
|
||||
commandObj.printUsage()
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
val sb = StringBuilder()
|
||||
val formatter = Formatter(sb)
|
||||
|
||||
Echo().execute("Codex: " + formatter.format(Lang.get("DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN"), args[1]).toString())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Usage: codex (command)")
|
||||
echo.execute("shows how to use 'command'")
|
||||
echo.execute("leave blank to get list of available commands")
|
||||
}
|
||||
|
||||
private fun printList() {
|
||||
val echo = Echo()
|
||||
echo.execute(Lang.get("DEV_MESSAGE_CONSOLE_AVAILABLE_COMMANDS"))
|
||||
CommandDict.dict.keys.forEach { s -> echo.execute("] " + s) }
|
||||
}
|
||||
|
||||
}
|
||||
47
src/com/torvald/terrarum/console/CommandDict.kt
Normal file
47
src/com/torvald/terrarum/console/CommandDict.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
*/
|
||||
object CommandDict {
|
||||
|
||||
internal var dict: HashMap<String, ConsoleCommand> = hashMapOf(
|
||||
Pair("echo", Echo()),
|
||||
Pair("setav", SetAV()),
|
||||
Pair("qqq", QuitApp()),
|
||||
Pair("codex", CodexEdictis()),
|
||||
Pair("export", ExportMap()),
|
||||
Pair("gc", ForceGC()),
|
||||
Pair("getav", GetAV()),
|
||||
Pair("getlocale", GetLocale()),
|
||||
Pair("togglenoclip", ToggleNoClip()),
|
||||
Pair("nc", ToggleNoClip()),
|
||||
Pair("setlocale", SetLocale()),
|
||||
Pair("zoom", Zoom()),
|
||||
Pair("teleport", TeleportPlayer()),
|
||||
Pair("tp", TeleportPlayer()),
|
||||
Pair("cat", CatStdout()),
|
||||
Pair("exportav", ExportAV()),
|
||||
Pair("setgl", SetGlobalLightLevel()),
|
||||
Pair("getfaction", GetFactioning()),
|
||||
Pair("auth", Terrarum.game.auth),
|
||||
Pair("spawnball", SpawnPhysTestBall()),
|
||||
Pair("batch", Batch()),
|
||||
Pair("settime", SetTime()),
|
||||
Pair("gettime", GetTime()),
|
||||
Pair("settimedelta", SetTimeDelta()),
|
||||
Pair("help", Help()),
|
||||
|
||||
// Test codes
|
||||
Pair("bulletintest", SetBulletin()),
|
||||
Pair("gsontest", GsonTest())
|
||||
)
|
||||
|
||||
fun getCommand(commandName: String): ConsoleCommand {
|
||||
return dict[commandName]!!
|
||||
}
|
||||
}
|
||||
116
src/com/torvald/terrarum/console/CommandInterpreter.kt
Normal file
116
src/com/torvald/terrarum/console/CommandInterpreter.kt
Normal file
@@ -0,0 +1,116 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Formatter
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
*/
|
||||
object CommandInterpreter {
|
||||
|
||||
private val commandsNoAuth = arrayOf("auth", "qqq", "zoom", "setlocale", "getlocale", "help")
|
||||
|
||||
fun execute(command: String) {
|
||||
val cmd = parse(command)
|
||||
|
||||
for (single_command in cmd) {
|
||||
var commandObj: ConsoleCommand? = null
|
||||
try {
|
||||
if (commandsNoAuth.contains(single_command!!.name.toLowerCase())) {
|
||||
commandObj = CommandDict.getCommand(single_command.name.toLowerCase())
|
||||
}
|
||||
else {
|
||||
if (Terrarum.game.auth.b()) {
|
||||
commandObj = CommandDict.getCommand(
|
||||
single_command.name.toLowerCase())
|
||||
}
|
||||
else {
|
||||
// System.out.println("ee1");
|
||||
throw NullPointerException() // if not authorised, say "Unknown command"
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (commandObj != null) {
|
||||
commandObj.execute(single_command!!.toStringArray())
|
||||
}
|
||||
else {
|
||||
echoUnknownCmd(single_command!!.name)
|
||||
// System.out.println("ee3");
|
||||
}
|
||||
}
|
||||
catch (e: Exception) {
|
||||
println("[CommandInterpreter] :")
|
||||
e.printStackTrace()
|
||||
Echo().execute(Lang.get("ERROR_GENERIC_TEXT"))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parse(input: String): Array<CommandInput?> {
|
||||
val patternCommands = Pattern.compile("[^;]+")
|
||||
val patternTokensInCommand = Pattern.compile("[\"'][^;]+[\"']|[^ ]+")
|
||||
|
||||
val commands = ArrayList<String>()
|
||||
|
||||
// split multiple commands
|
||||
var m = patternCommands.matcher(input)
|
||||
while (m.find()) commands.add(m.group())
|
||||
|
||||
// split command tokens from a command
|
||||
val parsedCommands = arrayOfNulls<CommandInput>(commands.size)
|
||||
|
||||
|
||||
for (i in parsedCommands.indices) {
|
||||
val tokens = ArrayList<String>()
|
||||
|
||||
m = patternTokensInCommand.matcher(commands[i])
|
||||
while (m.find()) {
|
||||
val regexGroup = m.group().replace("[\"\']".toRegex(), "")
|
||||
tokens.add(regexGroup)
|
||||
}
|
||||
|
||||
// create new command
|
||||
parsedCommands[i] = CommandInput(tokens.toArray())
|
||||
|
||||
}
|
||||
|
||||
return parsedCommands
|
||||
}
|
||||
|
||||
internal fun echoUnknownCmd(cmdname: String) {
|
||||
val sb = StringBuilder()
|
||||
val formatter = Formatter(sb)
|
||||
|
||||
Echo().execute(
|
||||
formatter.format(Lang.get("DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN"), cmdname).toString())
|
||||
}
|
||||
|
||||
private class CommandInput(o: Array<Any>) {
|
||||
private val tokens: Array<String>
|
||||
|
||||
init {
|
||||
tokens = Array<String>(o.size, { i -> o[i] as String })
|
||||
}
|
||||
|
||||
fun toStringArray(): Array<String> {
|
||||
return tokens
|
||||
}
|
||||
|
||||
val name: String
|
||||
get() = tokens[0]
|
||||
|
||||
val argsCount: Int
|
||||
get() = tokens.size
|
||||
}
|
||||
}
|
||||
13
src/com/torvald/terrarum/console/ConsoleCommand.kt
Normal file
13
src/com/torvald/terrarum/console/ConsoleCommand.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
*/
|
||||
interface ConsoleCommand {
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun execute(args: Array<String>)
|
||||
|
||||
fun printUsage()
|
||||
|
||||
}
|
||||
26
src/com/torvald/terrarum/console/Echo.kt
Normal file
26
src/com/torvald/terrarum/console/Echo.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.torvald.terrarum.ui.ConsoleWindow
|
||||
|
||||
import java.util.Arrays
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-16.
|
||||
*/
|
||||
internal class Echo : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val argsWoHeader = Array<String>(args.size - 1, {it -> args[it + 1]})
|
||||
|
||||
argsWoHeader.forEach(
|
||||
{ (Terrarum.game.consoleHandler.UI as ConsoleWindow).sendMessage(it) })
|
||||
}
|
||||
|
||||
fun execute(single_line: String) {
|
||||
(Terrarum.game.consoleHandler.UI as ConsoleWindow).sendMessage(single_line)
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
}
|
||||
}
|
||||
38
src/com/torvald/terrarum/console/ExportAV.kt
Normal file
38
src/com/torvald/terrarum/console/ExportAV.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.JsonWriter
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-10.
|
||||
*/
|
||||
class ExportAV : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
JsonWriter.writeToFile(
|
||||
Terrarum.game.player.actorValue,
|
||||
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
|
||||
|
||||
Echo().execute("ExportAV: exported to " + args[1] + ".json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo().execute("ExportAV: IOException raised.")
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Export ActorValue as JSON format.")
|
||||
echo.execute("Usage: exportav (id) filename-without-extension")
|
||||
echo.execute("blank ID for player")
|
||||
}
|
||||
}
|
||||
296
src/com/torvald/terrarum/console/ExportMap.kt
Normal file
296
src/com/torvald/terrarum/console/ExportMap.kt
Normal file
@@ -0,0 +1,296 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.colourutil.Col4096
|
||||
import com.torvald.RasterWriter
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
import javax.imageio.ImageIO
|
||||
import java.awt.*
|
||||
import java.awt.color.ColorSpace
|
||||
import java.awt.image.*
|
||||
import java.io.*
|
||||
import java.util.Hashtable
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-17.
|
||||
*/
|
||||
class ExportMap : ConsoleCommand {
|
||||
|
||||
//private var mapData: ByteArray? = null
|
||||
// private var mapDataPointer = 0
|
||||
|
||||
private val colorTable = Hashtable<Byte, Col4096>()
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
buildColorTable()
|
||||
|
||||
var mapData = ByteArray(Terrarum.game.map.width * Terrarum.game.map.height * 3)
|
||||
var mapDataPointer = 0
|
||||
|
||||
for (tile in Terrarum.game.map.layerTerrain) {
|
||||
val colArray = (colorTable as java.util.Map<Byte, Col4096>)
|
||||
.getOrDefault(tile, Col4096(0xFFF)).toByteArray()
|
||||
|
||||
for (i in 0..2) {
|
||||
mapData[mapDataPointer + i] = colArray[i]
|
||||
}
|
||||
|
||||
mapDataPointer += 3
|
||||
}
|
||||
|
||||
val dir = Terrarum.defaultDir + "/Exports/"
|
||||
val dirAsFile = File(dir)
|
||||
if (!dirAsFile.exists()) {
|
||||
dirAsFile.mkdir()
|
||||
}
|
||||
|
||||
try {
|
||||
RasterWriter.writePNG_RGB(
|
||||
Terrarum.game.map.width, Terrarum.game.map.height, mapData, dir + args[1] + ".png")
|
||||
Echo().execute("ExportMap: exported to " + args[1] + ".png")
|
||||
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo().execute("ExportMap: IOException raised.")
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
// mapData = null
|
||||
// mapDataPointer = 0
|
||||
|
||||
// Free up some memory
|
||||
System.gc()
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Usage: export <name>")
|
||||
echo.execute("Exports current map into visible image.")
|
||||
echo.execute("The image can be found at %adddata%/terrarum/Exports")
|
||||
}
|
||||
|
||||
private fun buildColorTable() {
|
||||
colorTable.put(AIR, Col4096(0xCEF))
|
||||
colorTable.put(STONE, Col4096(0x887))
|
||||
colorTable.put(DIRT, Col4096(0x763))
|
||||
colorTable.put(GRASS, Col4096(0x251))
|
||||
|
||||
colorTable.put(COPPER, Col4096(0x6A8))
|
||||
colorTable.put(IRON, Col4096(0xC75))
|
||||
colorTable.put(GOLD, Col4096(0xCB6))
|
||||
colorTable.put(ILMENITE, Col4096(0x8AB))
|
||||
colorTable.put(AURICHALCUM, Col4096(0xD92))
|
||||
colorTable.put(SILVER, Col4096(0xDDD))
|
||||
|
||||
colorTable.put(DIAMOND, Col4096(0x9CE))
|
||||
colorTable.put(RUBY, Col4096(0xB10))
|
||||
colorTable.put(EMERALD, Col4096(0x0B1))
|
||||
colorTable.put(SAPPHIRE, Col4096(0x01B))
|
||||
colorTable.put(TOPAZ, Col4096(0xC70))
|
||||
colorTable.put(AMETHYST, Col4096(0x70C))
|
||||
|
||||
colorTable.put(WATER, Col4096(0x038))
|
||||
colorTable.put(LAVA, Col4096(0xF50))
|
||||
|
||||
colorTable.put(SAND, Col4096(0xDCA))
|
||||
colorTable.put(GRAVEL, Col4096(0x664))
|
||||
|
||||
colorTable.put(ICE_NATURAL, Col4096(0x9AB))
|
||||
colorTable.put(ICE_MAGICAL, Col4096(0x7AC))
|
||||
colorTable.put(ICE_FRAGILE, Col4096(0x6AF))
|
||||
colorTable.put(SNOW, Col4096(0xCDE))
|
||||
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val AIR: Byte = 0
|
||||
|
||||
private val STONE: Byte = 1
|
||||
private val DIRT: Byte = 2
|
||||
private val GRASS: Byte = 3
|
||||
|
||||
private val SAND: Byte = 13
|
||||
private val GRAVEL: Byte = 14
|
||||
|
||||
private val COPPER: Byte = 15
|
||||
private val IRON: Byte = 16
|
||||
private val GOLD: Byte = 17
|
||||
private val SILVER: Byte = 18
|
||||
private val ILMENITE: Byte = 19
|
||||
private val AURICHALCUM: Byte = 20
|
||||
|
||||
private val DIAMOND: Byte = 25
|
||||
private val RUBY: Byte = 21
|
||||
private val EMERALD: Byte = 22
|
||||
private val SAPPHIRE: Byte = 23
|
||||
private val TOPAZ: Byte = 24
|
||||
private val AMETHYST: Byte = 26
|
||||
|
||||
private val SNOW: Byte = 27
|
||||
private val ICE_FRAGILE: Byte = 28
|
||||
private val ICE_NATURAL: Byte = 29
|
||||
private val ICE_MAGICAL: Byte = 30
|
||||
|
||||
private val WATER = 239.toByte()
|
||||
private val LAVA = 255.toByte()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
package com.torvald.terrarum.console;
|
||||
|
||||
import com.torvald.colourutil.Col4096;
|
||||
import com.torvald.RasterWriter;
|
||||
import com.torvald.terrarum.terrarum;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-17.
|
||||
*/
|
||||
public class ExportMap implements console {
|
||||
|
||||
private byte[] mapData;
|
||||
private int mapDataPointer = 0;
|
||||
|
||||
private static final byte AIR = 0;
|
||||
|
||||
private static final byte STONE = 1;
|
||||
private static final byte DIRT = 2;
|
||||
private static final byte GRASS = 3;
|
||||
|
||||
private static final byte SAND = 13;
|
||||
private static final byte GRAVEL = 14;
|
||||
|
||||
private static final byte COPPER = 15;
|
||||
private static final byte IRON = 16;
|
||||
private static final byte GOLD = 17;
|
||||
private static final byte SILVER = 18;
|
||||
private static final byte ILMENITE = 19;
|
||||
private static final byte AURICHALCUM = 20;
|
||||
|
||||
private static final byte DIAMOND = 25;
|
||||
private static final byte RUBY = 21;
|
||||
private static final byte EMERALD = 22;
|
||||
private static final byte SAPPHIRE = 23;
|
||||
private static final byte TOPAZ = 24;
|
||||
private static final byte AMETHYST = 26;
|
||||
|
||||
private static final byte SNOW = 27;
|
||||
private static final byte ICE_FRAGILE = 28;
|
||||
private static final byte ICE_NATURAL = 29;
|
||||
private static final byte ICE_MAGICAL = 30;
|
||||
|
||||
private static final byte WATER = (byte) 239;
|
||||
private static final byte LAVA = (byte) 255;
|
||||
|
||||
private Hashtable<Byte, Col4096> colorTable = new Hashtable<>();
|
||||
|
||||
@Override
|
||||
public void execute(String[] args) {
|
||||
if (args.length == 2) {
|
||||
buildColorTable();
|
||||
|
||||
mapData = new byte[terrarum.game.map.getWidth() * terrarum.game.map.getHeight() * 3];
|
||||
|
||||
for (byte tile : terrarum.game.map.getLayerTerrain()) {
|
||||
byte[] colArray = colorTable.getOrDefault(tile, new Col4096(0xFFF))
|
||||
.toByteArray();
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
mapData[mapDataPointer + i] = colArray[i];
|
||||
}
|
||||
|
||||
mapDataPointer += 3;
|
||||
}
|
||||
|
||||
String dir = terrarum.defaultDir + "/Exports/";
|
||||
File dirAsFile = new File(dir);
|
||||
if (!dirAsFile.exists()) {
|
||||
dirAsFile.mkdir();
|
||||
}
|
||||
|
||||
try {
|
||||
RasterWriter.INSTANCE.writePNG_RGB(
|
||||
terrarum.game.map.getWidth()
|
||||
, terrarum.game.map.getHeight()
|
||||
, mapData
|
||||
, dir + args[1] + ".png"
|
||||
);
|
||||
new Echo().execute("ExportMap: exported to " + args[1] + ".png");
|
||||
|
||||
} catch (IOException e) {
|
||||
new Echo().execute("ExportMap: IOException raised.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mapData = null;
|
||||
mapDataPointer = 0;
|
||||
|
||||
// Free up some memory
|
||||
System.gc();
|
||||
}
|
||||
else{
|
||||
printUsage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printUsage() {
|
||||
Echo echo = new Echo();
|
||||
echo.execute("Usage: export <name>");
|
||||
echo.execute("Exports current map into visible image.");
|
||||
echo.execute("The image can be found at %adddata%/terrarum/Exports");
|
||||
}
|
||||
|
||||
private void buildColorTable() {
|
||||
colorTable.put(AIR, new Col4096(0xCEF));
|
||||
colorTable.put(STONE, new Col4096(0x887));
|
||||
colorTable.put(DIRT, new Col4096(0x763));
|
||||
colorTable.put(GRASS, new Col4096(0x251));
|
||||
|
||||
colorTable.put(COPPER, new Col4096(0x6A8));
|
||||
colorTable.put(IRON, new Col4096(0xC75));
|
||||
colorTable.put(GOLD, new Col4096(0xCB6));
|
||||
colorTable.put(ILMENITE, new Col4096(0x8AB));
|
||||
colorTable.put(AURICHALCUM, new Col4096(0xD92));
|
||||
colorTable.put(SILVER, new Col4096(0xDDD));
|
||||
|
||||
colorTable.put(DIAMOND, new Col4096(0x9CE));
|
||||
colorTable.put(RUBY, new Col4096(0xB10));
|
||||
colorTable.put(EMERALD, new Col4096(0x0B1));
|
||||
colorTable.put(SAPPHIRE, new Col4096(0x01B));
|
||||
colorTable.put(TOPAZ, new Col4096(0xC70));
|
||||
colorTable.put(AMETHYST, new Col4096(0x70C));
|
||||
|
||||
colorTable.put(WATER, new Col4096(0x038));
|
||||
colorTable.put(LAVA, new Col4096(0xF50));
|
||||
|
||||
colorTable.put(SAND, new Col4096(0xDCA));
|
||||
colorTable.put(GRAVEL, new Col4096(0x664));
|
||||
|
||||
colorTable.put(ICE_NATURAL, new Col4096(0x9AB));
|
||||
colorTable.put(ICE_MAGICAL, new Col4096(0x7AC));
|
||||
colorTable.put(ICE_FRAGILE, new Col4096(0x6AF));
|
||||
colorTable.put(SNOW, new Col4096(0xCDE));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
15
src/com/torvald/terrarum/console/ForceGC.kt
Normal file
15
src/com/torvald/terrarum/console/ForceGC.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-18.
|
||||
*/
|
||||
class ForceGC : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
System.gc()
|
||||
Echo().execute("Invoked System.gc")
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Invoke garbage collection of JVM.")
|
||||
}
|
||||
}
|
||||
57
src/com/torvald/terrarum/console/GetAV.kt
Normal file
57
src/com/torvald/terrarum/console/GetAV.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.gameactors.ActorValue
|
||||
import com.torvald.terrarum.Game
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-19.
|
||||
*/
|
||||
class GetAV : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val echo = Echo()
|
||||
|
||||
try {
|
||||
if (args.size == 1) {
|
||||
// print all actorvalue of player
|
||||
val av = Terrarum.game.player.actorValue
|
||||
val keyset = av.keySet
|
||||
|
||||
keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") }
|
||||
|
||||
}
|
||||
else if (args.size != 3 && args.size != 2) {
|
||||
printUsage()
|
||||
}
|
||||
else if (args.size == 2) {
|
||||
echo.execute("player." + args[1] + " = "
|
||||
+ Terrarum.game.player.actorValue[args[1]]
|
||||
+ " ("
|
||||
+ Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName
|
||||
+ ")")
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
|
||||
}
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
if (args.size == 2) {
|
||||
echo.execute(args[1] + ": actor value does not exist.")
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
echo.execute(args[2] + ": actor value does not exist.")
|
||||
}
|
||||
else {
|
||||
throw NullPointerException()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Get desired actor value of specific target.")
|
||||
echo.execute("Usage: getav (id) <av>")
|
||||
echo.execute("blank ID for player")
|
||||
}
|
||||
}
|
||||
51
src/com/torvald/terrarum/console/GetFactioning.kt
Normal file
51
src/com/torvald/terrarum/console/GetFactioning.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.gameactors.faction.Faction
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
import java.util.HashSet
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-17.
|
||||
*/
|
||||
class GetFactioning : ConsoleCommand {
|
||||
|
||||
private val PRINT_INDENTATION = " --> "
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
val echo = Echo()
|
||||
|
||||
if (args.size == 1) {
|
||||
// get all factioning data of player
|
||||
val factionSet = Terrarum.game.player.faction
|
||||
|
||||
if (factionSet == null) {
|
||||
echo.execute("The actor has null faction set.")
|
||||
return
|
||||
}
|
||||
|
||||
val count = factionSet.size
|
||||
echo.execute(count.toString() + Lang.pluralise(" faction", count) + " assigned.")
|
||||
|
||||
for (faction in factionSet) {
|
||||
echo.execute("faction \"" + faction.factionName + "\"")
|
||||
echo.execute(" Amicable")
|
||||
faction.factionAmicable.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
|
||||
|
||||
echo.execute(" Explicit neutral")
|
||||
faction.factionNeutral.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
|
||||
|
||||
echo.execute(" Hostile")
|
||||
faction.factionHostile.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
|
||||
|
||||
echo.execute(" Fearful")
|
||||
faction.factionFearful.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
}
|
||||
}
|
||||
24
src/com/torvald/terrarum/console/GetLocale.kt
Normal file
24
src/com/torvald/terrarum/console/GetLocale.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-22.
|
||||
*/
|
||||
class GetLocale : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
Echo().execute(
|
||||
"Locale: "
|
||||
+ Lang.get("LANGUAGE_THIS")
|
||||
+ " ("
|
||||
+ Lang.get("LANGUAGE_EN")
|
||||
+ ")")
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Usage: getlocale")
|
||||
echo.execute("Get name of locale currently using.")
|
||||
}
|
||||
}
|
||||
21
src/com/torvald/terrarum/console/GetTime.kt
Normal file
21
src/com/torvald/terrarum/console/GetTime.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-20.
|
||||
*/
|
||||
class GetTime : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val echo = Echo()
|
||||
val worldTime = Terrarum.game.map.worldTime
|
||||
echo.execute("Year ${worldTime.years}, Month ${worldTime.months}, " +
|
||||
"Day ${worldTime.days} (${worldTime.getDayNameShort()}), " +
|
||||
"${worldTime.getFormattedTime()}"
|
||||
)
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Print current world time in convenient form")
|
||||
}
|
||||
}
|
||||
47
src/com/torvald/terrarum/console/GsonTest.kt
Normal file
47
src/com/torvald/terrarum/console/GsonTest.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonElement
|
||||
|
||||
import java.io.BufferedWriter
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-10.
|
||||
*/
|
||||
class GsonTest : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val avelem = Gson().toJsonTree(Terrarum.game.player)
|
||||
|
||||
val jsonString = avelem.toString()
|
||||
|
||||
val bufferedWriter: BufferedWriter
|
||||
val writer: FileWriter
|
||||
try {
|
||||
writer = FileWriter(Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
|
||||
bufferedWriter = BufferedWriter(writer)
|
||||
|
||||
bufferedWriter.write(jsonString)
|
||||
bufferedWriter.close()
|
||||
|
||||
Echo().execute("GsonTest: exported to " + args[1] + ".json")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo().execute("GsonTest: IOException raised.")
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Usage: gsontest filename-without-extension")
|
||||
}
|
||||
}
|
||||
25
src/com/torvald/terrarum/console/Help.kt
Normal file
25
src/com/torvald/terrarum/console/Help.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-22.
|
||||
*/
|
||||
class Help : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val echo = Echo()
|
||||
if (args.size == 1) {
|
||||
for (i in 1..6) echo.execute(Lang["HELP_OTF_MAIN_TEXT_$i"])
|
||||
}
|
||||
else if (args[1].toLowerCase() == "slow") {
|
||||
for (i in 1..4) echo.execute(Lang["HELP_OTF_SLOW_TEXT_$i"])
|
||||
}
|
||||
else {
|
||||
for (i in 1..6) echo.execute(Lang["HELP_OTF_MAIN_TEXT_$i"])
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Prints some utility functions assigned to function row of the keyboard.")
|
||||
}
|
||||
}
|
||||
15
src/com/torvald/terrarum/console/QuitApp.kt
Normal file
15
src/com/torvald/terrarum/console/QuitApp.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
*/
|
||||
class QuitApp : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
}
|
||||
}
|
||||
61
src/com/torvald/terrarum/console/SetAV.kt
Normal file
61
src/com/torvald/terrarum/console/SetAV.kt
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Game
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-15.
|
||||
*/
|
||||
internal class SetAV : ConsoleCommand {
|
||||
|
||||
override fun printUsage() {
|
||||
val echo = Echo()
|
||||
echo.execute("Set actor value of specific target to desired value.")
|
||||
echo.execute("Usage: setav (id) <av> <val>")
|
||||
echo.execute("blank ID for player")
|
||||
echo.execute("Contaminated (float -> string) actor value will crash the game,")
|
||||
echo.execute(" so make it sure before you issue the command.")
|
||||
echo.execute("Use '__true' and '__false' for boolean value.")
|
||||
}
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
val echo = Echo()
|
||||
|
||||
// setav <id or "player"> <av> <val>
|
||||
if (args.size != 4 && args.size != 3) {
|
||||
printUsage()
|
||||
}
|
||||
else if (args.size == 3) {
|
||||
val `val`: Any
|
||||
|
||||
try {
|
||||
`val` = Integer(args[2]) // try for integer
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
|
||||
try {
|
||||
`val` = args[2].toFloat() // try for float
|
||||
}
|
||||
catch (ee: NumberFormatException) {
|
||||
if (args[2].equals("__true", ignoreCase = true)) {
|
||||
`val` = true
|
||||
}
|
||||
else if (args[2].equals("__false", ignoreCase = true)) {
|
||||
`val` = false
|
||||
}
|
||||
else {
|
||||
`val` = args[2] // string if not number
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Terrarum.game.player.actorValue[args[1]] = `val`
|
||||
echo.execute("Set " + args[1] + " to " + `val`)
|
||||
}
|
||||
else if (args.size == 4) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
src/com/torvald/terrarum/console/SetBulletin.kt
Normal file
31
src/com/torvald/terrarum/console/SetBulletin.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.torvald.terrarum.ui.Notification
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-23.
|
||||
*/
|
||||
class SetBulletin : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val testMsg = arrayOf(
|
||||
Lang["ERROR_SAVE_CORRUPTED"],
|
||||
Lang["MENU_LABEL_CONTINUE_QUESTION"]
|
||||
)
|
||||
send(testMsg)
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually send notifinator
|
||||
* @param message real message
|
||||
*/
|
||||
fun send(message: Array<String>) {
|
||||
Terrarum.game.sendNotification(message)
|
||||
println("sent notifinator")
|
||||
}
|
||||
}
|
||||
52
src/com/torvald/terrarum/console/SetGlobalLightLevel.kt
Normal file
52
src/com/torvald/terrarum/console/SetGlobalLightLevel.kt
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-17.
|
||||
*/
|
||||
class SetGlobalLightLevel : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 4) {
|
||||
try {
|
||||
val r = args[1].toInt()
|
||||
val g = args[2].toInt()
|
||||
val b = args[3].toInt()
|
||||
val GL = LightmapRenderer.constructRGBFromInt(r, g, b)
|
||||
|
||||
Terrarum.game.map.globalLight = GL
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
Echo().execute("Wrong number input.")
|
||||
}
|
||||
catch (e1: IllegalArgumentException) {
|
||||
Echo().execute("Range: 0-" + LightmapRenderer.CHANNEL_MAX + " per channel")
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.size == 2) {
|
||||
try {
|
||||
val GL = args[1].toInt()
|
||||
|
||||
if (GL.toInt() < 0 || GL.toInt() >= LightmapRenderer.COLOUR_DOMAIN_SIZE) {
|
||||
Echo().execute("Range: 0-" + (LightmapRenderer.COLOUR_DOMAIN_SIZE - 1))
|
||||
}
|
||||
else {
|
||||
Terrarum.game.map.globalLight = GL
|
||||
}
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
Echo().execute("Wrong number input.")
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Usage: setgl [raw_value|r g b]")
|
||||
}
|
||||
}
|
||||
43
src/com/torvald/terrarum/console/SetLocale.kt
Normal file
43
src/com/torvald/terrarum/console/SetLocale.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.imagefont.GameFontBase
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
import org.newdawn.slick.SlickException
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-25.
|
||||
*/
|
||||
class SetLocale : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val prevLocale = Terrarum.gameLocale
|
||||
Terrarum.gameLocale = args[1]
|
||||
try {
|
||||
Echo().execute("Set locale to '" + Terrarum.gameLocale + "'.")
|
||||
}
|
||||
catch (e: IOException) {
|
||||
Echo().execute("could not read lang file.")
|
||||
Terrarum.gameLocale = prevLocale
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.size == 1) {
|
||||
val echo = Echo()
|
||||
echo.execute("Locales:")
|
||||
|
||||
val record = Lang.getRecord("LANGUAGE_ID")
|
||||
record.forEach { field -> echo.execute("] " + field) }
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Usage: setlocale [locale]")
|
||||
}
|
||||
}
|
||||
42
src/com/torvald/terrarum/console/SetTime.kt
Normal file
42
src/com/torvald/terrarum/console/SetTime.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.gamemap.WorldTime
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-20.
|
||||
*/
|
||||
class SetTime : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val lowercaseTime = args[1].toLowerCase()
|
||||
val timeToSet =
|
||||
if (args[1].length >= 4) {
|
||||
lowercaseTime.substringBefore('h').toInt() * WorldTime.HOUR_SEC +
|
||||
lowercaseTime.substringAfter('h').toInt() * WorldTime.MINUTE_SEC
|
||||
}
|
||||
else if (args[1].endsWith("h", true)) {
|
||||
lowercaseTime.substring(0, args[1].length - 1).toInt() * WorldTime.HOUR_SEC
|
||||
}
|
||||
else {
|
||||
lowercaseTime.toInt()
|
||||
}
|
||||
|
||||
Terrarum.game.map.worldTime.setTime(timeToSet)
|
||||
|
||||
Echo().execute("Set time to ${Terrarum.game.map.worldTime.elapsedSeconds()} " +
|
||||
"(${Terrarum.game.map.worldTime.hours}h${formatMin(Terrarum.game.map.worldTime.minutes)})")
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatMin(min: Int): String {
|
||||
return if (min < 10) "0${min.toString()}" else min.toString()
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("usage: settime <39201-in sec or 13h32-in hour>")
|
||||
}
|
||||
}
|
||||
25
src/com/torvald/terrarum/console/SetTimeDelta.kt
Normal file
25
src/com/torvald/terrarum/console/SetTimeDelta.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-20.
|
||||
*/
|
||||
class SetTimeDelta : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
Terrarum.game.map.worldTime.setTimeDelta(args[1].toInt())
|
||||
if (Terrarum.game.map.worldTime.timeDelta == 0)
|
||||
Echo().execute("時間よ止まれ!ザ・ワルド!!")
|
||||
else
|
||||
Echo().execute("Set time delta to ${Terrarum.game.map.worldTime.timeDelta}")
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("usage: settimedelta <int>")
|
||||
}
|
||||
}
|
||||
38
src/com/torvald/terrarum/console/SpawnPhysTestBall.kt
Normal file
38
src/com/torvald/terrarum/console/SpawnPhysTestBall.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.gameactors.Actor
|
||||
import com.torvald.terrarum.gameactors.ActorWithBody
|
||||
import com.torvald.terrarum.gameactors.PhysTestBall
|
||||
import com.torvald.terrarum.mapdrawer.MapCamera
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-05.
|
||||
*/
|
||||
class SpawnPhysTestBall : ConsoleCommand {
|
||||
@Throws(Exception::class)
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val mouseX = Terrarum.appgc.input.mouseX
|
||||
val mouseY = Terrarum.appgc.input.mouseY
|
||||
|
||||
val elasticity = args[1].toFloat()
|
||||
|
||||
val ball = PhysTestBall()
|
||||
ball.setPosition(
|
||||
(mouseX + MapCamera.cameraX).toFloat(),
|
||||
(mouseY + MapCamera.cameraY).toFloat()
|
||||
)
|
||||
ball.elasticity = elasticity
|
||||
|
||||
Terrarum.game.addActor(ball)
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("usage: spawnball [elasticity]")
|
||||
}
|
||||
}
|
||||
36
src/com/torvald/terrarum/console/TeleportPlayer.kt
Normal file
36
src/com/torvald/terrarum/console/TeleportPlayer.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Game
|
||||
import com.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-24.
|
||||
*/
|
||||
class TeleportPlayer : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size != 3) {
|
||||
printUsage()
|
||||
}
|
||||
else {
|
||||
|
||||
val x: Int
|
||||
val y: Int
|
||||
try {
|
||||
x = args[1].toInt() * MapDrawer.TILE_SIZE + MapDrawer.TILE_SIZE / 2
|
||||
y = args[2].toInt() * MapDrawer.TILE_SIZE + MapDrawer.TILE_SIZE / 2
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
Echo().execute("Wrong number input.")
|
||||
return
|
||||
}
|
||||
|
||||
Terrarum.game.player.setPosition(x.toFloat(), y.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Usage: teleport [x-tile] [y-tile]")
|
||||
}
|
||||
}
|
||||
20
src/com/torvald/terrarum/console/ToggleNoClip.kt
Normal file
20
src/com/torvald/terrarum/console/ToggleNoClip.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Game
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-19.
|
||||
*/
|
||||
class ToggleNoClip : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val status = Terrarum.game.player.isNoClip()
|
||||
|
||||
Terrarum.game.player.setNoClip(!status)
|
||||
Echo().execute("Set no-clip status to " + (!status).toString())
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("toggle no-clip status of player")
|
||||
}
|
||||
}
|
||||
42
src/com/torvald/terrarum/console/Zoom.kt
Normal file
42
src/com/torvald/terrarum/console/Zoom.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
package com.torvald.terrarum.console
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-25.
|
||||
*/
|
||||
class Zoom : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
|
||||
var zoom: Float
|
||||
try {
|
||||
zoom = args[1].toFloat()
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
Echo().execute("Wrong number input.")
|
||||
return
|
||||
}
|
||||
|
||||
if (zoom < Terrarum.game.ZOOM_MIN) {
|
||||
zoom = Terrarum.game.ZOOM_MIN
|
||||
}
|
||||
else if (zoom > Terrarum.game.ZOOM_MAX) {
|
||||
zoom = Terrarum.game.ZOOM_MAX
|
||||
}
|
||||
|
||||
Terrarum.game.screenZoom = zoom
|
||||
|
||||
System.gc()
|
||||
|
||||
Echo().execute("Set screen zoom to " + zoom.toString())
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo().execute("Usage: zoom [zoom]")
|
||||
}
|
||||
}
|
||||
81
src/com/torvald/terrarum/tilestats/TileStat.kt
Normal file
81
src/com/torvald/terrarum/tilestats/TileStat.kt
Normal file
@@ -0,0 +1,81 @@
|
||||
package com.torvald.terrarum.tilestats
|
||||
|
||||
import com.torvald.terrarum.gameactors.Player
|
||||
import com.torvald.terrarum.gamemap.GameMap
|
||||
import com.torvald.terrarum.gamemap.MapLayer
|
||||
import com.torvald.terrarum.mapdrawer.MapCamera
|
||||
import com.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.jme3.math.FastMath
|
||||
|
||||
import java.util.Arrays
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-01.
|
||||
*/
|
||||
object TileStat {
|
||||
|
||||
private val tilestat = ShortArray(GameMap.TILES_SUPPORTED)
|
||||
|
||||
private val TSIZE = MapDrawer.TILE_SIZE
|
||||
|
||||
/**
|
||||
* Update tile stats from tiles on screen
|
||||
*/
|
||||
fun update() {
|
||||
Arrays.fill(tilestat, 0.toShort())
|
||||
|
||||
// Get stats on no-zoomed screen area. In other words, will behave as if screen zoom were 1.0
|
||||
// no matter how the screen is zoomed.
|
||||
val map = Terrarum.game.map
|
||||
val player = Terrarum.game.player
|
||||
|
||||
val renderWidth = FastMath.ceil(Terrarum.WIDTH.toFloat())
|
||||
val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat())
|
||||
|
||||
val noZoomCameraX = Math.round(FastMath.clamp(
|
||||
player.hitbox!!.centeredX - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
|
||||
val noZoomCameraY = Math.round(FastMath.clamp(
|
||||
player.hitbox!!.centeredY - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
|
||||
|
||||
val for_x_start = MapCamera.div16(noZoomCameraX)
|
||||
val for_y_start = MapCamera.div16(noZoomCameraY)
|
||||
val for_y_end = MapCamera.clampHTile(for_y_start + MapCamera.div16(renderHeight) + 2)
|
||||
val for_x_end = MapCamera.clampWTile(for_x_start + MapCamera.div16(renderWidth) + 2)
|
||||
|
||||
for (y in for_y_start..for_y_end - 1) {
|
||||
for (x in for_x_start..for_x_end - 1) {
|
||||
val tileWall = map.getTileFromWall(x, y)
|
||||
val tileTerrain = map.getTileFromTerrain(x, y)
|
||||
++tilestat[tileWall]
|
||||
++tilestat[tileTerrain]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCount(vararg tile: Byte): Int {
|
||||
var sum = 0
|
||||
for (i in tile.indices) {
|
||||
val newArgs = java.lang.Byte.toUnsignedInt(tile[i])
|
||||
sum += java.lang.Short.toUnsignedInt(tilestat[newArgs])
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
||||
|
||||
fun getCount(vararg tile: Int): Int {
|
||||
var sum = 0
|
||||
for (i in tile.indices) {
|
||||
sum += java.lang.Short.toUnsignedInt(tilestat[tile[i]])
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @return copy of the stat data
|
||||
*/
|
||||
val statCopy: ShortArray
|
||||
get() = Arrays.copyOf(tilestat, MapLayer.RANGE)
|
||||
|
||||
}
|
||||
200
src/com/torvald/terrarum/ui/BasicDebugInfoWindow.kt
Normal file
200
src/com/torvald/terrarum/ui/BasicDebugInfoWindow.kt
Normal file
@@ -0,0 +1,200 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import com.torvald.terrarum.gamemap.PairedMapLayer
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||
import com.torvald.terrarum.mapdrawer.MapCamera
|
||||
import com.torvald.terrarum.mapdrawer.MapDrawer
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-14.
|
||||
*/
|
||||
class BasicDebugInfoWindow : UICanvas {
|
||||
|
||||
override var width: Int = Terrarum.WIDTH
|
||||
override var height: Int = Terrarum.HEIGHT
|
||||
|
||||
override var openCloseTime: Int = 0
|
||||
|
||||
private var prevPlayerX = 0f
|
||||
private var prevPlayerY = 0f
|
||||
|
||||
private var xdelta = 0f
|
||||
private var ydelta = 0f
|
||||
|
||||
override fun processInput(input: Input) {
|
||||
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta_t: Int) {
|
||||
val player = Terrarum.game.player
|
||||
val hitbox = player.hitbox!!
|
||||
|
||||
xdelta = hitbox.pointedX - prevPlayerX
|
||||
ydelta = hitbox.pointedY - prevPlayerY
|
||||
|
||||
prevPlayerX = hitbox.pointedX
|
||||
prevPlayerY = hitbox.pointedY
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
val player = Terrarum.game.player
|
||||
|
||||
val sb = StringBuilder()
|
||||
val formatter = Formatter(sb)
|
||||
|
||||
val mouseTileX = ((MapCamera.cameraX + gc.getInput().mouseX / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
|
||||
val mouseTileY = ((MapCamera.cameraY + gc.getInput().mouseY / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
|
||||
|
||||
g.color = Color.white
|
||||
|
||||
val hitbox = player.hitbox
|
||||
val nextHitbox = player.nextHitbox
|
||||
|
||||
printLine(g, 1, "posX: "
|
||||
+ "${hitbox!!.pointedX.toString()}"
|
||||
+ " ("
|
||||
+ "${(hitbox.pointedX / MapDrawer.TILE_SIZE).toInt().toString()}"
|
||||
+ ")")
|
||||
printLine(g, 2, "posY: "
|
||||
+ hitbox.pointedY.toString()
|
||||
+ " ("
|
||||
+ (hitbox.pointedY / MapDrawer.TILE_SIZE).toInt().toString()
|
||||
+ ")")
|
||||
|
||||
printLine(g, 3, "veloX reported: ${player.veloX}")
|
||||
printLine(g, 4, "veloY reported: ${player.veloY}")
|
||||
|
||||
printLineColumn(g, 2, 3, "veloX measured: ${xdelta}")
|
||||
printLineColumn(g, 2, 4, "veloY measured: ${ydelta}")
|
||||
|
||||
printLine(g, 5, "grounded : ${player.grounded}")
|
||||
printLine(g, 6, "noClip : ${player.noClip}")
|
||||
|
||||
val lightVal: String
|
||||
var mtX = mouseTileX.toString()
|
||||
var mtY = mouseTileY.toString()
|
||||
try {
|
||||
val valRaw = LightmapRenderer.getValueFromMap(mouseTileX, mouseTileY)
|
||||
val rawR = LightmapRenderer.getRawR(valRaw)
|
||||
val rawG = LightmapRenderer.getRawG(valRaw)
|
||||
val rawB = LightmapRenderer.getRawB(valRaw)
|
||||
lightVal = valRaw.toInt().toString() + " (" +
|
||||
rawR.toString() + " " +
|
||||
rawG.toString() + " " +
|
||||
rawB.toString() + ")"
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
lightVal = "out of bounds"
|
||||
mtX = "---"
|
||||
mtY = "---"
|
||||
}
|
||||
|
||||
printLine(g, 7, "light at cursor : " + lightVal)
|
||||
|
||||
val tileNo: String
|
||||
try {
|
||||
val tileNumRaw = Terrarum.game.map.getTileFromTerrain(mouseTileX, mouseTileY)
|
||||
val tilenum = tileNumRaw / PairedMapLayer.RANGE
|
||||
val tiledmg = tileNumRaw % PairedMapLayer.RANGE
|
||||
tileNo = "$tilenum:$tiledmg"
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
tileNo = "-"
|
||||
}
|
||||
|
||||
printLine(g, 8, "tile at cursor : $tileNo ($mtX, $mtY)")
|
||||
|
||||
/**
|
||||
* Second column
|
||||
*/
|
||||
|
||||
printLineColumn(g, 2, 1, "${Lang["MENU_OPTIONS_VSYNC"]} : " + Terrarum.appgc.isVSyncRequested)
|
||||
printLineColumn(g, 2, 2, "Env colour temp : " + MapDrawer.getColTemp())
|
||||
printLineColumn(g, 2, 5, "Time : ${Terrarum.game.map.worldTime.elapsedSeconds()}" +
|
||||
" (${Terrarum.game.map.worldTime.getFormattedTime()})")
|
||||
printLineColumn(g, 2, 6, "Mass : ${player.mass}")
|
||||
|
||||
/**
|
||||
* On screen
|
||||
*/
|
||||
|
||||
// Memory allocation
|
||||
val memInUse = Terrarum.game.memInUse
|
||||
val totalVMMem = Terrarum.game.totalVMMem
|
||||
|
||||
g.color = Color(0xFF7F00)
|
||||
g.drawString(
|
||||
Lang["DEV_MEMORY_SHORT_CAP"]
|
||||
+ " : "
|
||||
+ formatter.format(
|
||||
Lang["DEV_MEMORY_A_OF_B"], memInUse, totalVMMem), (Terrarum.WIDTH - 200).toFloat(), line(1).toFloat())
|
||||
|
||||
// Hitbox
|
||||
val zoom = Terrarum.game.screenZoom
|
||||
g.color = Color(0x007f00)
|
||||
g.drawRect(hitbox.hitboxStart.x * zoom - MapCamera.cameraX * zoom
|
||||
, hitbox.hitboxStart.y * zoom - MapCamera.cameraY * zoom
|
||||
, hitbox.width * zoom
|
||||
, hitbox.height * zoom)
|
||||
// ...and its point
|
||||
g.fillRect(
|
||||
(hitbox.pointedX - 1) * zoom - MapCamera.cameraX * zoom
|
||||
, (hitbox.pointedY - 1) * zoom - MapCamera.cameraY * zoom
|
||||
, 3f, 3f)
|
||||
g.drawString(
|
||||
Lang["DEV_COLOUR_LEGEND_GREEN"] + " : hitbox", (Terrarum.WIDTH - 200).toFloat()
|
||||
, line(2).toFloat())
|
||||
|
||||
// Next hitbox
|
||||
g.color = Color.blue
|
||||
g.drawRect(nextHitbox!!.hitboxStart.x * zoom - MapCamera.cameraX * zoom
|
||||
, nextHitbox.hitboxStart.y * zoom - MapCamera.cameraY * zoom
|
||||
, nextHitbox.width * zoom
|
||||
, nextHitbox.height * zoom)
|
||||
// ...and its point
|
||||
g.fillRect(
|
||||
(nextHitbox.pointedX - 1) * zoom - MapCamera.cameraX * zoom
|
||||
, (nextHitbox.pointedY - 1) * zoom - MapCamera.cameraY * zoom
|
||||
, 3f, 3f)
|
||||
g.drawString(
|
||||
Lang["DEV_COLOUR_LEGEND_BLUE"] + " : nextHitbox", (Terrarum.WIDTH - 200).toFloat()
|
||||
, line(3).toFloat())
|
||||
}
|
||||
|
||||
private fun printLine(g: Graphics, l: Int, s: String) {
|
||||
g.drawString(s, 20f, line(l).toFloat())
|
||||
}
|
||||
|
||||
private fun printLineColumn(g: Graphics, col: Int, row: Int, s: String) {
|
||||
g.drawString(s, (20 + column(col)).toFloat(), line(row).toFloat())
|
||||
}
|
||||
|
||||
private fun line(i: Int): Int {
|
||||
return i * 20
|
||||
}
|
||||
|
||||
private fun column(i: Int): Int {
|
||||
return 250 * (i - 1)
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
182
src/com/torvald/terrarum/ui/ConsoleWindow.kt
Normal file
182
src/com/torvald/terrarum/ui/ConsoleWindow.kt
Normal file
@@ -0,0 +1,182 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import com.torvald.terrarum.langpack.Lang
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.torvald.terrarum.console.CommandInterpreter
|
||||
import com.torvald.terrarum.gamecontroller.Key
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
class ConsoleWindow : UICanvas, UITypable {
|
||||
|
||||
internal var UIColour = Color(0xCC000000.toInt())
|
||||
|
||||
private var commandInputPool: StringBuffer? = null
|
||||
private var prevCommand: String? = null
|
||||
|
||||
private var inputCursorPos: Int = 0
|
||||
|
||||
private val MESSAGES_MAX = 5000
|
||||
private var messages = Array(MESSAGES_MAX, {""})
|
||||
private var messageDisplayPos: Int = 0
|
||||
private var messagesCount: Int = 0
|
||||
|
||||
private val LINE_HEIGHT = 20
|
||||
private val MESSAGES_DISPLAY_COUNT = 9
|
||||
|
||||
override var width: Int = Terrarum.WIDTH
|
||||
override var height: Int = 200
|
||||
|
||||
override var openCloseTime: Int = 0
|
||||
|
||||
private var drawOffX: Float = 0f
|
||||
private var drawOffY: Float = -height.toFloat()
|
||||
private var openingTimeCounter = 0
|
||||
|
||||
init {
|
||||
reset()
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta_t: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
// background
|
||||
g.color = UIColour
|
||||
g.fillRect(drawOffX, drawOffY, width.toFloat(), height.toFloat())
|
||||
g.fillRect(drawOffX, drawOffY, width.toFloat(), LINE_HEIGHT.toFloat())
|
||||
|
||||
val input = commandInputPool!!.toString()
|
||||
val inputDrawWidth = g.font.getWidth(input)
|
||||
val inputDrawHeight = g.font.lineHeight
|
||||
|
||||
// text and cursor
|
||||
g.color = Color.white
|
||||
g.drawString(input, 1f + drawOffX, drawOffY)
|
||||
g.fillRect(inputDrawWidth.toFloat() + drawOffX, drawOffY, 2f, inputDrawHeight.toFloat())
|
||||
|
||||
// messages
|
||||
for (i in 0..MESSAGES_DISPLAY_COUNT - 1) {
|
||||
val message = messages[messageDisplayPos + i]
|
||||
g.drawString(message, 1f + drawOffX, (LINE_HEIGHT * (i + 1)).toFloat() + drawOffY)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
// execute
|
||||
if (key == Key.RET && commandInputPool!!.length > 0) {
|
||||
prevCommand = commandInputPool!!.toString()
|
||||
executeCommand()
|
||||
commandInputPool = StringBuffer()
|
||||
}
|
||||
else if (key == Key.BKSP && commandInputPool!!.length > 0) {
|
||||
commandInputPool!!.deleteCharAt(commandInputPool!!.length - 1)
|
||||
}
|
||||
else if (key >= 2 && key <= 13
|
||||
|| key >= 16 && key <= 27
|
||||
|| key >= 30 && key <= 40
|
||||
|| key >= 44 && key <= 53
|
||||
|| commandInputPool!!.length > 0 && key == 57) {
|
||||
commandInputPool!!.append(c)
|
||||
inputCursorPos += 1
|
||||
}
|
||||
else if (key == Key.UP) {
|
||||
commandInputPool = StringBuffer()
|
||||
commandInputPool!!.append(prevCommand)
|
||||
}
|
||||
else if (key == Key.PGUP) {
|
||||
setDisplayPos(-MESSAGES_DISPLAY_COUNT + 1)
|
||||
}
|
||||
else if (key == Key.PGDN) {
|
||||
setDisplayPos(MESSAGES_DISPLAY_COUNT - 1)
|
||||
}// scroll down
|
||||
// scroll up
|
||||
// prev command
|
||||
// get input
|
||||
// backspace
|
||||
}
|
||||
|
||||
override fun keyReleased(key: Int, c: Char) {
|
||||
|
||||
}
|
||||
|
||||
override fun processInput(input: Input) {
|
||||
|
||||
}
|
||||
|
||||
private fun executeCommand() {
|
||||
sendMessage("> " + commandInputPool!!.toString())
|
||||
CommandInterpreter.execute(commandInputPool!!.toString())
|
||||
}
|
||||
|
||||
fun sendMessage(msg: String) {
|
||||
messages[messagesCount] = msg
|
||||
messagesCount += 1
|
||||
if (messagesCount > MESSAGES_DISPLAY_COUNT) {
|
||||
messageDisplayPos = messagesCount - MESSAGES_DISPLAY_COUNT
|
||||
}
|
||||
}
|
||||
|
||||
private fun setDisplayPos(change: Int) {
|
||||
val lowLim = 0
|
||||
val highLim = if (messagesCount <= MESSAGES_DISPLAY_COUNT)
|
||||
0
|
||||
else
|
||||
messagesCount - MESSAGES_DISPLAY_COUNT
|
||||
val newVal = messageDisplayPos + change
|
||||
|
||||
if (newVal < lowLim) {
|
||||
messageDisplayPos = lowLim
|
||||
}
|
||||
else if (newVal > highLim) {
|
||||
messageDisplayPos = highLim
|
||||
}
|
||||
else {
|
||||
messageDisplayPos = newVal
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
messages = Array(MESSAGES_MAX, {""})
|
||||
messageDisplayPos = 0
|
||||
messagesCount = 0
|
||||
inputCursorPos = 0
|
||||
prevCommand = ""
|
||||
commandInputPool = StringBuffer()
|
||||
|
||||
if (Terrarum.game.auth.b()) sendMessage(Lang.get("DEV_MESSAGE_CONSOLE_CODEX"))
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
/*openingTimeCounter += delta
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
-height.toFloat(), 0f
|
||||
)*/
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
/*openingTimeCounter += delta
|
||||
drawOffY = MovementInterpolator.fastPullOut(openingTimeCounter.toFloat() / openCloseTime.toFloat(),
|
||||
0f, -height.toFloat()
|
||||
)*/
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
drawOffY = 0f
|
||||
openingTimeCounter = 0
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
drawOffY = -height.toFloat()
|
||||
openingTimeCounter = 0
|
||||
}
|
||||
}
|
||||
121
src/com/torvald/terrarum/ui/MessageWindow.kt
Normal file
121
src/com/torvald/terrarum/ui/MessageWindow.kt
Normal file
@@ -0,0 +1,121 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import com.torvald.imagefont.GameFontWhite
|
||||
import com.jme3.math.FastMath
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.newdawn.slick.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-27.
|
||||
*/
|
||||
class MessageWindow @Throws(SlickException::class)
|
||||
constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
|
||||
|
||||
private var segmentLeft: Image? = null
|
||||
private var segmentRight: Image? = null
|
||||
private var segmentBody: Image? = null
|
||||
|
||||
private lateinit var messagesList: Array<String>
|
||||
override var height: Int = 0
|
||||
private val messageWindowRadius: Int
|
||||
|
||||
private var uiFont: Font? = null
|
||||
private val GLYPH_HEIGHT = 20
|
||||
|
||||
override var openCloseTime: Int = OPEN_CLOSE_TIME
|
||||
|
||||
internal var opacity = 0f
|
||||
internal var openCloseCounter = 0
|
||||
|
||||
private lateinit var uidrawCanvas: Image // render all the images and fonts here; will be faded
|
||||
|
||||
init {
|
||||
if (!isBlackVariant) {
|
||||
//segmentLeft = new Image("./res/graphics/gui/message_twoline_white_left.png");
|
||||
//segmentRight = new Image("./res/graphics/gui/message_twoline_white_right.png");
|
||||
//segmentBody = new Image("./res/graphics/gui/message_twoline_white_body.png");
|
||||
//uiFont = new GameFontBlack();
|
||||
TODO("Black font not supported for now")
|
||||
}
|
||||
else {
|
||||
segmentLeft = Image("./res/graphics/gui/message_twoline_black_left.png")
|
||||
segmentRight = Image("./res/graphics/gui/message_twoline_black_right.png")
|
||||
segmentBody = Image("./res/graphics/gui/message_twoline_black_body.png")
|
||||
uiFont = GameFontWhite()
|
||||
}
|
||||
height = segmentLeft!!.height
|
||||
messageWindowRadius = segmentLeft!!.width
|
||||
messagesList = arrayOf("", "")
|
||||
uidrawCanvas = Image(FastMath.nearestPowerOfTwo(width), FastMath.nearestPowerOfTwo(height))
|
||||
}
|
||||
|
||||
fun setMessage(messagesList: Array<String>) {
|
||||
this.messagesList = messagesList
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta_t: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
val canvasG = uidrawCanvas.graphics
|
||||
|
||||
canvasG.setDrawMode(Graphics.MODE_NORMAL)
|
||||
drawSegments(canvasG)
|
||||
canvasG.setDrawMode(Graphics.MODE_ALPHA_MAP)
|
||||
drawSegments(canvasG)
|
||||
|
||||
canvasG.font = uiFont
|
||||
|
||||
canvasG.setDrawMode(Graphics.MODE_NORMAL)
|
||||
for (i in 0..Math.min(messagesList.size, MESSAGES_DISPLAY) - 1) {
|
||||
canvasG.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
|
||||
}
|
||||
|
||||
g.drawImage(uidrawCanvas, 0f, 0f, Color(1f,1f,1f,opacity))
|
||||
|
||||
canvasG.clear()
|
||||
}
|
||||
|
||||
override fun processInput(input: Input) {
|
||||
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
openCloseCounter += delta
|
||||
opacity = FastMath.interpolateLinear(openCloseCounter.toFloat() / openCloseTime.toFloat(),
|
||||
0f, 1f
|
||||
)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
openCloseCounter += delta
|
||||
opacity = FastMath.interpolateLinear(openCloseCounter.toFloat() / openCloseTime.toFloat(),
|
||||
1f, 0f
|
||||
)
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
opacity = 1f
|
||||
openCloseCounter = 0
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
opacity = 0f
|
||||
openCloseCounter = 0
|
||||
}
|
||||
|
||||
private fun drawSegments(g: Graphics) {
|
||||
g.drawImage(segmentLeft, 0f, 0f)
|
||||
val scaledSegCentre = segmentBody!!.getScaledCopy(
|
||||
width - (segmentRight!!.width + segmentLeft!!.width), segmentLeft!!.height)
|
||||
g.drawImage(scaledSegCentre, segmentLeft!!.width.toFloat(), 0f)
|
||||
g.drawImage(segmentRight, (width - segmentRight!!.width).toFloat(), 0f)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// private int messagesShowingIndex = 0;
|
||||
val MESSAGES_DISPLAY = 2
|
||||
val OPEN_CLOSE_TIME = 200
|
||||
}
|
||||
}
|
||||
30
src/com/torvald/terrarum/ui/MovementInterpolator.kt
Normal file
30
src/com/torvald/terrarum/ui/MovementInterpolator.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-22.
|
||||
*/
|
||||
object MovementInterpolator {
|
||||
/**
|
||||
* Pretty fast at the beginning, getting slow over time.
|
||||
*/
|
||||
fun fastPullOut(scale: Float, start: Float = 0f, end: Float = 1f): Float =
|
||||
if (scale < 0f) start
|
||||
else if (scale > 1f) end
|
||||
else (start - end) * FastMath.sqr(scale - 1) + end
|
||||
|
||||
/**
|
||||
* Slow at the beginning, getting fast over time.
|
||||
*/
|
||||
fun dropDown(scale: Float, start: Float = 0f, end: Float = 1f): Float =
|
||||
if (scale < 0f) start
|
||||
else if (scale > 1f) end
|
||||
else (end - start) * FastMath.sqr(scale) + start
|
||||
|
||||
fun sinusoid(scale: Float, start: Float = 0f, end: Float = 1f): Float =
|
||||
if (scale < 0f) start
|
||||
else if (scale > 1f) end
|
||||
else (start - end) * FastMath.cos2(0.5f * FastMath.PI * scale) + end
|
||||
|
||||
}
|
||||
87
src/com/torvald/terrarum/ui/Notification.kt
Normal file
87
src/com/torvald/terrarum/ui/Notification.kt
Normal file
@@ -0,0 +1,87 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
import org.newdawn.slick.SlickException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-23.
|
||||
*/
|
||||
class Notification @Throws(SlickException::class)
|
||||
constructor() : UICanvas {
|
||||
|
||||
override var width: Int = 0
|
||||
override var height: Int = 0
|
||||
internal var visibleTime: Int
|
||||
internal var showupTimeConuter = 0
|
||||
|
||||
internal var isShowing = false
|
||||
internal var message: Array<String> = Array(MessageWindow.MESSAGES_DISPLAY, { i -> ""})
|
||||
|
||||
internal var msgUI: MessageWindow
|
||||
|
||||
override var openCloseTime: Int = MessageWindow.OPEN_CLOSE_TIME
|
||||
|
||||
private val SHOWUP_MAX = 15000
|
||||
|
||||
init {
|
||||
width = 500
|
||||
msgUI = MessageWindow(width, true)
|
||||
height = msgUI.height
|
||||
visibleTime = Math.min(
|
||||
Terrarum.getConfigInt("notificationshowuptime"),
|
||||
SHOWUP_MAX
|
||||
)
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
if (showupTimeConuter >= visibleTime && isShowing) {
|
||||
// invoke closing mode
|
||||
doClosing(gc, delta)
|
||||
// check if msgUI is fully fade out
|
||||
if (msgUI.opacity <= 0.001f) {
|
||||
endClosing(gc, delta)
|
||||
isShowing = false
|
||||
}
|
||||
}
|
||||
|
||||
if (isShowing) {
|
||||
showupTimeConuter += delta
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
if (isShowing) {
|
||||
msgUI.render(gc, g)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
msgUI.doOpening(gc, delta)
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
msgUI.doClosing(gc, delta)
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
msgUI.endOpening(gc, delta)
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
msgUI.endClosing(gc, delta)
|
||||
}
|
||||
|
||||
override fun processInput(input: Input) {
|
||||
|
||||
}
|
||||
|
||||
fun sendNotification(gc: GameContainer, delta: Int, message: Array<String>) {
|
||||
isShowing = true
|
||||
this.message = message
|
||||
msgUI.setMessage(this.message)
|
||||
showupTimeConuter = 0
|
||||
}
|
||||
}
|
||||
32
src/com/torvald/terrarum/ui/UICanvas.kt
Normal file
32
src/com/torvald/terrarum/ui/UICanvas.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
interface UICanvas {
|
||||
|
||||
var width: Int
|
||||
var height: Int
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
var openCloseTime: Int
|
||||
|
||||
fun update(gc: GameContainer, delta: Int)
|
||||
|
||||
fun render(gc: GameContainer, g: Graphics)
|
||||
|
||||
fun processInput(input: Input)
|
||||
|
||||
fun doOpening(gc: GameContainer, delta: Int)
|
||||
|
||||
fun doClosing(gc: GameContainer, delta: Int)
|
||||
|
||||
fun endOpening(gc: GameContainer, delta: Int)
|
||||
|
||||
fun endClosing(gc: GameContainer, delta: Int)
|
||||
}
|
||||
21
src/com/torvald/terrarum/ui/UIClickable.kt
Normal file
21
src/com/torvald/terrarum/ui/UIClickable.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-06.
|
||||
*/
|
||||
interface UIClickable {
|
||||
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
|
||||
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int)
|
||||
|
||||
fun mousePressed(button: Int, x: Int, y: Int)
|
||||
|
||||
fun mouseReleased(button: Int, x: Int, y: Int)
|
||||
|
||||
fun mouseWheelMoved(change: Int)
|
||||
|
||||
fun controllerButtonPressed(controller: Int, button: Int)
|
||||
|
||||
fun controllerButtonReleased(controller: Int, button: Int)
|
||||
|
||||
}
|
||||
238
src/com/torvald/terrarum/ui/UIHandler.kt
Normal file
238
src/com/torvald/terrarum/ui/UIHandler.kt
Normal file
@@ -0,0 +1,238 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
import com.torvald.terrarum.mapdrawer.MapCamera
|
||||
import com.torvald.terrarum.Terrarum
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
class UIHandler
|
||||
/**
|
||||
* Construct new UIHandler with given UI attached.
|
||||
* Invisible in default.
|
||||
* @param UI
|
||||
* *
|
||||
* @throws SlickException
|
||||
*/
|
||||
@Throws(SlickException::class)
|
||||
constructor(val UI: UICanvas) {
|
||||
|
||||
// X/Y Position to the game window.
|
||||
var posX: Int = 0
|
||||
private set
|
||||
var posY: Int = 0
|
||||
private set
|
||||
|
||||
private var alwaysVisible = false
|
||||
|
||||
private val UIGraphicInstance: Graphics
|
||||
private val UIDrawnCanvas: Image
|
||||
|
||||
private var opening = false
|
||||
private var closing = false
|
||||
private var opened = false // fully opened
|
||||
private var visible = false
|
||||
|
||||
var openCloseCounter = 0
|
||||
|
||||
init {
|
||||
println("[UIHandler] Creating UI '${UI.javaClass.simpleName}'")
|
||||
|
||||
UIDrawnCanvas = Image(
|
||||
FastMath.nearestPowerOfTwo(UI.width), FastMath.nearestPowerOfTwo(UI.height))
|
||||
|
||||
UIGraphicInstance = UIDrawnCanvas.graphics
|
||||
}
|
||||
|
||||
|
||||
fun update(gc: GameContainer, delta: Int) {
|
||||
if (visible || alwaysVisible) {
|
||||
UI.update(gc, delta)
|
||||
}
|
||||
|
||||
if (opening) {
|
||||
visible = true
|
||||
openCloseCounter += delta
|
||||
|
||||
// println("UI ${UI.javaClass.simpleName} (open)")
|
||||
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
|
||||
|
||||
if (openCloseCounter < UI.openCloseTime) {
|
||||
UI.doOpening(gc, delta)
|
||||
// println("UIHandler.opening ${UI.javaClass.simpleName}")
|
||||
}
|
||||
else {
|
||||
UI.endOpening(gc, delta)
|
||||
opening = false
|
||||
opened = true
|
||||
openCloseCounter = 0
|
||||
}
|
||||
}
|
||||
else if (closing) {
|
||||
openCloseCounter += delta
|
||||
|
||||
// println("UI ${UI.javaClass.simpleName} (close)")
|
||||
// println("-> timecounter $openCloseCounter / ${UI.openCloseTime} timetakes")
|
||||
|
||||
if (openCloseCounter < UI.openCloseTime) {
|
||||
UI.doClosing(gc, delta)
|
||||
// println("UIHandler.closing ${UI.javaClass.simpleName}")
|
||||
}
|
||||
else {
|
||||
UI.endClosing(gc, delta)
|
||||
closing = false
|
||||
opened = false
|
||||
visible = false
|
||||
openCloseCounter = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun render(gc: GameContainer, gameGraphicInstance: Graphics) {
|
||||
if (visible || alwaysVisible) {
|
||||
UIGraphicInstance.clear()
|
||||
UIGraphicInstance.font = Terrarum.gameFontWhite
|
||||
|
||||
UI.render(gc, UIGraphicInstance)
|
||||
gameGraphicInstance.drawImage(UIDrawnCanvas,
|
||||
posX + MapCamera.cameraX * Terrarum.game.screenZoom,
|
||||
posY + MapCamera.cameraY * Terrarum.game.screenZoom
|
||||
)// compensate for screenZoom AND camera translation
|
||||
// (see Game.render -> g.translate())
|
||||
}
|
||||
}
|
||||
|
||||
fun setPosition(x: Int, y: Int) {
|
||||
posX = x
|
||||
posY = y
|
||||
}
|
||||
|
||||
fun setVisibility(b: Boolean) {
|
||||
if (alwaysVisible) {
|
||||
throw RuntimeException("[UIHandler] Tried to 'set visibility of' constant UI")
|
||||
}
|
||||
visible = b
|
||||
}
|
||||
|
||||
val isVisible: Boolean
|
||||
get() {
|
||||
if (alwaysVisible) {
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return visible
|
||||
}
|
||||
}
|
||||
|
||||
fun setAsAlwaysVisible() {
|
||||
alwaysVisible = true
|
||||
visible = true
|
||||
opened = true
|
||||
opening = false
|
||||
closing = false
|
||||
}
|
||||
|
||||
|
||||
fun setAsOpening() {
|
||||
if (alwaysVisible) {
|
||||
throw RuntimeException("[UIHandler] Tried to 'open' constant UI")
|
||||
}
|
||||
opened = false
|
||||
opening = true
|
||||
}
|
||||
|
||||
fun setAsClosing() {
|
||||
if (alwaysVisible) {
|
||||
throw RuntimeException("[UIHandler] Tried to 'close' constant UI")
|
||||
}
|
||||
opened = false
|
||||
closing = true
|
||||
}
|
||||
|
||||
fun toggleOpening() {
|
||||
if (alwaysVisible) {
|
||||
throw RuntimeException("[UIHandler] Tried to 'toggle opening of' constant UI")
|
||||
}
|
||||
if (visible) {
|
||||
if (!closing) {
|
||||
setAsClosing()
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!opening) {
|
||||
setAsOpening()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun processInput(input: Input) {
|
||||
if (visible) {
|
||||
UI.processInput(input)
|
||||
}
|
||||
}
|
||||
|
||||
fun keyPressed(key: Int, c: Char) {
|
||||
if (visible && UI is UITypable) {
|
||||
UI.keyPressed(key, c)
|
||||
}
|
||||
}
|
||||
|
||||
fun keyReleased(key: Int, c: Char) {
|
||||
if (visible && UI is UITypable) {
|
||||
UI.keyReleased(key, c)
|
||||
}
|
||||
}
|
||||
|
||||
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.mouseMoved(oldx, oldy, newx, newy)
|
||||
}
|
||||
}
|
||||
|
||||
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.mouseDragged(oldx, oldy, newx, newy)
|
||||
}
|
||||
}
|
||||
|
||||
fun mousePressed(button: Int, x: Int, y: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.mousePressed(button, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
fun mouseReleased(button: Int, x: Int, y: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.mouseReleased(button, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
fun mouseWheelMoved(change: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.mouseWheelMoved(change)
|
||||
}
|
||||
}
|
||||
|
||||
fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.controllerButtonPressed(controller, button)
|
||||
}
|
||||
}
|
||||
|
||||
fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
if (visible && UI is UIClickable) {
|
||||
UI.controllerButtonReleased(controller, button)
|
||||
}
|
||||
}
|
||||
|
||||
// constant UI can't take control
|
||||
val isTakingControl: Boolean
|
||||
get() {
|
||||
if (alwaysVisible) {
|
||||
return false
|
||||
}
|
||||
return visible && !opening
|
||||
}
|
||||
}
|
||||
13
src/com/torvald/terrarum/ui/UIItem.kt
Normal file
13
src/com/torvald/terrarum/ui/UIItem.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
class UIItem {
|
||||
|
||||
// X/Y Position relative to the containing canvas
|
||||
internal var posX: Int = 0
|
||||
internal var posY: Int = 0
|
||||
|
||||
|
||||
}
|
||||
10
src/com/torvald/terrarum/ui/UITypable.kt
Normal file
10
src/com/torvald/terrarum/ui/UITypable.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.torvald.terrarum.ui
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-06.
|
||||
*/
|
||||
interface UITypable {
|
||||
fun keyPressed(key: Int, c: Char)
|
||||
|
||||
fun keyReleased(key: Int, c: Char)
|
||||
}
|
||||
Reference in New Issue
Block a user