mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 08:36:07 +09:00
btex serialisation
This commit is contained in:
1
.idea/artifacts/TerrarumBuild.xml
generated
1
.idea/artifacts/TerrarumBuild.xml
generated
@@ -90,6 +90,7 @@
|
|||||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-arm64-v8a.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-arm64-v8a.jar" path-in-jar="/" />
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-desktop.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-desktop.jar" path-in-jar="/" />
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-x86_64.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/lib/gdx-platform-1.12.1-natives-x86_64.jar" path-in-jar="/" />
|
||||||
|
<element id="extracted-dir" path="$PROJECT_DIR$/lib/TerranVirtualDisk.jar" path-in-jar="/" />
|
||||||
</root>
|
</root>
|
||||||
</artifact>
|
</artifact>
|
||||||
</component>
|
</component>
|
||||||
11
.idea/libraries/TerranVirtualDisk.xml
generated
Normal file
11
.idea/libraries/TerranVirtualDisk.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="TerranVirtualDisk">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/TerranVirtualDisk.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/lib/TerranVirtualDisk-src.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
@@ -19,5 +19,6 @@
|
|||||||
<orderEntry type="library" scope="PROVIDED" name="io.airlift.aircompressor" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="io.airlift.aircompressor" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.test1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="jetbrains.kotlin.test1" level="project" />
|
||||||
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
|
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
|
||||||
|
<orderEntry type="library" name="TerranVirtualDisk" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -29,5 +29,6 @@
|
|||||||
<orderEntry type="library" name="io.airlift.aircompressor" level="project" />
|
<orderEntry type="library" name="io.airlift.aircompressor" level="project" />
|
||||||
<orderEntry type="library" name="jetbrains.kotlin.test1" level="project" />
|
<orderEntry type="library" name="jetbrains.kotlin.test1" level="project" />
|
||||||
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
|
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
|
||||||
|
<orderEntry type="library" name="TerranVirtualDisk" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<btexdoc cover="hardcover" inner="standard" papersize="standard">
|
<btexdoc cover="hardcover" inner="standard" papersize="standard">
|
||||||
<cover>
|
<cover>
|
||||||
<title>The Way to Mastery of Lorem Ipsum<br />Or, How To Write and Publish a Book</title>
|
<title>The Way to Mastery of<br />Lorem Ipsum</title>
|
||||||
|
<subtitle>Or, How To Write and Publish a Book</subtitle>
|
||||||
<author>Terran Publishing</author>
|
<author>Terran Publishing</author>
|
||||||
<edition>Test Edition</edition>
|
<edition>Test Edition</edition>
|
||||||
</cover>
|
</cover>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
BIN
lib/TerranVirtualDisk-src.jar
LFS
Normal file
BIN
lib/TerranVirtualDisk-src.jar
LFS
Normal file
Binary file not shown.
BIN
lib/TerranVirtualDisk.jar
LFS
Normal file
BIN
lib/TerranVirtualDisk.jar
LFS
Normal file
Binary file not shown.
@@ -1,18 +1,25 @@
|
|||||||
package net.torvald.terrarum.btex
|
package net.torvald.terrarum.btex
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
import com.badlogic.gdx.graphics.Pixmap
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.PixmapIO
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.imagefont.TinyAlphNum
|
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.archivers.ClusteredFormatDOM
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.archivers.Clustfile
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.archivers.ClustfileOutputStream
|
||||||
|
import net.torvald.terrarum.serialise.Common
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarumsansbitmap.MovableType
|
import net.torvald.terrarumsansbitmap.MovableType
|
||||||
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
||||||
|
import java.io.File
|
||||||
|
import java.util.zip.Deflater
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2023-10-28.
|
* Created by minjaesong on 2023-10-28.
|
||||||
@@ -23,6 +30,11 @@ class BTeXDocument : Disposable {
|
|||||||
var inner = "standard"
|
var inner = "standard"
|
||||||
var papersize = "standard"
|
var papersize = "standard"
|
||||||
|
|
||||||
|
var theTitle = ""
|
||||||
|
var theSubtitle = ""
|
||||||
|
var theAuthor = ""
|
||||||
|
var theEdition = ""
|
||||||
|
|
||||||
var textWidth = 480
|
var textWidth = 480
|
||||||
var lineHeightInPx = 24
|
var lineHeightInPx = 24
|
||||||
var pageLines = 24
|
var pageLines = 24
|
||||||
@@ -44,11 +56,14 @@ class BTeXDocument : Disposable {
|
|||||||
val DEFAULT_PAGE_BACK = Color(0xe0dfdb_ff.toInt())
|
val DEFAULT_PAGE_BACK = Color(0xe0dfdb_ff.toInt())
|
||||||
val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
||||||
val DEFAULT_ORNAMENTS_COL = Color(0x3f3c3b_ff)
|
val DEFAULT_ORNAMENTS_COL = Color(0x3f3c3b_ff)
|
||||||
|
|
||||||
|
private fun String.escape() = this.replace("\"", "\\\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val pages = ArrayList<BTeXPage>()
|
internal val pages = ArrayList<BTeXPage>()
|
||||||
|
|
||||||
private lateinit var pageTextures: ArrayList<TextureRegion>
|
private lateinit var pageTextures: ArrayList<TextureRegion>
|
||||||
|
private lateinit var pageFrameBuffers: ArrayList<FrameBuffer>
|
||||||
|
|
||||||
val currentPage: Int
|
val currentPage: Int
|
||||||
get() = pages.size - 1
|
get() = pages.size - 1
|
||||||
@@ -80,6 +95,7 @@ class BTeXDocument : Disposable {
|
|||||||
if (isFinalised) throw IllegalStateException("Page is already been finalised")
|
if (isFinalised) throw IllegalStateException("Page is already been finalised")
|
||||||
|
|
||||||
pageTextures = ArrayList()
|
pageTextures = ArrayList()
|
||||||
|
pageFrameBuffers = ArrayList()
|
||||||
|
|
||||||
val camera = OrthographicCamera(pageDimensionWidth.toFloat(), pageDimensionHeight.toFloat())
|
val camera = OrthographicCamera(pageDimensionWidth.toFloat(), pageDimensionHeight.toFloat())
|
||||||
val batch = FlippingSpriteBatch()
|
val batch = FlippingSpriteBatch()
|
||||||
@@ -101,6 +117,7 @@ class BTeXDocument : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pageTextures.add(TextureRegion(fbo.colorBufferTexture))
|
pageTextures.add(TextureRegion(fbo.colorBufferTexture))
|
||||||
|
pageFrameBuffers.add(fbo)
|
||||||
}
|
}
|
||||||
isFinalised = true
|
isFinalised = true
|
||||||
|
|
||||||
@@ -110,9 +127,54 @@ class BTeXDocument : Disposable {
|
|||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
if (isFinalised) {
|
if (isFinalised) {
|
||||||
pageTextures.forEach { it.texture.dispose() }
|
pageTextures.forEach { it.texture.dispose() }
|
||||||
|
pageFrameBuffers.forEach { it.dispose() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun serialise(archiveFile: File) {
|
||||||
|
if (!isFinalised) throw IllegalStateException("Document must be finalised before being serialised")
|
||||||
|
|
||||||
|
val diskFile = ClusteredFormatDOM.createNewArchive(archiveFile, Common.CHARSET, "", 0x7FFFF)
|
||||||
|
val DOM = ClusteredFormatDOM(diskFile)
|
||||||
|
val tempFile = Gdx.files.external("./.btex-export.png")
|
||||||
|
|
||||||
|
val json = """
|
||||||
|
{
|
||||||
|
"title":"${theTitle.escape()}",
|
||||||
|
"subtitle":"${theSubtitle.escape()}",
|
||||||
|
"author":"${theAuthor.escape()}",
|
||||||
|
"edition":"${theEdition.escape()}",
|
||||||
|
"pages":"${pageTextures.size}",
|
||||||
|
"context":"${context.escape()}",
|
||||||
|
"font":"${font.escape()}",
|
||||||
|
"inner":"${inner.escape()}",
|
||||||
|
"papersize":"${papersize.escape()}"
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
Clustfile(DOM, "bibliography.json").also {
|
||||||
|
it.createNewFile()
|
||||||
|
it.writeBytes(json.encodeToByteArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
pageFrameBuffers.forEachIndexed { index, fbo ->
|
||||||
|
val file = Clustfile(DOM, "$index.png").also {
|
||||||
|
it.createNewFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
fbo.inAction(null, null) {
|
||||||
|
val pixmap = Pixmap.createFromFrameBuffer(0, 0, fbo.width, fbo.height)
|
||||||
|
PixmapIO.writePNG(tempFile, pixmap, Deflater.BEST_COMPRESSION, false)
|
||||||
|
val outstream = ClustfileOutputStream(file)
|
||||||
|
outstream.write(tempFile.readBytes())
|
||||||
|
outstream.flush(); outstream.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DOM.changeDiskCapacity(diskFile.length().div(4096f).ceilToInt())
|
||||||
|
tempFile.delete()
|
||||||
|
}
|
||||||
|
|
||||||
var isFinalised = false; private set
|
var isFinalised = false; private set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -747,24 +747,32 @@ object BTeXParser {
|
|||||||
val thePar = handler.paragraphBuffer.toString().trim()
|
val thePar = handler.paragraphBuffer.toString().trim()
|
||||||
typesetBookTitle(thePar, handler)
|
typesetBookTitle(thePar, handler)
|
||||||
handler.paragraphBuffer.clear()
|
handler.paragraphBuffer.clear()
|
||||||
|
|
||||||
|
doc.theTitle = thePar.replace("\n", " ")
|
||||||
}
|
}
|
||||||
@CloseTag // reflective access is impossible with 'private'
|
@CloseTag // reflective access is impossible with 'private'
|
||||||
fun closeElemSUBTITLE(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
fun closeElemSUBTITLE(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||||
val thePar = handler.paragraphBuffer.toString().trim()
|
val thePar = handler.paragraphBuffer.toString().trim()
|
||||||
typesetBookEdition(thePar, handler)
|
typesetBookEdition(thePar, handler)
|
||||||
handler.paragraphBuffer.clear()
|
handler.paragraphBuffer.clear()
|
||||||
|
|
||||||
|
doc.theSubtitle = thePar.replace("\n", " ")
|
||||||
}
|
}
|
||||||
@CloseTag // reflective access is impossible with 'private'
|
@CloseTag // reflective access is impossible with 'private'
|
||||||
fun closeElemAUTHOR(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
fun closeElemAUTHOR(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||||
val thePar = handler.paragraphBuffer.toString().trim()
|
val thePar = handler.paragraphBuffer.toString().trim()
|
||||||
typesetBookAuthor(thePar, handler)
|
typesetBookAuthor(thePar, handler)
|
||||||
handler.paragraphBuffer.clear()
|
handler.paragraphBuffer.clear()
|
||||||
|
|
||||||
|
doc.theAuthor = thePar.replace("\n", " ")
|
||||||
}
|
}
|
||||||
@CloseTag // reflective access is impossible with 'private'
|
@CloseTag // reflective access is impossible with 'private'
|
||||||
fun closeElemEDITION(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
fun closeElemEDITION(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||||
val thePar = handler.paragraphBuffer.toString().trim()
|
val thePar = handler.paragraphBuffer.toString().trim()
|
||||||
typesetBookEdition(thePar, handler)
|
typesetBookEdition(thePar, handler)
|
||||||
handler.paragraphBuffer.clear()
|
handler.paragraphBuffer.clear()
|
||||||
|
|
||||||
|
doc.theEdition = thePar.replace("\n", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import net.torvald.terrarum.savegame.ByteArray64InputStream
|
|||||||
import net.torvald.terrarum.savegame.ByteArray64Reader
|
import net.torvald.terrarum.savegame.ByteArray64Reader
|
||||||
import net.torvald.terrarum.utils.*
|
import net.torvald.terrarum.utils.*
|
||||||
import net.torvald.terrarum.weather.*
|
import net.torvald.terrarum.weather.*
|
||||||
import net.torvald.terrarum.weather.WeatherMixer
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils
|
import org.apache.commons.codec.digest.DigestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
@@ -470,7 +469,7 @@ object Common {
|
|||||||
|
|
||||||
fun bytesToZipdStr(byteIterator: Iterator<Byte>): String = enasciiToString(zip(byteIterator))
|
fun bytesToZipdStr(byteIterator: Iterator<Byte>): String = enasciiToString(zip(byteIterator))
|
||||||
|
|
||||||
fun zip(ba: ByteArray64) = Common.zip(ba.iterator())
|
fun zip(ba: ByteArray64, format: String = App.getConfigString("savegamecomp")) = Common.zip(ba.iterator(), format)
|
||||||
|
|
||||||
@Deprecated("New savegame standard should use Zstd")
|
@Deprecated("New savegame standard should use Zstd")
|
||||||
private fun zipG(byteIterator: Iterator<Byte>): ByteArray64 {
|
private fun zipG(byteIterator: Iterator<Byte>): ByteArray64 {
|
||||||
@@ -518,8 +517,8 @@ object Common {
|
|||||||
return bo.toByteArray64()
|
return bo.toByteArray64()
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
fun zip(byteIterator: Iterator<Byte>): ByteArray64 {
|
fun zip(byteIterator: Iterator<Byte>, format: String = App.getConfigString("savegamecomp")): ByteArray64 {
|
||||||
return when (App.getConfigString("savegamecomp")) {
|
return when (format) {
|
||||||
"snappy" -> zipS(byteIterator)
|
"snappy" -> zipS(byteIterator)
|
||||||
// "null" -> zipNull(byteIterator)
|
// "null" -> zipNull(byteIterator)
|
||||||
else -> zipZ(byteIterator)
|
else -> zipZ(byteIterator)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import net.torvald.terrarum.btex.BTeXDocument
|
|||||||
import net.torvald.terrarum.ceilToInt
|
import net.torvald.terrarum.ceilToInt
|
||||||
import net.torvald.terrarum.gdxClearAndEnableBlend
|
import net.torvald.terrarum.gdxClearAndEnableBlend
|
||||||
import net.torvald.terrarum.inUse
|
import net.torvald.terrarum.inUse
|
||||||
|
import java.io.File
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
|
|
||||||
@@ -24,8 +25,8 @@ import kotlin.system.measureTimeMillis
|
|||||||
*/
|
*/
|
||||||
class BTeXTest : ApplicationAdapter() {
|
class BTeXTest : ApplicationAdapter() {
|
||||||
|
|
||||||
// val filePath = "btex.xml"
|
val filePath = "btex.xml"
|
||||||
val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
|
// val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
|
||||||
// val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml"
|
// val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml"
|
||||||
// val filePath = "literature/koKR/yisang_nalgae.xml"
|
// val filePath = "literature/koKR/yisang_nalgae.xml"
|
||||||
|
|
||||||
@@ -60,6 +61,12 @@ class BTeXTest : ApplicationAdapter() {
|
|||||||
}.also {
|
}.also {
|
||||||
println("Time spent on finalising [ms]: $it")
|
println("Time spent on finalising [ms]: $it")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
measureTimeMillis {
|
||||||
|
document.serialise(File("./assets/mods/basegame/books/${filePath.replace(".xml", ".book")}"))
|
||||||
|
}.also {
|
||||||
|
println("Time spent on serialisation [ms]: $it")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var scroll = 0
|
private var scroll = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user