modularised lang

This commit is contained in:
Song Minjae
2017-04-27 23:41:19 +09:00
parent 3602ee3848
commit 048f96b554
49 changed files with 133 additions and 93 deletions

Binary file not shown.

View File

@@ -7,4 +7,5 @@ import net.torvald.terrarum.ModMgr
static void invoke(String module) {
ModMgr.GameBlockLoader.invoke(module)
ModMgr.GameItemLoader.invoke(module)
ModMgr.GameLanguageLoader.invoke(module)
}

View File

@@ -4,6 +4,7 @@ import net.torvald.CSVFetcher
import net.torvald.terrarum.itemproperties.InventoryItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.langpack.Lang
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser
import java.io.File
@@ -160,4 +161,13 @@ object ModMgr {
}
}
}
object GameLanguageLoader {
val langPath = "locales/"
@JvmStatic operator fun invoke(module: String) {
println("arstneitars")
Lang.load(getPath(module, langPath))
}
}
}

View File

@@ -29,15 +29,6 @@ nopqrstuvwxyz
override fun init(gc: GameContainer, game: StateBasedGame) {
canvas = Graphics(1024, 1024)
/*segfont = SpriteSheetFont(
SpriteSheet("./assets/graphics/fonts/24-seg_red.tga", 22, 31),
' '
)*/
mtfont = SpriteSheetFont(
SpriteSheet("./assets/graphics/fonts/mt-32.tga", 12, 16),
0.toChar()
)
}
override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) {
@@ -61,18 +52,18 @@ nopqrstuvwxyz
//g.drawString("Syö salmiakkia perkele", 480f, 10f)
/*val text = arrayOf(
val text = arrayOf(
"The bitmap font for game developers who seek good font that has real multilingual support,",
"for free (as in freedom AND without cost).",
"",
"There are many bitmap fonts on the internet. You care for the multilingual support, but alas!",
"most of them does not support your language, vector fonts takes too much time to be loaded,",
"even then their legibility suffers because fuck built-in antialias.",
"You somehow found a good font, and it makes your game look like a linux terminal, and you say:",
"“what the fuck? Is this a game or should I rm -rf this shit‽”",
"most of them do not support your language, vector fonts take too much time to load, and even",
"then their legibility suffers because fuck built-in antialias.",
"You somehow found a fine one, and it makes your game look like a linux terminal, and you say:",
"“Well, better than nothing *sigh*; No, its ugly.”",
"You speak Japanese, and you wish to support it, but then このクソなfontは only good for Japanese,",
"and it is not multilingual, and you don't have a time for this shenanigan.",
"Eventually you give up, saying “fuck it!” and just use the fonts that do not match well.",
"it is not even multilingual, and their English look ugly and inconsistent anyway.",
"Eventually you just use different fonts together, and the result was always mildly infuriating.",
"",
"No more suffering. This font has everything you need.",
"",
@@ -85,23 +76,23 @@ nopqrstuvwxyz
"ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ",
"Pack my box with five dozen liquor jugs",
"Voix ambiguë d'un cœur qui au zéphyr préfère les jattes de kiwi",
"정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날 뚫훍뚫훍뚫(읗) 뚫훍뚫훍뚫(읗) 뚫훍뚫훍뚫 따다다",
"정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날 하얬다 도럄직한 퀡봹퉪헰",
"Kæmi ný öxi hér, ykist þjófum nú bæði víl og ádrepa",
"Árvíztűrő tükörfúrógép Kŕdeľ ďatľov učí koňa žrať kôru",
"とりなくこゑす ゆめさませ みよあけわたる ひんかしを そらいろはえて おきつへに ほふねむれゐぬ もやのうち",
"鳥啼く声す 夢覚ませ 見よ明け渡る 空色栄えて 沖つ辺に 帆船群れゐぬ 靄の中",
"鳥啼ク声ス 夢覚マセ 見ヨ明ク渡ル 空色栄エテ 沖ツ辺ニ 帆船群レヰヌ 靄ノ中",
"Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila",
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства",
"Pijamalı hasta yağız şoföre çabucak güvendi",
"Also supports: Unicode „quotation marks“—dashes…「括弧」‼",
"ASCII Latin-1 Latin_Ext-A Latin_Ext-B Greek Cyrillic CJK-Ideo Kana Hangul_Syllables",
""
)*/
)
val SP = "${0x3000.toChar()}${0x3000.toChar()}"
val text = arrayOf(
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP${0xe011.toChar()}..${0xe019.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}"
)
/*val text = arrayOf(
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"p]}$SP${0xe011.toChar()}..${0xe019.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}"
)*/
text.forEachIndexed { i, s ->
g.drawString(s, 10f, 70f + 20 * i)

View File

@@ -10,6 +10,7 @@ import net.torvald.imagefont.TinyAlphNum
import net.torvald.terrarum.gamecontroller.mouseTileX
import net.torvald.terrarum.gamecontroller.mouseTileY
import net.torvald.terrarum.gameworld.toUint
import net.torvald.terrarum.langpack.Lang
import org.lwjgl.input.Controllers
import org.lwjgl.opengl.*
import org.newdawn.slick.*
@@ -314,7 +315,8 @@ object Terrarum : StateBasedGame(GAME_NAME) {
}
}
// load languages
Lang
// load modules
ModMgr

View File

@@ -8,7 +8,8 @@ import java.util.*
*/
internal object PrintRandomTips : ConsoleCommand {
override fun execute(args: Array<String>) {
Echo(Lang["GAME_TIPS_${Random().nextInt(Lang.TIPS_COUNT) + 1}"])
Echo("Nope.")
//Echo(Lang["GAME_TIPS_${Random().nextInt(Lang.TIPS_COUNT) + 1}"])
}
override fun printUsage() {

View File

@@ -15,15 +15,13 @@ object Lang {
*
* HashMap<"$key_$language", Value>
*/
var langpack: HashMap<String, String>
private set
val langpack = HashMap<String, String>()
private val FALLBACK_LANG_CODE = "en"
private val HANGUL_SYL_START = 0xAC00
val languageList: List<String>
val languageList = HashSet<String>()
private val PATH_TO_LANG = "./assets/locales/"
val POLYGLOT_VERSION = "100"
private val PREFIX_POLYGLOT = "Polyglot-${POLYGLOT_VERSION}_"
private val PREFIX_NAMESET = "nameset_"
@@ -37,71 +35,72 @@ object Lang {
private val FRENCH_WORD_NORMAL_PLURAL = arrayOf("bal", "banal", "fatal", "final")
var TIPS_COUNT = 0
private set
init {
langpack = HashMap<String, String>()
val localesDir = File(PATH_TO_LANG)
// load base langs
load("./assets/locales/")
}
fun load(localesDir: String) {
println("[Lang] Loading languages from $localesDir")
val localesDir = File(localesDir)
// get all of the languages installed
languageList = localesDir.listFiles().filter { it.isDirectory }.map { it.name }
localesDir.listFiles().filter { it.isDirectory }.forEach { languageList.add(it.name) }
for (lang in languageList) {
// load polyglot first
val polyglotFile = File("$PATH_TO_LANG$lang/$PREFIX_POLYGLOT$lang.json")
val json = JsonFetcher(polyglotFile)
/*
* Polyglot JSON structure is:
*
* (root object)
* "resources": object
* "polyglot": object
* (polyglot meta)
* "data": array
* [0]: object
* n = "CONTEXT_CHARACTER_CLASS"
* s = "Class"
* [1]: object
* n = "CONTEXT_CHARACTER_DELETE"
* s = "Delecte Character"
* (the array continues)
*
*/
json.getAsJsonObject("resources").getAsJsonArray("data").forEach {
langpack.put(
"${it.asJsonObject["n"].asString}_$lang",
it.asJsonObject["s"].asString
)
}
// and then the rest of the lang file
val langFileList = ArrayList<File>()
// --> filter out files to retrieve a list of valid lang files
val langFileListFiles = File("$PATH_TO_LANG$lang/").listFiles()
val langFileListFiles = File("$localesDir/$lang/").listFiles()
langFileListFiles.forEach {
if (!it.name.startsWith("Polyglot") && it.name.endsWith(".json"))
langFileList.add(it)
}
// --> put json entries in langpack
for (langFile in langFileList) {
val json = JsonFetcher(langFile)
/*
* Terrarum langpack JSON structure is:
*
* (root object)
* "<<STRING ID>>" = "<<LOCALISED TEXT>>"
*/
//println(json.entrySet())
json.entrySet().forEach {
langpack.put("${it.key}_$lang", it.value.asString)
// count up TIPS_COUNT
if (lang == "en" && it.key.startsWith("GAME_TIPS_")) TIPS_COUNT++
// not a polyglot
if (!it.name.startsWith("Polyglot") && it.name.endsWith(".json")) {
processRegularLangfile(it, lang)
}
else {
processPolyglotLangFile(it, lang)
}
}
}
}
private fun processRegularLangfile(file: File, lang: String) {
val json = JsonFetcher(file)
/*
* Terrarum langpack JSON structure is:
*
* (root object)
* "<<STRING ID>>" = "<<LOCALISED TEXT>>"
*/
//println(json.entrySet())
json.entrySet().forEach {
langpack.put("${it.key}_$lang", it.value.asString)
}
}
private fun processPolyglotLangFile(file: File, lang: String) {
val json = JsonFetcher(file)
/*
* Polyglot JSON structure is:
*
* (root object)
* "resources": object
* "polyglot": object
* (polyglot meta)
* "data": array
* [0]: object
* n = "CONTEXT_CHARACTER_CLASS"
* s = "Class"
* [1]: object
* n = "CONTEXT_CHARACTER_DELETE"
* s = "Delecte Character"
* (the array continues)
*
*/
json.getAsJsonObject("resources").getAsJsonArray("data").forEach {
langpack.put(
"${it.asJsonObject["n"].asString}_$lang",
it.asJsonObject["s"].asString
)
}
}

View File

@@ -83,7 +83,7 @@ object BlocksDrawer {
* It holds different shading rule to discriminate with group 02, index 0 is single tile.
* These are the tiles that only connects to itself, will not connect to colour variants
*/
val TILES_CONNECT_SELF = arrayListOf(
private val TILES_CONNECT_SELF = hashSetOf(
Block.ICE_MAGICAL,
Block.GLASS_CRUDE,
Block.GLASS_CLEAN,
@@ -128,17 +128,25 @@ object BlocksDrawer {
Block.DAYLIGHT_CAPACITOR
)
/**
* To interact with external modules
*/
@JvmStatic fun addConnectSelf(blockID: Int): Boolean {
return TILES_CONNECT_SELF.add(blockID)
}
/**
* Connectivity group 02 : natural tiles
* It holds different shading rule to discriminate with group 01, index 0 is middle tile.
*/
val TILES_CONNECT_MUTUAL = arrayListOf(
private val TILES_CONNECT_MUTUAL = hashSetOf(
Block.STONE,
Block.STONE_QUARRIED,
Block.STONE_TILE_WHITE,
Block.STONE_BRICKS,
Block.DIRT,
Block.GRASS,
Block.GRASSWALL,
Block.PLANK_BIRCH,
Block.PLANK_BLOODROSE,
Block.PLANK_EBONY,
@@ -194,20 +202,34 @@ object BlocksDrawer {
Block.LAVA_15
)
/**
* To interact with external modules
*/
@JvmStatic fun addConnectMutual(blockID: Int): Boolean {
return TILES_CONNECT_MUTUAL.add(blockID)
}
/**
* Torches, levers, switches, ...
*/
val TILES_WALL_STICKER = arrayListOf(
private val TILES_WALL_STICKER = hashSetOf(
Block.TORCH,
Block.TORCH_FROST,
Block.TORCH_OFF,
Block.TORCH_FROST_OFF
)
/**
* To interact with external modules
*/
@JvmStatic fun addWallSticker(blockID: Int): Boolean {
return TILES_WALL_STICKER.add(blockID)
}
/**
* platforms, ...
*/
val TILES_WALL_STICKER_CONNECT_SELF = arrayListOf(
private val TILES_WALL_STICKER_CONNECT_SELF = hashSetOf(
Block.PLATFORM_BIRCH,
Block.PLATFORM_BLOODROSE,
Block.PLATFORM_EBONY,
@@ -215,12 +237,19 @@ object BlocksDrawer {
Block.PLATFORM_WOODEN
)
/**
* To interact with external modules
*/
@JvmStatic fun addWallStickerConnectSelf(blockID: Int): Boolean {
return TILES_WALL_STICKER_CONNECT_SELF.add(blockID)
}
/**
* Tiles that half-transparent and has hue
* will blend colour using colour multiplication
* i.e. red hues get lost if you dive into the water
*/
val TILES_BLEND_MUL = arrayListOf(
private val TILES_BLEND_MUL = hashSetOf(
Block.WATER,
Block.WATER_1,
Block.WATER_2,
@@ -255,6 +284,13 @@ object BlocksDrawer {
Block.LAVA_15
)
/**
* To interact with external modules
*/
@JvmStatic fun addBlendMul(blockID: Int): Boolean {
return TILES_BLEND_MUL.add(blockID)
}
fun update() {
val player = Terrarum.ingame!!.player
}

Binary file not shown.