mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +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-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/TerranVirtualDisk.jar" path-in-jar="/" />
|
||||
</root>
|
||||
</artifact>
|
||||
</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="jetbrains.kotlin.test1" level="project" />
|
||||
<orderEntry type="library" name="gdx-platform-1.12.1-natives-arm64-v8a" level="project" />
|
||||
<orderEntry type="library" name="TerranVirtualDisk" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -29,5 +29,6 @@
|
||||
<orderEntry type="library" name="io.airlift.aircompressor" 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="TerranVirtualDisk" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,6 +1,7 @@
|
||||
<btexdoc cover="hardcover" inner="standard" papersize="standard">
|
||||
<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>
|
||||
<edition>Test Edition</edition>
|
||||
</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
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
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.TextureRegion
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.*
|
||||
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.terrarumsansbitmap.MovableType
|
||||
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
||||
import java.io.File
|
||||
import java.util.zip.Deflater
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-10-28.
|
||||
@@ -23,6 +30,11 @@ class BTeXDocument : Disposable {
|
||||
var inner = "standard"
|
||||
var papersize = "standard"
|
||||
|
||||
var theTitle = ""
|
||||
var theSubtitle = ""
|
||||
var theAuthor = ""
|
||||
var theEdition = ""
|
||||
|
||||
var textWidth = 480
|
||||
var lineHeightInPx = 24
|
||||
var pageLines = 24
|
||||
@@ -44,11 +56,14 @@ class BTeXDocument : Disposable {
|
||||
val DEFAULT_PAGE_BACK = Color(0xe0dfdb_ff.toInt())
|
||||
val DEFAULT_PAGE_FORE = Color(0x0a0706_ff)
|
||||
val DEFAULT_ORNAMENTS_COL = Color(0x3f3c3b_ff)
|
||||
|
||||
private fun String.escape() = this.replace("\"", "\\\"")
|
||||
}
|
||||
|
||||
internal val pages = ArrayList<BTeXPage>()
|
||||
|
||||
private lateinit var pageTextures: ArrayList<TextureRegion>
|
||||
private lateinit var pageFrameBuffers: ArrayList<FrameBuffer>
|
||||
|
||||
val currentPage: Int
|
||||
get() = pages.size - 1
|
||||
@@ -80,6 +95,7 @@ class BTeXDocument : Disposable {
|
||||
if (isFinalised) throw IllegalStateException("Page is already been finalised")
|
||||
|
||||
pageTextures = ArrayList()
|
||||
pageFrameBuffers = ArrayList()
|
||||
|
||||
val camera = OrthographicCamera(pageDimensionWidth.toFloat(), pageDimensionHeight.toFloat())
|
||||
val batch = FlippingSpriteBatch()
|
||||
@@ -101,6 +117,7 @@ class BTeXDocument : Disposable {
|
||||
}
|
||||
|
||||
pageTextures.add(TextureRegion(fbo.colorBufferTexture))
|
||||
pageFrameBuffers.add(fbo)
|
||||
}
|
||||
isFinalised = true
|
||||
|
||||
@@ -110,9 +127,54 @@ class BTeXDocument : Disposable {
|
||||
override fun dispose() {
|
||||
if (isFinalised) {
|
||||
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
|
||||
|
||||
/**
|
||||
|
||||
@@ -747,24 +747,32 @@ object BTeXParser {
|
||||
val thePar = handler.paragraphBuffer.toString().trim()
|
||||
typesetBookTitle(thePar, handler)
|
||||
handler.paragraphBuffer.clear()
|
||||
|
||||
doc.theTitle = thePar.replace("\n", " ")
|
||||
}
|
||||
@CloseTag // reflective access is impossible with 'private'
|
||||
fun closeElemSUBTITLE(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||
val thePar = handler.paragraphBuffer.toString().trim()
|
||||
typesetBookEdition(thePar, handler)
|
||||
handler.paragraphBuffer.clear()
|
||||
|
||||
doc.theSubtitle = thePar.replace("\n", " ")
|
||||
}
|
||||
@CloseTag // reflective access is impossible with 'private'
|
||||
fun closeElemAUTHOR(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||
val thePar = handler.paragraphBuffer.toString().trim()
|
||||
typesetBookAuthor(thePar, handler)
|
||||
handler.paragraphBuffer.clear()
|
||||
|
||||
doc.theAuthor = thePar.replace("\n", " ")
|
||||
}
|
||||
@CloseTag // reflective access is impossible with 'private'
|
||||
fun closeElemEDITION(handler: BTeXHandler, doc: BTeXDocument, uri: String, siblingIndex: Int) {
|
||||
val thePar = handler.paragraphBuffer.toString().trim()
|
||||
typesetBookEdition(thePar, handler)
|
||||
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.utils.*
|
||||
import net.torvald.terrarum.weather.*
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
@@ -470,7 +469,7 @@ object Common {
|
||||
|
||||
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")
|
||||
private fun zipG(byteIterator: Iterator<Byte>): ByteArray64 {
|
||||
@@ -518,8 +517,8 @@ object Common {
|
||||
return bo.toByteArray64()
|
||||
}*/
|
||||
|
||||
fun zip(byteIterator: Iterator<Byte>): ByteArray64 {
|
||||
return when (App.getConfigString("savegamecomp")) {
|
||||
fun zip(byteIterator: Iterator<Byte>, format: String = App.getConfigString("savegamecomp")): ByteArray64 {
|
||||
return when (format) {
|
||||
"snappy" -> zipS(byteIterator)
|
||||
// "null" -> zipNull(byteIterator)
|
||||
else -> zipZ(byteIterator)
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.torvald.terrarum.btex.BTeXDocument
|
||||
import net.torvald.terrarum.ceilToInt
|
||||
import net.torvald.terrarum.gdxClearAndEnableBlend
|
||||
import net.torvald.terrarum.inUse
|
||||
import java.io.File
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
|
||||
@@ -24,8 +25,8 @@ import kotlin.system.measureTimeMillis
|
||||
*/
|
||||
class BTeXTest : ApplicationAdapter() {
|
||||
|
||||
// val filePath = "btex.xml"
|
||||
val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
|
||||
val filePath = "btex.xml"
|
||||
// val filePath = "literature/en/daniel_defoe_robinson_crusoe.xml"
|
||||
// val filePath = "literature/ruRU/anton_chekhov_palata_no_6.xml"
|
||||
// val filePath = "literature/koKR/yisang_nalgae.xml"
|
||||
|
||||
@@ -60,6 +61,12 @@ class BTeXTest : ApplicationAdapter() {
|
||||
}.also {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user