aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-03-10 20:48:43 +0100
committernea <nea@nea.moe>2023-03-10 20:48:43 +0100
commit2f45a494964050ece8724c798a58e577f1a9aeec (patch)
treeecaf0103bdac89dfdaa6efa3096e33c61af3cb8a /src
parentd0dd7dafbaccb79f1ecaa574b85dcbb648d35128 (diff)
downloadmcprepack-2f45a494964050ece8724c798a58e577f1a9aeec.tar.gz
mcprepack-2f45a494964050ece8724c798a58e577f1a9aeec.tar.bz2
mcprepack-2f45a494964050ece8724c798a58e577f1a9aeec.zip
Better csv reading and comments
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/mcprepack/App.kt25
-rw-r--r--src/main/kotlin/mcprepack/CSVFile.kt8
2 files changed, 26 insertions, 7 deletions
diff --git a/src/main/kotlin/mcprepack/App.kt b/src/main/kotlin/mcprepack/App.kt
index 688716b..1972c62 100644
--- a/src/main/kotlin/mcprepack/App.kt
+++ b/src/main/kotlin/mcprepack/App.kt
@@ -107,21 +107,29 @@ fun main(): Unit = lifecycle("Repacking") {
val fields = readCSV(mcpStableFs.getPath("/fields.csv"))
val methods = readCSV(mcpStableFs.getPath("/methods.csv"))
val tinyFile = TinyV2Reader.read(classesTiny)
+ fun commentOrEmptyList(comment: String?) =
+ if (comment.isNullOrBlank()) listOf()
+ else listOf(comment)
+
val newTiny =
TinyFile(TinyHeader(listOf("official", "intermediary", "named"), 2, 0, mapOf()), tinyFile.classEntries.map {
TinyClass(it.classNames + listOf(it.classNames[1]), it.methods.map { method ->
val mcpMethod = methods.indexedBySearge[method.methodNames[1]]
- TinyMethod(method.methodDescriptorInFirstNamespace,
+ TinyMethod(
+ method.methodDescriptorInFirstNamespace,
method.methodNames + listOf(mcpMethod?.get("name") ?: method.methodNames[1]),
method.parameters,
method.localVariables,
- method.comments + (mcpMethod?.get("desc")?.let { listOf(it) } ?: listOf()))
- // TODO parameter names and better comments?
+ method.comments + commentOrEmptyList(mcpMethod?.get("desc"))
+ )
+ // TODO parameter names
}, it.fields.map { field ->
val mcpField = fields.indexedBySearge[field.fieldNames[1]]
- TinyField(findFieldDescriptorInMergedJar(it.classNames[0], field.fieldNames[0]),
+ TinyField(
+ findFieldDescriptorInMergedJar(it.classNames[0], field.fieldNames[0]),
field.fieldNames + listOf(mcpField?.get("name") ?: field.fieldNames[1]),
- field.comments + (mcpField?.get("desc")?.let { listOf(it) } ?: listOf()))
+ field.comments + commentOrEmptyList(mcpField?.get("desc"))
+ )
}, it.comments.map { it })
})
val newTinyFile = WorkContext.file("tiny-joined-enhanced", "tiny")
@@ -415,9 +423,12 @@ fun main(): Unit = lifecycle("Repacking") {
}
fun readCSV(path: Path): CSVFile {
- // TODO proper "" handling
val lines = Files.readAllLines(path)
val headers = lines.first().split(",")
- val entries = lines.drop(1).map { it.split(",", limit = headers.size) }
+ val entries = lines.drop(1).map {
+ it.split(",", limit = headers.size).map {
+ if (it.firstOrNull() == '"') it.drop(1).dropLast(1).replace("\"\"", "\"") else it
+ }
+ }
return CSVFile(headers, entries)
}
diff --git a/src/main/kotlin/mcprepack/CSVFile.kt b/src/main/kotlin/mcprepack/CSVFile.kt
index 1ddc03f..b2bcfaa 100644
--- a/src/main/kotlin/mcprepack/CSVFile.kt
+++ b/src/main/kotlin/mcprepack/CSVFile.kt
@@ -3,4 +3,12 @@ package mcprepack
data class CSVFile(val headers: List<String>, val entries: List<List<String>>) {
val map = entries.map { headers.zip(it).toMap() }
val indexedBySearge = map.associateBy { it["searge"] }
+ val indexedByParamName = map.groupBy {
+ val match = it["param"]?.let { paramRegex.matchEntire(it) } ?: return@groupBy null
+ match.groupValues[1].toInt()
+ }
+
+ companion object {
+ val paramRegex = "p_([0-9]+)_([0-9]+)_.*".toRegex()
+ }
}