more Kotlin, UIs now can open/close with animation, working world time with skybox colour changing (sunlight transition is still WIP), fixed project library settings so that the suggestion in IntelliJ IDEA would work properly
Former-commit-id: 82c857164f2636ad943d5a43f0690a3431ab0f26 Former-commit-id: 7c8b70e6b267f7c5c050d7d0902278739ec18b44
10
.idea/libraries/KotlinJavaRuntime.xml
generated
@@ -1,10 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="KotlinJavaRuntime">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/" />
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-reflect.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES />
|
|
||||||
</library>
|
|
||||||
</component>
|
|
||||||
21
.idea/libraries/lib.xml
generated
@@ -1,11 +1,23 @@
|
|||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="lib">
|
<library name="lib">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib" />
|
<root url="jar://$PROJECT_DIR$/lib/commons-codec-1.10.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/commons-csv-1.2.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/gson-2.5.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/ibxm.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/jbox2d-library-2.1.2.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/jinput.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/jnlp.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/jogg-0.0.7.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/jorbis-0.0.15.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/kotlin-reflect.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/lwjgl.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/lwjgl_util.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/slick.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC>
|
<JAVADOC>
|
||||||
<root url="http://slick.ninjacave.com/javadoc/" />
|
<root url="http://slick.ninjacave.com/javadoc/" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/gson-2.5-javadoc.jar!/" />
|
|
||||||
<root url="file://$PROJECT_DIR$/lib/javadoc" />
|
<root url="file://$PROJECT_DIR$/lib/javadoc" />
|
||||||
<root url="file://$PROJECT_DIR$/lib/apidocs" />
|
<root url="file://$PROJECT_DIR$/lib/apidocs" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/commons-codec-1.10-javadoc.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/commons-codec-1.10-javadoc.jar!/" />
|
||||||
@@ -21,10 +33,5 @@
|
|||||||
<root url="file://$USER_HOME$/Downloads/slick/src" />
|
<root url="file://$USER_HOME$/Downloads/slick/src" />
|
||||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime-sources.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
|
||||||
<root url="jar://$PROJECT_DIR$/lib/gson-2.5-javadoc.jar!/" />
|
|
||||||
<root url="file://$PROJECT_DIR$/lib/apidocs" />
|
|
||||||
</excluded>
|
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
||||||
@@ -9,6 +9,5 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="lib" level="project" />
|
<orderEntry type="library" name="lib" level="project" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
echo "Hello, world!"
|
echo "Hello, world! This is a batch test."
|
||||||
echo "This is a batch test."
|
echo "Will add actorvalue 'batch = true' to player"
|
||||||
setav batch true
|
setav batch true
|
||||||
|
echo "Checking if command did something."
|
||||||
getav batch
|
getav batch
|
||||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 377 B After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 433 B After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 451 B After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 902 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 347 KiB After Width: | Height: | Size: 346 KiB |
@@ -1,41 +0,0 @@
|
|||||||
package com.Torvald;
|
|
||||||
|
|
||||||
import org.apache.commons.csv.CSVFormat;
|
|
||||||
import org.apache.commons.csv.CSVParser;
|
|
||||||
import org.apache.commons.csv.CSVRecord;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.FileSystems;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-16.
|
|
||||||
*/
|
|
||||||
public class CSVFetcher {
|
|
||||||
|
|
||||||
private static StringBuffer csvString;
|
|
||||||
|
|
||||||
public static List<CSVRecord> readCSV(String csvFilePath) throws IOException {
|
|
||||||
csvString = new StringBuffer(); // reset buffer every time it called
|
|
||||||
readCsvFileAsString(csvFilePath);
|
|
||||||
|
|
||||||
CSVParser csvParser = CSVParser.parse(csvString.toString()
|
|
||||||
, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces().withHeader()
|
|
||||||
.withIgnoreEmptyLines().withDelimiter(';')
|
|
||||||
.withCommentMarker('#').withNullString("N/A")
|
|
||||||
.withRecordSeparator('\n')
|
|
||||||
);
|
|
||||||
|
|
||||||
List<CSVRecord> csvRecordList = csvParser.getRecords();
|
|
||||||
csvParser.close();
|
|
||||||
|
|
||||||
return csvRecordList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void readCsvFileAsString(String path) throws IOException {
|
|
||||||
Files.lines(
|
|
||||||
FileSystems.getDefault().getPath(path)
|
|
||||||
).forEach(s -> csvString.append(s += "\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
48
src/com/Torvald/CSVFetcher.kt
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package com.Torvald
|
||||||
|
|
||||||
|
import org.apache.commons.csv.CSVFormat
|
||||||
|
import org.apache.commons.csv.CSVParser
|
||||||
|
import org.apache.commons.csv.CSVRecord
|
||||||
|
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.FileSystems
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-02-16.
|
||||||
|
*/
|
||||||
|
object CSVFetcher {
|
||||||
|
|
||||||
|
private var csvString: StringBuffer? = null
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun readCSV(csvFilePath: String): List<CSVRecord> {
|
||||||
|
csvString = StringBuffer() // reset buffer every time it called
|
||||||
|
readCSVasString(csvFilePath)
|
||||||
|
|
||||||
|
val csvParser = CSVParser.parse(
|
||||||
|
csvString!!.toString(),
|
||||||
|
CSVFormat.DEFAULT.withIgnoreSurroundingSpaces()
|
||||||
|
.withHeader()
|
||||||
|
.withIgnoreEmptyLines()
|
||||||
|
.withDelimiter(';')
|
||||||
|
.withCommentMarker('#')
|
||||||
|
.withNullString("N/A")
|
||||||
|
.withRecordSeparator('\n')
|
||||||
|
)
|
||||||
|
|
||||||
|
val csvRecordList = csvParser.records
|
||||||
|
csvParser.close()
|
||||||
|
|
||||||
|
return csvRecordList
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun readCSVasString(path: String): String {
|
||||||
|
csvString = StringBuffer()
|
||||||
|
Files.lines(FileSystems.getDefault().getPath(path)).forEach(
|
||||||
|
{ s -> csvString!!.append("$s\n") }
|
||||||
|
)
|
||||||
|
return csvString!!.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package com.Torvald.ColourUtil;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-11.
|
|
||||||
*/
|
|
||||||
public class Col216 implements LimitedColours {
|
|
||||||
|
|
||||||
private byte data;
|
|
||||||
private static transient final int[] LOOKUP = {0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF};
|
|
||||||
|
|
||||||
public static final int MUL = 6;
|
|
||||||
public static final int MUL_2 = MUL * MUL;
|
|
||||||
public static final int MAX_STEP = MUL - 1;
|
|
||||||
public static final int COLOUR_DOMAIN_SIZE = MUL_2 * MUL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
public Col216(byte data) {
|
|
||||||
create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param r 0-5
|
|
||||||
* @param g 0-5
|
|
||||||
* @param b 0-5
|
|
||||||
*/
|
|
||||||
public Col216(int r, int g, int b) {
|
|
||||||
create(r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color createSlickColor(int raw) {
|
|
||||||
assertRaw(raw);
|
|
||||||
int r = raw / MUL_2;
|
|
||||||
int g = (raw % MUL_2) / MUL;
|
|
||||||
int b = raw % MUL;
|
|
||||||
|
|
||||||
return createSlickColor(r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color createSlickColor(int r, int g, int b) {
|
|
||||||
assertRGB(r, g, b);
|
|
||||||
return new Color(LOOKUP[r], LOOKUP[g], LOOKUP[b]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(int raw) {
|
|
||||||
assertRaw(raw);
|
|
||||||
data = (byte) raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(int r, int g, int b) {
|
|
||||||
assertRGB(r, g, b);
|
|
||||||
data = (byte) (MUL_2 * r + MUL * g + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getRaw() { return data; }
|
|
||||||
|
|
||||||
private void assertRaw(int i) {
|
|
||||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
|
||||||
System.out.println("i: " + String.valueOf(i));
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertRGB(int r, int g, int b) {
|
|
||||||
if (r > MAX_STEP || g > MAX_STEP || b > MAX_STEP || r < 0 || g < 0 || b < 0) {
|
|
||||||
System.out.println("r: " + String.valueOf(r));
|
|
||||||
System.out.println("g: " + String.valueOf(g));
|
|
||||||
System.out.println("b: " + String.valueOf(b));
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
82
src/com/Torvald/ColourUtil/Col216.kt
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package com.Torvald.ColourUtil
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 6-Step RGB with builtin utils.
|
||||||
|
* Created by minjaesong on 16-02-11.
|
||||||
|
*/
|
||||||
|
class Col216 : LimitedColours {
|
||||||
|
|
||||||
|
var raw: Byte = 0
|
||||||
|
private set
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
constructor(data: Byte) {
|
||||||
|
create(data.toInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
* @param r 0-5
|
||||||
|
* *
|
||||||
|
* @param g 0-5
|
||||||
|
* *
|
||||||
|
* @param b 0-5
|
||||||
|
*/
|
||||||
|
constructor(r: Int, g: Int, b: Int) {
|
||||||
|
create(r, g, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createSlickColor(raw: Int): Color {
|
||||||
|
assertRaw(raw)
|
||||||
|
val r = raw / MUL_2
|
||||||
|
val g = raw % MUL_2 / MUL
|
||||||
|
val b = raw % MUL
|
||||||
|
|
||||||
|
return createSlickColor(r, g, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||||
|
assertRGB(r, g, b)
|
||||||
|
return Color(LOOKUP[r], LOOKUP[g], LOOKUP[b])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(raw: Int) {
|
||||||
|
assertRaw(raw)
|
||||||
|
this.raw = raw.toByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(r: Int, g: Int, b: Int) {
|
||||||
|
assertRGB(r, g, b)
|
||||||
|
raw = (MUL_2 * r + MUL * g + b).toByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRaw(i: Int) {
|
||||||
|
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||||
|
println("i: " + i.toString())
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRGB(r: Int, g: Int, b: Int) {
|
||||||
|
if (r !in 0..MAX_STEP || g !in 0..MAX_STEP || b !in 0..MAX_STEP) {
|
||||||
|
println("r: " + r.toString())
|
||||||
|
println("g: " + g.toString())
|
||||||
|
println("b: " + b.toString())
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Transient private val LOOKUP = intArrayOf(0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF)
|
||||||
|
|
||||||
|
const val MUL = 6
|
||||||
|
const val MUL_2 = MUL * MUL
|
||||||
|
const val MAX_STEP = MUL - 1
|
||||||
|
const val COLOUR_DOMAIN_SIZE = MUL_2 * MUL
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.Torvald.ColourUtil;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-20.
|
|
||||||
*/
|
|
||||||
public class Col40 implements LimitedColours {
|
|
||||||
|
|
||||||
private char data;
|
|
||||||
private static transient final int[] LOOKUP = {0,7,13,20,26,33,39,46,52,59,65,72,78,85,92,98,105,111,118,124
|
|
||||||
,131,137,144,150,157,163,170,177,183,190,196,203,209,216,222,229,235,242,248,255};
|
|
||||||
|
|
||||||
public static final int MUL = 40;
|
|
||||||
public static final int MUL_2 = MUL * MUL;
|
|
||||||
public static final int MAX_STEP = MUL - 1;
|
|
||||||
public static final int COLOUR_DOMAIN_SIZE = MUL_2 * MUL;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color createSlickColor(int raw) {
|
|
||||||
assertRaw(raw);
|
|
||||||
int r = raw / MUL_2;
|
|
||||||
int g = (raw % MUL_2) / MUL;
|
|
||||||
int b = raw % MUL;
|
|
||||||
|
|
||||||
return createSlickColor(r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color createSlickColor(int r, int g, int b) {
|
|
||||||
assertRGB(r, g, b);
|
|
||||||
return new Color((LOOKUP[r] << 16) | (LOOKUP[g] << 8) | LOOKUP[b]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(int raw) {
|
|
||||||
assertRaw(raw);
|
|
||||||
data = (char) raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(int r, int g, int b) {
|
|
||||||
assertRGB(r, g, b);
|
|
||||||
data = (char) (MUL_2 * r + MUL * g + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public char getRaw() { return data; }
|
|
||||||
|
|
||||||
private void assertRaw(int i) {
|
|
||||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
|
||||||
System.out.println("i: " + String.valueOf(i));
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertRGB(int r, int g, int b) {
|
|
||||||
if (r > MAX_STEP || g > MAX_STEP || b > MAX_STEP || r < 0 || g < 0 || b < 0) {
|
|
||||||
System.out.println("r: " + String.valueOf(r));
|
|
||||||
System.out.println("g: " + String.valueOf(g));
|
|
||||||
System.out.println("b: " + String.valueOf(b));
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
72
src/com/Torvald/ColourUtil/Col40.kt
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package com.Torvald.ColourUtil
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 40-Step RGB with builtin utils.
|
||||||
|
* Created by minjaesong on 16-02-20.
|
||||||
|
*/
|
||||||
|
class Col40 : LimitedColours {
|
||||||
|
|
||||||
|
var raw: Char = ' '
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun createSlickColor(raw: Int): Color {
|
||||||
|
assertRaw(raw)
|
||||||
|
val r = raw / MUL_2
|
||||||
|
val g = raw % MUL_2 / MUL
|
||||||
|
val b = raw % MUL
|
||||||
|
|
||||||
|
return createSlickColor(r, g, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||||
|
assertRGB(r, g, b)
|
||||||
|
return Color(LOOKUP[r] shl 16 or (LOOKUP[g] shl 8) or LOOKUP[b])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(raw: Int) {
|
||||||
|
assertRaw(raw)
|
||||||
|
this.raw = raw.toChar()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(r: Int, g: Int, b: Int) {
|
||||||
|
assertRGB(r, g, b)
|
||||||
|
raw = (MUL_2 * r + MUL * g + b).toChar()
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(c: Color) {
|
||||||
|
create(
|
||||||
|
Math.round(c.r * (MUL - 1)),
|
||||||
|
Math.round(c.g * (MUL - 1)),
|
||||||
|
Math.round(c.b * (MUL - 1)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRaw(i: Int) {
|
||||||
|
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||||
|
println("i: " + i.toString())
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRGB(r: Int, g: Int, b: Int) {
|
||||||
|
if (r !in 0..MAX_STEP || g !in 0..MAX_STEP || b !in 0..MAX_STEP) {
|
||||||
|
println("r: " + r.toString())
|
||||||
|
println("g: " + g.toString())
|
||||||
|
println("b: " + b.toString())
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Transient private val LOOKUP = intArrayOf(0, 7, 13, 20, 26, 33, 39, 46, 52, 59, 65, 72, 78, 85, 92, 98, 105, 111, 118, 124, 131, 137, 144, 150, 157, 163, 170, 177, 183, 190, 196, 203, 209, 216, 222, 229, 235, 242, 248, 255)
|
||||||
|
|
||||||
|
const val MUL = 40
|
||||||
|
const val MUL_2 = MUL * MUL
|
||||||
|
const val MAX_STEP = MUL - 1
|
||||||
|
const val COLOUR_DOMAIN_SIZE = MUL_2 * MUL
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
package com.Torvald.ColourUtil;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-23.
|
|
||||||
*
|
|
||||||
* 12-bit RGB
|
|
||||||
*/
|
|
||||||
public class Col4096 implements LimitedColours {
|
|
||||||
|
|
||||||
private short data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
public Col4096(int data) {
|
|
||||||
create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param r 0-15
|
|
||||||
* @param g 0-15
|
|
||||||
* @param b 0-15
|
|
||||||
*/
|
|
||||||
public Col4096(int r, int g, int b) {
|
|
||||||
create(r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create Col4096 colour and convert it to Slick Color
|
|
||||||
* @param i
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Color createSlickColor(int i) {
|
|
||||||
assertRaw(i);
|
|
||||||
|
|
||||||
int a, r, g, b;
|
|
||||||
|
|
||||||
r = (i & 0xF00) >> 8;
|
|
||||||
g = (i & 0x0F0) >> 4;
|
|
||||||
b = i & 0x00F;
|
|
||||||
|
|
||||||
if (i > 0xFFF) {
|
|
||||||
a = (i & 0xF000) >> 12;
|
|
||||||
|
|
||||||
return new Color(
|
|
||||||
(r << 4) | r
|
|
||||||
, (g << 4) | g
|
|
||||||
, (b << 4) | b
|
|
||||||
, (a << 4) | a
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new Color(
|
|
||||||
(r << 4) | r
|
|
||||||
, (g << 4) | g
|
|
||||||
, (b << 4) | b
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color createSlickColor(int r, int g, int b) {
|
|
||||||
assertARGB(0, r, g, b);
|
|
||||||
return createSlickColor(r << 8 | g << 4 | b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color createSlickColor(int a, int r, int g, int b) {
|
|
||||||
assertARGB(a, r, g, b);
|
|
||||||
return createSlickColor(a << 12 |r << 8 | g << 4 | b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(int raw) {
|
|
||||||
assertRaw(raw);
|
|
||||||
data = (short) (raw & 0xFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(int r, int g, int b) {
|
|
||||||
assertARGB(0, r, g, b);
|
|
||||||
data = (short) (r << 8 | g << 4 | b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void create(int a, int r, int g, int b) {
|
|
||||||
assertARGB(a, r, g, b);
|
|
||||||
data = (short) (a << 12 | r << 8 | g << 4 | b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert to 3 byte values, for raster imaging.
|
|
||||||
* @return byte[RR, GG, BB] e.g. 0x4B3 -> 0x44, 0xBB, 0x33
|
|
||||||
*/
|
|
||||||
public byte[] toByteArray() {
|
|
||||||
byte[] ret = new byte[3];
|
|
||||||
int r = (data & 0xF00) >> 8;
|
|
||||||
int g = (data & 0x0F0) >> 4;
|
|
||||||
int b = data & 0x00F;
|
|
||||||
|
|
||||||
ret[0] = (byte) ((r << 4) | r);
|
|
||||||
ret[1] = (byte) ((g << 4) | g);
|
|
||||||
ret[2] = (byte) ((b << 4) | b);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve raw ARGB value
|
|
||||||
* @return 0xARGB
|
|
||||||
*/
|
|
||||||
public short getRaw() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertRaw(int i) {
|
|
||||||
if (i > 0xFFFF || i < 0) {
|
|
||||||
System.out.println("i: " + String.valueOf(i));
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertARGB(int a, int r, int g, int b) {
|
|
||||||
if (a > 16 || r > 16 || g > 16 || b > 16 || r < 0 || g < 0 || b < 0 || a < 0) {
|
|
||||||
System.out.println("a: " + String.valueOf(a));
|
|
||||||
System.out.println("r: " + String.valueOf(r));
|
|
||||||
System.out.println("g: " + String.valueOf(g));
|
|
||||||
System.out.println("b: " + String.valueOf(b));
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
127
src/com/Torvald/ColourUtil/Col4096.kt
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
package com.Torvald.ColourUtil
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 12-bit (16-step) RGB with builtin utils.
|
||||||
|
* Created by minjaesong on 16-01-23.
|
||||||
|
*/
|
||||||
|
class Col4096 : LimitedColours {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve raw ARGB value
|
||||||
|
* @return 0xARGB
|
||||||
|
*/
|
||||||
|
var raw: Short = 0
|
||||||
|
private set
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
constructor(data: Int) {
|
||||||
|
create(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
* @param r 0-15
|
||||||
|
* *
|
||||||
|
* @param g 0-15
|
||||||
|
* *
|
||||||
|
* @param b 0-15
|
||||||
|
*/
|
||||||
|
constructor(r: Int, g: Int, b: Int) {
|
||||||
|
create(r, g, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Col4096 colour and convert it to Slick Color
|
||||||
|
* @param i
|
||||||
|
* *
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
override fun createSlickColor(raw: Int): Color {
|
||||||
|
assertRaw(raw)
|
||||||
|
|
||||||
|
val a: Int
|
||||||
|
val r: Int
|
||||||
|
val g: Int
|
||||||
|
val b: Int
|
||||||
|
|
||||||
|
r = raw and 0xF00 shr 8
|
||||||
|
g = raw and 0x0F0 shr 4
|
||||||
|
b = raw and 0x00F
|
||||||
|
|
||||||
|
if (raw > 0xFFF) {
|
||||||
|
a = raw and 0xF000 shr 12
|
||||||
|
|
||||||
|
return Color(
|
||||||
|
r shl 4 or r, g shl 4 or g, b shl 4 or b, a shl 4 or a)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Color(
|
||||||
|
r shl 4 or r, g shl 4 or g, b shl 4 or b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||||
|
assertARGB(0, r, g, b)
|
||||||
|
return createSlickColor(r shl 8 or g shl 4 or b)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createSlickColor(a: Int, r: Int, g: Int, b: Int): Color {
|
||||||
|
assertARGB(a, r, g, b)
|
||||||
|
return createSlickColor(a shl 12 or r shl 8 or g shl 4 or b)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(raw: Int) {
|
||||||
|
assertRaw(raw)
|
||||||
|
this.raw = (raw and 0xFFFF).toShort()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(r: Int, g: Int, b: Int) {
|
||||||
|
assertARGB(0, r, g, b)
|
||||||
|
raw = (r shl 8 or g shl 4 or b).toShort()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun create(a: Int, r: Int, g: Int, b: Int) {
|
||||||
|
assertARGB(a, r, g, b)
|
||||||
|
raw = (a shl 12 or r shl 8 or g shl 4 or b).toShort()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert to 3 byte values, for raster imaging.
|
||||||
|
* @return byte[RR, GG, BB] e.g. 0x4B3 -> 0x44, 0xBB, 0x33
|
||||||
|
*/
|
||||||
|
fun toByteArray(): ByteArray {
|
||||||
|
val ret = ByteArray(3)
|
||||||
|
val r = (raw.toInt() and 0xF00) shr 8
|
||||||
|
val g = (raw.toInt() and 0x0F0) shr 4
|
||||||
|
val b = (raw.toInt() and 0x00F)
|
||||||
|
|
||||||
|
ret[0] = (r shl 4 or r).toByte()
|
||||||
|
ret[1] = (g shl 4 or g).toByte()
|
||||||
|
ret[2] = (b shl 4 or b).toByte()
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertRaw(i: Int) {
|
||||||
|
if (i > 0xFFFF || i < 0) {
|
||||||
|
println("i: " + i.toString())
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertARGB(a: Int, r: Int, g: Int, b: Int) {
|
||||||
|
if (a !in 0..16 || r !in 0..16 || g !in 0..16 || b !in 0..16) {
|
||||||
|
println("a: " + a.toString())
|
||||||
|
println("r: " + r.toString())
|
||||||
|
println("g: " + g.toString())
|
||||||
|
println("b: " + b.toString())
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.Torvald.ColourUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-10.
|
|
||||||
*/
|
|
||||||
public class HSV {
|
|
||||||
private float H;
|
|
||||||
private float S;
|
|
||||||
private float V;
|
|
||||||
|
|
||||||
public HSV() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param h 0-359
|
|
||||||
* @param s 0-1
|
|
||||||
* @param v 0-1
|
|
||||||
*/
|
|
||||||
public HSV(float h, float s, float v) {
|
|
||||||
H = h;
|
|
||||||
S = s;
|
|
||||||
V = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getH() {
|
|
||||||
return H;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setH(float h) {
|
|
||||||
H = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getS() {
|
|
||||||
return S;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setS(float s) {
|
|
||||||
S = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getV() {
|
|
||||||
return V;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setV(float v) {
|
|
||||||
V = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
15
src/com/Torvald/ColourUtil/HSV.kt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package com.Torvald.ColourUtil
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-10.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @param h : Hue 0-359
|
||||||
|
* @param s : Saturation 0-1
|
||||||
|
* @param v : Value (brightness in Adobe Photoshop(TM)) 0-1
|
||||||
|
*/
|
||||||
|
data class HSV(
|
||||||
|
var h: Float,
|
||||||
|
var s: Float,
|
||||||
|
var v: Float
|
||||||
|
)
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package com.Torvald.ColourUtil;
|
|
||||||
|
|
||||||
import com.jme3.math.FastMath;
|
|
||||||
import org.newdawn.slick.Color;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-16.
|
|
||||||
*/
|
|
||||||
public class HSVUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert HSV parameters to RGB color.
|
|
||||||
* @param H 0-359 Hue
|
|
||||||
* @param S 0-1 Saturation
|
|
||||||
* @param V 0-1 Value
|
|
||||||
* @return org.newdawn.slick.Color
|
|
||||||
* @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
|
|
||||||
*/
|
|
||||||
public static Color toRGB(float H, float S, float V) {
|
|
||||||
H %= 360;
|
|
||||||
|
|
||||||
float C = V * S;
|
|
||||||
float X = C * (1 - FastMath.abs(
|
|
||||||
(H / 60f) % 2 - 1
|
|
||||||
));
|
|
||||||
float m = V - C;
|
|
||||||
|
|
||||||
float R_prime = Float.NaN;
|
|
||||||
float G_prime = Float.NaN;
|
|
||||||
float B_prime = Float.NaN;
|
|
||||||
|
|
||||||
if (H < 60) {
|
|
||||||
R_prime = C;
|
|
||||||
G_prime = X;
|
|
||||||
B_prime = 0;
|
|
||||||
}
|
|
||||||
else if (H < 120) {
|
|
||||||
R_prime = X;
|
|
||||||
G_prime = C;
|
|
||||||
B_prime = 0;
|
|
||||||
}
|
|
||||||
else if (H < 180) {
|
|
||||||
R_prime = 0;
|
|
||||||
G_prime = C;
|
|
||||||
B_prime = X;
|
|
||||||
}
|
|
||||||
else if (H < 240) {
|
|
||||||
R_prime = 0;
|
|
||||||
G_prime = X;
|
|
||||||
B_prime = C;
|
|
||||||
}
|
|
||||||
else if (H < 300) {
|
|
||||||
R_prime = X;
|
|
||||||
G_prime = 0;
|
|
||||||
B_prime = C;
|
|
||||||
}
|
|
||||||
else if (H < 360) {
|
|
||||||
R_prime = C;
|
|
||||||
G_prime = 0;
|
|
||||||
B_prime = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Color(
|
|
||||||
(R_prime + m)
|
|
||||||
, (G_prime + m)
|
|
||||||
, (B_prime + m)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Color toRGB(HSV hsv) {
|
|
||||||
return toRGB(hsv.getH(), hsv.getS(), hsv.getV());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HSV fromRGB(Color color) {
|
|
||||||
float r = color.r;
|
|
||||||
float g = color.g;
|
|
||||||
float b = color.b;
|
|
||||||
|
|
||||||
float rgbMin = FastMath.min(r, g, b);
|
|
||||||
float rgbMax = FastMath.max(r, g, b);
|
|
||||||
|
|
||||||
float h;
|
|
||||||
float s;
|
|
||||||
float v = rgbMax;
|
|
||||||
|
|
||||||
float delta = rgbMax - rgbMin;
|
|
||||||
|
|
||||||
if (rgbMax != 0)
|
|
||||||
s = delta / rgbMax;
|
|
||||||
else {
|
|
||||||
h = 0;
|
|
||||||
s = 0;
|
|
||||||
return new HSV(h, s, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r == rgbMax)
|
|
||||||
h = (g - b) / delta;
|
|
||||||
else if (g == rgbMax)
|
|
||||||
h = 2 + (b - r) / delta;
|
|
||||||
else
|
|
||||||
h = 4 + (r - g) / delta;
|
|
||||||
|
|
||||||
h *= 60;
|
|
||||||
if (h < 0) h += 360;
|
|
||||||
|
|
||||||
return new HSV(h, s, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
110
src/com/Torvald/ColourUtil/HSVUtil.kt
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package com.Torvald.ColourUtil
|
||||||
|
|
||||||
|
import com.jme3.math.FastMath
|
||||||
|
import org.newdawn.slick.Color
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-01-16.
|
||||||
|
*/
|
||||||
|
object HSVUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert HSV parameters to RGB color.
|
||||||
|
* @param H 0-359 Hue
|
||||||
|
* *
|
||||||
|
* @param S 0-1 Saturation
|
||||||
|
* *
|
||||||
|
* @param V 0-1 Value
|
||||||
|
* *
|
||||||
|
* @return org.newdawn.slick.Color
|
||||||
|
* *
|
||||||
|
* @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
|
||||||
|
*/
|
||||||
|
fun toRGB(H: Float, S: Float, V: Float): Color {
|
||||||
|
var H = H
|
||||||
|
H %= 360f
|
||||||
|
|
||||||
|
val C = V * S
|
||||||
|
val X = C * (1 - FastMath.abs(
|
||||||
|
H / 60f % 2 - 1))
|
||||||
|
val m = V - C
|
||||||
|
|
||||||
|
var R_prime = java.lang.Float.NaN
|
||||||
|
var G_prime = java.lang.Float.NaN
|
||||||
|
var B_prime = java.lang.Float.NaN
|
||||||
|
|
||||||
|
if (H < 60) {
|
||||||
|
R_prime = C
|
||||||
|
G_prime = X
|
||||||
|
B_prime = 0f
|
||||||
|
}
|
||||||
|
else if (H < 120) {
|
||||||
|
R_prime = X
|
||||||
|
G_prime = C
|
||||||
|
B_prime = 0f
|
||||||
|
}
|
||||||
|
else if (H < 180) {
|
||||||
|
R_prime = 0f
|
||||||
|
G_prime = C
|
||||||
|
B_prime = X
|
||||||
|
}
|
||||||
|
else if (H < 240) {
|
||||||
|
R_prime = 0f
|
||||||
|
G_prime = X
|
||||||
|
B_prime = C
|
||||||
|
}
|
||||||
|
else if (H < 300) {
|
||||||
|
R_prime = X
|
||||||
|
G_prime = 0f
|
||||||
|
B_prime = C
|
||||||
|
}
|
||||||
|
else if (H < 360) {
|
||||||
|
R_prime = C
|
||||||
|
G_prime = 0f
|
||||||
|
B_prime = X
|
||||||
|
}
|
||||||
|
|
||||||
|
return Color(
|
||||||
|
R_prime + m, G_prime + m, B_prime + m)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toRGB(hsv: HSV): Color {
|
||||||
|
return toRGB(hsv.h, hsv.s, hsv.v)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fromRGB(color: Color): HSV {
|
||||||
|
val r = color.r
|
||||||
|
val g = color.g
|
||||||
|
val b = color.b
|
||||||
|
|
||||||
|
val rgbMin = FastMath.min(r, g, b)
|
||||||
|
val rgbMax = FastMath.max(r, g, b)
|
||||||
|
|
||||||
|
var h: Float
|
||||||
|
val s: Float
|
||||||
|
val v = rgbMax
|
||||||
|
|
||||||
|
val delta = rgbMax - rgbMin
|
||||||
|
|
||||||
|
if (rgbMax != 0f)
|
||||||
|
s = delta / rgbMax
|
||||||
|
else {
|
||||||
|
h = 0f
|
||||||
|
s = 0f
|
||||||
|
return HSV(h, s, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r == rgbMax)
|
||||||
|
h = (g - b) / delta
|
||||||
|
else if (g == rgbMax)
|
||||||
|
h = 2 + (b - r) / delta
|
||||||
|
else
|
||||||
|
h = 4 + (r - g) / delta
|
||||||
|
|
||||||
|
h *= 60f
|
||||||
|
if (h < 0) h += 360f
|
||||||
|
|
||||||
|
return HSV(h, s, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.Torvald.ColourUtil;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-11.
|
|
||||||
*/
|
|
||||||
public interface LimitedColours {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Color createSlickColor(int raw);
|
|
||||||
Color createSlickColor(int r, int g, int b);
|
|
||||||
|
|
||||||
void create(int raw);
|
|
||||||
void create(int r, int g, int b);
|
|
||||||
|
|
||||||
}
|
|
||||||
17
src/com/Torvald/ColourUtil/LimitedColours.kt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.Torvald.ColourUtil
|
||||||
|
|
||||||
|
import org.newdawn.slick.Color
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-02-11.
|
||||||
|
*/
|
||||||
|
interface LimitedColours {
|
||||||
|
|
||||||
|
|
||||||
|
fun createSlickColor(raw: Int): Color
|
||||||
|
fun createSlickColor(r: Int, g: Int, b: Int): Color
|
||||||
|
|
||||||
|
fun create(raw: Int)
|
||||||
|
fun create(r: Int, g: Int, b: Int)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,621 +0,0 @@
|
|||||||
package com.Torvald.ImageFont;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
import org.newdawn.slick.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-27.
|
|
||||||
*/
|
|
||||||
public class GameFontBase implements Font {
|
|
||||||
|
|
||||||
static SpriteSheet hangulSheet;
|
|
||||||
static SpriteSheet asciiSheet;
|
|
||||||
static SpriteSheet asciiSheetEF;
|
|
||||||
static SpriteSheet runicSheet;
|
|
||||||
static SpriteSheet extASheet;
|
|
||||||
static SpriteSheet extASheetEF;
|
|
||||||
static SpriteSheet kanaSheet;
|
|
||||||
static SpriteSheet cjkPunct;
|
|
||||||
// static SpriteSheet uniHan;
|
|
||||||
static SpriteSheet cyrilic;
|
|
||||||
static SpriteSheet cyrilicEF;
|
|
||||||
static SpriteSheet fullwidthForms;
|
|
||||||
static SpriteSheet uniPunct;
|
|
||||||
static SpriteSheet wenQuanYi_1;
|
|
||||||
static SpriteSheet wenQuanYi_2;
|
|
||||||
|
|
||||||
static final int JUNG_COUNT = 21;
|
|
||||||
static final int JONG_COUNT = 28;
|
|
||||||
|
|
||||||
static final int W_CJK = 10;
|
|
||||||
static final int W_UNIHAN = 16;
|
|
||||||
static final int W_LATIN_WIDE = 9; // width of regular letters, including m
|
|
||||||
static final int W_LATIN_NARROW = 5; // width of letter f, t, i, l
|
|
||||||
static final int H = 20;
|
|
||||||
static final int H_HANGUL = 16;
|
|
||||||
static final int H_UNIHAN = 16;
|
|
||||||
static final int H_KANA = 20;
|
|
||||||
|
|
||||||
static final int SHEET_ASCII_EM = 0;
|
|
||||||
static final int SHEET_ASCII_EF = 1;
|
|
||||||
static final int SHEET_HANGUL = 2;
|
|
||||||
static final int SHEET_RUNIC = 3;
|
|
||||||
static final int SHEET_EXTA_EM = 4;
|
|
||||||
static final int SHEET_EXTA_EF = 5;
|
|
||||||
static final int SHEET_KANA = 6;
|
|
||||||
static final int SHEET_CJK_PUNCT = 7;
|
|
||||||
static final int SHEET_UNIHAN = 8;
|
|
||||||
static final int SHEET_CYRILIC_EM = 9;
|
|
||||||
static final int SHEET_CYRILIC_EF = 10;
|
|
||||||
static final int SHEET_FW_UNI = 11;
|
|
||||||
static final int SHEET_UNI_PUNCT = 12;
|
|
||||||
static final int SHEET_WENQUANYI_1 = 13;
|
|
||||||
static final int SHEET_WENQUANYI_2 = 14;
|
|
||||||
|
|
||||||
static SpriteSheet[] sheetKey;
|
|
||||||
static final Character[] asciiEFList = {
|
|
||||||
' ','!','"','\'','(',')',',','.',':',';','I','[',']','`','f','i'
|
|
||||||
,'j','l','t','{','|','}',0xA1,'Ì','Í','Î','Ï','ì','í','î','ï','·'
|
|
||||||
};
|
|
||||||
|
|
||||||
static final Character[] extAEFList = {
|
|
||||||
0x12E, 0x12F, 0x130, 0x131, 0x135, 0x13A, 0x13C, 0x142, 0x163, 0x167, 0x17F
|
|
||||||
};
|
|
||||||
|
|
||||||
static final Character[] cyrilecEFList = {
|
|
||||||
0x406, 0x407, 0x456, 0x457, 0x458
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runic letters list used for game. The set is
|
|
||||||
* Younger Futhark + Medieval rune 'e' + Punct + Runic Almanac
|
|
||||||
*
|
|
||||||
* BEWARE OF SIMILAR-LOOKING RUNES, especially:
|
|
||||||
*
|
|
||||||
* * Algiz ᛉ instead of Maðr ᛘ
|
|
||||||
*
|
|
||||||
* * Short-Twig Hagall ᚽ instead of Runic Letter E ᛂ
|
|
||||||
*
|
|
||||||
* * Runic Letter OE ᚯ instead of Óss ᚬ
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
* ᛭ᛋᛁᚴᚱᛁᚦᛦ᛭
|
|
||||||
* ᛭ᛂᛚᛋᛅ᛭ᛏᚱᚢᛏᚾᛁᚾᚴᚢᚾᛅ᛬ᛅᚱᚾᛅᛏᛅᛚᛋ
|
|
||||||
*/
|
|
||||||
static final Character[] runicList = {
|
|
||||||
'ᚠ','ᚢ','ᚦ','ᚬ','ᚱ','ᚴ','ᚼ','ᚾ','ᛁ','ᛅ','ᛋ','ᛏ','ᛒ','ᛘ','ᛚ','ᛦ'
|
|
||||||
,'ᛂ','᛬','᛫','᛭','ᛮ','ᛯ','ᛰ'
|
|
||||||
};
|
|
||||||
|
|
||||||
static int interchar = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public GameFontBase() throws SlickException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private int[] getHan(int hanIndex) {
|
|
||||||
int han_x = hanIndex % JONG_COUNT;
|
|
||||||
int han_y = hanIndex / JONG_COUNT;
|
|
||||||
int[] ret = {han_x, han_y};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getHanChosung(int hanIndex) {
|
|
||||||
return hanIndex / (JUNG_COUNT * JONG_COUNT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getHanJungseong(int hanIndex) {
|
|
||||||
return hanIndex / (JONG_COUNT) % JUNG_COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getHanJongseong(int hanIndex) {
|
|
||||||
return hanIndex % JONG_COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getHanChoseongRow(int hanIndex) {
|
|
||||||
int jungseongIndex = getHanJungseong(hanIndex);
|
|
||||||
Integer[] jungseongWide = {8, 12, 13, 17, 18, 21};
|
|
||||||
Integer[] jungseongComplex = {9, 10, 11, 14, 15, 16, 22};
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (Arrays.asList(jungseongWide).contains(jungseongIndex)) {
|
|
||||||
ret = 2;
|
|
||||||
}
|
|
||||||
else if (Arrays.asList(jungseongComplex).contains(jungseongIndex)) {
|
|
||||||
ret = 4;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
return (getHanJongseong(hanIndex) == 0) ? ret : ret + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getHanJungseongRow(int hanIndex) {
|
|
||||||
return (getHanJongseong(hanIndex) == 0) ? 6 : 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getHanJongseongRow() {
|
|
||||||
return 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isAsciiEF(char c) {
|
|
||||||
return (Arrays.asList(asciiEFList).contains(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isExtAEF(char c) {
|
|
||||||
return (Arrays.asList(extAEFList).contains(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isHangul(char c) {
|
|
||||||
return (c >= 0xAC00 && c < 0xD7A4);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isAscii(char c) { return (c > 0 && c <= 0xFF); }
|
|
||||||
|
|
||||||
private boolean isRunic(char c) {
|
|
||||||
return (Arrays.asList(runicList).contains(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isExtA(char c) {
|
|
||||||
return (c >= 0x100 && c < 0x180);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isKana(char c) {
|
|
||||||
return (c >= 0x3040 && c < 0x3100);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCJKPunct(char c) {
|
|
||||||
return (c >= 0x3000 && c < 0x3040);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUniHan(char c) {
|
|
||||||
return (c >= 0x3400 && c < 0xA000);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCyrilic(char c) {
|
|
||||||
return (c >= 0x400 && c < 0x460);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCyrilicEF(char c) {
|
|
||||||
return (Arrays.asList(cyrilecEFList).contains(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isFullwidthUni(char c) {
|
|
||||||
return (c >= 0xFF00 && c < 0xFF20);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUniPunct(char c) {
|
|
||||||
return (c >= 0x2000 && c < 0x2070);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isWenQuanYi1(char c) {
|
|
||||||
return (c >= 0x33F3 && c <= 0x69FC);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isWenQuanYi2(char c) {
|
|
||||||
return (c >= 0x69FD && c <= 0x9FDC);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
|
||||||
|
|
||||||
private int asciiEFindexX(char c) {
|
|
||||||
return (Arrays.asList(asciiEFList).indexOf(c) % 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int asciiEFindexY(char c) {
|
|
||||||
return (Arrays.asList(asciiEFList).indexOf(c) / 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int extAEFindexX(char c) {
|
|
||||||
return (Arrays.asList(extAEFList).indexOf(c) % 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int extAEFindexY(char c) {
|
|
||||||
return (Arrays.asList(extAEFList).indexOf(c) / 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int runicIndexX(char c) {
|
|
||||||
return (Arrays.asList(runicList).indexOf(c) % 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int runicIndexY(char c) {
|
|
||||||
return (Arrays.asList(runicList).indexOf(c) / 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int kanaIndexX(char c) {
|
|
||||||
return (c - 0x3040) % 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int kanaIndexY(char c) {
|
|
||||||
return (c - 0x3040) / 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cjkPunctIndexX(char c) {
|
|
||||||
return (c - 0x3000) % 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cjkPunctIndexY(char c) {
|
|
||||||
return (c - 0x3000) / 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int uniHanIndexX(char c) {
|
|
||||||
return (c - 0x3400) % 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int uniHanIndexY(char c) {
|
|
||||||
return (c - 0x3400) / 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cyrilicIndexX(char c) {
|
|
||||||
return (c - 0x400) % 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cyrilicIndexY(char c) {
|
|
||||||
return (c - 0x400) / 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cyrilicEFindexX(char c) {
|
|
||||||
return (Arrays.asList(cyrilecEFList).indexOf(c) % 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int cyrilicEFindexY(char c) {
|
|
||||||
return (Arrays.asList(cyrilecEFList).indexOf(c) / 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int fullwidthUniIndexX(char c) {
|
|
||||||
return (c - 0xFF00) % 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int fullwidthUniIndexY(char c) {
|
|
||||||
return (c - 0xFF00) / 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int uniPunctIndexX(char c) {
|
|
||||||
return (c - 0x2000) % 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int uniPunctIndexY(char c) {
|
|
||||||
return (c - 0x2000) / 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int wenQuanYiIndexX(char c) {
|
|
||||||
// v Ext1 v Unihan
|
|
||||||
return (c - (c <= 0x4DB5 ? 0x33F3 : 0x33F3 + 0x4A)) % 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int wenQuanYi1IndexY(char c) {
|
|
||||||
return (c - (0x33F3 + 0x4A)) / 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int wenQuanYi2IndexY(char c) {
|
|
||||||
return (c - 0x69FD) / 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth(String s) {
|
|
||||||
return getWidthSubstr(s, s.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getWidthSubstr(String s, int endIndex) {
|
|
||||||
int len = 0;
|
|
||||||
for (int i = 0; i < endIndex; i++) {
|
|
||||||
int c = getSheetType(s.charAt(i));
|
|
||||||
|
|
||||||
if (i > 0 && s.charAt(i) > 0x20) { // Kerning
|
|
||||||
int cpre = getSheetType(s.charAt(i - 1));
|
|
||||||
if (
|
|
||||||
((cpre == SHEET_UNIHAN || cpre == SHEET_HANGUL)
|
|
||||||
&& !(c == SHEET_UNIHAN || c == SHEET_HANGUL))
|
|
||||||
|
|
||||||
|| ((c == SHEET_UNIHAN || c == SHEET_HANGUL)
|
|
||||||
&& !(cpre == SHEET_UNIHAN || cpre == SHEET_HANGUL))
|
|
||||||
) {
|
|
||||||
// margin after/before hangul/unihan
|
|
||||||
len += 2;
|
|
||||||
}
|
|
||||||
else if ((c == SHEET_HANGUL || c == SHEET_KANA)
|
|
||||||
&& (cpre == SHEET_HANGUL || cpre == SHEET_KANA)) {
|
|
||||||
// margin between hangul/kana
|
|
||||||
len += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == SHEET_ASCII_EF || c == SHEET_EXTA_EF || c == SHEET_CYRILIC_EF)
|
|
||||||
len += W_LATIN_NARROW;
|
|
||||||
else if (c == SHEET_KANA || c == SHEET_HANGUL || c == SHEET_CJK_PUNCT)
|
|
||||||
len += W_CJK;
|
|
||||||
else if (c == SHEET_UNIHAN || c == SHEET_FW_UNI || c == SHEET_WENQUANYI_1 || c == SHEET_WENQUANYI_2)
|
|
||||||
len += W_UNIHAN;
|
|
||||||
else
|
|
||||||
len += W_LATIN_WIDE;
|
|
||||||
|
|
||||||
if (i < endIndex - 1) len += interchar;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight(String s) {
|
|
||||||
return H;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLineHeight() {
|
|
||||||
return H;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawString(float x, float y, String s) {
|
|
||||||
drawString(x, y, s, Color.white);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawString(float x, float y, String s, Color color) {
|
|
||||||
// hangul fonts first
|
|
||||||
hangulSheet.startUse();
|
|
||||||
// JOHAB
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char ch = s.charAt(i);
|
|
||||||
|
|
||||||
if (isHangul(ch)) {
|
|
||||||
int hIndex = ch - 0xAC00;
|
|
||||||
|
|
||||||
int indexCho = getHanChosung(hIndex);
|
|
||||||
int indexJung = getHanJungseong(hIndex);
|
|
||||||
int indexJong = getHanJongseong(hIndex);
|
|
||||||
|
|
||||||
int choRow = getHanChoseongRow(hIndex);
|
|
||||||
int jungRow = getHanJungseongRow(hIndex);
|
|
||||||
int jongRow = getHanJongseongRow();
|
|
||||||
|
|
||||||
int glyphW = getWidth("" + ch);
|
|
||||||
|
|
||||||
// chosung
|
|
||||||
hangulSheet.renderInUse(
|
|
||||||
Math.round(x
|
|
||||||
+ getWidthSubstr(s, i + 1) - glyphW
|
|
||||||
)
|
|
||||||
, Math.round((H - H_HANGUL) / 2 + y + 1)
|
|
||||||
, indexCho
|
|
||||||
, choRow
|
|
||||||
);
|
|
||||||
// jungseong
|
|
||||||
hangulSheet.renderInUse(
|
|
||||||
Math.round(x
|
|
||||||
+ getWidthSubstr(s, i + 1) - glyphW
|
|
||||||
)
|
|
||||||
, Math.round((H - H_HANGUL) / 2 + y + 1)
|
|
||||||
, indexJung
|
|
||||||
, jungRow
|
|
||||||
);
|
|
||||||
// jongseong
|
|
||||||
hangulSheet.renderInUse(
|
|
||||||
Math.round(x
|
|
||||||
+ getWidthSubstr(s, i + 1) - glyphW
|
|
||||||
)
|
|
||||||
, Math.round((H - H_HANGUL) / 2 + y + 1)
|
|
||||||
, indexJong
|
|
||||||
, jongRow
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hangulSheet.endUse();
|
|
||||||
|
|
||||||
// unihan fonts
|
|
||||||
/*uniHan.startUse();
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char ch = s.charAt(i);
|
|
||||||
|
|
||||||
if (isUniHan(ch)) {
|
|
||||||
int glyphW = getWidth("" + ch);
|
|
||||||
uniHan.renderInUse(
|
|
||||||
Math.round(x
|
|
||||||
+ getWidthSubstr(s, i + 1) - glyphW
|
|
||||||
)
|
|
||||||
, Math.round((H - H_UNIHAN) / 2 + y)
|
|
||||||
, uniHanIndexX(ch)
|
|
||||||
, uniHanIndexY(ch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uniHan.endUse();*/
|
|
||||||
|
|
||||||
// WenQuanYi 1
|
|
||||||
wenQuanYi_1.startUse();
|
|
||||||
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char ch = s.charAt(i);
|
|
||||||
|
|
||||||
if (isWenQuanYi1(ch)) {
|
|
||||||
int glyphW = getWidth("" + ch);
|
|
||||||
wenQuanYi_1.renderInUse(
|
|
||||||
Math.round(x
|
|
||||||
+ getWidthSubstr(s, i + 1) - glyphW
|
|
||||||
)
|
|
||||||
, Math.round((H - H_UNIHAN) / 2 + y - 1)
|
|
||||||
, wenQuanYiIndexX(ch)
|
|
||||||
, wenQuanYi1IndexY(ch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wenQuanYi_1.endUse();
|
|
||||||
wenQuanYi_2.startUse();
|
|
||||||
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char ch = s.charAt(i);
|
|
||||||
|
|
||||||
if (isWenQuanYi2(ch)) {
|
|
||||||
int glyphW = getWidth("" + ch);
|
|
||||||
wenQuanYi_2.renderInUse(
|
|
||||||
Math.round(x
|
|
||||||
+ getWidthSubstr(s, i + 1) - glyphW
|
|
||||||
)
|
|
||||||
, Math.round((H - H_UNIHAN) / 2 + y - 1)
|
|
||||||
, wenQuanYiIndexX(ch)
|
|
||||||
, wenQuanYi2IndexY(ch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wenQuanYi_2.endUse();
|
|
||||||
|
|
||||||
//ascii fonts
|
|
||||||
int prevInstance = -1;
|
|
||||||
for (int i = 0; i < s.length(); i++) {
|
|
||||||
char ch = s.charAt(i);
|
|
||||||
|
|
||||||
if (!isHangul(ch) && !isUniHan(ch)) {
|
|
||||||
|
|
||||||
// if not init, enduse first
|
|
||||||
if (prevInstance != -1) {
|
|
||||||
sheetKey[prevInstance].endUse();
|
|
||||||
}
|
|
||||||
sheetKey[getSheetType(ch)].startUse();
|
|
||||||
prevInstance = getSheetType(ch);
|
|
||||||
|
|
||||||
int sheetX;
|
|
||||||
int sheetY;
|
|
||||||
switch (prevInstance) {
|
|
||||||
case SHEET_ASCII_EF:
|
|
||||||
sheetX = asciiEFindexX(ch);
|
|
||||||
sheetY = asciiEFindexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_EXTA_EF:
|
|
||||||
sheetX = extAEFindexX(ch);
|
|
||||||
sheetY = extAEFindexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_RUNIC:
|
|
||||||
sheetX = runicIndexX(ch);
|
|
||||||
sheetY = runicIndexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_EXTA_EM:
|
|
||||||
sheetX = (ch - 0x100) % 16;
|
|
||||||
sheetY = (ch - 0x100) / 16;
|
|
||||||
break;
|
|
||||||
case SHEET_KANA:
|
|
||||||
sheetX = kanaIndexX(ch);
|
|
||||||
sheetY = kanaIndexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_CJK_PUNCT:
|
|
||||||
sheetX = cjkPunctIndexX(ch);
|
|
||||||
sheetY = cjkPunctIndexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_CYRILIC_EM:
|
|
||||||
sheetX = cyrilicIndexX(ch);
|
|
||||||
sheetY = cyrilicIndexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_CYRILIC_EF:
|
|
||||||
sheetX = cyrilicEFindexX(ch);
|
|
||||||
sheetY = cyrilicEFindexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_FW_UNI:
|
|
||||||
sheetX = fullwidthUniIndexX(ch);
|
|
||||||
sheetY = fullwidthUniIndexY(ch);
|
|
||||||
break;
|
|
||||||
case SHEET_UNI_PUNCT:
|
|
||||||
sheetX = uniPunctIndexX(ch);
|
|
||||||
sheetY = uniPunctIndexY(ch);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sheetX = ch % 16;
|
|
||||||
sheetY = ch / 16;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
int glyphW = getWidth("" + ch);
|
|
||||||
sheetKey[prevInstance].renderInUse(
|
|
||||||
Math.round(x + getWidthSubstr(s, i + 1) - glyphW)
|
|
||||||
// Interchar: pull punct right next to hangul to the left
|
|
||||||
+ ((i > 0 && isHangul(s.charAt(i - 1))) ? -3 : 0)
|
|
||||||
, Math.round(y)
|
|
||||||
+ ((prevInstance == SHEET_CJK_PUNCT) ? -1 :
|
|
||||||
(prevInstance == SHEET_FW_UNI) ? (H - H_HANGUL) / 2 : 0)
|
|
||||||
, sheetX
|
|
||||||
, sheetY
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
// System.out.println("ArrayIndexOutOfBoundsException")
|
|
||||||
// System.out.println("char: '" + ch + "' (" + String.valueOf((int) ch) + ")");
|
|
||||||
// System.out.println("sheet: " + prevInstance);
|
|
||||||
// System.out.println("sheetX: " + sheetX);
|
|
||||||
// System.out.println("sheetY: " + sheetY);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (prevInstance != -1) {
|
|
||||||
sheetKey[prevInstance].endUse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getSheetType(char c) {
|
|
||||||
// EFs
|
|
||||||
if (isAsciiEF(c)) return SHEET_ASCII_EF;
|
|
||||||
else if (isExtAEF(c)) return SHEET_EXTA_EF;
|
|
||||||
else if (isCyrilicEF(c)) return SHEET_CYRILIC_EF;
|
|
||||||
// fixed width
|
|
||||||
else if (isRunic(c)) return SHEET_RUNIC;
|
|
||||||
else if (isHangul(c)) return SHEET_HANGUL;
|
|
||||||
else if (isKana(c)) return SHEET_KANA;
|
|
||||||
else if (isUniHan(c)) return SHEET_UNIHAN;
|
|
||||||
else if (isAscii(c)) return SHEET_ASCII_EM;
|
|
||||||
else if (isExtA(c)) return SHEET_EXTA_EM;
|
|
||||||
else if (isCyrilic(c)) return SHEET_CYRILIC_EM;
|
|
||||||
else if (isUniPunct(c)) return SHEET_UNI_PUNCT;
|
|
||||||
// fixed width punctuations
|
|
||||||
else if (isCJKPunct(c)) return SHEET_CJK_PUNCT;
|
|
||||||
else if (isFullwidthUni(c)) return SHEET_FW_UNI;
|
|
||||||
|
|
||||||
else return SHEET_ASCII_EM; // fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw part of a string to the screen. Note that this will still position the text as though
|
|
||||||
* it's part of the bigger string.
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param s
|
|
||||||
* @param color
|
|
||||||
* @param startIndex
|
|
||||||
* @param endIndex
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void drawString(float x, float y, String s, Color color, int startIndex, int endIndex) {
|
|
||||||
String unprintedHead = s.substring(0, startIndex);
|
|
||||||
String printedBody = s.substring(startIndex, endIndex);
|
|
||||||
int xoff = getWidth(unprintedHead);
|
|
||||||
drawString(x + xoff, y, printedBody, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadUnihan() throws SlickException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set margin between characters
|
|
||||||
* @param margin
|
|
||||||
*/
|
|
||||||
public void setInterchar(int margin) {
|
|
||||||
interchar = margin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setBlendModeMul() {
|
|
||||||
GL11.glEnable(GL11.GL_BLEND);
|
|
||||||
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setBlendModeNormal() {
|
|
||||||
GL11.glDisable(GL11.GL_BLEND);
|
|
||||||
Terrarum.appgc.getGraphics().setDrawMode(Graphics.MODE_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
500
src/com/Torvald/ImageFont/GameFontBase.kt
Normal file
@@ -0,0 +1,500 @@
|
|||||||
|
package com.Torvald.ImageFont
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
import org.newdawn.slick.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-01-27.
|
||||||
|
*/
|
||||||
|
open class GameFontBase @Throws(SlickException::class)
|
||||||
|
constructor() : Font {
|
||||||
|
|
||||||
|
private fun getHan(hanIndex: Int): IntArray {
|
||||||
|
val han_x = hanIndex % JONG_COUNT
|
||||||
|
val han_y = hanIndex / JONG_COUNT
|
||||||
|
val ret = intArrayOf(han_x, han_y)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getHanChosung(hanIndex: Int) = hanIndex / (JUNG_COUNT * JONG_COUNT)
|
||||||
|
|
||||||
|
private fun getHanJungseong(hanIndex: Int) = hanIndex / JONG_COUNT % JUNG_COUNT
|
||||||
|
|
||||||
|
private fun getHanJongseong(hanIndex: Int) = hanIndex % JONG_COUNT
|
||||||
|
|
||||||
|
|
||||||
|
private fun getHanChoseongRow(hanIndex: Int): Int {
|
||||||
|
val jungseongIndex = getHanJungseong(hanIndex)
|
||||||
|
val jungseongWide = arrayOf(8, 12, 13, 17, 18, 21)
|
||||||
|
val jungseongComplex = arrayOf(9, 10, 11, 14, 15, 16, 22)
|
||||||
|
val ret: Int
|
||||||
|
|
||||||
|
if (jungseongWide.contains(jungseongIndex)) {
|
||||||
|
ret = 2
|
||||||
|
}
|
||||||
|
else if (jungseongComplex.contains(jungseongIndex)) {
|
||||||
|
ret = 4
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = 0
|
||||||
|
}
|
||||||
|
return if (getHanJongseong(hanIndex) == 0) ret else ret + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getHanJungseongRow(hanIndex: Int) = if (getHanJongseong(hanIndex) == 0) 6 else 7
|
||||||
|
|
||||||
|
private val hanJongseongRow: Int
|
||||||
|
get() = 8
|
||||||
|
|
||||||
|
private fun isAsciiEF(c: Char) = asciiEFList.contains(c)
|
||||||
|
|
||||||
|
private fun isExtAEF(c: Char) = extAEFList.contains(c)
|
||||||
|
|
||||||
|
private fun isHangul(c: Char) = c.toInt() >= 0xAC00 && c.toInt() < 0xD7A4
|
||||||
|
|
||||||
|
private fun isAscii(c: Char) = c.toInt() > 0 && c.toInt() <= 0xFF
|
||||||
|
|
||||||
|
private fun isRunic(c: Char) = runicList.contains(c)
|
||||||
|
|
||||||
|
private fun isExtA(c: Char) = c.toInt() >= 0x100 && c.toInt() < 0x180
|
||||||
|
|
||||||
|
private fun isKana(c: Char) = c.toInt() >= 0x3040 && c.toInt() < 0x3100
|
||||||
|
|
||||||
|
private fun isCJKPunct(c: Char) = c.toInt() >= 0x3000 && c.toInt() < 0x3040
|
||||||
|
|
||||||
|
private fun isUniHan(c: Char) = c.toInt() >= 0x3400 && c.toInt() < 0xA000
|
||||||
|
|
||||||
|
private fun isCyrilic(c: Char) = c.toInt() >= 0x400 && c.toInt() < 0x460
|
||||||
|
|
||||||
|
private fun isCyrilicEF(c: Char) = cyrilecEFList.contains(c)
|
||||||
|
|
||||||
|
private fun isFullwidthUni(c: Char) = c.toInt() >= 0xFF00 && c.toInt() < 0xFF20
|
||||||
|
|
||||||
|
private fun isUniPunct(c: Char) = c.toInt() >= 0x2000 && c.toInt() < 0x2070
|
||||||
|
|
||||||
|
private fun isWenQuanYi1(c: Char) = c.toInt() >= 0x33F3 && c.toInt() <= 0x69FC
|
||||||
|
|
||||||
|
private fun isWenQuanYi2(c: Char) = c.toInt() >= 0x69FD && c.toInt() <= 0x9FDC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun asciiEFindexX(c: Char) = asciiEFList.indexOf(c) % 16
|
||||||
|
private fun asciiEFindexY(c: Char) = asciiEFList.indexOf(c) / 16
|
||||||
|
|
||||||
|
private fun extAEFindexX(c: Char) = extAEFList.indexOf(c) % 16
|
||||||
|
private fun extAEFindexY(c: Char) = extAEFList.indexOf(c) / 16
|
||||||
|
|
||||||
|
private fun runicIndexX(c: Char) = runicList.indexOf(c) % 16
|
||||||
|
private fun runicIndexY(c: Char) = runicList.indexOf(c) / 16
|
||||||
|
|
||||||
|
private fun kanaIndexX(c: Char) = (c.toInt() - 0x3040) % 16
|
||||||
|
private fun kanaIndexY(c: Char) = (c.toInt() - 0x3040) / 16
|
||||||
|
|
||||||
|
private fun cjkPunctIndexX(c: Char) = (c.toInt() - 0x3000) % 16
|
||||||
|
private fun cjkPunctIndexY(c: Char) = (c.toInt() - 0x3000) / 16
|
||||||
|
|
||||||
|
private fun uniHanIndexX(c: Char) = (c.toInt() - 0x3400) % 256
|
||||||
|
private fun uniHanIndexY(c: Char) = (c.toInt() - 0x3400) / 256
|
||||||
|
|
||||||
|
private fun cyrilicIndexX(c: Char) = (c.toInt() - 0x400) % 16
|
||||||
|
private fun cyrilicIndexY(c: Char) = (c.toInt() - 0x400) / 16
|
||||||
|
|
||||||
|
private fun cyrilicEFindexX(c: Char) = cyrilecEFList.indexOf(c) % 16
|
||||||
|
private fun cyrilicEFindexY(c: Char) = cyrilecEFList.indexOf(c) / 16
|
||||||
|
|
||||||
|
private fun fullwidthUniIndexX(c: Char) = (c.toInt() - 0xFF00) % 16
|
||||||
|
private fun fullwidthUniIndexY(c: Char) = (c.toInt() - 0xFF00) / 16
|
||||||
|
|
||||||
|
private fun uniPunctIndexX(c: Char) = (c.toInt() - 0x2000) % 16
|
||||||
|
private fun uniPunctIndexY(c: Char) = (c.toInt() - 0x2000) / 16
|
||||||
|
|
||||||
|
private fun wenQuanYiIndexX(c: Char) =
|
||||||
|
(c.toInt() - if (c.toInt() <= 0x4DB5) 0x33F3 else 0x33F3 + 0x4A) % 32
|
||||||
|
private fun wenQuanYi1IndexY(c: Char) = (c.toInt() - (0x33F3 + 0x4A)) / 32
|
||||||
|
private fun wenQuanYi2IndexY(c: Char) = (c.toInt() - 0x69FD) / 32
|
||||||
|
|
||||||
|
override fun getWidth(s: String) = getWidthSubstr(s, s.length)
|
||||||
|
|
||||||
|
|
||||||
|
private fun getWidthSubstr(s: String, endIndex: Int): Int {
|
||||||
|
var len = 0
|
||||||
|
for (i in 0..endIndex - 1) {
|
||||||
|
val c = getSheetType(s[i])
|
||||||
|
|
||||||
|
if (i > 0 && s[i].toInt() > 0x20) {
|
||||||
|
// Kerning
|
||||||
|
val cpre = getSheetType(s[i - 1])
|
||||||
|
if ((cpre == SHEET_UNIHAN || cpre == SHEET_HANGUL) && !(c == SHEET_UNIHAN || c == SHEET_HANGUL)
|
||||||
|
|
||||||
|
|| (c == SHEET_UNIHAN || c == SHEET_HANGUL) && !(cpre == SHEET_UNIHAN || cpre == SHEET_HANGUL)) {
|
||||||
|
// margin after/before hangul/unihan
|
||||||
|
len += 2
|
||||||
|
}
|
||||||
|
else if ((c == SHEET_HANGUL || c == SHEET_KANA) && (cpre == SHEET_HANGUL || cpre == SHEET_KANA)) {
|
||||||
|
// margin between hangul/kana
|
||||||
|
len += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == SHEET_ASCII_EF || c == SHEET_EXTA_EF || c == SHEET_CYRILIC_EF)
|
||||||
|
len += W_LATIN_NARROW
|
||||||
|
else if (c == SHEET_KANA || c == SHEET_HANGUL || c == SHEET_CJK_PUNCT)
|
||||||
|
len += W_CJK
|
||||||
|
else if (c == SHEET_UNIHAN || c == SHEET_FW_UNI || c == SHEET_WENQUANYI_1 || c == SHEET_WENQUANYI_2)
|
||||||
|
len += W_UNIHAN
|
||||||
|
else
|
||||||
|
len += W_LATIN_WIDE
|
||||||
|
|
||||||
|
if (i < endIndex - 1) len += interchar
|
||||||
|
}
|
||||||
|
return len
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getHeight(s: String) = H
|
||||||
|
|
||||||
|
override fun getLineHeight() = H
|
||||||
|
|
||||||
|
override fun drawString(x: Float, y: Float, s: String) {
|
||||||
|
drawString(x, y, s, Color.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun drawString(x: Float, y: Float, s: String, color: Color) {
|
||||||
|
// hangul fonts first
|
||||||
|
hangulSheet.startUse()
|
||||||
|
// JOHAB
|
||||||
|
for (i in 0..s.length - 1) {
|
||||||
|
val ch = s[i]
|
||||||
|
|
||||||
|
if (isHangul(ch)) {
|
||||||
|
val hIndex = ch.toInt() - 0xAC00
|
||||||
|
|
||||||
|
val indexCho = getHanChosung(hIndex)
|
||||||
|
val indexJung = getHanJungseong(hIndex)
|
||||||
|
val indexJong = getHanJongseong(hIndex)
|
||||||
|
|
||||||
|
val choRow = getHanChoseongRow(hIndex)
|
||||||
|
val jungRow = getHanJungseongRow(hIndex)
|
||||||
|
val jongRow = hanJongseongRow
|
||||||
|
|
||||||
|
val glyphW = getWidth("" + ch)
|
||||||
|
|
||||||
|
// chosung
|
||||||
|
hangulSheet.renderInUse(
|
||||||
|
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f), indexCho, choRow)
|
||||||
|
// jungseong
|
||||||
|
hangulSheet.renderInUse(
|
||||||
|
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f), indexJung, jungRow)
|
||||||
|
// jongseong
|
||||||
|
hangulSheet.renderInUse(
|
||||||
|
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f), indexJong, jongRow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hangulSheet.endUse()
|
||||||
|
|
||||||
|
// unihan fonts
|
||||||
|
/*uniHan.startUse();
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char ch = s.charAt(i);
|
||||||
|
|
||||||
|
if (isUniHan(ch)) {
|
||||||
|
int glyphW = getWidth("" + ch);
|
||||||
|
uniHan.renderInUse(
|
||||||
|
Math.round(x
|
||||||
|
+ getWidthSubstr(s, i + 1) - glyphW
|
||||||
|
)
|
||||||
|
, Math.round((H - H_UNIHAN) / 2 + y)
|
||||||
|
, uniHanIndexX(ch)
|
||||||
|
, uniHanIndexY(ch)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uniHan.endUse();*/
|
||||||
|
|
||||||
|
// WenQuanYi 1
|
||||||
|
wenQuanYi_1.startUse()
|
||||||
|
|
||||||
|
for (i in 0..s.length - 1) {
|
||||||
|
val ch = s[i]
|
||||||
|
|
||||||
|
if (isWenQuanYi1(ch)) {
|
||||||
|
val glyphW = getWidth("" + ch)
|
||||||
|
wenQuanYi_1.renderInUse(
|
||||||
|
Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
|
||||||
|
Math.round((H - H_UNIHAN) / 2 + y),
|
||||||
|
wenQuanYiIndexX(ch),
|
||||||
|
wenQuanYi1IndexY(ch)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wenQuanYi_1.endUse()
|
||||||
|
wenQuanYi_2.startUse()
|
||||||
|
|
||||||
|
for (i in 0..s.length - 1) {
|
||||||
|
val ch = s[i]
|
||||||
|
|
||||||
|
if (isWenQuanYi2(ch)) {
|
||||||
|
val glyphW = getWidth("" + ch)
|
||||||
|
wenQuanYi_2.renderInUse(
|
||||||
|
Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
|
||||||
|
Math.round((H - H_UNIHAN) / 2 + y),
|
||||||
|
wenQuanYiIndexX(ch),
|
||||||
|
wenQuanYi2IndexY(ch)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wenQuanYi_2.endUse()
|
||||||
|
|
||||||
|
//ascii fonts
|
||||||
|
var prevInstance = -1
|
||||||
|
for (i in 0..s.length - 1) {
|
||||||
|
val ch = s[i]
|
||||||
|
|
||||||
|
if (!isHangul(ch) && !isUniHan(ch)) {
|
||||||
|
|
||||||
|
// if not init, endUse first
|
||||||
|
if (prevInstance != -1) {
|
||||||
|
sheetKey[prevInstance].endUse()
|
||||||
|
}
|
||||||
|
sheetKey[getSheetType(ch)].startUse()
|
||||||
|
prevInstance = getSheetType(ch)
|
||||||
|
|
||||||
|
val sheetX: Int
|
||||||
|
val sheetY: Int
|
||||||
|
when (prevInstance) {
|
||||||
|
SHEET_ASCII_EF -> {
|
||||||
|
sheetX = asciiEFindexX(ch)
|
||||||
|
sheetY = asciiEFindexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_EXTA_EF -> {
|
||||||
|
sheetX = extAEFindexX(ch)
|
||||||
|
sheetY = extAEFindexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_RUNIC -> {
|
||||||
|
sheetX = runicIndexX(ch)
|
||||||
|
sheetY = runicIndexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_EXTA_EM -> {
|
||||||
|
sheetX = (ch.toInt() - 0x100) % 16
|
||||||
|
sheetY = (ch.toInt() - 0x100) / 16
|
||||||
|
}
|
||||||
|
SHEET_KANA -> {
|
||||||
|
sheetX = kanaIndexX(ch)
|
||||||
|
sheetY = kanaIndexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_CJK_PUNCT -> {
|
||||||
|
sheetX = cjkPunctIndexX(ch)
|
||||||
|
sheetY = cjkPunctIndexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_CYRILIC_EM -> {
|
||||||
|
sheetX = cyrilicIndexX(ch)
|
||||||
|
sheetY = cyrilicIndexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_CYRILIC_EF -> {
|
||||||
|
sheetX = cyrilicEFindexX(ch)
|
||||||
|
sheetY = cyrilicEFindexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_FW_UNI -> {
|
||||||
|
sheetX = fullwidthUniIndexX(ch)
|
||||||
|
sheetY = fullwidthUniIndexY(ch)
|
||||||
|
}
|
||||||
|
SHEET_UNI_PUNCT -> {
|
||||||
|
sheetX = uniPunctIndexX(ch)
|
||||||
|
sheetY = uniPunctIndexY(ch)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
sheetX = ch.toInt() % 16
|
||||||
|
sheetY = ch.toInt() / 16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val glyphW = getWidth("" + ch)
|
||||||
|
sheetKey[prevInstance].renderInUse(
|
||||||
|
Math.round(x + getWidthSubstr(s, i + 1) - glyphW) // Interchar: pull punct right next to hangul to the left
|
||||||
|
+ if (i > 0 && isHangul(s[i - 1])) -3 else 0, Math.round(y) + if (prevInstance == SHEET_CJK_PUNCT)
|
||||||
|
-1
|
||||||
|
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2 else 0, sheetX, sheetY)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (prevInstance != -1) {
|
||||||
|
sheetKey[prevInstance].endUse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSheetType(c: Char): Int {
|
||||||
|
// EFs
|
||||||
|
if (isAsciiEF(c))
|
||||||
|
return SHEET_ASCII_EF
|
||||||
|
else if (isExtAEF(c))
|
||||||
|
return SHEET_EXTA_EF
|
||||||
|
else if (isCyrilicEF(c))
|
||||||
|
return SHEET_CYRILIC_EF
|
||||||
|
else if (isRunic(c))
|
||||||
|
return SHEET_RUNIC
|
||||||
|
else if (isHangul(c))
|
||||||
|
return SHEET_HANGUL
|
||||||
|
else if (isKana(c))
|
||||||
|
return SHEET_KANA
|
||||||
|
else if (isUniHan(c))
|
||||||
|
return SHEET_UNIHAN
|
||||||
|
else if (isAscii(c))
|
||||||
|
return SHEET_ASCII_EM
|
||||||
|
else if (isExtA(c))
|
||||||
|
return SHEET_EXTA_EM
|
||||||
|
else if (isCyrilic(c))
|
||||||
|
return SHEET_CYRILIC_EM
|
||||||
|
else if (isUniPunct(c))
|
||||||
|
return SHEET_UNI_PUNCT
|
||||||
|
else if (isCJKPunct(c))
|
||||||
|
return SHEET_CJK_PUNCT
|
||||||
|
else if (isFullwidthUni(c))
|
||||||
|
return SHEET_FW_UNI
|
||||||
|
else
|
||||||
|
return SHEET_ASCII_EM// fixed width punctuations
|
||||||
|
// fixed width
|
||||||
|
// fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw part of a string to the screen. Note that this will still position the text as though
|
||||||
|
* it's part of the bigger string.
|
||||||
|
* @param x
|
||||||
|
* *
|
||||||
|
* @param y
|
||||||
|
* *
|
||||||
|
* @param s
|
||||||
|
* *
|
||||||
|
* @param color
|
||||||
|
* *
|
||||||
|
* @param startIndex
|
||||||
|
* *
|
||||||
|
* @param endIndex
|
||||||
|
*/
|
||||||
|
override fun drawString(x: Float, y: Float, s: String, color: Color, startIndex: Int, endIndex: Int) {
|
||||||
|
val unprintedHead = s.substring(0, startIndex)
|
||||||
|
val printedBody = s.substring(startIndex, endIndex)
|
||||||
|
val xoff = getWidth(unprintedHead)
|
||||||
|
drawString(x + xoff, y, printedBody, color)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(SlickException::class)
|
||||||
|
open fun reloadUnihan() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set margin between characters
|
||||||
|
* @param margin
|
||||||
|
*/
|
||||||
|
fun setInterchar(margin: Int) {
|
||||||
|
interchar = margin
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setBlendModeMul() {
|
||||||
|
GL11.glEnable(GL11.GL_BLEND)
|
||||||
|
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setBlendModeNormal() {
|
||||||
|
GL11.glDisable(GL11.GL_BLEND)
|
||||||
|
Terrarum.appgc.graphics.setDrawMode(Graphics.MODE_NORMAL)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
lateinit internal var hangulSheet: SpriteSheet
|
||||||
|
lateinit internal var asciiSheet: SpriteSheet
|
||||||
|
lateinit internal var asciiSheetEF: SpriteSheet
|
||||||
|
lateinit internal var runicSheet: SpriteSheet
|
||||||
|
lateinit internal var extASheet: SpriteSheet
|
||||||
|
lateinit internal var extASheetEF: SpriteSheet
|
||||||
|
lateinit internal var kanaSheet: SpriteSheet
|
||||||
|
lateinit internal var cjkPunct: SpriteSheet
|
||||||
|
// static SpriteSheet uniHan;
|
||||||
|
lateinit internal var cyrilic: SpriteSheet
|
||||||
|
lateinit internal var cyrilicEF: SpriteSheet
|
||||||
|
lateinit internal var fullwidthForms: SpriteSheet
|
||||||
|
lateinit internal var uniPunct: SpriteSheet
|
||||||
|
lateinit internal var wenQuanYi_1: SpriteSheet
|
||||||
|
lateinit internal var wenQuanYi_2: SpriteSheet
|
||||||
|
|
||||||
|
internal val JUNG_COUNT = 21
|
||||||
|
internal val JONG_COUNT = 28
|
||||||
|
|
||||||
|
internal val W_CJK = 10
|
||||||
|
internal val W_UNIHAN = 16
|
||||||
|
internal val W_LATIN_WIDE = 9 // width of regular letters, including m
|
||||||
|
internal val W_LATIN_NARROW = 5 // width of letter f, t, i, l
|
||||||
|
internal val H = 20
|
||||||
|
internal val H_HANGUL = 16
|
||||||
|
internal val H_UNIHAN = 16
|
||||||
|
internal val H_KANA = 20
|
||||||
|
|
||||||
|
internal val SHEET_ASCII_EM = 0
|
||||||
|
internal val SHEET_ASCII_EF = 1
|
||||||
|
internal val SHEET_HANGUL = 2
|
||||||
|
internal val SHEET_RUNIC = 3
|
||||||
|
internal val SHEET_EXTA_EM = 4
|
||||||
|
internal val SHEET_EXTA_EF = 5
|
||||||
|
internal val SHEET_KANA = 6
|
||||||
|
internal val SHEET_CJK_PUNCT = 7
|
||||||
|
internal val SHEET_UNIHAN = 8
|
||||||
|
internal val SHEET_CYRILIC_EM = 9
|
||||||
|
internal val SHEET_CYRILIC_EF = 10
|
||||||
|
internal val SHEET_FW_UNI = 11
|
||||||
|
internal val SHEET_UNI_PUNCT = 12
|
||||||
|
internal val SHEET_WENQUANYI_1 = 13
|
||||||
|
internal val SHEET_WENQUANYI_2 = 14
|
||||||
|
|
||||||
|
lateinit internal var sheetKey: Array<SpriteSheet>
|
||||||
|
internal val asciiEFList = arrayOf(' ', '!', '"', '\'', '(', ')', ',', '.', ':', ';', 'I', '[', ']', '`', 'f', 'i', 'j', 'l', 't', '{', '|', '}', 0xA1.toChar(), 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', '·')
|
||||||
|
|
||||||
|
internal val extAEFList = arrayOf(
|
||||||
|
0x12E.toChar(),
|
||||||
|
0x12F.toChar(),
|
||||||
|
0x130.toChar(),
|
||||||
|
0x131.toChar(),
|
||||||
|
0x135.toChar(),
|
||||||
|
0x13A.toChar(),
|
||||||
|
0x13C.toChar(),
|
||||||
|
0x142.toChar(),
|
||||||
|
0x163.toChar(),
|
||||||
|
0x167.toChar(),
|
||||||
|
0x17F.toChar()
|
||||||
|
)
|
||||||
|
|
||||||
|
internal val cyrilecEFList = arrayOf(
|
||||||
|
0x406.toChar(),
|
||||||
|
0x407.toChar(),
|
||||||
|
0x456.toChar(),
|
||||||
|
0x457.toChar(),
|
||||||
|
0x458.toChar()
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runic letters list used for game. The set is
|
||||||
|
* Younger Futhark + Medieval rune 'e' + Punct + Runic Almanac
|
||||||
|
|
||||||
|
* BEWARE OF SIMILAR-LOOKING RUNES, especially:
|
||||||
|
|
||||||
|
* * Algiz ᛉ instead of Maðr ᛘ
|
||||||
|
|
||||||
|
* * Short-Twig Hagall ᚽ instead of Runic Letter E ᛂ
|
||||||
|
|
||||||
|
* * Runic Letter OE ᚯ instead of Óss ᚬ
|
||||||
|
|
||||||
|
* Examples:
|
||||||
|
* ᛭ᛋᛁᚴᚱᛁᚦᛦ᛭
|
||||||
|
* ᛭ᛂᛚᛋᛅ᛭ᛏᚱᚢᛏᚾᛁᚾᚴᚢᚾᛅ᛬ᛅᚱᚾᛅᛏᛅᛚᛋ
|
||||||
|
*/
|
||||||
|
internal val runicList = arrayOf('ᚠ', 'ᚢ', 'ᚦ', 'ᚬ', 'ᚱ', 'ᚴ', 'ᚼ', 'ᚾ', 'ᛁ', 'ᛅ', 'ᛋ', 'ᛏ', 'ᛒ', 'ᛘ', 'ᛚ', 'ᛦ', 'ᛂ', '᛬', '᛫', '᛭', 'ᛮ', 'ᛯ', 'ᛰ')
|
||||||
|
|
||||||
|
internal var interchar = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package com.Torvald.ImageFont;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
import org.newdawn.slick.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-20.
|
|
||||||
*/
|
|
||||||
public class GameFontWhite extends GameFontBase {
|
|
||||||
|
|
||||||
public GameFontWhite() throws SlickException {
|
|
||||||
super();
|
|
||||||
|
|
||||||
hangulSheet = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/han_johab.png"
|
|
||||||
, W_CJK, H_HANGUL
|
|
||||||
);
|
|
||||||
asciiSheet = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/ascii_majuscule.png"
|
|
||||||
, W_LATIN_WIDE, H
|
|
||||||
);
|
|
||||||
asciiSheetEF = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/ascii_special_ef.png"
|
|
||||||
, W_LATIN_NARROW, H
|
|
||||||
);
|
|
||||||
runicSheet = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/futhark.png"
|
|
||||||
, W_LATIN_WIDE, H
|
|
||||||
);
|
|
||||||
extASheet = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/LatinExtA_majuscule.png"
|
|
||||||
, W_LATIN_WIDE, H
|
|
||||||
);
|
|
||||||
extASheetEF = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/LatinExtA_ef.png"
|
|
||||||
, W_LATIN_NARROW, H
|
|
||||||
);
|
|
||||||
kanaSheet = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/kana.png"
|
|
||||||
, W_CJK, H_KANA
|
|
||||||
);
|
|
||||||
cjkPunct = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/cjkpunct.png"
|
|
||||||
, W_CJK, H_KANA
|
|
||||||
);
|
|
||||||
/*uniHan = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/unifont_unihan"
|
|
||||||
+ ((!Terrarum.gameLocale.contains("zh"))
|
|
||||||
? "_ja" : "")
|
|
||||||
+".png"
|
|
||||||
, W_UNIHAN, H_UNIHAN
|
|
||||||
);*/
|
|
||||||
cyrilic = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/cyrilic_majuscule.png"
|
|
||||||
, W_LATIN_WIDE, H
|
|
||||||
);
|
|
||||||
cyrilicEF = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/cyrilic_ef.png"
|
|
||||||
, W_LATIN_NARROW, H
|
|
||||||
);
|
|
||||||
fullwidthForms = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/fullwidth_forms.png"
|
|
||||||
, W_UNIHAN, H_UNIHAN
|
|
||||||
);
|
|
||||||
uniPunct = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/unipunct.png"
|
|
||||||
, W_LATIN_WIDE, H
|
|
||||||
);
|
|
||||||
wenQuanYi_1 = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/wenquanyi_11pt_part1.png"
|
|
||||||
, 16, 18, 2
|
|
||||||
);
|
|
||||||
wenQuanYi_2 = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/wenquanyi_11pt_part2.png"
|
|
||||||
, 16, 18, 2
|
|
||||||
);
|
|
||||||
|
|
||||||
SpriteSheet[] shk = {
|
|
||||||
asciiSheet
|
|
||||||
, asciiSheetEF
|
|
||||||
, hangulSheet
|
|
||||||
, runicSheet
|
|
||||||
, extASheet
|
|
||||||
, extASheetEF
|
|
||||||
, kanaSheet
|
|
||||||
, cjkPunct
|
|
||||||
//, uniHan
|
|
||||||
, null
|
|
||||||
, cyrilic
|
|
||||||
, cyrilicEF
|
|
||||||
, fullwidthForms
|
|
||||||
, uniPunct
|
|
||||||
, wenQuanYi_1
|
|
||||||
, wenQuanYi_2
|
|
||||||
};
|
|
||||||
sheetKey = shk;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reloadUnihan() throws SlickException {
|
|
||||||
/*uniHan = new SpriteSheet(
|
|
||||||
"./res/graphics/fonts/unifont_unihan"
|
|
||||||
+ ((!Terrarum.gameLocale.contains("zh"))
|
|
||||||
? "_ja" : "")
|
|
||||||
+".png"
|
|
||||||
, W_UNIHAN, H_UNIHAN
|
|
||||||
);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
79
src/com/Torvald/ImageFont/GameFontWhite.kt
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package com.Torvald.ImageFont
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
import org.newdawn.slick.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-01-20.
|
||||||
|
*/
|
||||||
|
class GameFontWhite @Throws(SlickException::class)
|
||||||
|
constructor() : GameFontBase() {
|
||||||
|
|
||||||
|
init {
|
||||||
|
|
||||||
|
GameFontBase.hangulSheet = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/han_johab.png", GameFontBase.W_CJK, GameFontBase.H_HANGUL)
|
||||||
|
GameFontBase.asciiSheet = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/ascii_majuscule.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
|
||||||
|
GameFontBase.asciiSheetEF = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/ascii_special_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
|
||||||
|
GameFontBase.runicSheet = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/futhark.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
|
||||||
|
GameFontBase.extASheet = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/LatinExtA_majuscule.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
|
||||||
|
GameFontBase.extASheetEF = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/LatinExtA_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
|
||||||
|
GameFontBase.kanaSheet = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/kana.png", GameFontBase.W_CJK, GameFontBase.H_KANA)
|
||||||
|
GameFontBase.cjkPunct = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/cjkpunct.png", GameFontBase.W_CJK, GameFontBase.H_KANA)
|
||||||
|
/*uniHan = new SpriteSheet(
|
||||||
|
"./res/graphics/fonts/unifont_unihan"
|
||||||
|
+ ((!Terrarum.gameLocale.contains("zh"))
|
||||||
|
? "_ja" : "")
|
||||||
|
+".png"
|
||||||
|
, W_UNIHAN, H_UNIHAN
|
||||||
|
);*/
|
||||||
|
GameFontBase.cyrilic = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/cyrilic_majuscule.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
|
||||||
|
GameFontBase.cyrilicEF = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/cyrilic_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
|
||||||
|
GameFontBase.fullwidthForms = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/fullwidth_forms.png", GameFontBase.W_UNIHAN, GameFontBase.H_UNIHAN)
|
||||||
|
GameFontBase.uniPunct = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/unipunct.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
|
||||||
|
GameFontBase.wenQuanYi_1 = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/wenquanyi_11pt_part1.png", 16, 18, 2)
|
||||||
|
GameFontBase.wenQuanYi_2 = SpriteSheet(
|
||||||
|
"./res/graphics/fonts/wenquanyi_11pt_part2.png", 16, 18, 2)
|
||||||
|
|
||||||
|
val shk = arrayOf<SpriteSheet>(
|
||||||
|
GameFontBase.asciiSheet,
|
||||||
|
GameFontBase.asciiSheetEF,
|
||||||
|
GameFontBase.hangulSheet,
|
||||||
|
GameFontBase.runicSheet,
|
||||||
|
GameFontBase.extASheet,
|
||||||
|
GameFontBase.extASheetEF,
|
||||||
|
GameFontBase.kanaSheet,
|
||||||
|
GameFontBase.cjkPunct,
|
||||||
|
GameFontBase.asciiSheet, // Filler
|
||||||
|
GameFontBase.cyrilic,
|
||||||
|
GameFontBase.cyrilicEF,
|
||||||
|
GameFontBase.fullwidthForms,
|
||||||
|
GameFontBase.uniPunct,
|
||||||
|
GameFontBase.wenQuanYi_1,
|
||||||
|
GameFontBase.wenQuanYi_2)//, uniHan
|
||||||
|
GameFontBase.sheetKey = shk
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(SlickException::class)
|
||||||
|
override fun reloadUnihan() {
|
||||||
|
/*uniHan = new SpriteSheet(
|
||||||
|
"./res/graphics/fonts/unifont_unihan"
|
||||||
|
+ ((!Terrarum.gameLocale.contains("zh"))
|
||||||
|
? "_ja" : "")
|
||||||
|
+".png"
|
||||||
|
, W_UNIHAN, H_UNIHAN
|
||||||
|
);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.Torvald;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.FileSystems;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-15.
|
|
||||||
*/
|
|
||||||
public class JsonFetcher {
|
|
||||||
|
|
||||||
private static StringBuffer jsonString;
|
|
||||||
|
|
||||||
public static JsonObject readJson(String jsonFilePath) throws IOException {
|
|
||||||
jsonString = new StringBuffer(); // reset buffer every time it called
|
|
||||||
readJsonFileAsString(jsonFilePath);
|
|
||||||
|
|
||||||
JsonParser jsonParser = new JsonParser();
|
|
||||||
JsonObject jsonObj = jsonParser.parse(jsonString.toString()).getAsJsonObject();
|
|
||||||
|
|
||||||
return jsonObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<String> readJsonAsString(String jsonFilePath) throws IOException {
|
|
||||||
ArrayList<String> jsonFileLines = new ArrayList<>();
|
|
||||||
Files.lines(
|
|
||||||
FileSystems.getDefault().getPath(jsonFilePath)
|
|
||||||
).forEach(jsonFileLines::add);
|
|
||||||
return jsonFileLines;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void readJsonFileAsString(String path) throws IOException {
|
|
||||||
Files.lines(
|
|
||||||
FileSystems.getDefault().getPath(path)
|
|
||||||
).forEach(jsonString::append); // JSON does not require line break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
36
src/com/Torvald/JsonFetcher.kt
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package com.Torvald
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import com.google.gson.JsonParser
|
||||||
|
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.FileSystems
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.util.ArrayList
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-02-15.
|
||||||
|
*/
|
||||||
|
object JsonFetcher {
|
||||||
|
|
||||||
|
private var jsonString: StringBuffer? = null
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun readJson(jsonFilePath: String): JsonObject {
|
||||||
|
jsonString = StringBuffer() // reset buffer every time it called
|
||||||
|
readJsonFileAsString(jsonFilePath)
|
||||||
|
|
||||||
|
val jsonParser = JsonParser()
|
||||||
|
val jsonObj = jsonParser.parse(jsonString!!.toString()).asJsonObject
|
||||||
|
|
||||||
|
return jsonObj
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
private fun readJsonFileAsString(path: String) {
|
||||||
|
Files.lines(FileSystems.getDefault().getPath(path)).forEach(
|
||||||
|
{ jsonString!!.append(it) }
|
||||||
|
) // JSON does not require line break
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.Torvald;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-04.
|
|
||||||
*/
|
|
||||||
public class JsonWriter {
|
|
||||||
|
|
||||||
public static void writeToFile(Object c, String path) throws IOException {
|
|
||||||
JsonElement classElem = new Gson().toJsonTree(c);
|
|
||||||
String jsonString = classElem.toString();
|
|
||||||
FileWriter writer = new FileWriter(path);
|
|
||||||
writer.write(jsonString);
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeToFile(JsonObject jsonObject, String path) throws IOException {
|
|
||||||
FileWriter writer = new FileWriter(path);
|
|
||||||
writer.write(jsonObject.toString());
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
31
src/com/Torvald/JsonWriter.kt
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.Torvald
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonElement
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-04.
|
||||||
|
*/
|
||||||
|
object JsonWriter {
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun writeToFile(c: Any, path: String) {
|
||||||
|
val classElem = Gson().toJsonTree(c)
|
||||||
|
val jsonString = classElem.toString()
|
||||||
|
val writer = FileWriter(path)
|
||||||
|
writer.write(jsonString)
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun writeToFile(jsonObject: JsonObject, path: String) {
|
||||||
|
val writer = FileWriter(path)
|
||||||
|
writer.write(jsonObject.toString())
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.Torvald.Rand;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-03.
|
|
||||||
*/
|
|
||||||
public class Fudge3 extends FudgeDice {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define new set of fudge dice with three dice.
|
|
||||||
* @param randfunc java.util.Random or its extension
|
|
||||||
*/
|
|
||||||
public Fudge3(Random randfunc) {
|
|
||||||
super(randfunc, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
13
src/com/Torvald/Rand/Fudge3.kt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.Torvald.Rand
|
||||||
|
|
||||||
|
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)
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package com.Torvald.Rand;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-03.
|
|
||||||
*/
|
|
||||||
public class FudgeDice {
|
|
||||||
|
|
||||||
private Random randfunc;
|
|
||||||
private int diceCounts;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define new set of fudge dice with given counts.
|
|
||||||
* @param randfunc java.util.Random or its extension
|
|
||||||
* @param counts amount of die
|
|
||||||
*/
|
|
||||||
public FudgeDice(Random randfunc, int counts) {
|
|
||||||
this.randfunc = randfunc;
|
|
||||||
diceCounts = counts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Roll dice and get result.
|
|
||||||
* @return Normal distributed integer [-N , N] for diceCount of N. 0 is the most frequent return.
|
|
||||||
*/
|
|
||||||
public int roll() {
|
|
||||||
int diceResult = 0;
|
|
||||||
for (int c = 0; c < diceCounts; c++) {
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
public int rollForArray() {
|
|
||||||
return roll() + diceCounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDiceCounts() {
|
|
||||||
return diceCounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSizeOfProbabilityRange() {
|
|
||||||
return 2 * diceCounts + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return integer randomly picked from {-1, 0, 1}
|
|
||||||
*/
|
|
||||||
private int rollSingleDie() {
|
|
||||||
return (randfunc.nextInt(3)) - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
47
src/com/Torvald/Rand/FudgeDice.kt
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package com.Torvald.Rand
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package com.Torvald;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.color.ColorSpace;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-04.
|
|
||||||
*/
|
|
||||||
public class RasterWriter {
|
|
||||||
|
|
||||||
public static final int[] BANDOFFSET_RGB = {0, 1, 2};
|
|
||||||
public static final int[] BANDOFFSET_RGBA = {0, 1, 2, 3};
|
|
||||||
public static final int[] BANDOFFSET_ARGB = {3, 0, 1, 2};
|
|
||||||
public static final int[] BANDOFFSET_MONO = {0};
|
|
||||||
|
|
||||||
public static final int COLORSPACE_SRGB = ColorSpace.CS_sRGB;
|
|
||||||
public static final int COLORSPACE_GRAY = ColorSpace.CS_GRAY;
|
|
||||||
public static final int COLORSPACE_GREY = COLORSPACE_GRAY;
|
|
||||||
public static final int COLORSPACE_CIEXYZ = ColorSpace.CS_CIEXYZ;
|
|
||||||
public static final int COLORSPACE_RGB_LINEAR_GAMMA = ColorSpace.CS_LINEAR_RGB;
|
|
||||||
|
|
||||||
public static void writePNG_RGB(int w, int h, byte[] rasterData, String path) throws IOException {
|
|
||||||
writePNG(w, h, rasterData, BANDOFFSET_RGB, COLORSPACE_SRGB, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writePNG_Mono(int w, int h, byte[] rasterData, String path) throws IOException {
|
|
||||||
writePNG(w, h, rasterData, BANDOFFSET_MONO, COLORSPACE_GREY, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writePNG(int w, int h, byte[] rasterData, int[] bandOffsets, int awt_colorspace, String path) throws IOException {
|
|
||||||
DataBuffer buffer = new DataBufferByte(rasterData, rasterData.length);
|
|
||||||
WritableRaster raster = Raster.createInterleavedRaster(
|
|
||||||
buffer
|
|
||||||
, w
|
|
||||||
, h
|
|
||||||
, bandOffsets.length * w
|
|
||||||
, bandOffsets.length
|
|
||||||
, bandOffsets
|
|
||||||
, null
|
|
||||||
);
|
|
||||||
|
|
||||||
ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(awt_colorspace), false, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
|
|
||||||
|
|
||||||
BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
|
|
||||||
|
|
||||||
ImageIO.write(image, "PNG", new File(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
51
src/com/Torvald/RasterWriter.kt
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package com.Torvald
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO
|
||||||
|
import java.awt.*
|
||||||
|
import java.awt.color.ColorSpace
|
||||||
|
import java.awt.image.*
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-04.
|
||||||
|
*/
|
||||||
|
object RasterWriter {
|
||||||
|
|
||||||
|
val BANDOFFSET_RGB = intArrayOf(0, 1, 2)
|
||||||
|
val BANDOFFSET_RGBA = intArrayOf(0, 1, 2, 3)
|
||||||
|
val BANDOFFSET_ARGB = intArrayOf(3, 0, 1, 2)
|
||||||
|
val BANDOFFSET_MONO = intArrayOf(0)
|
||||||
|
|
||||||
|
val COLORSPACE_SRGB = ColorSpace.CS_sRGB
|
||||||
|
val COLORSPACE_GRAY = ColorSpace.CS_GRAY
|
||||||
|
val COLORSPACE_GREY = COLORSPACE_GRAY
|
||||||
|
val COLORSPACE_CIEXYZ = ColorSpace.CS_CIEXYZ
|
||||||
|
val COLORSPACE_RGB_LINEAR_GAMMA = ColorSpace.CS_LINEAR_RGB
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun writePNG_RGB(w: Int, h: Int, rasterData: ByteArray, path: String) {
|
||||||
|
writePNG(w, h, rasterData, BANDOFFSET_RGB, COLORSPACE_SRGB, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun writePNG_Mono(w: Int, h: Int, rasterData: ByteArray, path: String) {
|
||||||
|
writePNG(w, h, rasterData, BANDOFFSET_MONO, COLORSPACE_GREY, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun writePNG(w: Int, h: Int, rasterData: ByteArray, bandOffsets: IntArray, awt_colorspace: Int, path: String) {
|
||||||
|
val buffer = DataBufferByte(rasterData, rasterData.size)
|
||||||
|
val raster = Raster.createInterleavedRaster(
|
||||||
|
buffer, w, h, bandOffsets.size * w, bandOffsets.size, bandOffsets, null)
|
||||||
|
|
||||||
|
val colorModel = ComponentColorModel(ColorSpace.getInstance(awt_colorspace), false, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE)
|
||||||
|
|
||||||
|
val image = BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied, null)
|
||||||
|
|
||||||
|
ImageIO.write(image, "PNG", File(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
65
src/com/Torvald/Serialise/WriteCSV.kt
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package com.Torvald.Serialise
|
||||||
|
|
||||||
|
import com.Torvald.CSVFetcher
|
||||||
|
import com.Torvald.Terrarum.ItemProperties.ItemPropCodex
|
||||||
|
import com.Torvald.Terrarum.ItemProperties.MaterialPropCodex
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
import com.Torvald.Terrarum.TileProperties.TilePropCodex
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import java.nio.file.StandardCopyOption
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-18.
|
||||||
|
*/
|
||||||
|
object WriteCSV {
|
||||||
|
val META_FILENAME_TILE = "worldinfo2"
|
||||||
|
val META_FILENAME_ITEM = "worldinfo3"
|
||||||
|
val META_FILENAME_MAT = "worldinfo4"
|
||||||
|
|
||||||
|
fun write(saveDirectoryName: String): Boolean {
|
||||||
|
val tileCSV = CSVFetcher.readCSVasString(TilePropCodex.CSV_PATH)
|
||||||
|
val itemCSV = CSVFetcher.readCSVasString(ItemPropCodex.CSV_PATH)
|
||||||
|
val matCSV = CSVFetcher.readCSVasString(MaterialPropCodex.CSV_PATH)
|
||||||
|
|
||||||
|
val pathTile = Paths.get("${Terrarum.defaultSaveDir}" +
|
||||||
|
"/$saveDirectoryName/${META_FILENAME_TILE}")
|
||||||
|
val pathItem = Paths.get("${Terrarum.defaultSaveDir}" +
|
||||||
|
"/$saveDirectoryName/${META_FILENAME_ITEM}")
|
||||||
|
val pathMat = Paths.get("${Terrarum.defaultSaveDir}" +
|
||||||
|
"/$saveDirectoryName/${META_FILENAME_MAT}")
|
||||||
|
val tempPathTile = Files.createTempFile(pathTile.toString(), "_temp")
|
||||||
|
val tempPathItem = Files.createTempFile(pathItem.toString(), "_temp")
|
||||||
|
val tempPathMat = Files.createTempFile(pathMat.toString(), "_temp")
|
||||||
|
|
||||||
|
// TODO gzip
|
||||||
|
|
||||||
|
// write CSV to path
|
||||||
|
Files.write(tempPathTile, tileCSV.toByteArray(Charsets.UTF_8))
|
||||||
|
Files.write(tempPathItem, itemCSV.toByteArray(Charsets.UTF_8))
|
||||||
|
Files.write(tempPathMat, matCSV.toByteArray(Charsets.UTF_8))
|
||||||
|
|
||||||
|
// replace savemeta with tempfile
|
||||||
|
try {
|
||||||
|
Files.copy(tempPathTile, pathTile, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
Files.deleteIfExists(tempPathTile)
|
||||||
|
|
||||||
|
Files.copy(tempPathItem, pathItem, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
Files.deleteIfExists(tempPathItem)
|
||||||
|
|
||||||
|
Files.copy(tempPathMat, pathMat, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
Files.deleteIfExists(tempPathMat)
|
||||||
|
|
||||||
|
println("Saved map data '${WriteGameMapData.META_FILENAME}' to $saveDirectoryName.")
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
79
src/com/Torvald/Serialise/WriteGameMapData.kt
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package com.Torvald.Serialise
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.GameMap.GameMap
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import java.nio.file.StandardCopyOption
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-18.
|
||||||
|
*/
|
||||||
|
object WriteGameMapData {
|
||||||
|
|
||||||
|
val META_FILENAME = "worldinfo1"
|
||||||
|
|
||||||
|
val MAGIC: ByteArray = byteArrayOf(
|
||||||
|
'T'.toByte(),
|
||||||
|
'E'.toByte(),
|
||||||
|
'M'.toByte(),
|
||||||
|
'D'.toByte()
|
||||||
|
)
|
||||||
|
|
||||||
|
val BYTE_NULL: Byte = 0
|
||||||
|
|
||||||
|
|
||||||
|
fun write(saveDirectoryName: String): Boolean {
|
||||||
|
val path = Paths.get("${Terrarum.defaultSaveDir}" +
|
||||||
|
"/$saveDirectoryName/${WriteMeta.META_FILENAME}")
|
||||||
|
val tempPath = Files.createTempFile(path.toString(), "_temp")
|
||||||
|
val map = Terrarum.game.map
|
||||||
|
|
||||||
|
// TODO gzip
|
||||||
|
|
||||||
|
// write binary
|
||||||
|
Files.write(tempPath, MAGIC)
|
||||||
|
Files.write(tempPath, byteArrayOf(GameMap.BITS))
|
||||||
|
Files.write(tempPath, byteArrayOf(GameMap.LAYERS))
|
||||||
|
Files.write(tempPath, byteArrayOf(BYTE_NULL))
|
||||||
|
Files.write(tempPath, byteArrayOf(BYTE_NULL))
|
||||||
|
Files.write(tempPath, toByteArray(map.width))
|
||||||
|
Files.write(tempPath, toByteArray(map.height))
|
||||||
|
Files.write(tempPath, toByteArray(map.spawnX))
|
||||||
|
Files.write(tempPath, toByteArray(map.spawnY))
|
||||||
|
map.layerTerrain.forEach(
|
||||||
|
{b -> Files.write(tempPath, byteArrayOf(b))})
|
||||||
|
map.layerWall.forEach(
|
||||||
|
{b -> Files.write(tempPath, byteArrayOf(b))})
|
||||||
|
map.terrainDamage.forEach(
|
||||||
|
{b -> Files.write(tempPath, byteArrayOf(b))})
|
||||||
|
map.wallDamage.forEach(
|
||||||
|
{b -> Files.write(tempPath, byteArrayOf(b))})
|
||||||
|
map.layerWire.forEach(
|
||||||
|
{b -> Files.write(tempPath, byteArrayOf(b))})
|
||||||
|
|
||||||
|
// replace savemeta with tempfile
|
||||||
|
try {
|
||||||
|
Files.copy(tempPath, path, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
Files.deleteIfExists(tempPath)
|
||||||
|
println("Saved map data '$META_FILENAME' to $saveDirectoryName.")
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toByteArray(int: Int): ByteArray {
|
||||||
|
return byteArrayOf(
|
||||||
|
((int ushr 0x18) and 0xFF).toByte(),
|
||||||
|
((int ushr 0x10) and 0xFF).toByte(),
|
||||||
|
((int ushr 0x08) and 0xFF).toByte(),
|
||||||
|
((int ) and 0xFF).toByte()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,13 @@ package com.Torvald.Serialise
|
|||||||
|
|
||||||
import com.Torvald.Terrarum.MapGenerator.MapGenerator
|
import com.Torvald.Terrarum.MapGenerator.MapGenerator
|
||||||
import com.Torvald.Terrarum.MapGenerator.RoguelikeRandomiser
|
import com.Torvald.Terrarum.MapGenerator.RoguelikeRandomiser
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
import com.Torvald.Terrarum.TileProperties.TilePropCodex
|
import com.Torvald.Terrarum.TileProperties.TilePropCodex
|
||||||
import org.apache.commons.codec.digest.DigestUtils
|
import org.apache.commons.codec.digest.DigestUtils
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,19 +16,31 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
object WriteMeta {
|
object WriteMeta {
|
||||||
|
|
||||||
val MAGIC: Array<Byte> = arrayOf(
|
val META_FILENAME = "world"
|
||||||
'T'.toByte()
|
|
||||||
, 'E'.toByte()
|
val MAGIC: ByteArray = byteArrayOf(
|
||||||
, 'S'.toByte()
|
'T'.toByte(),
|
||||||
, 'V'.toByte()
|
'E'.toByte(),
|
||||||
|
'S'.toByte(),
|
||||||
|
'V'.toByte()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val BYTE_NULL: Byte = 0
|
||||||
|
|
||||||
val terraseed: Long = MapGenerator.getGeneratorSeed()
|
val terraseed: Long = MapGenerator.getGeneratorSeed()
|
||||||
val rogueseed: Long = RoguelikeRandomiser.getGeneratorSeed()
|
val rogueseed: Long = RoguelikeRandomiser.getGeneratorSeed()
|
||||||
|
|
||||||
fun write() {
|
/**
|
||||||
var hashArray: ArrayList<ByteArray> = ArrayList()
|
* Write save meta to specified directory. Returns false if something went wrong.
|
||||||
|
* @param saveDirectoryName
|
||||||
|
* @param savegameName -- Nullable. If the value is not specified, saveDirectoryName will be used instead.
|
||||||
|
*/
|
||||||
|
fun write(saveDirectoryName: String, savegameName: String?): Boolean {
|
||||||
|
val hashArray: ArrayList<ByteArray> = ArrayList()
|
||||||
|
val savenameAsByteArray: ByteArray =
|
||||||
|
(savegameName ?: saveDirectoryName).toByteArray(Charsets.UTF_8)
|
||||||
|
|
||||||
|
// define files to get hash
|
||||||
val fileArray: Array<File> = arrayOf(
|
val fileArray: Array<File> = arrayOf(
|
||||||
File(TilePropCodex.CSV_PATH)
|
File(TilePropCodex.CSV_PATH)
|
||||||
//, File(ItemPropCodex.CSV_PATH)
|
//, File(ItemPropCodex.CSV_PATH)
|
||||||
@@ -33,11 +48,54 @@ object WriteMeta {
|
|||||||
//,
|
//,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// get and store hash from fileArray
|
||||||
for (file in fileArray) {
|
for (file in fileArray) {
|
||||||
val inputStream = FileInputStream(file)
|
val inputStream = FileInputStream(file)
|
||||||
val hash = DigestUtils.sha256(inputStream)
|
val hash = DigestUtils.sha256(inputStream)
|
||||||
|
|
||||||
hashArray.add(hash)
|
hashArray.add(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// open file and delete it
|
||||||
|
val metaPath = Paths.get("${Terrarum.defaultSaveDir}" +
|
||||||
|
"/$saveDirectoryName/$META_FILENAME")
|
||||||
|
val metaTempPath = Files.createTempFile(metaPath.toString(), "_temp")
|
||||||
|
|
||||||
|
// TODO gzip
|
||||||
|
|
||||||
|
// write bytes in tempfile
|
||||||
|
Files.write(metaTempPath, MAGIC)
|
||||||
|
Files.write(metaTempPath, savenameAsByteArray)
|
||||||
|
Files.write(metaTempPath, byteArrayOf(BYTE_NULL))
|
||||||
|
Files.write(metaTempPath, toByteArray(terraseed))
|
||||||
|
Files.write(metaTempPath, toByteArray(rogueseed))
|
||||||
|
for (hash in hashArray)
|
||||||
|
Files.write(metaTempPath, hash)
|
||||||
|
|
||||||
|
// replace savemeta with tempfile
|
||||||
|
try {
|
||||||
|
Files.copy(metaTempPath, metaPath, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
Files.deleteIfExists(metaTempPath)
|
||||||
|
println("Saved metadata to $saveDirectoryName.")
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toByteArray(long: Long): ByteArray {
|
||||||
|
return byteArrayOf(
|
||||||
|
((long ushr 0x38) and 0xFF).toByte(),
|
||||||
|
((long ushr 0x30) and 0xFF).toByte(),
|
||||||
|
((long ushr 0x28) and 0xFF).toByte(),
|
||||||
|
((long ushr 0x20) and 0xFF).toByte(),
|
||||||
|
((long ushr 0x18) and 0xFF).toByte(),
|
||||||
|
((long ushr 0x10) and 0xFF).toByte(),
|
||||||
|
((long ushr 0x08) and 0xFF).toByte(),
|
||||||
|
((long ) and 0xFF).toByte()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
77
src/com/Torvald/SimpleCipher/ROTUtil.kt
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package com.Torvald.SimpleCipher
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-20.
|
||||||
|
*/
|
||||||
|
object ROTUtil {
|
||||||
|
|
||||||
|
const val CODE_CAP_A = 'A'.toInt()
|
||||||
|
const val CODE_LOW_A = 'a'.toInt()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ROT encryption, default setting
|
||||||
|
*
|
||||||
|
* * Latin alph: removes diacritics and do ROT13, string reverse, capitalised.
|
||||||
|
* Ligatures are disassembled. Even if the target language does not have
|
||||||
|
* certain alphabet (e.g. C in Icelandic), such alphabet will be printed anyway.
|
||||||
|
*
|
||||||
|
* * Cyrillic: removes diacritics and do ROTnn, string reverse, capitalised.
|
||||||
|
*
|
||||||
|
* * Kana: raise Sutegana, ROT3 on vowels (a i u e o -> e o a i u), string reverse
|
||||||
|
* (Wa Wo -> Wo Wa), Nn will remain untouched, forced Katakana.
|
||||||
|
*
|
||||||
|
* * Hangul: ROT3 on initials\*, lower double initials to single
|
||||||
|
* (ㄱ ㄲ ㄴ ㄷ ㄸ ㄹ ㅁ ㅂ ㅃ ㅅ ㅆ ㅇ ㅈ ㅉ ㅊ ㅋ ㅌ ㅍ ㅎ -> ㄹ ㄹ ㅁ ㅂ ㅂ ㅅ ㅇ ㅇ ㅈ ㅈ ㅊ ㅋ ㅋ ㅌ ㅍ ㅎ ㄱ ㄴ ㄷ),
|
||||||
|
* string reverse
|
||||||
|
*
|
||||||
|
* * Chinese: NOT SUPPORTED
|
||||||
|
*
|
||||||
|
* * Numeric: no encrypt
|
||||||
|
*/
|
||||||
|
fun encrypt(plaintext: String): String {
|
||||||
|
|
||||||
|
fun removeDiacritics(c: Char): Char {
|
||||||
|
val normaliseMap = hashMapOf(
|
||||||
|
Pair('À', "A"),
|
||||||
|
Pair('Á', "A"),
|
||||||
|
Pair('Â', "A"),
|
||||||
|
Pair('À', "A"),
|
||||||
|
Pair('Ã', "A"),
|
||||||
|
Pair('Å', "A"),
|
||||||
|
Pair('Æ', "AE"),
|
||||||
|
Pair('Ç', "C"),
|
||||||
|
Pair('È', "E"),
|
||||||
|
Pair('É', "E"),
|
||||||
|
Pair('Ê', "E"),
|
||||||
|
Pair('Ë', "E"),
|
||||||
|
Pair('Ì', "I"),
|
||||||
|
Pair('Í', "I"),
|
||||||
|
Pair('Î', "I"),
|
||||||
|
Pair('Ï', "I"),
|
||||||
|
Pair('Ð', "D")
|
||||||
|
)
|
||||||
|
throw NotImplementedError("Feature WIP")
|
||||||
|
}
|
||||||
|
|
||||||
|
throw NotImplementedError("Feature WIP")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note; range starts with zero
|
||||||
|
* @param number to rotate
|
||||||
|
* @param rotation
|
||||||
|
* @param range size of the rotation table. 4 means (0,1,2,3)
|
||||||
|
*/
|
||||||
|
fun rotN(number: Int, rotation: Int, range: Int): Int {
|
||||||
|
return if (number < range - rotation + 1) number + rotation
|
||||||
|
else number - (range - rotation + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rot13(c: Char): Char {
|
||||||
|
return if (c in 'a'..'z')
|
||||||
|
(rotN((c.toInt() - CODE_LOW_A), 13, 26) + CODE_LOW_A).toChar()
|
||||||
|
else if (c in 'A'..'Z')
|
||||||
|
(rotN((c.toInt() - CODE_CAP_A), 13, 26) + CODE_CAP_A).toChar()
|
||||||
|
else c
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.Torvald.Terrarum.Actors
|
package com.Torvald.Terrarum.Actors
|
||||||
|
|
||||||
import com.Torvald.Terrarum.GameItem.InventoryItem
|
import com.Torvald.Terrarum.GameItem.InventoryItem
|
||||||
import com.Torvald.Terrarum.GameItem.ItemPropCodex
|
import com.Torvald.Terrarum.ItemProperties.ItemPropCodex
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-03-15.
|
* Created by minjaesong on 16-03-15.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ActorInventory {
|
class ActorInventory() {
|
||||||
|
|
||||||
@Transient val CAPACITY_MAX = 0x7FFFFFFF
|
@Transient val CAPACITY_MAX = 0x7FFFFFFF
|
||||||
@Transient val CAPACITY_MODE_NO_ENCUMBER = 0
|
@Transient val CAPACITY_MODE_NO_ENCUMBER = 0
|
||||||
@@ -16,22 +16,31 @@ class ActorInventory {
|
|||||||
@Transient val CAPACITY_MODE_WEIGHT = 2
|
@Transient val CAPACITY_MODE_WEIGHT = 2
|
||||||
|
|
||||||
|
|
||||||
private var capacityByCount: Int = 0
|
private var capacityByCount: Int
|
||||||
private var capacityByWeight: Int = 0
|
private var capacityByWeight: Int
|
||||||
private var capacityMode: Int = 0
|
private var capacityMode: Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <ReferenceID, Amounts>
|
* <ReferenceID, Amounts>
|
||||||
*/
|
*/
|
||||||
private val itemList: HashMap<Long, Int> = HashMap()
|
private val itemList: HashMap<Long, Int> = HashMap()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor with no encumbrance.
|
||||||
|
*/
|
||||||
|
init {
|
||||||
|
capacityMode = CAPACITY_MODE_NO_ENCUMBER
|
||||||
|
capacityByCount = 0
|
||||||
|
capacityByWeight = 0
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct new inventory with specified capacity.
|
* Construct new inventory with specified capacity.
|
||||||
* @param capacity if is_weight is true, killogramme value is required, counts of items otherwise.
|
* @param capacity if is_weight is true, killogramme value is required, counts of items otherwise.
|
||||||
* *
|
* *
|
||||||
* @param is_weight whether encumbrance should be calculated upon the weight of the inventory. False to use item counts.
|
* @param is_weight whether encumbrance should be calculated upon the weight of the inventory. False to use item counts.
|
||||||
*/
|
*/
|
||||||
constructor(capacity: Int, is_weight: Boolean) {
|
constructor(capacity: Int, is_weight: Boolean) : this() {
|
||||||
if (is_weight) {
|
if (is_weight) {
|
||||||
capacityByWeight = capacity
|
capacityByWeight = capacity
|
||||||
capacityMode = CAPACITY_MODE_WEIGHT
|
capacityMode = CAPACITY_MODE_WEIGHT
|
||||||
@@ -81,7 +90,7 @@ class ActorInventory {
|
|||||||
var weight = 0f
|
var weight = 0f
|
||||||
|
|
||||||
for (item in itemList.entries) {
|
for (item in itemList.entries) {
|
||||||
weight += ItemPropCodex.getItem(item.key).weight * item.value
|
weight += ItemPropCodex.getItem(item.key).mass * item.value
|
||||||
}
|
}
|
||||||
|
|
||||||
return weight
|
return weight
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.Actors;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.KVHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-03.
|
|
||||||
*/
|
|
||||||
public class ActorValue extends KVHashMap {
|
|
||||||
|
|
||||||
}
|
|
||||||
8
src/com/Torvald/Terrarum/Actors/ActorValue.kt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package com.Torvald.Terrarum.Actors
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.KVHashMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-19.
|
||||||
|
*/
|
||||||
|
class ActorValue : KVHashMap()
|
||||||
@@ -252,10 +252,8 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
val A = scale * scale
|
val A = scale * scale
|
||||||
val D = DRAG_COEFF * 0.5f * 1.292f * veloY * veloY * A
|
val D = DRAG_COEFF * 0.5f * 1.292f * veloY * veloY * A
|
||||||
|
|
||||||
val fluidResistance = tileMvmtRstc
|
|
||||||
|
|
||||||
veloY += clampCeil(
|
veloY += clampCeil(
|
||||||
(W - D) / mass * SI_TO_GAME_ACC * G_MUL_PLAYABLE_CONST, VELO_HARD_LIMIT)// * mvmtRstcToMultiplier(fluidResistance) // eliminate shoot-up from fluids
|
(W - D) / mass * SI_TO_GAME_ACC * G_MUL_PLAYABLE_CONST, VELO_HARD_LIMIT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,30 +404,6 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
// set tile positions
|
// set tile positions
|
||||||
val tileX: Int
|
val tileX: Int
|
||||||
val tileY: Int
|
val tileY: Int
|
||||||
/*if (side == CONTACT_AREA_BOTTOM) {
|
|
||||||
tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX())
|
|
||||||
+ i + translateX);
|
|
||||||
tileY = div16TruncateToMapHeight(FastMath.floor(nextHitbox.getHitboxEnd().getY())
|
|
||||||
+ translateY);
|
|
||||||
}
|
|
||||||
else if (side == CONTACT_AREA_TOP) {
|
|
||||||
tileX = div16TruncateToMapWidth(Math.round(nextHitbox.getHitboxStart().getX())
|
|
||||||
+ i + translateX);
|
|
||||||
tileY = div16TruncateToMapHeight(FastMath.ceil(nextHitbox.getHitboxStart().getY())
|
|
||||||
+ translateY);
|
|
||||||
}
|
|
||||||
else if (side == CONTACT_AREA_RIGHT) {
|
|
||||||
tileX = div16TruncateToMapWidth(FastMath.floor(nextHitbox.getHitboxEnd().getX())
|
|
||||||
+ translateX);
|
|
||||||
tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY())
|
|
||||||
+ i + translateY);
|
|
||||||
}
|
|
||||||
else if (side == CONTACT_AREA_LEFT) {
|
|
||||||
tileX = div16TruncateToMapWidth(FastMath.ceil(nextHitbox.getHitboxStart().getX())
|
|
||||||
+ translateX);
|
|
||||||
tileY = div16TruncateToMapHeight(Math.round(nextHitbox.getHitboxStart().getY())
|
|
||||||
+ i + translateY);
|
|
||||||
}*/
|
|
||||||
if (side == CONTACT_AREA_BOTTOM) {
|
if (side == CONTACT_AREA_BOTTOM) {
|
||||||
tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x)
|
tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x)
|
||||||
+ i + translateX)
|
+ i + translateX)
|
||||||
@@ -459,6 +433,41 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
return contactAreaCounter
|
return contactAreaCounter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getContactingAreaFluid(side: Int, translateX: Int = 0, translateY: Int = 0): Int {
|
||||||
|
var contactAreaCounter = 0
|
||||||
|
for (i in 0..Math.round(if (side % 2 == 0) nextHitbox!!.width else nextHitbox!!.height) - 1) {
|
||||||
|
// set tile positions
|
||||||
|
val tileX: Int
|
||||||
|
val tileY: Int
|
||||||
|
if (side == CONTACT_AREA_BOTTOM) {
|
||||||
|
tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x)
|
||||||
|
+ i + translateX)
|
||||||
|
tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxEnd.y) + translateY)
|
||||||
|
} else if (side == CONTACT_AREA_TOP) {
|
||||||
|
tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x)
|
||||||
|
+ i + translateX)
|
||||||
|
tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxStart.y) + translateY)
|
||||||
|
} else if (side == CONTACT_AREA_RIGHT) {
|
||||||
|
tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxEnd.x) + translateX)
|
||||||
|
tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxStart.y)
|
||||||
|
+ i + translateY)
|
||||||
|
} else if (side == CONTACT_AREA_LEFT) {
|
||||||
|
tileX = div16TruncateToMapWidth(Math.round(nextHitbox!!.hitboxStart.x) + translateX)
|
||||||
|
tileY = div16TruncateToMapHeight(Math.round(nextHitbox!!.hitboxStart.y)
|
||||||
|
+ i + translateY)
|
||||||
|
} else {
|
||||||
|
throw IllegalArgumentException(side.toString() + ": Wrong side input")
|
||||||
|
}
|
||||||
|
|
||||||
|
// evaluate
|
||||||
|
if (TilePropCodex.getProp(map.getTileFromTerrain(tileX, tileY)).isFluid) {
|
||||||
|
contactAreaCounter += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return contactAreaCounter
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [N] = [kg * m / s^2]
|
* [N] = [kg * m / s^2]
|
||||||
* F(bo) = density * submerged_volume * gravitational_acceleration [N]
|
* F(bo) = density * submerged_volume * gravitational_acceleration [N]
|
||||||
@@ -476,52 +485,25 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private //System.out.println("fluidHeight: "+fluidHeight+", submerged: "+submergedVolume);
|
private val submergedVolume: Float
|
||||||
//submergedHeight / TILE_SIZE * 1^2 (pixel to meter)
|
get() = submergedHeight * hitbox!!.width * hitbox!!.width
|
||||||
val submergedVolume: Float
|
|
||||||
get() {
|
|
||||||
val GAME_TO_SI_VOL = FastMath.pow(1f / METER, 3f)
|
|
||||||
|
|
||||||
if (density > 0) {
|
|
||||||
return submergedHeight *
|
|
||||||
nextHitbox!!.width * nextHitbox!!.width *
|
|
||||||
GAME_TO_SI_VOL
|
|
||||||
} else {
|
|
||||||
return 0f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val submergedHeight: Float
|
private val submergedHeight: Float
|
||||||
get() = FastMath.clamp(
|
get() = Math.max(
|
||||||
nextHitbox!!.pointedY - fluidLevel, 0f, nextHitbox!!.height)
|
getContactingAreaFluid(CONTACT_AREA_LEFT),
|
||||||
|
getContactingAreaFluid(CONTACT_AREA_RIGHT)
|
||||||
|
).toFloat()
|
||||||
|
|
||||||
private val fluidLevel: Int
|
|
||||||
get() {
|
|
||||||
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
|
||||||
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
|
||||||
val tilePosY = Math.round(nextHitbox!!.posY / TSIZE)
|
|
||||||
|
|
||||||
var fluidHeight = 2147483647
|
|
||||||
|
|
||||||
for (x in tilePosXStart..tilePosXEnd) {
|
|
||||||
val tile = map.getTileFromTerrain(x, tilePosY)
|
|
||||||
if (TilePropCodex.getProp(tile).isFluid && tilePosY * TSIZE < fluidHeight) {
|
|
||||||
fluidHeight = tilePosY * TSIZE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fluidHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get highest friction value from feet tiles.
|
* Get highest friction value from feet tiles.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private //get density
|
private val tileFriction: Int
|
||||||
val tileFriction: Int
|
|
||||||
get() {
|
get() {
|
||||||
var friction = 0
|
var friction = 0
|
||||||
|
|
||||||
|
//get highest fluid density
|
||||||
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
||||||
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
||||||
val tilePosY = Math.round(nextHitbox!!.pointedY / TSIZE)
|
val tilePosY = Math.round(nextHitbox!!.pointedY / TSIZE)
|
||||||
@@ -541,11 +523,11 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
* Get highest movement resistance value from tiles that the body occupies.
|
* Get highest movement resistance value from tiles that the body occupies.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private //get density
|
private val tileMvmtRstc: Int
|
||||||
val tileMvmtRstc: Int
|
|
||||||
get() {
|
get() {
|
||||||
var resistance = 0
|
var resistance = 0
|
||||||
|
|
||||||
|
//get highest fluid density
|
||||||
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
||||||
val tilePosYStart = Math.round(nextHitbox!!.posY / TSIZE)
|
val tilePosYStart = Math.round(nextHitbox!!.posY / TSIZE)
|
||||||
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
||||||
@@ -568,11 +550,11 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
* Get highest density (specific gravity) value from tiles that the body occupies.
|
* Get highest density (specific gravity) value from tiles that the body occupies.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private //get density
|
private val tileDensity: Int
|
||||||
val tileDensity: Int
|
|
||||||
get() {
|
get() {
|
||||||
var density = 0
|
var density = 0
|
||||||
|
|
||||||
|
//get highest fluid density
|
||||||
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
val tilePosXStart = Math.round(nextHitbox!!.posX / TSIZE)
|
||||||
val tilePosYStart = Math.round(nextHitbox!!.posY / TSIZE)
|
val tilePosYStart = Math.round(nextHitbox!!.posY / TSIZE)
|
||||||
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
val tilePosXEnd = Math.round(nextHitbox!!.hitboxEnd.x / TSIZE)
|
||||||
@@ -608,18 +590,19 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
private fun updateNextHitboxFromVelo() {
|
private fun updateNextHitboxFromVelo() {
|
||||||
val fluidResistance = mvmtRstcToMultiplier(tileMvmtRstc)
|
val fluidResistance = mvmtRstcToMultiplier(tileMvmtRstc)
|
||||||
val submergedRatio = FastMath.clamp(
|
val submergedRatio = FastMath.clamp(
|
||||||
submergedHeight / nextHitbox!!.height, 0f, 1f)
|
submergedHeight / nextHitbox!!.height,
|
||||||
|
0f, 1f
|
||||||
val applyResistance = !isNoSubjectToFluidResistance && submergedRatio > FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO
|
)
|
||||||
val resistanceMulInterValueSize = FLUID_RESISTANCE_APPLY_FULL_RATIO - FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO
|
val applyResistance: Boolean = !isNoSubjectToFluidResistance
|
||||||
val resistanceMultiplier = FastMath.interpolateLinear(
|
&& submergedRatio > FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO
|
||||||
(submergedRatio - FLUID_RESISTANCE_IGNORE_THRESHOLD_RATIO) * FastMath.pow(resistanceMulInterValueSize, -1f), 0f, 1f)
|
val resistance: Float = FastMath.interpolateLinear(
|
||||||
val adjustedResistance = FastMath.interpolateLinear(
|
submergedRatio,
|
||||||
resistanceMultiplier, 1f, fluidResistance)
|
1f, fluidResistance
|
||||||
|
)
|
||||||
|
|
||||||
nextHitbox!!.set(
|
nextHitbox!!.set(
|
||||||
Math.round(hitbox!!.posX + veloX * (if (!applyResistance) 1f else adjustedResistance)).toFloat()
|
Math.round(hitbox!!.posX + veloX * (if (!applyResistance) 1f else resistance)).toFloat()
|
||||||
, Math.round(hitbox!!.posY + veloY * (if (!applyResistance) 1f else adjustedResistance)).toFloat()
|
, Math.round(hitbox!!.posY + veloY * (if (!applyResistance) 1f else resistance)).toFloat()
|
||||||
, Math.round(baseHitboxW * scale).toFloat()
|
, Math.round(baseHitboxW * scale).toFloat()
|
||||||
, Math.round(baseHitboxH * scale).toFloat())
|
, Math.round(baseHitboxH * scale).toFloat())
|
||||||
/** Full quantisation; wonder what havoc these statements would wreak...
|
/** Full quantisation; wonder what havoc these statements would wreak...
|
||||||
@@ -658,12 +641,12 @@ open class ActorWithBody constructor() : Actor, Visible, Glowing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateGlowSprite(gc: GameContainer, delta_t: Int) {
|
override fun updateGlowSprite(gc: GameContainer, delta: Int) {
|
||||||
if (spriteGlow != null) spriteGlow!!.update(delta_t)
|
if (spriteGlow != null) spriteGlow!!.update(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateBodySprite(gc: GameContainer, delta_t: Int) {
|
override fun updateBodySprite(gc: GameContainer, delta: Int) {
|
||||||
if (sprite != null) sprite!!.update(delta_t)
|
if (sprite != null) sprite!!.update(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clampW(x: Float): Float {
|
private fun clampW(x: Float): Float {
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.Actors.Faction;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-15.
|
|
||||||
*/
|
|
||||||
public class Faction {
|
|
||||||
|
|
||||||
private String factionName;
|
|
||||||
private HashSet<String> factionAmicable;
|
|
||||||
private HashSet<String> factionNeutral;
|
|
||||||
private HashSet<String> factionHostile;
|
|
||||||
private HashSet<String> factionFearful;
|
|
||||||
|
|
||||||
public Faction(String factionName) {
|
|
||||||
this.factionName = factionName;
|
|
||||||
factionAmicable = new HashSet<>();
|
|
||||||
factionNeutral = new HashSet<>();
|
|
||||||
factionHostile = new HashSet<>();
|
|
||||||
factionFearful = new HashSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFactionName() {
|
|
||||||
return factionName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renewFactionName(String factionName) {
|
|
||||||
this.factionName = factionName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<String> getFactionFearful() {
|
|
||||||
return factionFearful;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFactionFearful(HashSet<String> factionFearful) {
|
|
||||||
this.factionFearful = factionFearful;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<String> getFactionAmicable() {
|
|
||||||
return factionAmicable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFactionAmicable(HashSet<String> factionAmicable) {
|
|
||||||
this.factionAmicable = factionAmicable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<String> getFactionNeutral() {
|
|
||||||
return factionNeutral;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFactionNeutral(HashSet<String> factionNeutral) {
|
|
||||||
this.factionNeutral = factionNeutral;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<String> getFactionHostile() {
|
|
||||||
return factionHostile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFactionHostile(HashSet<String> factionHostile) {
|
|
||||||
this.factionHostile = factionHostile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFactionAmicable(String faction) {
|
|
||||||
factionAmicable.add(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFactionNeutral(String faction) {
|
|
||||||
factionNeutral.add(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFactionHostile(String faction) {
|
|
||||||
factionHostile.add(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFactionFearful(String faction) {
|
|
||||||
factionFearful.add(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFactionAmicable(String faction) {
|
|
||||||
factionAmicable.remove(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFactionNeutral(String faction) {
|
|
||||||
factionNeutral.remove(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFactionHostile(String faction) {
|
|
||||||
factionHostile.remove(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFactionFearful(String faction) {
|
|
||||||
factionFearful.remove(faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
60
src/com/Torvald/Terrarum/Actors/Faction/Faction.kt
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package com.Torvald.Terrarum.Actors.Faction
|
||||||
|
|
||||||
|
import java.util.HashSet
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-02-15.
|
||||||
|
*/
|
||||||
|
class Faction(factionName: String) {
|
||||||
|
|
||||||
|
lateinit var factionName: String
|
||||||
|
lateinit var factionAmicable: HashSet<String>
|
||||||
|
lateinit var factionNeutral: HashSet<String>
|
||||||
|
lateinit var factionHostile: HashSet<String>
|
||||||
|
lateinit var factionFearful: HashSet<String>
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.factionName = factionName
|
||||||
|
factionAmicable = HashSet<String>()
|
||||||
|
factionNeutral = HashSet<String>()
|
||||||
|
factionHostile = HashSet<String>()
|
||||||
|
factionFearful = HashSet<String>()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun renewFactionName(factionName: String) {
|
||||||
|
this.factionName = factionName
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addFactionAmicable(faction: String) {
|
||||||
|
factionAmicable.add(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addFactionNeutral(faction: String) {
|
||||||
|
factionNeutral.add(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addFactionHostile(faction: String) {
|
||||||
|
factionHostile.add(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addFactionFearful(faction: String) {
|
||||||
|
factionFearful.add(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFactionAmicable(faction: String) {
|
||||||
|
factionAmicable.remove(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFactionNeutral(faction: String) {
|
||||||
|
factionNeutral.remove(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFactionHostile(faction: String) {
|
||||||
|
factionHostile.remove(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeFactionFearful(faction: String) {
|
||||||
|
factionFearful.remove(faction)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.Actors.Faction;
|
|
||||||
|
|
||||||
import com.Torvald.JsonFetcher;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-15.
|
|
||||||
*/
|
|
||||||
public class FactionRelatorFactory {
|
|
||||||
|
|
||||||
private static final String JSONPATH = "./res/raw/";
|
|
||||||
|
|
||||||
public Faction build(String filename) throws IOException {
|
|
||||||
JsonObject jsonObj = JsonFetcher.readJson(JSONPATH + filename);
|
|
||||||
Faction factionObj = new Faction(jsonObj.get("factionname").getAsString());
|
|
||||||
|
|
||||||
|
|
||||||
jsonObj.get("factionamicable").getAsJsonArray().forEach(
|
|
||||||
s -> factionObj.addFactionAmicable(s.getAsString())
|
|
||||||
);
|
|
||||||
jsonObj.get("factionneutral").getAsJsonArray().forEach(
|
|
||||||
s -> factionObj.addFactionNeutral(s.getAsString())
|
|
||||||
);
|
|
||||||
jsonObj.get("factionhostile").getAsJsonArray().forEach(
|
|
||||||
s -> factionObj.addFactionHostile(s.getAsString())
|
|
||||||
);
|
|
||||||
jsonObj.get("factionfearful").getAsJsonArray().forEach(
|
|
||||||
s -> factionObj.addFactionFearful(s.getAsString())
|
|
||||||
);
|
|
||||||
|
|
||||||
return factionObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.Torvald.Terrarum.Actors.Faction
|
||||||
|
|
||||||
|
import com.Torvald.JsonFetcher
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-02-15.
|
||||||
|
*/
|
||||||
|
class FactionRelatorFactory {
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun build(filename: String): Faction {
|
||||||
|
val jsonObj = JsonFetcher.readJson(JSONPATH + filename)
|
||||||
|
val factionObj = Faction(jsonObj.get("factionname").asString)
|
||||||
|
|
||||||
|
|
||||||
|
jsonObj.get("factionamicable").asJsonArray.forEach { s -> factionObj.addFactionAmicable(s.asString) }
|
||||||
|
jsonObj.get("factionneutral").asJsonArray.forEach { s -> factionObj.addFactionNeutral(s.asString) }
|
||||||
|
jsonObj.get("factionhostile").asJsonArray.forEach { s -> factionObj.addFactionHostile(s.asString) }
|
||||||
|
jsonObj.get("factionfearful").asJsonArray.forEach { s -> factionObj.addFactionFearful(s.asString) }
|
||||||
|
|
||||||
|
return factionObj
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
val JSONPATH = "./res/raw/"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,8 +8,6 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
interface Factionable {
|
interface Factionable {
|
||||||
|
|
||||||
fun assignFaction(f: Faction)
|
var faction: HashSet<Faction>
|
||||||
fun unassignFaction(f: Faction)
|
|
||||||
var faction: HashSet<Faction>?
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.Actors.ItemProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-06.
|
|
||||||
*/
|
|
||||||
public class Material {
|
|
||||||
|
|
||||||
/** How sharp the material is. Default to 1000.*/
|
|
||||||
int maxEdge;
|
|
||||||
/** Self-explanatory. [kPa in Vickers hardness]*/
|
|
||||||
int hardness;
|
|
||||||
/** Self-explanatory. [g/l]*/
|
|
||||||
int density;
|
|
||||||
|
|
||||||
public Material() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxEdge() {
|
|
||||||
return maxEdge;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMaxEdge(int maxEdge) {
|
|
||||||
this.maxEdge = maxEdge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHardness() {
|
|
||||||
return hardness;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHardness(int hardness) {
|
|
||||||
this.hardness = hardness;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDensity() {
|
|
||||||
return density;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDensity(int density) {
|
|
||||||
this.density = density;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.Actors.ItemProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-06.
|
|
||||||
*/
|
|
||||||
public class MaterialFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load from CSV
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,17 @@ open class NPCIntelligentBase : ActorWithBody()
|
|||||||
override var itemData: InventoryItem = object : InventoryItem {
|
override var itemData: InventoryItem = object : InventoryItem {
|
||||||
override var itemID = HQRNG().nextLong()
|
override var itemID = HQRNG().nextLong()
|
||||||
|
|
||||||
override var weight = 0f
|
override var mass: Float
|
||||||
|
get() = actorValue.get("mass") as Float
|
||||||
|
set(value) {
|
||||||
|
actorValue.set("mass", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
override var scale: Float
|
||||||
|
get() = actorValue.get("scale") as Float
|
||||||
|
set(value) {
|
||||||
|
actorValue.set("scale", value)
|
||||||
|
}
|
||||||
|
|
||||||
override fun effectWhileInPocket(gc: GameContainer, delta_t: Int) {
|
override fun effectWhileInPocket(gc: GameContainer, delta_t: Int) {
|
||||||
|
|
||||||
@@ -41,13 +51,13 @@ open class NPCIntelligentBase : ActorWithBody()
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transient private var ai: ActorAI? = null
|
@Transient private var ai: ActorAI? = null
|
||||||
override var inventory: ActorInventory? = null
|
override var inventory: ActorInventory = ActorInventory()
|
||||||
|
|
||||||
private val factionSet = HashSet<Faction>()
|
private val factionSet = HashSet<Faction>()
|
||||||
|
|
||||||
override var referenceID: Long = HQRNG().nextLong()
|
override var referenceID: Long = HQRNG().nextLong()
|
||||||
|
|
||||||
override var faction: HashSet<Faction>? = null
|
override var faction: HashSet<Faction> = HashSet()
|
||||||
|
|
||||||
override var houseDesignation: ArrayList<Int>? = null
|
override var houseDesignation: ArrayList<Int>? = null
|
||||||
/**
|
/**
|
||||||
@@ -56,14 +66,6 @@ open class NPCIntelligentBase : ActorWithBody()
|
|||||||
*/
|
*/
|
||||||
private var houseTiles = ArrayList<Int>()
|
private var houseTiles = ArrayList<Int>()
|
||||||
|
|
||||||
override fun assignFaction(f: Faction) {
|
|
||||||
factionSet.add(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unassignFaction(f: Faction) {
|
|
||||||
factionSet.remove(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun attachItemData() {
|
override fun attachItemData() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,13 +69,13 @@ object PFSigrid {
|
|||||||
|
|
||||||
p.setPosition((4096 * 16).toFloat(), (300 * 16).toFloat())
|
p.setPosition((4096 * 16).toFloat(), (300 * 16).toFloat())
|
||||||
|
|
||||||
p.assignFaction(loadFactioningData("FactionSigrid.json"))
|
p.faction.add(loadFactioningData("FactionSigrid.json"))
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFactioningData(filename: String): Faction {
|
private fun loadFactioningData(filename: String): Faction {
|
||||||
var jsonObject: JsonObject? = null
|
var jsonObject: JsonObject = JsonObject()
|
||||||
try {
|
try {
|
||||||
jsonObject = JsonFetcher.readJson(FACTION_PATH + filename)
|
jsonObject = JsonFetcher.readJson(FACTION_PATH + filename)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@@ -83,7 +83,7 @@ object PFSigrid {
|
|||||||
System.exit(-1)
|
System.exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
val faction = Faction(jsonObject!!.get("factionname").asString)
|
val faction = Faction(jsonObject.get("factionname").asString)
|
||||||
|
|
||||||
jsonObject.get("factionamicable").asJsonArray.forEach { jobj -> faction.addFactionAmicable(jobj.asString) }
|
jsonObject.get("factionamicable").asJsonArray.forEach { jobj -> faction.addFactionAmicable(jobj.asString) }
|
||||||
jsonObject.get("factionneutral").asJsonArray.forEach { jobj -> faction.addFactionNeutral(jobj.asString) }
|
jsonObject.get("factionneutral").asJsonArray.forEach { jobj -> faction.addFactionNeutral(jobj.asString) }
|
||||||
|
|||||||
@@ -61,16 +61,20 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
@Transient private val BASE_DENSITY = 1020
|
@Transient private val BASE_DENSITY = 1020
|
||||||
|
|
||||||
/** Must be set by PlayerFactory */
|
/** Must be set by PlayerFactory */
|
||||||
override var inventory: ActorInventory? = null
|
override var inventory: ActorInventory = ActorInventory()
|
||||||
|
|
||||||
/** Must be set by PlayerFactory */
|
/** Must be set by PlayerFactory */
|
||||||
override var faction: HashSet<Faction>? = null
|
override var faction: HashSet<Faction> = HashSet()
|
||||||
|
|
||||||
override var houseDesignation: ArrayList<Int>? = null
|
override var houseDesignation: ArrayList<Int>? = null
|
||||||
|
|
||||||
override var luminosity: Char
|
override var luminosity: Char
|
||||||
get() = if (actorValue.get("luminosity") != null) actorValue.getAsInt("luminosity").toChar()
|
get() {
|
||||||
else 0 as Char
|
if (actorValue.get("luminosity") != null)
|
||||||
|
return actorValue.getAsInt("luminosity")!!.toChar()
|
||||||
|
else
|
||||||
|
return 0.toChar()
|
||||||
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
actorValue.set("luminosity", value)
|
actorValue.set("luminosity", value)
|
||||||
}
|
}
|
||||||
@@ -115,8 +119,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePhysicalInfos() {
|
private fun updatePhysicalInfos() {
|
||||||
scale = actorValue.getAsFloat("scale")
|
scale = actorValue.getAsFloat("scale")!!
|
||||||
mass = actorValue.getAsFloat("basemass") * FastMath.pow(scale, 3f)
|
mass = actorValue.getAsFloat("basemass")!! * FastMath.pow(scale, 3f)
|
||||||
if (elasticity != 0f) elasticity = 0f
|
if (elasticity != 0f) elasticity = 0f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,8 +133,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
|
private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
|
||||||
//if ((!super.isWalledLeft() && left) || (!super.isWalledRight() && !left)) {
|
//if ((!super.isWalledLeft() && left) || (!super.isWalledRight() && !left)) {
|
||||||
readonly_totalX = veloX +
|
readonly_totalX = veloX +
|
||||||
actorValue.getAsFloat("accel") *
|
actorValue.getAsFloat("accel")!! *
|
||||||
actorValue.getAsFloat("accelmult") *
|
actorValue.getAsFloat("accelmult")!! *
|
||||||
FastMath.sqrt(scale) *
|
FastMath.sqrt(scale) *
|
||||||
applyAccelRealism(walkPowerCounter) *
|
applyAccelRealism(walkPowerCounter) *
|
||||||
(if (left) -1 else 1).toFloat() *
|
(if (left) -1 else 1).toFloat() *
|
||||||
@@ -143,8 +147,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clamp veloX
|
// Clamp veloX
|
||||||
veloX = absClamp(veloX, actorValue.getAsFloat("speed")
|
veloX = absClamp(veloX, actorValue.getAsFloat("speed")!!
|
||||||
* actorValue.getAsFloat("speedmult")
|
* actorValue.getAsFloat("speedmult")!!
|
||||||
* FastMath.sqrt(scale))
|
* FastMath.sqrt(scale))
|
||||||
|
|
||||||
// Heading flag
|
// Heading flag
|
||||||
@@ -163,8 +167,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
*/
|
*/
|
||||||
private fun walkVertical(up: Boolean, absAxisVal: Float) {
|
private fun walkVertical(up: Boolean, absAxisVal: Float) {
|
||||||
readonly_totalY = veloY +
|
readonly_totalY = veloY +
|
||||||
actorValue.getAsFloat("accel") *
|
actorValue.getAsFloat("accel")!! *
|
||||||
actorValue.getAsFloat("accelmult") *
|
actorValue.getAsFloat("accelmult")!! *
|
||||||
FastMath.sqrt(scale) *
|
FastMath.sqrt(scale) *
|
||||||
applyAccelRealism(walkPowerCounter) *
|
applyAccelRealism(walkPowerCounter) *
|
||||||
(if (up) -1 else 1).toFloat() *
|
(if (up) -1 else 1).toFloat() *
|
||||||
@@ -177,8 +181,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clamp veloX
|
// Clamp veloX
|
||||||
veloY = absClamp(veloY, actorValue.getAsFloat("speed")
|
veloY = absClamp(veloY, actorValue.getAsFloat("speed")!!
|
||||||
* actorValue.getAsFloat("speedmult")
|
* actorValue.getAsFloat("speedmult")!!
|
||||||
* FastMath.sqrt(scale))
|
* FastMath.sqrt(scale))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,15 +215,15 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
|
|
||||||
private fun walkHStop() {
|
private fun walkHStop() {
|
||||||
if (veloX > 0) {
|
if (veloX > 0) {
|
||||||
veloX -= actorValue.getAsFloat("accel") *
|
veloX -= actorValue.getAsFloat("accel")!! *
|
||||||
actorValue.getAsFloat("accelmult") *
|
actorValue.getAsFloat("accelmult")!! *
|
||||||
FastMath.sqrt(scale)
|
FastMath.sqrt(scale)
|
||||||
|
|
||||||
// compensate overshoot
|
// compensate overshoot
|
||||||
if (veloX < 0) veloX = 0f
|
if (veloX < 0) veloX = 0f
|
||||||
} else if (veloX < 0) {
|
} else if (veloX < 0) {
|
||||||
veloX += actorValue.getAsFloat("accel") *
|
veloX += actorValue.getAsFloat("accel")!! *
|
||||||
actorValue.getAsFloat("accelmult") *
|
actorValue.getAsFloat("accelmult")!! *
|
||||||
FastMath.sqrt(scale)
|
FastMath.sqrt(scale)
|
||||||
|
|
||||||
// compensate overshoot
|
// compensate overshoot
|
||||||
@@ -234,7 +238,7 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
private fun walkVStop() {
|
private fun walkVStop() {
|
||||||
if (veloY > 0) {
|
if (veloY > 0) {
|
||||||
veloY -= WALK_STOP_ACCEL *
|
veloY -= WALK_STOP_ACCEL *
|
||||||
actorValue.getAsFloat("accelmult") *
|
actorValue.getAsFloat("accelmult")!! *
|
||||||
FastMath.sqrt(scale)
|
FastMath.sqrt(scale)
|
||||||
|
|
||||||
// compensate overshoot
|
// compensate overshoot
|
||||||
@@ -242,7 +246,7 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
veloY = 0f
|
veloY = 0f
|
||||||
} else if (veloY < 0) {
|
} else if (veloY < 0) {
|
||||||
veloY += WALK_STOP_ACCEL *
|
veloY += WALK_STOP_ACCEL *
|
||||||
actorValue.getAsFloat("accelmult") *
|
actorValue.getAsFloat("accelmult")!! *
|
||||||
FastMath.sqrt(scale)
|
FastMath.sqrt(scale)
|
||||||
|
|
||||||
// compensate overshoot
|
// compensate overshoot
|
||||||
@@ -406,22 +410,10 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
private fun jump() {
|
private fun jump() {
|
||||||
if (jumping) {
|
if (jumping) {
|
||||||
val len = MAX_JUMP_LENGTH.toFloat()
|
val len = MAX_JUMP_LENGTH.toFloat()
|
||||||
val pwr = actorValue.getAsFloat("jumppower")
|
val pwr = actorValue.getAsFloat("jumppower")!!
|
||||||
|
|
||||||
// increment jump counter
|
// increment jump counter
|
||||||
if (jumpCounter < len) jumpCounter += 1
|
if (jumpCounter < len) jumpCounter += 1
|
||||||
// quadratic time (convex) mode
|
|
||||||
/*
|
|
||||||
float sumT = (jumpCounter * (jumpCounter + 1)) / 2f;
|
|
||||||
float timedJumpCharge = ((len + 1) / 2f) - (sumT / len);
|
|
||||||
if (timedJumpCharge < 0) timedJumpCharge = 0;
|
|
||||||
|
|
||||||
float jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD;
|
|
||||||
|
|
||||||
super.setVeloY(veloY
|
|
||||||
- jumpAcc
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// linear time mode
|
// linear time mode
|
||||||
val init = (len + 1) / 2f
|
val init = (len + 1) / 2f
|
||||||
@@ -432,7 +424,7 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
|
|
||||||
veloY -= jumpAcc
|
veloY -= jumpAcc
|
||||||
|
|
||||||
// concave mode?
|
// try concave mode?
|
||||||
}
|
}
|
||||||
|
|
||||||
// for mob AI:
|
// for mob AI:
|
||||||
@@ -501,14 +493,6 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
|
|||||||
return actorValue
|
return actorValue
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun assignFaction(f: Faction) {
|
|
||||||
factionSet.add(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unassignFaction(f: Faction) {
|
|
||||||
factionSet.remove(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addHouseTile(x: Int, y: Int) {
|
override fun addHouseTile(x: Int, y: Int) {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ package com.Torvald.Terrarum.Actors
|
|||||||
*/
|
*/
|
||||||
interface Pocketed {
|
interface Pocketed {
|
||||||
|
|
||||||
var inventory: ActorInventory?
|
var inventory: ActorInventory
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
import com.Torvald.Terrarum.UserInterface.ConsoleWindow;
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-19.
|
|
||||||
*/
|
|
||||||
public class Authenticator implements ConsoleCommand {
|
|
||||||
|
|
||||||
private static boolean a = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(String[] args) {
|
|
||||||
if (args.length == 2) {
|
|
||||||
String pwd = args[1];
|
|
||||||
String hashedPwd = DigestUtils.sha256Hex(pwd);
|
|
||||||
|
|
||||||
if ("54c5b3dd459d5ef778bb2fa1e23a5fb0e1b62ae66970bcb436e8f81a1a1a8e41"
|
|
||||||
.equalsIgnoreCase(hashedPwd)) { // alpine
|
|
||||||
String msg = (a) ? "Locked" : "Authenticated";
|
|
||||||
new Echo().execute(msg);
|
|
||||||
System.out.println("[Authenticator] " + msg);
|
|
||||||
a = !a;
|
|
||||||
((ConsoleWindow) (Terrarum.game.consoleHandler.getUI())).reset();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printUsage(); // thou shalt not pass!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean b() {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printUsage() {
|
|
||||||
CommandInterpreter.echoUnknownCmd("auth");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
46
src/com/Torvald/Terrarum/ConsoleCommand/Authenticator.kt
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
import com.Torvald.Terrarum.UserInterface.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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import java.nio.file.FileSystems;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-07.
|
|
||||||
*/
|
|
||||||
public class Batch implements ConsoleCommand {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] args) throws Exception {
|
|
||||||
if (args.length == 2) {
|
|
||||||
Files.lines(FileSystems.getDefault().getPath(args[1])).forEach
|
|
||||||
(CommandInterpreter::execute);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printUsage() {
|
|
||||||
new Echo().execute("batch path/to/batch.txt");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
src/com/Torvald/Terrarum/ConsoleCommand/Batch.kt
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Game;
|
|
||||||
import com.Torvald.Terrarum.LangPack.Lang;
|
|
||||||
import com.Torvald.Terrarum.UserInterface.ConsoleWindow;
|
|
||||||
|
|
||||||
import java.util.Formatter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-16.
|
|
||||||
*/
|
|
||||||
public class CodexEdictis implements ConsoleCommand {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] args) {
|
|
||||||
if (args.length == 1) {
|
|
||||||
printList();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
try {
|
|
||||||
ConsoleCommand commandObj = CommandDict.getCommand(args[1].toLowerCase());
|
|
||||||
commandObj.printUsage();
|
|
||||||
}
|
|
||||||
catch (NullPointerException e) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
Formatter formatter = new Formatter(sb);
|
|
||||||
|
|
||||||
new Echo().execute("Codex: "
|
|
||||||
+ formatter.format(Lang.get("DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN")
|
|
||||||
, args[1]
|
|
||||||
).toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printUsage() {
|
|
||||||
Echo echo = new Echo();
|
|
||||||
echo.execute("Usage: codex (command)");
|
|
||||||
echo.execute("shows how to use 'command'");
|
|
||||||
echo.execute("leave blank to get list of available commands");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printList() {
|
|
||||||
Echo echo = new Echo();
|
|
||||||
echo.execute(Lang.get("DEV_MESSAGE_CONSOLE_AVAILABLE_COMMANDS"));
|
|
||||||
CommandDict.dict.keySet().forEach((s) -> echo.execute("] " + s));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
45
src/com/Torvald/Terrarum/ConsoleCommand/CodexEdictis.kt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Game
|
||||||
|
import com.Torvald.Terrarum.LangPack.Lang
|
||||||
|
import com.Torvald.Terrarum.UserInterface.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) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-15.
|
|
||||||
*/
|
|
||||||
public class CommandDict {
|
|
||||||
|
|
||||||
protected static HashMap<String, ConsoleCommand> dict;
|
|
||||||
|
|
||||||
public CommandDict() {
|
|
||||||
dict = new HashMap<>();
|
|
||||||
|
|
||||||
dict.put("echo", new Echo());
|
|
||||||
dict.put("setav", new SetAV());
|
|
||||||
dict.put("qqq", new QuitApp());
|
|
||||||
dict.put("codex", new CodexEdictis());
|
|
||||||
dict.put("export", new ExportMap());
|
|
||||||
dict.put("gc", new ForceGC());
|
|
||||||
dict.put("getav", new GetAV());
|
|
||||||
dict.put("getlocale", new GetLocale());
|
|
||||||
dict.put("togglenoclip", new ToggleNoClip());
|
|
||||||
dict.put("nc", dict.get("togglenoclip"));
|
|
||||||
dict.put("bulletintest", new SetBulletin());
|
|
||||||
dict.put("setlocale", new SetLocale());
|
|
||||||
dict.put("zoom", new Zoom());
|
|
||||||
dict.put("teleport", new TeleportPlayer());
|
|
||||||
dict.put("tp", dict.get("teleport"));
|
|
||||||
dict.put("cat", new CatStdout());
|
|
||||||
dict.put("exportav", new ExportAV());
|
|
||||||
dict.put("gsontest", new GsonTest());
|
|
||||||
dict.put("setgl", new SetGlobalLightLevel());
|
|
||||||
dict.put("getfaction", new GetFactioning());
|
|
||||||
dict.put("auth", Terrarum.game.auth);
|
|
||||||
dict.put("spawnball", new SpawnPhysTestBall());
|
|
||||||
dict.put("batch", new Batch());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConsoleCommand getCommand(String commandName) {
|
|
||||||
return dict.get(commandName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
47
src/com/Torvald/Terrarum/ConsoleCommand/CommandDict.kt
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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]!!
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.LangPack.Lang;
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Formatter;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-15.
|
|
||||||
*/
|
|
||||||
public class CommandInterpreter {
|
|
||||||
|
|
||||||
private static String[] commandsAvailableWOAuth = {"auth", "qqq", "zoom", "setlocale", "getlocale"};
|
|
||||||
|
|
||||||
public static void execute(String command) {
|
|
||||||
CommandInput[] cmd = parse(command);
|
|
||||||
|
|
||||||
for (CommandInput single_command : cmd) {
|
|
||||||
ConsoleCommand commandObj = null;
|
|
||||||
try {
|
|
||||||
if (Arrays.asList(commandsAvailableWOAuth).contains(single_command.getName().toLowerCase())) {
|
|
||||||
commandObj = CommandDict.getCommand(single_command.getName().toLowerCase());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (Terrarum.game.auth.b()) {
|
|
||||||
commandObj = CommandDict.getCommand(
|
|
||||||
single_command.getName().toLowerCase()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// System.out.println("ee1");
|
|
||||||
throw new NullPointerException(); // if not authorised, say "Unknown command"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (NullPointerException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
if (commandObj != null) {
|
|
||||||
commandObj.execute(single_command.toStringArray());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
echoUnknownCmd(single_command.getName());
|
|
||||||
// System.out.println("ee3");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
System.out.println("[CommandInterpreter] :");
|
|
||||||
e.printStackTrace();
|
|
||||||
new Echo().execute(Lang.get("ERROR_GENERIC_TEXT"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CommandInput[] parse(String input) {
|
|
||||||
Pattern patternCommands = Pattern.compile("[^;]+");
|
|
||||||
Pattern patternTokensInCommand = Pattern.compile("[\"'][^;]+[\"']|[^ ]+");
|
|
||||||
|
|
||||||
ArrayList<String> commands = new ArrayList<>();
|
|
||||||
|
|
||||||
// split multiple commands
|
|
||||||
Matcher m = patternCommands.matcher(input);
|
|
||||||
while (m.find()) commands.add(m.group());
|
|
||||||
|
|
||||||
// split command tokens from a command
|
|
||||||
CommandInput[] parsedCommands = new CommandInput[commands.size()];
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < parsedCommands.length; i++) {
|
|
||||||
ArrayList<String> tokens = new ArrayList<>();
|
|
||||||
|
|
||||||
m = patternTokensInCommand.matcher(commands.get(i));
|
|
||||||
while (m.find()) {
|
|
||||||
String regexGroup = m.group().replaceAll("[\"\']", "");
|
|
||||||
tokens.add(regexGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create new command
|
|
||||||
parsedCommands[i] = new CommandInput(tokens.toArray());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsedCommands;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void echoUnknownCmd(String cmdname) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
Formatter formatter = new Formatter(sb);
|
|
||||||
|
|
||||||
new Echo().execute(
|
|
||||||
formatter.format(Lang.get("DEV_MESSAGE_CONSOLE_COMMAND_UNKNOWN")
|
|
||||||
, cmdname
|
|
||||||
).toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class CommandInput {
|
|
||||||
private String[] tokens;
|
|
||||||
|
|
||||||
CommandInput(Object[] o) {
|
|
||||||
tokens = new String[o.length];
|
|
||||||
for (int i = 0; i < o.length; i++) {
|
|
||||||
tokens[i] = (String) o[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] toStringArray() {
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getName() {
|
|
||||||
return tokens[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
int getArgsCount() {
|
|
||||||
return tokens.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
116
src/com/Torvald/Terrarum/ConsoleCommand/CommandInterpreter.kt
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-03-15.
|
* Created by minjaesong on 16-01-15.
|
||||||
*/
|
*/
|
||||||
interface ConsoleCommand {
|
interface ConsoleCommand {
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.Torvald.Terrarum.Terrarum;
|
|||||||
import com.Torvald.Terrarum.UserInterface.ConsoleWindow;
|
import com.Torvald.Terrarum.UserInterface.ConsoleWindow;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 16-01-16.
|
* Created by minjaesong on 16-01-16.
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class ExportAV implements ConsoleCommand {
|
|||||||
public void execute(String[] args) {
|
public void execute(String[] args) {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
try {
|
try {
|
||||||
JsonWriter.writeToFile(Terrarum.game.getPlayer().getActorValue()
|
JsonWriter.INSTANCE.writeToFile(Terrarum.game.player.getActorValue()
|
||||||
, Terrarum.defaultDir + "/Exports/" + args[1] + ".json"
|
, Terrarum.defaultDir + "/Exports/" + args[1] + ".json"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class ExportMap implements ConsoleCommand {
|
|||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
buildColorTable();
|
buildColorTable();
|
||||||
|
|
||||||
mapData = new byte[Terrarum.game.map.width * Terrarum.game.map.height * 3];
|
mapData = new byte[Terrarum.game.map.getWidth() * Terrarum.game.map.getHeight() * 3];
|
||||||
|
|
||||||
for (byte tile : Terrarum.game.map.getLayerTerrain()) {
|
for (byte tile : Terrarum.game.map.getLayerTerrain()) {
|
||||||
byte[] colArray = colorTable.getOrDefault(tile, new Col4096(0xFFF))
|
byte[] colArray = colorTable.getOrDefault(tile, new Col4096(0xFFF))
|
||||||
@@ -77,9 +77,9 @@ public class ExportMap implements ConsoleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RasterWriter.writePNG_RGB(
|
RasterWriter.INSTANCE.writePNG_RGB(
|
||||||
Terrarum.game.map.width
|
Terrarum.game.map.getWidth()
|
||||||
, Terrarum.game.map.height
|
, Terrarum.game.map.getHeight()
|
||||||
, mapData
|
, mapData
|
||||||
, dir + args[1] + ".png"
|
, dir + args[1] + ".png"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class GetAV implements ConsoleCommand {
|
|||||||
try {
|
try {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
// print all actorvalue of player
|
// print all actorvalue of player
|
||||||
ActorValue av = Terrarum.game.getPlayer().getActorValue();
|
ActorValue av = Terrarum.game.player.getActorValue();
|
||||||
Set keyset = av.getKeySet();
|
Set keyset = av.getKeySet();
|
||||||
|
|
||||||
keyset.forEach(
|
keyset.forEach(
|
||||||
@@ -31,9 +31,9 @@ public class GetAV implements ConsoleCommand {
|
|||||||
}
|
}
|
||||||
else if (args.length == 2) {
|
else if (args.length == 2) {
|
||||||
echo.execute("player." + args[1] + " = "
|
echo.execute("player." + args[1] + " = "
|
||||||
+ Terrarum.game.getPlayer().getActorValue().get(args[1])
|
+ Terrarum.game.player.getActorValue().get(args[1])
|
||||||
+ " ("
|
+ " ("
|
||||||
+ Terrarum.game.getPlayer().getActorValue().get(args[1]).getClass()
|
+ Terrarum.game.player.getActorValue().get(args[1]).getClass()
|
||||||
.getSimpleName()
|
.getSimpleName()
|
||||||
+ ")"
|
+ ")"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,12 @@ public class GetFactioning implements ConsoleCommand {
|
|||||||
Echo echo = new Echo();
|
Echo echo = new Echo();
|
||||||
|
|
||||||
if (args.length == 1) { // get all factioning data of player
|
if (args.length == 1) { // get all factioning data of player
|
||||||
HashSet<Faction> factionSet = Terrarum.game.getPlayer().getFaction();
|
HashSet<Faction> factionSet = Terrarum.game.player.getFaction();
|
||||||
|
|
||||||
|
if (factionSet == null) {
|
||||||
|
echo.execute("The actor has null faction set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int count = factionSet.size();
|
int count = factionSet.size();
|
||||||
echo.execute(String.valueOf(count) + Lang.pluralise(" faction", count) + " assigned.");
|
echo.execute(String.valueOf(count) + Lang.pluralise(" faction", count) + " assigned.");
|
||||||
|
|||||||
20
src/com/Torvald/Terrarum/ConsoleCommand/Gettime.kt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-20.
|
||||||
|
*/
|
||||||
|
class GetTime : ConsoleCommand {
|
||||||
|
override fun execute(args: Array<String>) {
|
||||||
|
val echo = Echo()
|
||||||
|
echo.execute("Day ${Terrarum.game.map.worldTime.days}, " +
|
||||||
|
"${Terrarum.game.map.worldTime.getFormattedTime()} " +
|
||||||
|
"(${Terrarum.game.map.worldTime.elapsedSeconds()} s)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun printUsage() {
|
||||||
|
Echo().execute("Print current world time in convenient form")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ public class GsonTest implements ConsoleCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(String[] args) {
|
public void execute(String[] args) {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
JsonElement avelem = new Gson().toJsonTree(Terrarum.game.getPlayer());
|
JsonElement avelem = new Gson().toJsonTree(Terrarum.game.player);
|
||||||
|
|
||||||
String jsonString = avelem.toString();
|
String jsonString = avelem.toString();
|
||||||
|
|
||||||
|
|||||||
20
src/com/Torvald/Terrarum/ConsoleCommand/Help.kt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-22.
|
||||||
|
*/
|
||||||
|
class Help : ConsoleCommand {
|
||||||
|
override fun execute(args: Array<String>) {
|
||||||
|
Echo().execute(arrayOf(
|
||||||
|
"echo",
|
||||||
|
"Utility keys:",
|
||||||
|
"F3: Basic debug information",
|
||||||
|
"F7: Toggle lightmap blending",
|
||||||
|
"F8: Toggle smooth lighting"
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun printUsage() {
|
||||||
|
Echo().execute("Prints some utility functions assigned to runction row of the keyboard.")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ class SetAV implements ConsoleCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Terrarum.game.getPlayer().getActorValue().set(args[1], val);
|
Terrarum.game.player.getActorValue().set(args[1], val);
|
||||||
echo.execute("Set " + args[1] + " to " + val);
|
echo.execute("Set " + args[1] + " to " + val);
|
||||||
}
|
}
|
||||||
else if (args.length == 4) {
|
else if (args.length == 4) {
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ public class SetBulletin implements ConsoleCommand {
|
|||||||
String[] testMsg = {
|
String[] testMsg = {
|
||||||
//Lang.get("ERROR_SAVE_CORRUPTED")
|
//Lang.get("ERROR_SAVE_CORRUPTED")
|
||||||
//, Lang.get("MENU_LABEL_CONTINUE_QUESTION")
|
//, Lang.get("MENU_LABEL_CONTINUE_QUESTION")
|
||||||
"갎갎갎갎갎갎갎갎갎갎갎갎갎갎"
|
"Bulletin test “Hello, world!”",
|
||||||
|
"世界一みんなの人気者 それは彼女のこと アシュリー 달이 차오른다 가자"
|
||||||
};
|
};
|
||||||
send(testMsg);
|
send(testMsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.MapDrawer.LightmapRenderer;
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-02-17.
|
|
||||||
*/
|
|
||||||
public class SetGlobalLightLevel implements ConsoleCommand {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] args) {
|
|
||||||
if (args.length == 4) {
|
|
||||||
try {
|
|
||||||
int r = new Integer(args[1]);
|
|
||||||
int g = new Integer(args[2]);
|
|
||||||
int b = new Integer(args[3]);
|
|
||||||
char GL = LightmapRenderer.constructRGBFromInt(r, g, b);
|
|
||||||
|
|
||||||
Terrarum.game.map.setGlobalLight(GL);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e) {
|
|
||||||
new Echo().execute("Wrong number input.");
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e1) {
|
|
||||||
new Echo().execute("Range: 0-" + LightmapRenderer.getCHANNEL_MAX() + " per channel");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (args.length == 2) {
|
|
||||||
try {
|
|
||||||
char GL = (char) (new Integer(args[1]).intValue());
|
|
||||||
|
|
||||||
if (GL < 0 || GL >= LightmapRenderer.getCOLOUR_DOMAIN_SIZE()) {
|
|
||||||
new Echo().execute("Range: 0-" + (LightmapRenderer.getCOLOUR_DOMAIN_SIZE() - 1));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Terrarum.game.map.setGlobalLight(GL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e) {
|
|
||||||
new Echo().execute("Wrong number input.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printUsage() {
|
|
||||||
new Echo().execute("Usage: setgl [raw_value|r g b]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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 = Integer(args[1]).toInt().toChar()
|
||||||
|
|
||||||
|
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]")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,15 +15,15 @@ public class SetLocale implements ConsoleCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(String[] args) {
|
public void execute(String[] args) {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
String prevLocale = Terrarum.gameLocale;
|
String prevLocale = Terrarum.Companion.getGameLocale();
|
||||||
Terrarum.gameLocale = args[1];
|
Terrarum.Companion.setGameLocale(args[1]);
|
||||||
try {
|
try {
|
||||||
new Lang();
|
new Lang();
|
||||||
new Echo().execute("Set locale to '" + Terrarum.gameLocale + "'.");
|
new Echo().execute("Set locale to '" + Terrarum.Companion.getGameLocale() + "'.");
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
new Echo().execute("could not read lang file.");
|
new Echo().execute("could not read lang file.");
|
||||||
Terrarum.gameLocale = prevLocale;
|
Terrarum.Companion.setGameLocale(prevLocale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (args.length == 1) {
|
else if (args.length == 1) {
|
||||||
|
|||||||
25
src/com/Torvald/Terrarum/ConsoleCommand/SetTimeDelta.kt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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>")
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/com/Torvald/Terrarum/ConsoleCommand/Settime.kt
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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>")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ public class TeleportPlayer implements ConsoleCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Terrarum.game.getPlayer().setPosition(x, y);
|
Terrarum.game.player.setPosition(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import com.Torvald.Terrarum.Terrarum;
|
|||||||
public class ToggleNoClip implements ConsoleCommand {
|
public class ToggleNoClip implements ConsoleCommand {
|
||||||
@Override
|
@Override
|
||||||
public void execute(String[] args) {
|
public void execute(String[] args) {
|
||||||
boolean status = Terrarum.game.getPlayer().isNoClip();
|
boolean status = Terrarum.game.player.isNoClip();
|
||||||
|
|
||||||
Terrarum.game.getPlayer().setNoClip(!status);
|
Terrarum.game.player.setNoClip(!status);
|
||||||
new Echo().execute("Set no-clip status to " + String.valueOf(!status));
|
new Echo().execute("Set no-clip status to " + String.valueOf(!status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.ConsoleCommand;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Game;
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-25.
|
|
||||||
*/
|
|
||||||
public class Zoom implements ConsoleCommand {
|
|
||||||
@Override
|
|
||||||
public void execute(String[] args) {
|
|
||||||
if (args.length == 2) {
|
|
||||||
|
|
||||||
float zoom;
|
|
||||||
try {
|
|
||||||
zoom = new Float(args[1]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e) {
|
|
||||||
new 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();
|
|
||||||
|
|
||||||
new Echo().execute("Set screen zoom to " + String.valueOf(zoom));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void printUsage() {
|
|
||||||
new Echo().execute("Usage: zoom [zoom]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
42
src/com/Torvald/Terrarum/ConsoleCommand/Zoom.kt
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package com.Torvald.Terrarum.ConsoleCommand
|
||||||
|
|
||||||
|
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]")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.Torvald.Terrarum;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-03-12.
|
|
||||||
*/
|
|
||||||
public class DefaultConfig {
|
|
||||||
|
|
||||||
public static JsonObject fetch() {
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
|
||||||
|
|
||||||
jsonObject.addProperty("smoothlighting", true);
|
|
||||||
jsonObject.addProperty("imtooyoungtodie", false);
|
|
||||||
jsonObject.addProperty("language", Terrarum.getSysLang());
|
|
||||||
jsonObject.addProperty("notificationshowuptime", 6500);
|
|
||||||
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
19
src/com/Torvald/Terrarum/DefaultConfig.kt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.Torvald.Terrarum
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-19.
|
||||||
|
*/
|
||||||
|
object DefaultConfig {
|
||||||
|
fun fetch(): JsonObject {
|
||||||
|
val jsonObject = JsonObject()
|
||||||
|
|
||||||
|
jsonObject.addProperty("smoothlighting", true)
|
||||||
|
jsonObject.addProperty("imtooyoungtodie", false)
|
||||||
|
jsonObject.addProperty("language", Terrarum.sysLang)
|
||||||
|
jsonObject.addProperty("notificationshowuptime", 6500)
|
||||||
|
|
||||||
|
return jsonObject
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.Exceptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-04.
|
|
||||||
*/
|
|
||||||
public class InvalidValueException extends Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -51,7 +51,7 @@ public class Game extends BasicGameState {
|
|||||||
public UIHandler debugWindow;
|
public UIHandler debugWindow;
|
||||||
public UIHandler notifinator;
|
public UIHandler notifinator;
|
||||||
|
|
||||||
@NotNull Player player;
|
Player player;
|
||||||
|
|
||||||
private Image GRADIENT_IMAGE;
|
private Image GRADIENT_IMAGE;
|
||||||
private Rectangle skyBox;
|
private Rectangle skyBox;
|
||||||
@@ -101,7 +101,7 @@ public class Game extends BasicGameState {
|
|||||||
map.setGravitation(9.8f);
|
map.setGravitation(9.8f);
|
||||||
|
|
||||||
MapGenerator.attachMap(map);
|
MapGenerator.attachMap(map);
|
||||||
MapGenerator.setSeed(0x51621D);
|
MapGenerator.setSeed(0x51621D2);
|
||||||
//MapGenerator.setSeed(new HQRNG().nextLong());
|
//MapGenerator.setSeed(new HQRNG().nextLong());
|
||||||
MapGenerator.generateMap();
|
MapGenerator.generateMap();
|
||||||
|
|
||||||
357
src/com/Torvald/Terrarum/Game.kt
Normal file
@@ -0,0 +1,357 @@
|
|||||||
|
package com.Torvald.Terrarum
|
||||||
|
|
||||||
|
import com.Torvald.ColourUtil.Col40
|
||||||
|
import com.Torvald.Terrarum.Actors.*
|
||||||
|
import com.Torvald.Terrarum.ConsoleCommand.Authenticator
|
||||||
|
import com.Torvald.Terrarum.ConsoleCommand.CommandDict
|
||||||
|
import com.Torvald.Terrarum.GameControl.GameController
|
||||||
|
import com.Torvald.Terrarum.GameControl.Key
|
||||||
|
import com.Torvald.Terrarum.GameControl.KeyMap
|
||||||
|
import com.Torvald.Terrarum.GameControl.KeyToggler
|
||||||
|
import com.Torvald.Terrarum.GameMap.GameMap
|
||||||
|
import com.Torvald.Terrarum.GameMap.WorldTime
|
||||||
|
import com.Torvald.Terrarum.MapDrawer.LightmapRenderer
|
||||||
|
import com.Torvald.Terrarum.MapDrawer.MapCamera
|
||||||
|
import com.Torvald.Terrarum.MapDrawer.MapDrawer
|
||||||
|
import com.Torvald.Terrarum.MapGenerator.MapGenerator
|
||||||
|
import com.Torvald.Terrarum.MapGenerator.RoguelikeRandomiser
|
||||||
|
import com.Torvald.Terrarum.TileProperties.TilePropCodex
|
||||||
|
import com.Torvald.Terrarum.TileStat.TileStat
|
||||||
|
import com.Torvald.Terrarum.UserInterface.BasicDebugInfoWindow
|
||||||
|
import com.Torvald.Terrarum.UserInterface.ConsoleWindow
|
||||||
|
import com.Torvald.Terrarum.UserInterface.Notification
|
||||||
|
import com.Torvald.Terrarum.UserInterface.UIHandler
|
||||||
|
import com.jme3.math.FastMath
|
||||||
|
import org.lwjgl.opengl.ARBShaderObjects
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
import org.newdawn.slick.*
|
||||||
|
import org.newdawn.slick.fills.GradientFill
|
||||||
|
import org.newdawn.slick.geom.Rectangle
|
||||||
|
import org.newdawn.slick.state.BasicGameState
|
||||||
|
import org.newdawn.slick.state.StateBasedGame
|
||||||
|
import shader.Shader
|
||||||
|
import java.lang.management.ManagementFactory
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-19.
|
||||||
|
*/
|
||||||
|
class Game @Throws(SlickException::class)
|
||||||
|
constructor() : BasicGameState() {
|
||||||
|
internal var game_mode = 0
|
||||||
|
|
||||||
|
lateinit var map: GameMap
|
||||||
|
|
||||||
|
var actorContainer = HashSet<Actor>()
|
||||||
|
var uiContainer = HashSet<UIHandler>()
|
||||||
|
|
||||||
|
lateinit var consoleHandler: UIHandler
|
||||||
|
lateinit var debugWindow: UIHandler
|
||||||
|
lateinit var notifinator: UIHandler
|
||||||
|
|
||||||
|
lateinit internal var player: Player
|
||||||
|
|
||||||
|
private var GRADIENT_IMAGE: Image? = null
|
||||||
|
private var skyBox: Rectangle? = null
|
||||||
|
|
||||||
|
var screenZoom = 1.0f
|
||||||
|
val ZOOM_MAX = 2.0f
|
||||||
|
val ZOOM_MIN = 0.25f
|
||||||
|
|
||||||
|
private var shader12BitCol: Shader? = null
|
||||||
|
private var shaderBlurH: Shader? = null
|
||||||
|
private var shaderBlurV: Shader? = null
|
||||||
|
|
||||||
|
|
||||||
|
private val useShader: Boolean = false
|
||||||
|
private val shaderProgram = 0
|
||||||
|
|
||||||
|
|
||||||
|
private val ENV_COLTEMP_SUNRISE = 2500
|
||||||
|
private val ENV_SUNLIGHT_DELTA = MapDrawer.ENV_COLTEMP_NOON - ENV_COLTEMP_SUNRISE
|
||||||
|
|
||||||
|
|
||||||
|
var memInUse: Long = 0
|
||||||
|
get() = ManagementFactory.getMemoryMXBean().heapMemoryUsage.used shr 20
|
||||||
|
var totalVMMem: Long = 0
|
||||||
|
get() = Runtime.getRuntime().maxMemory() shr 20
|
||||||
|
|
||||||
|
var auth = Authenticator()
|
||||||
|
|
||||||
|
private var update_delta: Int = 0
|
||||||
|
|
||||||
|
private val KEY_LIGHTMAP_RENDER = Key.F7
|
||||||
|
private val KEY_LIGHTMAP_SMOOTH = Key.F8
|
||||||
|
|
||||||
|
@Throws(SlickException::class)
|
||||||
|
override fun init(gameContainer: GameContainer, stateBasedGame: StateBasedGame) {
|
||||||
|
KeyMap.build()
|
||||||
|
|
||||||
|
shader12BitCol = Shader.makeShader("./res/4096.vrt", "./res/4096.frg")
|
||||||
|
shaderBlurH = Shader.makeShader("./res/blurH.vrt", "./res/blur.frg")
|
||||||
|
shaderBlurV = Shader.makeShader("./res/blurV.vrt", "./res/blur.frg")
|
||||||
|
|
||||||
|
|
||||||
|
GRADIENT_IMAGE = Image("res/graphics/sky_colour.png")
|
||||||
|
skyBox = Rectangle(0f, 0f, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
|
||||||
|
|
||||||
|
TilePropCodex()
|
||||||
|
// new ItemPropCodex() -- This is kotlin object and already initialised.
|
||||||
|
|
||||||
|
map = GameMap(8192, 2048)
|
||||||
|
map.gravitation = 9.8f
|
||||||
|
|
||||||
|
MapGenerator.attachMap(map)
|
||||||
|
MapGenerator.setSeed(0x51621D2)
|
||||||
|
//MapGenerator.setSeed(new HQRNG().nextLong());
|
||||||
|
MapGenerator.generateMap()
|
||||||
|
|
||||||
|
RoguelikeRandomiser.setSeed(0x540198)
|
||||||
|
//RoguelikeRandomiser.setSeed(new HQRNG().nextLong());
|
||||||
|
|
||||||
|
|
||||||
|
// add new player and put it to actorContainer
|
||||||
|
//player = new Player();
|
||||||
|
player = PFSigrid.build()
|
||||||
|
//player.setNoClip(true);
|
||||||
|
actorContainer.add(player)
|
||||||
|
|
||||||
|
consoleHandler = UIHandler(ConsoleWindow())
|
||||||
|
consoleHandler.setPosition(0, 0)
|
||||||
|
|
||||||
|
debugWindow = UIHandler(BasicDebugInfoWindow())
|
||||||
|
debugWindow.setPosition(0, 0)
|
||||||
|
|
||||||
|
notifinator = UIHandler(Notification())
|
||||||
|
notifinator.setPosition(
|
||||||
|
(Terrarum.WIDTH - notifinator.UI.width) / 2, Terrarum.HEIGHT - notifinator.UI.height)
|
||||||
|
notifinator.setVisibility(true)
|
||||||
|
|
||||||
|
if (Terrarum.gameConfig.getAsBoolean("smoothlighting") == true)
|
||||||
|
KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, true)
|
||||||
|
else
|
||||||
|
KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {
|
||||||
|
update_delta = delta
|
||||||
|
setAppTitle()
|
||||||
|
|
||||||
|
// GL at after_sunrise-noon_before_sunset
|
||||||
|
map.updateWorldTime(delta)
|
||||||
|
map.setGlobalLight(globalLightByTime);
|
||||||
|
|
||||||
|
GameController.processInput(gc.input)
|
||||||
|
|
||||||
|
TileStat.update()
|
||||||
|
|
||||||
|
MapDrawer.update(gc, delta)
|
||||||
|
MapCamera.update(gc, delta)
|
||||||
|
|
||||||
|
actorContainer.forEach { actor -> actor.update(gc, delta) }
|
||||||
|
actorContainer.forEach { actor ->
|
||||||
|
if (actor is Visible) {
|
||||||
|
actor.updateBodySprite(gc, delta)
|
||||||
|
}
|
||||||
|
if (actor is Glowing) {
|
||||||
|
actor.updateGlowSprite(gc, delta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uiContainer.forEach { ui -> ui.update(gc, delta) }
|
||||||
|
consoleHandler.update(gc, delta)
|
||||||
|
debugWindow.update(gc, delta)
|
||||||
|
|
||||||
|
|
||||||
|
notifinator.update(gc, delta)
|
||||||
|
|
||||||
|
Terrarum.appgc.setVSync(Terrarum.appgc.fps >= Terrarum.VSYNC_TRIGGER_THRESHOLD)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setAppTitle() {
|
||||||
|
Terrarum.appgc.setTitle(
|
||||||
|
"Simple Slick Game — FPS: "
|
||||||
|
+ Terrarum.appgc.fps + " ("
|
||||||
|
+ Terrarum.TARGET_INTERNAL_FPS.toString()
|
||||||
|
+ ") — "
|
||||||
|
+ memInUse.toString() + "M / "
|
||||||
|
+ totalVMMem.toString() + "M")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||||
|
Terrarum.gameConfig["smoothlighting"] = KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH)
|
||||||
|
|
||||||
|
if (!g.isAntiAlias) g.isAntiAlias = true
|
||||||
|
|
||||||
|
drawSkybox(g)
|
||||||
|
|
||||||
|
// compensate for zoom. UIs have to be treated specially! (see UIHandler)
|
||||||
|
g.translate(
|
||||||
|
-MapCamera.getCameraX() * screenZoom, -MapCamera.getCameraY() * screenZoom)
|
||||||
|
|
||||||
|
MapCamera.renderBehind(gc, g)
|
||||||
|
|
||||||
|
actorContainer.forEach { actor -> if (actor is Visible) actor.drawBody(gc, g) }
|
||||||
|
actorContainer.forEach { actor -> if (actor is Glowing) actor.drawGlow(gc, g) }
|
||||||
|
|
||||||
|
LightmapRenderer.renderLightMap()
|
||||||
|
|
||||||
|
MapCamera.renderFront(gc, g)
|
||||||
|
MapDrawer.render(gc, g)
|
||||||
|
|
||||||
|
|
||||||
|
setBlendModeMul()
|
||||||
|
|
||||||
|
MapDrawer.drawEnvOverlay(g)
|
||||||
|
|
||||||
|
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) setBlendModeMul()
|
||||||
|
else setBlendModeNormal()
|
||||||
|
|
||||||
|
LightmapRenderer.draw(g)
|
||||||
|
|
||||||
|
setBlendModeNormal()
|
||||||
|
|
||||||
|
uiContainer.forEach { ui -> ui.render(gc, g) }
|
||||||
|
debugWindow.render(gc, g)
|
||||||
|
consoleHandler.render(gc, g)
|
||||||
|
notifinator.render(gc, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addActor(e: Actor): Boolean {
|
||||||
|
return actorContainer.add(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeActor(e: Actor): Boolean {
|
||||||
|
return actorContainer.remove(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getGradientColour(): Array<Color> {
|
||||||
|
val gradMapWidth = GRADIENT_IMAGE!!.width
|
||||||
|
val phase = Math.round(
|
||||||
|
map.worldTime.elapsedSeconds().toFloat() / WorldTime.DAY_LENGTH.toFloat() * gradMapWidth
|
||||||
|
)
|
||||||
|
|
||||||
|
//update in every INTERNAL_FRAME frames
|
||||||
|
return arrayOf(
|
||||||
|
GRADIENT_IMAGE!!.getColor(phase, 0),
|
||||||
|
GRADIENT_IMAGE!!.getColor(phase, GRADIENT_IMAGE!!.height - 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
|
GameController.keyPressed(key, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun keyReleased(key: Int, c: Char) {
|
||||||
|
GameController.keyReleased(key, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||||
|
GameController.mouseMoved(oldx, oldy, newx, newy)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||||
|
GameController.mouseDragged(oldx, oldy, newx, newy)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mousePressed(button: Int, x: Int, y: Int) {
|
||||||
|
GameController.mousePressed(button, x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseReleased(button: Int, x: Int, y: Int) {
|
||||||
|
GameController.mouseReleased(button, x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseWheelMoved(change: Int) {
|
||||||
|
GameController.mouseWheelMoved(change)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun controllerButtonPressed(controller: Int, button: Int) {
|
||||||
|
GameController.controllerButtonPressed(controller, button)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun controllerButtonReleased(controller: Int, button: Int) {
|
||||||
|
GameController.controllerButtonReleased(controller, button)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getID(): Int {
|
||||||
|
return Terrarum.SCENE_ID_GAME
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun drawSkybox(g: Graphics) {
|
||||||
|
val colourTable = getGradientColour()
|
||||||
|
val skyColourFill = GradientFill(
|
||||||
|
0f, 0f, colourTable[0],
|
||||||
|
0f, Terrarum.HEIGHT.toFloat(), colourTable[1]
|
||||||
|
)
|
||||||
|
g.fill(skyBox, skyColourFill)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setBlendModeMul() {
|
||||||
|
GL11.glEnable(GL11.GL_BLEND)
|
||||||
|
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setBlendModeNormal() {
|
||||||
|
GL11.glDisable(GL11.GL_BLEND)
|
||||||
|
Terrarum.appgc.graphics.setDrawMode(Graphics.MODE_NORMAL)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sendNotification(msg: Array<String>) {
|
||||||
|
(notifinator.UI as Notification).sendNotification(Terrarum.appgc, update_delta, msg)
|
||||||
|
notifinator.setAsOpening()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val globalLightByTime: Char
|
||||||
|
get() {
|
||||||
|
/**
|
||||||
|
* y = -DELTA(x-1)^RAYLEIGH + MAX
|
||||||
|
* See documentation 'sky colour'
|
||||||
|
*/
|
||||||
|
val INTENSITY_MIN = 9
|
||||||
|
val INTENSITY_MAX = 39
|
||||||
|
|
||||||
|
val COLTEMP_MIN = 2500
|
||||||
|
val COLTEMP_MAX = MapDrawer.ENV_COLTEMP_NOON
|
||||||
|
val COLTEMP_DELTA = COLTEMP_MAX - COLTEMP_MIN
|
||||||
|
val RAYLEIGH_INDEX = 3.3f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get colour temperature
|
||||||
|
*/
|
||||||
|
val dusk_len_colouring = 0.5f
|
||||||
|
val daytime_len = 10
|
||||||
|
var secs_offset: Int = Math.round(WorldTime.HOUR_SEC * dusk_len_colouring) // 1h as Seconds
|
||||||
|
var time_domain_x_in_sec = (daytime_len + 2*dusk_len_colouring) * WorldTime.HOUR_SEC // 11h as Seconds
|
||||||
|
|
||||||
|
var today_secs: Float = map.worldTime.elapsedSeconds().toFloat() + secs_offset
|
||||||
|
if (today_secs > time_domain_x_in_sec - secs_offset) today_secs - WorldTime.DAY_LENGTH // 79000 -> -200
|
||||||
|
|
||||||
|
var func_x: Float = (today_secs / time_domain_x_in_sec) * 2f // 0-46800 -> 0-2.0
|
||||||
|
if (func_x < 1) func_x = 2f - func_x // mirror graph
|
||||||
|
if (func_x > 2) func_x = 2f // clamp
|
||||||
|
|
||||||
|
// println("x: $func_x")
|
||||||
|
|
||||||
|
val sunAltColouring: Int = FastMath.ceil(
|
||||||
|
-COLTEMP_DELTA * FastMath.pow(func_x - 1, RAYLEIGH_INDEX) + COLTEMP_MAX
|
||||||
|
)
|
||||||
|
val sunColour: Col40 = Col40(MapDrawer.getColourFromMap(sunAltColouring))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get intensity
|
||||||
|
*/
|
||||||
|
val dusk_len = 1.5f
|
||||||
|
val intensity: Int = 39
|
||||||
|
secs_offset = Math.round(WorldTime.HOUR_SEC * dusk_len) // 1h30 as Seconds
|
||||||
|
time_domain_x_in_sec = (daytime_len + 2*dusk_len) * WorldTime.HOUR_SEC // 13h as Seconds
|
||||||
|
|
||||||
|
today_secs = map.worldTime.elapsedSeconds().toFloat() + secs_offset
|
||||||
|
if (today_secs > time_domain_x_in_sec - secs_offset) today_secs - WorldTime.DAY_LENGTH // 79000 -> -200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return LightmapRenderer.darkenUniformInt(sunColour.raw, INTENSITY_MAX - intensity)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.Torvald.Terrarum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 15-12-30.
|
|
||||||
*/
|
|
||||||
public class GameConfig extends KVHashMap {
|
|
||||||
|
|
||||||
}
|
|
||||||
6
src/com/Torvald/Terrarum/GameConfig.kt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package com.Torvald.Terrarum
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 16-03-19.
|
||||||
|
*/
|
||||||
|
class GameConfig : KVHashMap()
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.Torvald.Terrarum.GameControl;
|
package com.Torvald.Terrarum.GameControl
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 15-12-31.
|
* Created by minjaesong on 15-12-31.
|
||||||
*/
|
*/
|
||||||
public enum EnumKeyFunc{
|
enum class EnumKeyFunc {
|
||||||
UI_CONSOLE, UI_BASIC_INFO,
|
UI_CONSOLE, UI_BASIC_INFO,
|
||||||
MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, JUMP
|
MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, JUMP
|
||||||
}
|
}
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.GameControl;
|
|
||||||
|
|
||||||
import com.Torvald.Terrarum.Actors.Controllable;
|
|
||||||
import com.Torvald.Terrarum.Actors.Player;
|
|
||||||
import com.Torvald.Terrarum.MapDrawer.MapCamera;
|
|
||||||
import com.Torvald.Terrarum.MapDrawer.MapDrawer;
|
|
||||||
import com.Torvald.Terrarum.Terrarum;
|
|
||||||
import com.Torvald.Terrarum.TileProperties.TileNameCode;
|
|
||||||
import com.Torvald.Terrarum.TileProperties.TilePropCodex;
|
|
||||||
import com.Torvald.Terrarum.UserInterface.UIHandler;
|
|
||||||
import org.newdawn.slick.Input;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 15-12-31.
|
|
||||||
*/
|
|
||||||
public class GameController {
|
|
||||||
|
|
||||||
private static KeyMap keyMap;
|
|
||||||
|
|
||||||
public GameController() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setKeyMap(KeyMap map) {
|
|
||||||
keyMap = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void processInput(Input input) {
|
|
||||||
int mouseTileX = (int) ((MapCamera.getCameraX() + input.getMouseX() / Terrarum.game.screenZoom)
|
|
||||||
/ MapDrawer.getTILE_SIZE());
|
|
||||||
int mouseTileY = (int) ((MapCamera.getCameraY() + input.getMouseY() / Terrarum.game.screenZoom)
|
|
||||||
/ MapDrawer.getTILE_SIZE());
|
|
||||||
|
|
||||||
|
|
||||||
KeyToggler.update(input);
|
|
||||||
|
|
||||||
|
|
||||||
if (!Terrarum.game.consoleHandler.isTakingControl()) {
|
|
||||||
if (Terrarum.game.getPlayer().getVehicleRiding() != null) {
|
|
||||||
Terrarum.game.getPlayer().getVehicleRiding().processInput(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
Terrarum.game.getPlayer().processInput(input);
|
|
||||||
|
|
||||||
for (UIHandler ui : Terrarum.game.uiContainer) {
|
|
||||||
ui.processInput(input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Terrarum.game.consoleHandler.processInput(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
|
|
||||||
// test tile remove
|
|
||||||
try {
|
|
||||||
Terrarum.game.map.setTileTerrain(mouseTileX, mouseTileY, TileNameCode.AIR);
|
|
||||||
// Terrarum.game.map.setTileWall(mouseTileX, mouseTileY, TileNameCode.AIR);
|
|
||||||
}
|
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
|
|
||||||
// test tile place
|
|
||||||
try {
|
|
||||||
Terrarum.game.map.setTileTerrain(mouseTileX, mouseTileY
|
|
||||||
, Terrarum.game.getPlayer().getActorValue().getAsInt("selectedtile"));
|
|
||||||
}
|
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void keyPressed(int key, char c) {
|
|
||||||
if (keyPressedByCode(key, EnumKeyFunc.UI_CONSOLE)) {
|
|
||||||
Terrarum.game.consoleHandler.toggleOpening();
|
|
||||||
}
|
|
||||||
else if (keyPressedByCode(key, EnumKeyFunc.UI_BASIC_INFO)) {
|
|
||||||
Terrarum.game.debugWindow.toggleOpening();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!Terrarum.game.consoleHandler.isTakingControl()) {
|
|
||||||
if (Terrarum.game.getPlayer().getVehicleRiding() != null) {
|
|
||||||
Terrarum.game.getPlayer().getVehicleRiding().keyPressed(key, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
Terrarum.game.getPlayer().keyPressed(key, c);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Terrarum.game.consoleHandler.keyPressed(key, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
//System.out.println(String.valueOf(key) + ", " + String.valueOf(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void keyReleased(int key, char c) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void mouseMoved(int oldx, int oldy, int newx, int newy) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void mousePressed(int button, int x, int y) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void mouseReleased(int button, int x, int y) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void mouseWheelMoved(int change) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void controllerButtonPressed(int controller, int button) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void controllerButtonReleased(int controller, int button) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean keyPressedByCode(int key, EnumKeyFunc fn) {
|
|
||||||
return (KeyMap.getKeyCode(fn) == key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
122
src/com/Torvald/Terrarum/GameControl/GameController.kt
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package com.Torvald.Terrarum.GameControl
|
||||||
|
|
||||||
|
import com.Torvald.Terrarum.Actors.Controllable
|
||||||
|
import com.Torvald.Terrarum.Actors.Player
|
||||||
|
import com.Torvald.Terrarum.MapDrawer.MapCamera
|
||||||
|
import com.Torvald.Terrarum.MapDrawer.MapDrawer
|
||||||
|
import com.Torvald.Terrarum.Terrarum
|
||||||
|
import com.Torvald.Terrarum.TileProperties.TileNameCode
|
||||||
|
import com.Torvald.Terrarum.TileProperties.TilePropCodex
|
||||||
|
import com.Torvald.Terrarum.UserInterface.UIHandler
|
||||||
|
import org.newdawn.slick.Input
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 15-12-31.
|
||||||
|
*/
|
||||||
|
object GameController {
|
||||||
|
|
||||||
|
fun processInput(input: Input) {
|
||||||
|
val mouseTileX = ((MapCamera.getCameraX() + input.mouseX / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
|
||||||
|
val mouseTileY = ((MapCamera.getCameraY() + input.mouseY / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
|
||||||
|
|
||||||
|
|
||||||
|
KeyToggler.update(input)
|
||||||
|
|
||||||
|
|
||||||
|
if (!Terrarum.game.consoleHandler.isTakingControl) {
|
||||||
|
if (Terrarum.game.player.vehicleRiding != null) {
|
||||||
|
Terrarum.game.player.vehicleRiding!!.processInput(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
Terrarum.game.player.processInput(input)
|
||||||
|
|
||||||
|
for (ui in Terrarum.game.uiContainer) {
|
||||||
|
ui.processInput(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Terrarum.game.consoleHandler.processInput(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
|
||||||
|
// test tile remove
|
||||||
|
try {
|
||||||
|
Terrarum.game.map.setTileTerrain(mouseTileX, mouseTileY, TileNameCode.AIR)
|
||||||
|
// Terrarum.game.map.setTileWall(mouseTileX, mouseTileY, TileNameCode.AIR);
|
||||||
|
}
|
||||||
|
catch (e: ArrayIndexOutOfBoundsException) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
|
||||||
|
// test tile place
|
||||||
|
try {
|
||||||
|
Terrarum.game.map.setTileTerrain(mouseTileX, mouseTileY, Terrarum.game.player.getActorValue().getAsInt("selectedtile")!!)
|
||||||
|
}
|
||||||
|
catch (e: ArrayIndexOutOfBoundsException) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun keyPressed(key: Int, c: Char) {
|
||||||
|
if (keyPressedByCode(key, EnumKeyFunc.UI_CONSOLE)) {
|
||||||
|
Terrarum.game.consoleHandler.toggleOpening()
|
||||||
|
}
|
||||||
|
else if (keyPressedByCode(key, EnumKeyFunc.UI_BASIC_INFO)) {
|
||||||
|
Terrarum.game.debugWindow.toggleOpening()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!Terrarum.game.consoleHandler.isTakingControl) {
|
||||||
|
if (Terrarum.game.player.vehicleRiding != null) {
|
||||||
|
Terrarum.game.player.vehicleRiding!!.keyPressed(key, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
Terrarum.game.player.keyPressed(key, c)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Terrarum.game.consoleHandler.keyPressed(key, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
//System.out.println(String.valueOf(key) + ", " + String.valueOf(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
fun keyReleased(key: Int, c: Char) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun keyPressedByCode(key: Int, fn: EnumKeyFunc): Boolean {
|
||||||
|
return KeyMap.getKeyCode(fn) == key
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package com.Torvald.Terrarum.GameControl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by minjaesong on 16-01-15.
|
|
||||||
*/
|
|
||||||
public class Key {
|
|
||||||
|
|
||||||
public static final int RET = 28;
|
|
||||||
public static final int BKSP = 14;
|
|
||||||
public static final int GRAVE = 41;
|
|
||||||
public static final int TAB = 15;
|
|
||||||
public static final int ESCAPE = 1;
|
|
||||||
public static final int SPACE = 57;
|
|
||||||
|
|
||||||
public static final int L_SHIFT = 42;
|
|
||||||
public static final int R_SHIFT = 54;
|
|
||||||
|
|
||||||
public static final int UP = 200;
|
|
||||||
public static final int DOWN = 208;
|
|
||||||
public static final int LEFT = 203;
|
|
||||||
public static final int RIGHT = 205;
|
|
||||||
|
|
||||||
public static final int F1 = 59;
|
|
||||||
public static final int F2 = 60;
|
|
||||||
public static final int F3 = 61;
|
|
||||||
public static final int F4 = 62;
|
|
||||||
|
|
||||||
public static final int F5 = 63;
|
|
||||||
public static final int F6 = 64;
|
|
||||||
public static final int F7 = 65;
|
|
||||||
public static final int F8 = 66;
|
|
||||||
|
|
||||||
public static final int F9 = 67;
|
|
||||||
public static final int F10 = 68;
|
|
||||||
public static final int F11 = 87;
|
|
||||||
public static final int F12 = 88;
|
|
||||||
|
|
||||||
public static final int NUM_1 = 2;
|
|
||||||
public static final int NUM_2 = 3;
|
|
||||||
public static final int NUM_3 = 4;
|
|
||||||
public static final int NUM_4 = 5;
|
|
||||||
public static final int NUM_5 = 6;
|
|
||||||
public static final int NUM_6 = 7;
|
|
||||||
public static final int NUM_7 = 8;
|
|
||||||
public static final int NUM_8 = 9;
|
|
||||||
public static final int NUM_9 = 10;
|
|
||||||
public static final int NUM_0 = 11;
|
|
||||||
|
|
||||||
public static final int Q = 16;
|
|
||||||
public static final int W = 17;
|
|
||||||
public static final int E = 18;
|
|
||||||
public static final int R = 19;
|
|
||||||
public static final int T = 20;
|
|
||||||
|
|
||||||
public static final int Y = 21;
|
|
||||||
public static final int U = 22;
|
|
||||||
public static final int I = 23;
|
|
||||||
public static final int O = 24;
|
|
||||||
public static final int P = 25;
|
|
||||||
|
|
||||||
public static final int A = 30;
|
|
||||||
public static final int S = 31;
|
|
||||||
public static final int D = 32;
|
|
||||||
public static final int F = 33;
|
|
||||||
public static final int G = 34;
|
|
||||||
|
|
||||||
public static final int H = 35;
|
|
||||||
public static final int J = 36;
|
|
||||||
public static final int K = 37;
|
|
||||||
public static final int L = 38;
|
|
||||||
public static final int SEMICOLON = 39;
|
|
||||||
|
|
||||||
public static final int Z = 44;
|
|
||||||
public static final int X = 45;
|
|
||||||
public static final int C = 46;
|
|
||||||
public static final int V = 47;
|
|
||||||
public static final int B = 48;
|
|
||||||
|
|
||||||
public static final int N = 49;
|
|
||||||
public static final int M = 50;
|
|
||||||
|
|
||||||
public static final int PGUP = 201;
|
|
||||||
public static final int PGDN = 209;
|
|
||||||
public static final int HOME = 199;
|
|
||||||
public static final int END = 207;
|
|
||||||
}
|
|
||||||