feat(codegen): generate Pokemon moves and unify map/move codegen into one module (#16)
This commit is contained in:
1 parent
75fe4ae0d2
commit
b44bd1cc26
36 files changed
+635
-71
No files matched your search
@@ -0,0 +1,43 @@
|
||||
@import de.fiereu.openmmo.codegen.maps.ParsedMap
|
||||
@import de.fiereu.openmmo.codegen.maps.RenderUtil
|
||||
|
||||
@param String packageName
|
||||
@param String objectName
|
||||
@param ParsedMap map
|
||||
package ${packageName}
|
||||
|
||||
import de.fiereu.openmmo.common.Tile2D
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.common.enums.EncounterType
|
||||
import de.fiereu.openmmo.common.enums.Lighting
|
||||
import de.fiereu.openmmo.common.enums.MapType
|
||||
import de.fiereu.openmmo.common.enums.MovementType
|
||||
import de.fiereu.openmmo.common.enums.Weather
|
||||
import de.fiereu.openmmo.maps.BgEventDef
|
||||
import de.fiereu.openmmo.maps.MapDef
|
||||
import de.fiereu.openmmo.maps.NpcDef
|
||||
import de.fiereu.openmmo.maps.WarpTile
|
||||
import de.fiereu.openmmo.net.game.packets.MapData
|
||||
|
||||
internal val ${objectName}: MapDef =
|
||||
MapDef(
|
||||
regionId = ${map.getRegion()},
|
||||
bankId = ${map.getBank()},
|
||||
mapId = ${map.getIndex()},
|
||||
width = ${map.getWidth()},
|
||||
height = ${map.getHeight()},
|
||||
paletteIdx1 = ${map.getPaletteIdx1()},
|
||||
paletteIdx2 = ${map.getPaletteIdx2()},
|
||||
unknownShort = ${map.getMusicId()},
|
||||
unknownByte = ${map.getMapsecId()},
|
||||
borderTiles = ${RenderUtil.INSTANCE.borderTiles(map.getBorderTiles())},
|
||||
blockData = "${map.getBlockData()}",
|
||||
lighting = ${map.getLighting()},
|
||||
weather = ${map.getWeather()},
|
||||
mapType = ${map.getMapType()},
|
||||
encounterType = ${map.getEncounterType()},
|
||||
connections = ${RenderUtil.INSTANCE.connections(map.getConnections())},
|
||||
warps = ${RenderUtil.INSTANCE.warps(map.getWarps())},
|
||||
npcs = ${RenderUtil.INSTANCE.npcs(map.getVisibleNpcs())},
|
||||
bgEvents = ${RenderUtil.INSTANCE.bgEvents(map.getBgEvents())},
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
@import java.util.List
|
||||
|
||||
@param List<List<String>> chunks
|
||||
package de.fiereu.openmmo.maps.generated
|
||||
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
|
||||
internal object GeneratedMaps {
|
||||
fun loadInto(mgr: MapManager) {
|
||||
@for(int i = 0; i < chunks.size(); i++)
|
||||
registerChunk${i}(mgr)
|
||||
@endfor
|
||||
}
|
||||
|
||||
@for(int chunkIndex = 0; chunkIndex < chunks.size(); chunkIndex++)
|
||||
private fun registerChunk${chunkIndex}(mgr: MapManager) {
|
||||
@for(String ref : chunks.get(chunkIndex))
|
||||
mgr.register(${ref})
|
||||
@endfor
|
||||
}
|
||||
|
||||
@endfor
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
@import java.util.List
|
||||
@import de.fiereu.openmmo.codegen.move.ParsedMove
|
||||
@import de.fiereu.openmmo.codegen.move.RenderUtil
|
||||
|
||||
@param List<List<ParsedMove>> chunks
|
||||
package de.fiereu.openmmo.moves.generated
|
||||
|
||||
import de.fiereu.openmmo.common.enums.MoveEffect
|
||||
import de.fiereu.openmmo.common.enums.MoveFlag
|
||||
import de.fiereu.openmmo.common.enums.MoveTarget
|
||||
import de.fiereu.openmmo.common.enums.PokemonType
|
||||
import de.fiereu.openmmo.moves.MoveDef
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
|
||||
internal object GeneratedMoves {
|
||||
fun loadInto(reg: MoveRegistry) {
|
||||
@for(int i = 0; i < chunks.size(); i++)
|
||||
registerChunk${i}(reg)
|
||||
@endfor
|
||||
}
|
||||
|
||||
@for(int c = 0; c < chunks.size(); c++)
|
||||
private fun registerChunk${c}(reg: MoveRegistry) {
|
||||
@for(ParsedMove m : chunks.get(c))
|
||||
reg.register(${RenderUtil.INSTANCE.move(m)})
|
||||
@endfor
|
||||
}
|
||||
|
||||
@endfor
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
internal const val BANK_GROUP_OFFSET = 50
|
||||
|
||||
internal val COMMON_DIR_MAP =
|
||||
mapOf(
|
||||
"down" to "Direction.DOWN",
|
||||
"up" to "Direction.UP",
|
||||
"left" to "Direction.LEFT",
|
||||
"right" to "Direction.RIGHT",
|
||||
"dive" to "Direction.DIVE",
|
||||
"emerge" to "Direction.EMERGE",
|
||||
)
|
||||
|
||||
internal val COMMON_WEATHER_MAP =
|
||||
mapOf(
|
||||
"WEATHER_NONE" to "Weather.IN_HOUSE_WEATHER",
|
||||
"WEATHER_SUNNY" to "Weather.REGULAR_WEATHER",
|
||||
"WEATHER_RAIN" to "Weather.RAINY_WEATHER",
|
||||
"WEATHER_SNOW" to "Weather.THREE_SNOW_FLAKES",
|
||||
"WEATHER_FOG_HORIZONTAL" to "Weather.STEADY_MIST",
|
||||
"WEATHER_FOG_DIAGONAL" to "Weather.STEADY_MIST",
|
||||
"WEATHER_SHADE" to "Weather.CLOUDY",
|
||||
"WEATHER_UNDERWATER_BUBBLES" to "Weather.UNDERWATER_MIST",
|
||||
"WEATHER_VOLCANIC_ASH" to "Weather.DENSE_BRIGHT_MIST",
|
||||
)
|
||||
|
||||
internal val COMMON_MAP_TYPE_MAP =
|
||||
mapOf(
|
||||
"MAP_TYPE_INDOOR" to "MapType.INSIDE",
|
||||
"MAP_TYPE_TOWN" to "MapType.UNKNOWN_0x01",
|
||||
"MAP_TYPE_CITY" to "MapType.CITY",
|
||||
"MAP_TYPE_ROUTE" to "MapType.ROUTE",
|
||||
"MAP_TYPE_UNDERGROUND" to "MapType.UNDERGROUND",
|
||||
"MAP_TYPE_UNDERWATER" to "MapType.UNDERWATER",
|
||||
"MAP_TYPE_OCEAN_ROUTE" to "MapType.ROUTE",
|
||||
"MAP_TYPE_SECRET_BASE" to "MapType.SECRET_BASE",
|
||||
)
|
||||
|
||||
private const val ENCOUNTER_RANDOM = "EncounterType.RANDOM"
|
||||
private const val ENCOUNTER_UNKNOWN_0X03 = "EncounterType.UNKNOWN_0x03"
|
||||
|
||||
internal val COMMON_ENCOUNTER_MAP =
|
||||
mapOf(
|
||||
"MAP_TYPE_INDOOR" to ENCOUNTER_RANDOM,
|
||||
"MAP_TYPE_TOWN" to ENCOUNTER_RANDOM,
|
||||
"MAP_TYPE_CITY" to ENCOUNTER_RANDOM,
|
||||
"MAP_TYPE_ROUTE" to ENCOUNTER_RANDOM,
|
||||
"MAP_TYPE_UNDERGROUND" to ENCOUNTER_RANDOM,
|
||||
"MAP_TYPE_UNDERWATER" to ENCOUNTER_UNKNOWN_0X03,
|
||||
"MAP_TYPE_OCEAN_ROUTE" to ENCOUNTER_RANDOM,
|
||||
"MAP_TYPE_SECRET_BASE" to ENCOUNTER_UNKNOWN_0X03,
|
||||
)
|
||||
|
||||
private val FACING_REFS =
|
||||
listOf("Direction.DOWN", "Direction.UP", "Direction.LEFT", "Direction.RIGHT")
|
||||
|
||||
internal fun movementToFacingRef(movementType: Int): String =
|
||||
FACING_REFS[
|
||||
when (movementType) {
|
||||
7 -> 1
|
||||
8 -> 0
|
||||
9 -> 2
|
||||
10 -> 3
|
||||
in 64..67 -> movementType - 64
|
||||
in 68..71 -> movementType - 68
|
||||
in 72..75 -> movementType - 72
|
||||
else -> 0
|
||||
}]
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
object HoennConstants :
|
||||
RegionConstants(
|
||||
name = "hoenn",
|
||||
regionId = 1,
|
||||
defaultVisibleNpcs =
|
||||
mapOf(
|
||||
"LittlerootTown_MaysHouse_1F" to listOf(0),
|
||||
"LittlerootTown_BrendansHouse_1F" to listOf(3, 5),
|
||||
"LittlerootTown_ProfessorBirchsLab" to listOf(0),
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
object KantoConstants :
|
||||
RegionConstants(
|
||||
name = "kanto",
|
||||
regionId = 0,
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
@file:JvmName("Main")
|
||||
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
import java.io.File
|
||||
|
||||
private data class RegionSource(val region: RegionConstants, val dir: File)
|
||||
|
||||
private fun parseRegionSource(spec: String): RegionSource {
|
||||
val parts = spec.split("|")
|
||||
require(parts.size == 2) { "Invalid region spec '$spec', expected <region>|<dir>" }
|
||||
val region = REGIONS[parts[0]] ?: error("Unknown region '${parts[0]}', known: ${REGIONS.keys}")
|
||||
return RegionSource(region = region, dir = File(parts[1]))
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
require(args.size >= 4) {
|
||||
"Usage: <output-dir> <templates-dir> <class-cache-dir> <region|dir>... got ${args.toList()}"
|
||||
}
|
||||
val outputDir = File(args[0])
|
||||
val templatesDir = File(args[1])
|
||||
val classCacheDir = File(args[2])
|
||||
val sources = args.drop(3).map(::parseRegionSource)
|
||||
|
||||
val maps =
|
||||
sources.flatMap { (region, dir) ->
|
||||
println("[maps] parsing ${region.name} (region ${region.regionId}) from $dir")
|
||||
PretGbaParser(dir, region, MovementTypes.read(dir)).parseAll()
|
||||
}
|
||||
println("[maps] parsed ${maps.size} maps. writing to $outputDir")
|
||||
MapsRenderer(templatesDir, outputDir, classCacheDir).render(maps)
|
||||
println("[maps] done")
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
import gg.jte.ContentType
|
||||
import gg.jte.TemplateEngine
|
||||
import gg.jte.output.FileOutput
|
||||
import gg.jte.resolve.DirectoryCodeResolver
|
||||
import java.io.File
|
||||
|
||||
class MapsRenderer(
|
||||
private val templatesDir: File,
|
||||
private val outputDir: File,
|
||||
private val classCacheDir: File,
|
||||
private val registryChunkSize: Int = 100,
|
||||
) {
|
||||
|
||||
fun render(maps: List<ParsedMap>) {
|
||||
classCacheDir.mkdirs()
|
||||
val engine =
|
||||
TemplateEngine.create(
|
||||
DirectoryCodeResolver(templatesDir.toPath()),
|
||||
classCacheDir.toPath(),
|
||||
ContentType.Plain,
|
||||
)
|
||||
|
||||
val packageRoot = File(outputDir, BASE_PACKAGE.replace('.', '/'))
|
||||
if (packageRoot.exists()) packageRoot.deleteRecursively()
|
||||
|
||||
val references = mutableListOf<String>()
|
||||
for (map in maps) {
|
||||
val packageName = packageFor(map)
|
||||
val objectName = identifier(map.sourceName)
|
||||
references += "$packageName.$objectName"
|
||||
|
||||
val target = File(outputDir, "${packageName.replace('.', '/')}/$objectName.kt")
|
||||
target.parentFile.mkdirs()
|
||||
FileOutput(target.toPath()).use { out ->
|
||||
engine.render(
|
||||
"MapDef.jte",
|
||||
mapOf("packageName" to packageName, "objectName" to objectName, "map" to map),
|
||||
out,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val chunks = references.sorted().chunked(registryChunkSize)
|
||||
val registry = File(outputDir, "${BASE_PACKAGE.replace('.', '/')}/GeneratedMaps.kt")
|
||||
registry.parentFile.mkdirs()
|
||||
FileOutput(registry.toPath()).use { out ->
|
||||
engine.render("MapsRegistry.jte", mapOf("chunks" to chunks), out)
|
||||
}
|
||||
}
|
||||
|
||||
private fun packageFor(map: ParsedMap): String =
|
||||
"$BASE_PACKAGE.${identifier(map.regionName)}.${groupSegment(map.groupName)}"
|
||||
|
||||
private fun groupSegment(groupName: String): String {
|
||||
val stripped = groupName.removePrefix("gMapGroup_")
|
||||
val sanitized = stripped.filter { it.isLetterOrDigit() }.lowercase()
|
||||
return sanitized.ifEmpty { "misc" }
|
||||
}
|
||||
|
||||
private fun identifier(name: String): String {
|
||||
val sanitized = name.map { if (it.isLetterOrDigit() || it == '_') it else '_' }.joinToString("")
|
||||
return if (sanitized.firstOrNull()?.isDigit() == true) "_$sanitized" else sanitized
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val BASE_PACKAGE = "de.fiereu.openmmo.maps.generated"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
import java.io.File
|
||||
|
||||
class MovementTypes(private val ids: Map<String, Int>) {
|
||||
|
||||
fun ref(name: String): String =
|
||||
if (name in ids) "MovementType.${name.removePrefix("MOVEMENT_TYPE_")}"
|
||||
else "MovementType.NONE"
|
||||
|
||||
fun facingRef(name: String): String = movementToFacingRef(ids[name] ?: 0)
|
||||
|
||||
companion object {
|
||||
private const val HEADER = "include/constants/event_object_movement.h"
|
||||
|
||||
fun read(dir: File): MovementTypes = MovementTypes(readMovementDefines(File(dir, HEADER)))
|
||||
|
||||
private fun readMovementDefines(file: File): Map<String, Int> {
|
||||
if (!file.exists()) return emptyMap()
|
||||
val pattern = Regex("""^#define\s+(MOVEMENT_TYPE_\w+)\s+(0x[0-9A-Fa-f]+|\d+)""")
|
||||
return file
|
||||
.readLines()
|
||||
.mapNotNull { pattern.find(it.trim()) }
|
||||
.associate {
|
||||
val value = it.groupValues[2]
|
||||
it.groupValues[1] to
|
||||
if (value.startsWith("0x")) value.substring(2).toInt(16) else value.toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
data class ParsedMap(
|
||||
val regionName: String,
|
||||
val sourceName: String,
|
||||
val groupName: String,
|
||||
val mapId: String,
|
||||
val region: Int,
|
||||
val bank: Int,
|
||||
val index: Int,
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
val paletteIdx1: Int,
|
||||
val paletteIdx2: Int,
|
||||
val musicId: Int,
|
||||
val mapsecId: Int,
|
||||
val borderTiles: List<Int>,
|
||||
val blockData: String,
|
||||
val lighting: String,
|
||||
val weather: String,
|
||||
val mapType: String,
|
||||
val encounterType: String,
|
||||
val connections: List<ParsedConnection>,
|
||||
val warps: List<ParsedWarp>,
|
||||
val visibleNpcs: List<ParsedNpc>,
|
||||
val bgEvents: List<ParsedBgEvent>,
|
||||
)
|
||||
|
||||
data class ParsedConnection(
|
||||
val direction: String,
|
||||
val offset: Int,
|
||||
val targetBank: Int,
|
||||
val targetMap: Int,
|
||||
)
|
||||
|
||||
data class ParsedWarp(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val elevation: Int,
|
||||
val targetRegion: Int,
|
||||
val targetBank: Int,
|
||||
val targetMap: Int,
|
||||
val targetX: Int,
|
||||
val targetY: Int,
|
||||
val targetElevation: Int,
|
||||
)
|
||||
|
||||
data class ParsedNpc(
|
||||
val entityIdx: Int,
|
||||
val graphicsId: Int,
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val elevation: Int,
|
||||
val movementType: String,
|
||||
val movementRangeX: Int,
|
||||
val movementRangeY: Int,
|
||||
val trainerType: Int,
|
||||
val facing: String,
|
||||
val script: String,
|
||||
)
|
||||
|
||||
data class ParsedBgEvent(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val facingDir: String,
|
||||
val script: String,
|
||||
)
|
||||
@@ -0,0 +1,320 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
import java.io.File
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import java.util.Base64
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.intOrNull
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
class PretGbaParser(
|
||||
private val rootDir: File,
|
||||
private val region: RegionConstants,
|
||||
private val movementTypes: MovementTypes,
|
||||
) {
|
||||
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
|
||||
private data class Address(val groupIndex: Int, val mapIndex: Int, val mapName: String)
|
||||
|
||||
private class MapGroups(val order: List<String>, val entries: Map<String, List<String>>)
|
||||
|
||||
private class Context(
|
||||
val layouts: Map<String, JsonObject>,
|
||||
val musicIds: Map<String, Int>,
|
||||
val gfxIds: Map<String, Int>,
|
||||
val mapsecIds: Map<String, Int>,
|
||||
val tilesetPaletteIds: Map<String, Int>,
|
||||
val addresses: Map<String, Address>,
|
||||
val mapJsons: Map<String, JsonObject>,
|
||||
)
|
||||
|
||||
fun parseAll(): List<ParsedMap> {
|
||||
val groups = readMapGroups()
|
||||
val context = buildContext(groups)
|
||||
|
||||
return buildList {
|
||||
for ((groupIndex, groupName) in groups.order.withIndex()) {
|
||||
val maps = groups.entries[groupName] ?: continue
|
||||
for ((mapIndex, mapDirName) in maps.withIndex()) {
|
||||
parseMap(groupIndex, groupName, mapIndex, mapDirName, context)?.let { add(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readMapGroups(): MapGroups {
|
||||
val file = File(rootDir, "data/maps/map_groups.json")
|
||||
require(file.exists()) {
|
||||
"Decomp not initialized at $rootDir (missing ${file.path}). " +
|
||||
"Run: git submodule update --init --recursive"
|
||||
}
|
||||
val mapGroups = readJson(file).jsonObject
|
||||
val order =
|
||||
(mapGroups["group_order"] ?: error("group_order missing")).jsonArray.map {
|
||||
it.jsonPrimitive.content
|
||||
}
|
||||
val entries =
|
||||
order.associateWith { group ->
|
||||
(mapGroups[group]?.jsonArray ?: error("group $group missing")).map {
|
||||
it.jsonPrimitive.content
|
||||
}
|
||||
}
|
||||
return MapGroups(order, entries)
|
||||
}
|
||||
|
||||
private fun readLayouts(): Map<String, JsonObject> =
|
||||
(readJson(File(rootDir, "data/layouts/layouts.json")).jsonObject["layouts"]
|
||||
?: error("layouts missing"))
|
||||
.jsonArray
|
||||
.mapNotNull { it as? JsonObject }
|
||||
.filter { it["id"]?.jsonPrimitive?.contentOrNull != null }
|
||||
.associateBy { it["id"]?.jsonPrimitive?.content ?: error("layout id") }
|
||||
|
||||
private fun buildContext(groups: MapGroups): Context {
|
||||
// Pre-parse every map.json once so warp lookups don't re-read files.
|
||||
val addresses = mutableMapOf<String, Address>()
|
||||
val mapJsons = mutableMapOf<String, JsonObject>()
|
||||
for ((groupIndex, groupName) in groups.order.withIndex()) {
|
||||
val maps = groups.entries[groupName] ?: continue
|
||||
for ((mapIndex, mapDirName) in maps.withIndex()) {
|
||||
val mapJsonFile = File(rootDir, "data/maps/$mapDirName/map.json")
|
||||
if (!mapJsonFile.exists()) continue
|
||||
val parsed = readJson(mapJsonFile).jsonObject
|
||||
mapJsons[mapDirName] = parsed
|
||||
addresses[mapDirName] = Address(groupIndex, mapIndex, mapDirName)
|
||||
val mapId = parsed["id"]?.jsonPrimitive?.contentOrNull
|
||||
if (mapId != null) addresses[mapId] = Address(groupIndex, mapIndex, mapDirName)
|
||||
}
|
||||
}
|
||||
|
||||
return Context(
|
||||
layouts = readLayouts(),
|
||||
musicIds = readDefineTable(File(rootDir, "include/constants/songs.h"), "MUS_"),
|
||||
gfxIds = readGfxIds(File(rootDir, "include/constants/event_objects.h")),
|
||||
mapsecIds = readMapsecIds(),
|
||||
tilesetPaletteIds = readTilesetPaletteIds(),
|
||||
addresses = addresses,
|
||||
mapJsons = mapJsons,
|
||||
)
|
||||
}
|
||||
|
||||
private fun parseMap(
|
||||
groupIndex: Int,
|
||||
groupName: String,
|
||||
mapIndex: Int,
|
||||
mapDirName: String,
|
||||
ctx: Context,
|
||||
): ParsedMap? {
|
||||
val mapJson = ctx.mapJsons[mapDirName] ?: return null
|
||||
val layoutId = mapJson["layout"]?.jsonPrimitive?.contentOrNull ?: return null
|
||||
val layout = ctx.layouts[layoutId] ?: return null
|
||||
|
||||
val mapType = mapJson["map_type"]?.jsonPrimitive?.contentOrNull ?: "MAP_TYPE_INDOOR"
|
||||
val musicName = mapJson["music"]?.jsonPrimitive?.contentOrNull ?: "MUS_NONE"
|
||||
val mapsecName = mapJson["region_map_section"]?.jsonPrimitive?.contentOrNull ?: "MAPSEC_NONE"
|
||||
|
||||
return ParsedMap(
|
||||
regionName = region.name,
|
||||
sourceName = mapDirName,
|
||||
groupName = groupName,
|
||||
mapId = mapJson["id"]?.jsonPrimitive?.contentOrNull ?: mapDirName,
|
||||
region = region.regionId,
|
||||
bank = groupIndex + BANK_GROUP_OFFSET,
|
||||
index = mapIndex,
|
||||
width = layout["width"]?.jsonPrimitive?.intOrNull ?: 20,
|
||||
height = layout["height"]?.jsonPrimitive?.intOrNull ?: 15,
|
||||
paletteIdx1 =
|
||||
ctx.tilesetPaletteIds[layout["primary_tileset"]?.jsonPrimitive?.contentOrNull] ?: 80,
|
||||
paletteIdx2 =
|
||||
ctx.tilesetPaletteIds[layout["secondary_tileset"]?.jsonPrimitive?.contentOrNull] ?: 82,
|
||||
musicId = ctx.musicIds[musicName] ?: 405,
|
||||
mapsecId = ctx.mapsecIds[mapsecName] ?: 0,
|
||||
borderTiles = parseBorderTiles(layout),
|
||||
blockData = parseBlockData(layout),
|
||||
lighting = "Lighting.REGULAR",
|
||||
weather =
|
||||
region.weatherMap[mapJson["weather"]?.jsonPrimitive?.contentOrNull]
|
||||
?: "Weather.REGULAR_WEATHER",
|
||||
mapType = region.mapTypeMap[mapType] ?: "MapType.INSIDE",
|
||||
encounterType = region.encounterMap[mapType] ?: "EncounterType.RANDOM",
|
||||
connections = parseConnections(mapJson, ctx),
|
||||
warps = parseWarps(mapJson, ctx),
|
||||
visibleNpcs = parseNpcs(mapJson, mapDirName, ctx),
|
||||
bgEvents = parseBgEvents(mapJson),
|
||||
)
|
||||
}
|
||||
|
||||
private fun parseConnections(mapJson: JsonObject, ctx: Context): List<ParsedConnection> =
|
||||
mapJson["connections"]?.jsonArrayOrNull()?.mapNotNull { conn ->
|
||||
val obj = conn.jsonObject
|
||||
val dirName = obj["direction"]?.jsonPrimitive?.contentOrNull ?: return@mapNotNull null
|
||||
val dir = region.dirMap[dirName] ?: error("Unknown connection direction '$dirName'")
|
||||
val mapName = obj["map"]?.jsonPrimitive?.contentOrNull ?: return@mapNotNull null
|
||||
val addr = ctx.addresses[mapName] ?: return@mapNotNull null
|
||||
ParsedConnection(
|
||||
direction = dir,
|
||||
offset = obj["offset"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
targetBank = addr.groupIndex + BANK_GROUP_OFFSET,
|
||||
targetMap = addr.mapIndex,
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
private fun parseWarps(mapJson: JsonObject, ctx: Context): List<ParsedWarp> =
|
||||
mapJson["warp_events"]?.jsonArrayOrNull()?.mapNotNull { warp ->
|
||||
val obj = warp.jsonObject
|
||||
val destName = obj["dest_map"]?.jsonPrimitive?.contentOrNull ?: return@mapNotNull null
|
||||
val destAddr = ctx.addresses[destName] ?: return@mapNotNull null
|
||||
val x = obj["x"]?.jsonPrimitive?.intOrNull ?: 0
|
||||
val y = obj["y"]?.jsonPrimitive?.intOrNull ?: 0
|
||||
val srcElevation = (obj["elevation"]?.jsonPrimitive?.intOrNull ?: 0)
|
||||
val destWarpId =
|
||||
obj["dest_warp_id"]?.jsonPrimitive?.let { it.intOrNull ?: it.content.toIntOrNull() }
|
||||
?: 0
|
||||
val destWarps =
|
||||
ctx.mapJsons[destAddr.mapName]?.get("warp_events")?.jsonArrayOrNull().orEmpty()
|
||||
val target = destWarps.getOrNull(destWarpId)?.jsonObject
|
||||
ParsedWarp(
|
||||
x = x,
|
||||
y = y,
|
||||
elevation = (srcElevation - 1).coerceAtLeast(0),
|
||||
targetRegion = region.regionId,
|
||||
targetBank = destAddr.groupIndex + BANK_GROUP_OFFSET,
|
||||
targetMap = destAddr.mapIndex,
|
||||
targetX = target?.get("x")?.jsonPrimitive?.intOrNull ?: x,
|
||||
targetY = target?.get("y")?.jsonPrimitive?.intOrNull ?: y,
|
||||
targetElevation =
|
||||
((target?.get("elevation")?.jsonPrimitive?.intOrNull ?: 0) - 1).coerceAtLeast(0),
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
private fun parseNpcs(mapJson: JsonObject, mapDirName: String, ctx: Context): List<ParsedNpc> {
|
||||
val visibleOverride = region.defaultVisibleNpcs[mapDirName]
|
||||
return mapJson["object_events"]?.jsonArrayOrNull().orEmpty().mapIndexedNotNull { idx, npcElement
|
||||
->
|
||||
val npc = npcElement.jsonObject
|
||||
val isVisible =
|
||||
if (visibleOverride != null) idx in visibleOverride
|
||||
else npc["flag"]?.jsonPrimitive?.contentOrNull == "0"
|
||||
if (!isVisible) return@mapIndexedNotNull null
|
||||
val gfxName = npc["graphics_id"]?.jsonPrimitive?.contentOrNull ?: "OBJ_EVENT_GFX_BOY_1"
|
||||
val movementName = npc["movement_type"]?.jsonPrimitive?.contentOrNull ?: "MOVEMENT_TYPE_NONE"
|
||||
ParsedNpc(
|
||||
entityIdx = idx,
|
||||
graphicsId = ctx.gfxIds[gfxName] ?: 0,
|
||||
x = npc["x"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
y = npc["y"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
elevation = npc["elevation"]?.jsonPrimitive?.intOrNull ?: 3,
|
||||
movementType = movementTypes.ref(movementName),
|
||||
movementRangeX = npc["movement_range_x"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
movementRangeY = npc["movement_range_y"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
trainerType =
|
||||
if (npc["trainer_type"]?.jsonPrimitive?.contentOrNull == "TRAINER_TYPE_NONE") 0
|
||||
else 1,
|
||||
facing = movementTypes.facingRef(movementName),
|
||||
script = npc["script"]?.jsonPrimitive?.contentOrNull ?: "0x0",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseBgEvents(mapJson: JsonObject): List<ParsedBgEvent> =
|
||||
mapJson["bg_events"]?.jsonArrayOrNull()?.map { be ->
|
||||
val obj = be.jsonObject
|
||||
ParsedBgEvent(
|
||||
x = obj["x"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
y = obj["y"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
facingDir =
|
||||
obj["player_facing_dir"]?.jsonPrimitive?.contentOrNull
|
||||
?: "BG_EVENT_PLAYER_FACING_ANY",
|
||||
script = obj["script"]?.jsonPrimitive?.contentOrNull ?: "0x0",
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
private fun parseBorderTiles(layout: JsonObject): List<Int> =
|
||||
layout["border_filepath"]?.jsonPrimitive?.contentOrNull?.let {
|
||||
readBorderTiles(File(rootDir, it))
|
||||
} ?: emptyList()
|
||||
|
||||
private fun parseBlockData(layout: JsonObject): String {
|
||||
val path = layout["blockdata_filepath"]?.jsonPrimitive?.contentOrNull ?: return ""
|
||||
val file = File(rootDir, path)
|
||||
if (!file.exists()) return ""
|
||||
return Base64.getEncoder().encodeToString(file.readBytes())
|
||||
}
|
||||
|
||||
private fun readJson(file: File): JsonElement = json.parseToJsonElement(file.readText())
|
||||
|
||||
private fun readDefineTable(file: File, prefix: String): Map<String, Int> {
|
||||
if (!file.exists()) return emptyMap()
|
||||
val pattern = Regex("""^#define\s+($prefix\w+)\s+(\d+)""")
|
||||
return file
|
||||
.readLines()
|
||||
.mapNotNull { pattern.find(it.trim()) }
|
||||
.associate { it.groupValues[1] to it.groupValues[2].toInt() }
|
||||
}
|
||||
|
||||
private fun readIntDefine(file: File, name: String): Int? {
|
||||
if (!file.exists()) return null
|
||||
val pattern = Regex("""^#define\s+$name\s+(\d+)""")
|
||||
return file.readLines().firstNotNullOfOrNull {
|
||||
pattern.find(it.trim())?.groupValues?.get(1)?.toInt()
|
||||
}
|
||||
}
|
||||
|
||||
private fun readGfxIds(file: File): Map<String, Int> {
|
||||
val gfx = readDefineTable(file, "OBJ_EVENT_GFX_").toMutableMap()
|
||||
val varsBase =
|
||||
gfx["OBJ_EVENT_GFX_VARS"] ?: readIntDefine(file, "NUM_OBJ_EVENT_GFX")?.plus(1) ?: return gfx
|
||||
val varPattern =
|
||||
Regex(
|
||||
"""^#define\s+(OBJ_EVENT_GFX_VAR_[0-9A-Fa-f]+)\s+\(OBJ_EVENT_GFX_VARS\s*\+\s*0x([0-9A-Fa-f]+)\)""")
|
||||
file.forEachLine { line ->
|
||||
val m = varPattern.find(line.trim()) ?: return@forEachLine
|
||||
gfx[m.groupValues[1]] = varsBase + m.groupValues[2].toInt(16)
|
||||
}
|
||||
return gfx
|
||||
}
|
||||
|
||||
private fun readMapsecIds(): Map<String, Int> {
|
||||
val file = File(rootDir, "src/data/region_map/region_map_sections.json")
|
||||
if (!file.exists()) return emptyMap()
|
||||
val sections = readJson(file).jsonObject["map_sections"]?.jsonArray ?: return emptyMap()
|
||||
return sections
|
||||
.mapIndexedNotNull { i, el ->
|
||||
el.jsonObject["id"]?.jsonPrimitive?.contentOrNull?.let { it to i }
|
||||
}
|
||||
.toMap()
|
||||
}
|
||||
|
||||
private fun readTilesetPaletteIds(): Map<String, Int> {
|
||||
val file = File(rootDir, "src/data/tilesets/headers.h")
|
||||
if (!file.exists()) return emptyMap()
|
||||
val pattern = Regex("""^const struct Tileset\s+(gTileset_\w+)\s*=""")
|
||||
var index = 0
|
||||
val out = mutableMapOf<String, Int>()
|
||||
file.forEachLine { line ->
|
||||
val m = pattern.find(line.trim()) ?: return@forEachLine
|
||||
out[m.groupValues[1]] = 100 + index
|
||||
index++
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
private fun readBorderTiles(file: File): List<Int> {
|
||||
if (!file.exists()) return emptyList()
|
||||
val bytes = file.readBytes()
|
||||
val buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)
|
||||
val out = mutableListOf<Int>()
|
||||
while (buf.remaining() >= 2) out += buf.short.toInt() and 0xFFFF
|
||||
return out
|
||||
}
|
||||
|
||||
private fun JsonElement.jsonArrayOrNull() = (this as? JsonArray)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
open class RegionConstants(
|
||||
val name: String,
|
||||
val regionId: Int,
|
||||
val defaultVisibleNpcs: Map<String, List<Int>> = emptyMap(),
|
||||
val dirMap: Map<String, String> = COMMON_DIR_MAP,
|
||||
val weatherMap: Map<String, String> = COMMON_WEATHER_MAP,
|
||||
val mapTypeMap: Map<String, String> = COMMON_MAP_TYPE_MAP,
|
||||
val encounterMap: Map<String, String> = COMMON_ENCOUNTER_MAP,
|
||||
)
|
||||
|
||||
val REGIONS: Map<String, RegionConstants> =
|
||||
listOf(HoennConstants, KantoConstants).associateBy { it.name }
|
||||
@@ -0,0 +1,59 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
object RenderUtil {
|
||||
|
||||
private const val EMPTY_LIST = "emptyList()"
|
||||
private const val LIST_OPEN = "listOf(\n "
|
||||
private const val LIST_SEP = ",\n "
|
||||
private const val LIST_CLOSE = ",\n )"
|
||||
|
||||
fun borderTiles(tiles: List<Int>): String {
|
||||
val take = tiles.take(4)
|
||||
val filled =
|
||||
if (take.size < 4) take + List(4 - take.size) { if (take.isEmpty()) 8 else take.last() }
|
||||
else take
|
||||
return filled.joinToString(", ", "listOf(", ")") {
|
||||
"Tile2D(0x${it.toString(16).uppercase().padStart(4, '0')}, 0)"
|
||||
}
|
||||
}
|
||||
|
||||
fun connections(conns: List<ParsedConnection>): String {
|
||||
if (conns.isEmpty()) return EMPTY_LIST
|
||||
return conns.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
"MapData.GbaConnection(direction = ${it.direction}, unknown = ${it.offset}," +
|
||||
" targetBank = ${it.targetBank}, targetMap = ${it.targetMap})"
|
||||
}
|
||||
}
|
||||
|
||||
fun warps(warps: List<ParsedWarp>): String {
|
||||
if (warps.isEmpty()) return EMPTY_LIST
|
||||
return warps.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
"WarpTile(x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," +
|
||||
" targetRegionId = ${it.targetRegion}, targetBankId = ${it.targetBank}," +
|
||||
" targetMapId = ${it.targetMap}," +
|
||||
" targetX = ${it.targetX}, targetY = ${it.targetY}, targetElevation = ${it.targetElevation})"
|
||||
}
|
||||
}
|
||||
|
||||
fun npcs(npcs: List<ParsedNpc>): String {
|
||||
if (npcs.isEmpty()) return EMPTY_LIST
|
||||
return npcs.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
"NpcDef(entityIdx = ${it.entityIdx}, graphicsId = ${it.graphicsId}," +
|
||||
" x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," +
|
||||
" movementType = ${it.movementType}, movementRangeX = ${it.movementRangeX}," +
|
||||
" movementRangeY = ${it.movementRangeY}, trainerType = ${it.trainerType}," +
|
||||
" facing = ${it.facing}, script = ${escapeString(it.script)})"
|
||||
}
|
||||
}
|
||||
|
||||
fun bgEvents(events: List<ParsedBgEvent>): String {
|
||||
if (events.isEmpty()) return EMPTY_LIST
|
||||
return events.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
"BgEventDef(x = ${it.x}, y = ${it.y}," +
|
||||
" facingDir = ${escapeString(it.facingDir)}, script = ${escapeString(it.script)})"
|
||||
}
|
||||
}
|
||||
|
||||
private fun escapeString(s: String): String =
|
||||
"\"" + s.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.fiereu.openmmo.codegen.move
|
||||
|
||||
fun typeRef(token: String): String {
|
||||
val name = token.removePrefix("TYPE_")
|
||||
val mapped = if (name == "MYSTERY") "QUESTIONQUESTIONQUESTION" else name
|
||||
return "PokemonType.$mapped"
|
||||
}
|
||||
|
||||
fun effectRef(token: String): String = "MoveEffect.${token.removePrefix("EFFECT_")}"
|
||||
|
||||
fun targetRef(token: String): String = "MoveTarget.${token.removePrefix("MOVE_TARGET_")}"
|
||||
|
||||
fun flagRefs(expr: String): List<String> =
|
||||
expr
|
||||
.split("|")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() && it != "0" }
|
||||
.map { "MoveFlag.${it.removePrefix("FLAG_")}" }
|
||||
@@ -0,0 +1,21 @@
|
||||
@file:JvmName("Main")
|
||||
|
||||
package de.fiereu.openmmo.codegen.move
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
require(args.size >= 4) {
|
||||
"Usage: <output-dir> <templates-dir> <class-cache-dir> <decomp-dir> got ${args.toList()}"
|
||||
}
|
||||
val outputDir = File(args[0])
|
||||
val templatesDir = File(args[1])
|
||||
val classCacheDir = File(args[2])
|
||||
val decompDir = File(args[3])
|
||||
|
||||
println("[moves] parsing from $decompDir")
|
||||
val moves = MoveParser(decompDir).parseAll()
|
||||
println("[moves] parsed ${moves.size} moves. writing to $outputDir")
|
||||
MovesRenderer(templatesDir, outputDir, classCacheDir).render(moves)
|
||||
println("[moves] done")
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package de.fiereu.openmmo.codegen.move
|
||||
|
||||
import java.io.File
|
||||
|
||||
class MoveParser(private val rootDir: File) {
|
||||
|
||||
fun parseAll(): List<ParsedMove> {
|
||||
val ids = readMoveIds()
|
||||
val names = readMoveNames()
|
||||
val entries = readBattleMoves()
|
||||
|
||||
return ids.entries
|
||||
.sortedBy { it.value }
|
||||
.mapNotNull { (constant, id) ->
|
||||
val fields = entries[constant] ?: return@mapNotNull null
|
||||
ParsedMove(
|
||||
id = id,
|
||||
name = names[constant] ?: constant.removePrefix("MOVE_"),
|
||||
effect = effectRef(fields.getValue("effect")),
|
||||
power = fields.getValue("power").toInt(),
|
||||
type = typeRef(fields.getValue("type")),
|
||||
accuracy = fields.getValue("accuracy").toInt(),
|
||||
pp = fields.getValue("pp").toInt(),
|
||||
secondaryEffectChance = fields.getValue("secondaryEffectChance").toInt(),
|
||||
target = targetRef(fields.getValue("target")),
|
||||
priority = fields.getValue("priority").toInt(),
|
||||
flags = flagRefs(fields.getValue("flags")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun readMoveIds(): Map<String, Int> {
|
||||
val file = File(rootDir, "include/constants/moves.h")
|
||||
require(file.exists()) {
|
||||
"Decomp not initialized at $rootDir (missing ${file.path}). " +
|
||||
"Run: git submodule update --init --recursive"
|
||||
}
|
||||
val regex = Regex("""^#define\s+(MOVE_\w+)\s+(\d+)\s*$""")
|
||||
return file
|
||||
.readLines()
|
||||
.mapNotNull { regex.find(it.trim()) }
|
||||
.associate { it.groupValues[1] to it.groupValues[2].toInt() }
|
||||
}
|
||||
|
||||
private fun readMoveNames(): Map<String, String> {
|
||||
val file = File(rootDir, "src/data/text/move_names.h")
|
||||
require(file.exists()) { "Missing move names table at ${file.path}" }
|
||||
val regex = Regex("""\[(MOVE_\w+)\]\s*=\s*_\("([^"]*)"\)""")
|
||||
return regex.findAll(file.readText()).associate { it.groupValues[1] to it.groupValues[2] }
|
||||
}
|
||||
|
||||
private fun readBattleMoves(): Map<String, Map<String, String>> {
|
||||
val file = File(rootDir, "src/data/battle_moves.h")
|
||||
require(file.exists()) { "Missing battle move data at ${file.path}" }
|
||||
val entry = Regex("""\[(MOVE_\w+)\]\s*=\s*\{(.*?)\}""", RegexOption.DOT_MATCHES_ALL)
|
||||
val field = Regex("""\.(\w+)\s*=\s*([^,\n]+?)\s*,""")
|
||||
return entry.findAll(file.readText()).associate { match ->
|
||||
val constant = match.groupValues[1]
|
||||
val fields =
|
||||
field.findAll(match.groupValues[2]).associate {
|
||||
it.groupValues[1] to it.groupValues[2].trim()
|
||||
}
|
||||
constant to fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package de.fiereu.openmmo.codegen.move
|
||||
|
||||
import gg.jte.ContentType
|
||||
import gg.jte.TemplateEngine
|
||||
import gg.jte.output.FileOutput
|
||||
import gg.jte.resolve.DirectoryCodeResolver
|
||||
import java.io.File
|
||||
|
||||
class MovesRenderer(
|
||||
private val templatesDir: File,
|
||||
private val outputDir: File,
|
||||
private val classCacheDir: File,
|
||||
private val registryChunkSize: Int = 50,
|
||||
) {
|
||||
|
||||
fun render(moves: List<ParsedMove>) {
|
||||
classCacheDir.mkdirs()
|
||||
val engine =
|
||||
TemplateEngine.create(
|
||||
DirectoryCodeResolver(templatesDir.toPath()),
|
||||
classCacheDir.toPath(),
|
||||
ContentType.Plain,
|
||||
)
|
||||
|
||||
val packageRoot = File(outputDir, BASE_PACKAGE.replace('.', '/'))
|
||||
if (packageRoot.exists()) packageRoot.deleteRecursively()
|
||||
|
||||
val chunks = moves.sortedBy { it.id }.chunked(registryChunkSize)
|
||||
val registry = File(outputDir, "${BASE_PACKAGE.replace('.', '/')}/GeneratedMoves.kt")
|
||||
registry.parentFile.mkdirs()
|
||||
FileOutput(registry.toPath()).use { out ->
|
||||
engine.render("MovesRegistry.jte", mapOf("chunks" to chunks), out)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val BASE_PACKAGE = "de.fiereu.openmmo.moves.generated"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.fiereu.openmmo.codegen.move
|
||||
|
||||
data class ParsedMove(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val effect: String,
|
||||
val power: Int,
|
||||
val type: String,
|
||||
val accuracy: Int,
|
||||
val pp: Int,
|
||||
val secondaryEffectChance: Int,
|
||||
val target: String,
|
||||
val priority: Int,
|
||||
val flags: List<String>,
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.fiereu.openmmo.codegen.move
|
||||
|
||||
object RenderUtil {
|
||||
|
||||
fun move(m: ParsedMove): String {
|
||||
val flags = if (m.flags.isEmpty()) "emptySet()" else m.flags.joinToString(", ", "setOf(", ")")
|
||||
return "MoveDef(id = ${m.id}, name = ${escapeString(m.name)}, effect = ${m.effect}," +
|
||||
" power = ${m.power}, type = ${m.type}, accuracy = ${m.accuracy}, pp = ${m.pp}," +
|
||||
" secondaryEffectChance = ${m.secondaryEffectChance}, target = ${m.target}," +
|
||||
" priority = ${m.priority}, flags = $flags)"
|
||||
}
|
||||
|
||||
private fun escapeString(s: String): String =
|
||||
"\"" + s.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
|
||||
}
|
||||
Reference in new issue
Block a user