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
@@ -6,6 +6,15 @@ kotlin {
|
|||||||
jvmToolchain(25)
|
jvmToolchain(25)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
create("jteCodegen") {
|
||||||
|
id = "buildsrc.convention.jte-codegen"
|
||||||
|
implementationClass = "buildsrc.convention.JteCodegenPlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.kotlinGradlePlugin)
|
implementation(libs.kotlinGradlePlugin)
|
||||||
implementation(libs.spotlessGradlePlugin)
|
implementation(libs.spotlessGradlePlugin)
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package buildsrc.convention
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
import org.gradle.api.Action
|
||||||
|
import org.gradle.api.Named
|
||||||
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.file.ConfigurableFileCollection
|
||||||
|
import org.gradle.api.model.ObjectFactory
|
||||||
|
import org.gradle.api.provider.ListProperty
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
|
import org.gradle.api.tasks.JavaExec
|
||||||
|
import org.gradle.api.tasks.SourceSetContainer
|
||||||
|
import org.gradle.kotlin.dsl.create
|
||||||
|
import org.gradle.kotlin.dsl.getByType
|
||||||
|
import org.gradle.kotlin.dsl.register
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||||
|
|
||||||
|
abstract class JteCodegenSpec @Inject constructor(private val specName: String) : Named {
|
||||||
|
override fun getName(): String = specName
|
||||||
|
|
||||||
|
abstract val mainClass: Property<String>
|
||||||
|
abstract val templatesSubdir: Property<String>
|
||||||
|
abstract val extraArgs: ListProperty<String>
|
||||||
|
abstract val inputDirs: ConfigurableFileCollection
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JteCodegenExtension @Inject constructor(objects: ObjectFactory) {
|
||||||
|
val generators: NamedDomainObjectContainer<JteCodegenSpec> =
|
||||||
|
objects.domainObjectContainer(JteCodegenSpec::class.java)
|
||||||
|
|
||||||
|
fun register(name: String, action: Action<JteCodegenSpec>) = generators.register(name, action)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JteCodegenPlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
val generator = project.extensions.getByType<SourceSetContainer>().create("generator")
|
||||||
|
val ext = project.extensions.create<JteCodegenExtension>("jteCodegen")
|
||||||
|
val templatesBase = project.layout.projectDirectory.dir("src/generator/jte")
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
ext.generators.forEach { spec ->
|
||||||
|
val templatesDir = templatesBase.dir(spec.templatesSubdir.getOrElse(spec.name))
|
||||||
|
val outDir = project.layout.buildDirectory.dir("generated/source/${spec.name}/kotlin")
|
||||||
|
val jteCacheDir = project.layout.buildDirectory.dir("jte-classes/${spec.name}")
|
||||||
|
|
||||||
|
val generate =
|
||||||
|
project.tasks.register<JavaExec>(
|
||||||
|
"generate${spec.name.replaceFirstChar { it.uppercase() }}") {
|
||||||
|
group = "openmmo"
|
||||||
|
description = "Render ${spec.name} sources from the GBA decomp data via JTE"
|
||||||
|
dependsOn(project.tasks.named("${generator.name}Classes"))
|
||||||
|
spec.inputDirs.forEach { inputs.dir(it) }
|
||||||
|
inputs.dir(templatesDir)
|
||||||
|
outputs.dir(outDir)
|
||||||
|
classpath = generator.runtimeClasspath
|
||||||
|
mainClass.set(spec.mainClass)
|
||||||
|
setArgs(
|
||||||
|
buildList {
|
||||||
|
add(outDir.get().asFile.absolutePath)
|
||||||
|
add(templatesDir.asFile.absolutePath)
|
||||||
|
add(jteCacheDir.get().asFile.absolutePath)
|
||||||
|
addAll(spec.extraArgs.get())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
project.extensions
|
||||||
|
.getByType<KotlinJvmProjectExtension>()
|
||||||
|
.sourceSets
|
||||||
|
.getByName("main")
|
||||||
|
.kotlin
|
||||||
|
.srcDir(generate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
plugins {
|
||||||
|
id("buildsrc.convention.kotlin-jvm")
|
||||||
|
id("buildsrc.convention.spotless")
|
||||||
|
id("buildsrc.convention.sonarlint")
|
||||||
|
id("buildsrc.convention.jte-codegen")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api(project(":common"))
|
||||||
|
api(project(":protocols.game"))
|
||||||
|
api(libs.dagger)
|
||||||
|
"generatorImplementation"(libs.jte)
|
||||||
|
"generatorImplementation"(libs.kotlinx.serialization.json)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Region name -> source decomp. Only non-NDS (GBA, 2D) decomps that share the pret
|
||||||
|
// map format are listed. The NDS decomps (pokeblack, pokeheartgold, pokeplatinum) use
|
||||||
|
// 3D maps and are not parsed here. Region ids live in the per-region constants.
|
||||||
|
val regionSources =
|
||||||
|
mapOf(
|
||||||
|
"hoenn" to "pokeemerald",
|
||||||
|
"kanto" to "pokefirered",
|
||||||
|
)
|
||||||
|
|
||||||
|
val movesDecompDir = rootProject.layout.projectDirectory.dir("decomp/pokeemerald")
|
||||||
|
|
||||||
|
jteCodegen {
|
||||||
|
register("maps") {
|
||||||
|
mainClass.set("de.fiereu.openmmo.codegen.maps.Main")
|
||||||
|
inputDirs.from(
|
||||||
|
regionSources.values.map { rootProject.layout.projectDirectory.dir("decomp/$it") })
|
||||||
|
extraArgs.set(
|
||||||
|
regionSources.map { (region, decomp) ->
|
||||||
|
"$region|${rootProject.layout.projectDirectory.dir("decomp/$decomp").asFile.absolutePath}"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
register("moves") {
|
||||||
|
mainClass.set("de.fiereu.openmmo.codegen.move.Main")
|
||||||
|
templatesSubdir.set("move")
|
||||||
|
inputDirs.from(movesDecompDir)
|
||||||
|
extraArgs.set(listOf(movesDecompDir.asFile.absolutePath))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
@import de.fiereu.openmmo.maps.generator.ParsedMap
|
@import de.fiereu.openmmo.codegen.maps.ParsedMap
|
||||||
@import de.fiereu.openmmo.maps.generator.RenderUtil
|
@import de.fiereu.openmmo.codegen.maps.RenderUtil
|
||||||
|
|
||||||
@param String packageName
|
@param String packageName
|
||||||
@param String objectName
|
@param String objectName
|
||||||
File renamed without changes.
@@ -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
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
internal const val BANK_GROUP_OFFSET = 50
|
internal const val BANK_GROUP_OFFSET = 50
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
object HoennConstants :
|
object HoennConstants :
|
||||||
RegionConstants(
|
RegionConstants(
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
object KantoConstants :
|
object KantoConstants :
|
||||||
RegionConstants(
|
RegionConstants(
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
@file:JvmName("Main")
|
@file:JvmName("Main")
|
||||||
|
|
||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
import gg.jte.ContentType
|
import gg.jte.ContentType
|
||||||
import gg.jte.TemplateEngine
|
import gg.jte.TemplateEngine
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
data class ParsedMap(
|
data class ParsedMap(
|
||||||
val regionName: String,
|
val regionName: String,
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
open class RegionConstants(
|
open class RegionConstants(
|
||||||
val name: String,
|
val name: String,
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.maps.generator
|
package de.fiereu.openmmo.codegen.maps
|
||||||
|
|
||||||
object RenderUtil {
|
object RenderUtil {
|
||||||
|
|
||||||
@@ -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("\"", "\\\"") + "\""
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,22 @@
|
|||||||
|
package de.fiereu.openmmo.moves
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
data class MoveDef(
|
||||||
|
val id: Int,
|
||||||
|
val name: String,
|
||||||
|
val effect: MoveEffect,
|
||||||
|
val power: Int,
|
||||||
|
val type: PokemonType,
|
||||||
|
val accuracy: Int,
|
||||||
|
val pp: Int,
|
||||||
|
val secondaryEffectChance: Int,
|
||||||
|
val target: MoveTarget,
|
||||||
|
val priority: Int,
|
||||||
|
val flags: Set<MoveFlag> = emptySet(),
|
||||||
|
) {
|
||||||
|
fun hasFlag(flag: MoveFlag): Boolean = flag in flags
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.fiereu.openmmo.moves
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.moves.generated.GeneratedMoves
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class MoveRegistry @Inject constructor() {
|
||||||
|
|
||||||
|
private val moves = ConcurrentHashMap<Int, MoveDef>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
GeneratedMoves.loadInto(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun register(move: MoveDef) {
|
||||||
|
moves[move.id] = move
|
||||||
|
}
|
||||||
|
|
||||||
|
fun get(id: Int): MoveDef? = moves[id]
|
||||||
|
|
||||||
|
fun all(): Collection<MoveDef> = moves.values
|
||||||
|
|
||||||
|
fun size(): Int = moves.size
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class MoveEffect {
|
||||||
|
HIT,
|
||||||
|
SLEEP,
|
||||||
|
POISON_HIT,
|
||||||
|
ABSORB,
|
||||||
|
BURN_HIT,
|
||||||
|
FREEZE_HIT,
|
||||||
|
PARALYZE_HIT,
|
||||||
|
EXPLOSION,
|
||||||
|
DREAM_EATER,
|
||||||
|
MIRROR_MOVE,
|
||||||
|
ATTACK_UP,
|
||||||
|
DEFENSE_UP,
|
||||||
|
SPEED_UP,
|
||||||
|
SPECIAL_ATTACK_UP,
|
||||||
|
SPECIAL_DEFENSE_UP,
|
||||||
|
ACCURACY_UP,
|
||||||
|
EVASION_UP,
|
||||||
|
ALWAYS_HIT,
|
||||||
|
ATTACK_DOWN,
|
||||||
|
DEFENSE_DOWN,
|
||||||
|
SPEED_DOWN,
|
||||||
|
SPECIAL_ATTACK_DOWN,
|
||||||
|
SPECIAL_DEFENSE_DOWN,
|
||||||
|
ACCURACY_DOWN,
|
||||||
|
EVASION_DOWN,
|
||||||
|
HAZE,
|
||||||
|
BIDE,
|
||||||
|
RAMPAGE,
|
||||||
|
ROAR,
|
||||||
|
MULTI_HIT,
|
||||||
|
CONVERSION,
|
||||||
|
FLINCH_HIT,
|
||||||
|
RESTORE_HP,
|
||||||
|
TOXIC,
|
||||||
|
PAY_DAY,
|
||||||
|
LIGHT_SCREEN,
|
||||||
|
TRI_ATTACK,
|
||||||
|
REST,
|
||||||
|
OHKO,
|
||||||
|
RAZOR_WIND,
|
||||||
|
SUPER_FANG,
|
||||||
|
DRAGON_RAGE,
|
||||||
|
TRAP,
|
||||||
|
HIGH_CRITICAL,
|
||||||
|
DOUBLE_HIT,
|
||||||
|
RECOIL_IF_MISS,
|
||||||
|
MIST,
|
||||||
|
FOCUS_ENERGY,
|
||||||
|
RECOIL,
|
||||||
|
CONFUSE,
|
||||||
|
ATTACK_UP_2,
|
||||||
|
DEFENSE_UP_2,
|
||||||
|
SPEED_UP_2,
|
||||||
|
SPECIAL_ATTACK_UP_2,
|
||||||
|
SPECIAL_DEFENSE_UP_2,
|
||||||
|
ACCURACY_UP_2,
|
||||||
|
EVASION_UP_2,
|
||||||
|
TRANSFORM,
|
||||||
|
ATTACK_DOWN_2,
|
||||||
|
DEFENSE_DOWN_2,
|
||||||
|
SPEED_DOWN_2,
|
||||||
|
SPECIAL_ATTACK_DOWN_2,
|
||||||
|
SPECIAL_DEFENSE_DOWN_2,
|
||||||
|
ACCURACY_DOWN_2,
|
||||||
|
EVASION_DOWN_2,
|
||||||
|
REFLECT,
|
||||||
|
POISON,
|
||||||
|
PARALYZE,
|
||||||
|
ATTACK_DOWN_HIT,
|
||||||
|
DEFENSE_DOWN_HIT,
|
||||||
|
SPEED_DOWN_HIT,
|
||||||
|
SPECIAL_ATTACK_DOWN_HIT,
|
||||||
|
SPECIAL_DEFENSE_DOWN_HIT,
|
||||||
|
ACCURACY_DOWN_HIT,
|
||||||
|
EVASION_DOWN_HIT,
|
||||||
|
SKY_ATTACK,
|
||||||
|
CONFUSE_HIT,
|
||||||
|
TWINEEDLE,
|
||||||
|
VITAL_THROW,
|
||||||
|
SUBSTITUTE,
|
||||||
|
RECHARGE,
|
||||||
|
RAGE,
|
||||||
|
MIMIC,
|
||||||
|
METRONOME,
|
||||||
|
LEECH_SEED,
|
||||||
|
SPLASH,
|
||||||
|
DISABLE,
|
||||||
|
LEVEL_DAMAGE,
|
||||||
|
PSYWAVE,
|
||||||
|
COUNTER,
|
||||||
|
ENCORE,
|
||||||
|
PAIN_SPLIT,
|
||||||
|
SNORE,
|
||||||
|
CONVERSION_2,
|
||||||
|
LOCK_ON,
|
||||||
|
SKETCH,
|
||||||
|
UNUSED_60,
|
||||||
|
SLEEP_TALK,
|
||||||
|
DESTINY_BOND,
|
||||||
|
FLAIL,
|
||||||
|
SPITE,
|
||||||
|
FALSE_SWIPE,
|
||||||
|
HEAL_BELL,
|
||||||
|
QUICK_ATTACK,
|
||||||
|
TRIPLE_KICK,
|
||||||
|
THIEF,
|
||||||
|
MEAN_LOOK,
|
||||||
|
NIGHTMARE,
|
||||||
|
MINIMIZE,
|
||||||
|
CURSE,
|
||||||
|
UNUSED_6E,
|
||||||
|
PROTECT,
|
||||||
|
SPIKES,
|
||||||
|
FORESIGHT,
|
||||||
|
PERISH_SONG,
|
||||||
|
SANDSTORM,
|
||||||
|
ENDURE,
|
||||||
|
ROLLOUT,
|
||||||
|
SWAGGER,
|
||||||
|
FURY_CUTTER,
|
||||||
|
ATTRACT,
|
||||||
|
RETURN,
|
||||||
|
PRESENT,
|
||||||
|
FRUSTRATION,
|
||||||
|
SAFEGUARD,
|
||||||
|
THAW_HIT,
|
||||||
|
MAGNITUDE,
|
||||||
|
BATON_PASS,
|
||||||
|
PURSUIT,
|
||||||
|
RAPID_SPIN,
|
||||||
|
SONICBOOM,
|
||||||
|
UNUSED_83,
|
||||||
|
MORNING_SUN,
|
||||||
|
SYNTHESIS,
|
||||||
|
MOONLIGHT,
|
||||||
|
HIDDEN_POWER,
|
||||||
|
RAIN_DANCE,
|
||||||
|
SUNNY_DAY,
|
||||||
|
DEFENSE_UP_HIT,
|
||||||
|
ATTACK_UP_HIT,
|
||||||
|
ALL_STATS_UP_HIT,
|
||||||
|
UNUSED_8D,
|
||||||
|
BELLY_DRUM,
|
||||||
|
PSYCH_UP,
|
||||||
|
MIRROR_COAT,
|
||||||
|
SKULL_BASH,
|
||||||
|
TWISTER,
|
||||||
|
EARTHQUAKE,
|
||||||
|
FUTURE_SIGHT,
|
||||||
|
GUST,
|
||||||
|
FLINCH_MINIMIZE_HIT,
|
||||||
|
SOLAR_BEAM,
|
||||||
|
THUNDER,
|
||||||
|
TELEPORT,
|
||||||
|
BEAT_UP,
|
||||||
|
SEMI_INVULNERABLE,
|
||||||
|
DEFENSE_CURL,
|
||||||
|
SOFTBOILED,
|
||||||
|
FAKE_OUT,
|
||||||
|
UPROAR,
|
||||||
|
STOCKPILE,
|
||||||
|
SPIT_UP,
|
||||||
|
SWALLOW,
|
||||||
|
UNUSED_A3,
|
||||||
|
HAIL,
|
||||||
|
TORMENT,
|
||||||
|
FLATTER,
|
||||||
|
WILL_O_WISP,
|
||||||
|
MEMENTO,
|
||||||
|
FACADE,
|
||||||
|
FOCUS_PUNCH,
|
||||||
|
SMELLINGSALT,
|
||||||
|
FOLLOW_ME,
|
||||||
|
NATURE_POWER,
|
||||||
|
CHARGE,
|
||||||
|
TAUNT,
|
||||||
|
HELPING_HAND,
|
||||||
|
TRICK,
|
||||||
|
ROLE_PLAY,
|
||||||
|
WISH,
|
||||||
|
ASSIST,
|
||||||
|
INGRAIN,
|
||||||
|
SUPERPOWER,
|
||||||
|
MAGIC_COAT,
|
||||||
|
RECYCLE,
|
||||||
|
REVENGE,
|
||||||
|
BRICK_BREAK,
|
||||||
|
YAWN,
|
||||||
|
KNOCK_OFF,
|
||||||
|
ENDEAVOR,
|
||||||
|
ERUPTION,
|
||||||
|
SKILL_SWAP,
|
||||||
|
IMPRISON,
|
||||||
|
REFRESH,
|
||||||
|
GRUDGE,
|
||||||
|
SNATCH,
|
||||||
|
LOW_KICK,
|
||||||
|
SECRET_POWER,
|
||||||
|
DOUBLE_EDGE,
|
||||||
|
TEETER_DANCE,
|
||||||
|
BLAZE_KICK,
|
||||||
|
MUD_SPORT,
|
||||||
|
POISON_FANG,
|
||||||
|
WEATHER_BALL,
|
||||||
|
OVERHEAT,
|
||||||
|
TICKLE,
|
||||||
|
COSMIC_POWER,
|
||||||
|
SKY_UPPERCUT,
|
||||||
|
BULK_UP,
|
||||||
|
POISON_TAIL,
|
||||||
|
WATER_SPORT,
|
||||||
|
CALM_MIND,
|
||||||
|
DRAGON_DANCE,
|
||||||
|
CAMOUFLAGE,
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class MoveFlag(val bit: Int) {
|
||||||
|
MAKES_CONTACT(1 shl 0),
|
||||||
|
PROTECT_AFFECTED(1 shl 1),
|
||||||
|
MAGIC_COAT_AFFECTED(1 shl 2),
|
||||||
|
SNATCH_AFFECTED(1 shl 3),
|
||||||
|
MIRROR_MOVE_AFFECTED(1 shl 4),
|
||||||
|
KINGS_ROCK_AFFECTED(1 shl 5),
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class MoveTarget(val mask: Int) {
|
||||||
|
SELECTED(0),
|
||||||
|
DEPENDS(1 shl 0),
|
||||||
|
USER_OR_SELECTED(1 shl 1),
|
||||||
|
RANDOM(1 shl 2),
|
||||||
|
BOTH(1 shl 3),
|
||||||
|
USER(1 shl 4),
|
||||||
|
FOES_AND_ALLY(1 shl 5),
|
||||||
|
OPPONENTS_FIELD(1 shl 6),
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("buildsrc.convention.kotlin-jvm")
|
|
||||||
id("buildsrc.convention.spotless")
|
|
||||||
id("buildsrc.convention.sonarlint")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
api(project(":common"))
|
|
||||||
api(project(":protocols.game"))
|
|
||||||
api(libs.dagger)
|
|
||||||
}
|
|
||||||
|
|
||||||
val generator: SourceSet by sourceSets.creating
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
"generatorImplementation"(libs.jte)
|
|
||||||
"generatorImplementation"(libs.kotlinx.serialization.json)
|
|
||||||
}
|
|
||||||
|
|
||||||
val generatedSrc = layout.buildDirectory.dir("generated/source/maps/kotlin")
|
|
||||||
val templatesDir = layout.projectDirectory.dir("src/generator/jte")
|
|
||||||
val jteCacheDir = layout.buildDirectory.dir("jte-classes")
|
|
||||||
|
|
||||||
// Region name -> source decomp. Only non-NDS (GBA, 2D) decomps that share the pret
|
|
||||||
// map format are listed. The NDS decomps (pokeblack, pokeheartgold, pokeplatinum) use
|
|
||||||
// 3D maps and are not parsed here. Region ids live in the per-region constants.
|
|
||||||
val regionSources =
|
|
||||||
mapOf(
|
|
||||||
"hoenn" to "pokeemerald",
|
|
||||||
"kanto" to "pokefirered",
|
|
||||||
)
|
|
||||||
|
|
||||||
val generatedArg = generatedSrc.get().asFile.absolutePath
|
|
||||||
val templatesArg = templatesDir.asFile.absolutePath
|
|
||||||
val jteCacheArg = jteCacheDir.get().asFile.absolutePath
|
|
||||||
|
|
||||||
val decompDirs = regionSources.values.map { rootProject.layout.projectDirectory.dir("decomp/$it") }
|
|
||||||
val regionArgs =
|
|
||||||
regionSources.map { (region, decomp) ->
|
|
||||||
"$region|${rootProject.layout.projectDirectory.dir("decomp/$decomp").asFile.absolutePath}"
|
|
||||||
}
|
|
||||||
|
|
||||||
val generateMaps by
|
|
||||||
tasks.registering(JavaExec::class) {
|
|
||||||
group = "openmmo"
|
|
||||||
description = "Render the per-map MapDef sources from the GBA decomp data via JTE"
|
|
||||||
dependsOn(tasks.named("${generator.name}Classes"))
|
|
||||||
decompDirs.forEach { inputs.dir(it) }
|
|
||||||
inputs.dir(templatesDir)
|
|
||||||
outputs.dir(generatedSrc)
|
|
||||||
classpath = generator.runtimeClasspath
|
|
||||||
mainClass.set("de.fiereu.openmmo.maps.generator.Main")
|
|
||||||
args = listOf(generatedArg, templatesArg, jteCacheArg) + regionArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
// generated maps aren't committed, regenerated on every build
|
|
||||||
sourceSets.main { kotlin.srcDir(generateMaps) }
|
|
||||||
@@ -17,7 +17,7 @@ dependencies {
|
|||||||
api(project(":network"))
|
api(project(":network"))
|
||||||
api(project(":protocols.game"))
|
api(project(":protocols.game"))
|
||||||
api(project(":common"))
|
api(project(":common"))
|
||||||
api(project(":maps"))
|
api(project(":codegen"))
|
||||||
|
|
||||||
implementation(libs.dagger)
|
implementation(libs.dagger)
|
||||||
ksp(libs.dagger.compiler)
|
ksp(libs.dagger.compiler)
|
||||||
|
|||||||
+1
-1
@@ -20,4 +20,4 @@ include(":protocols.login")
|
|||||||
include(":protocols.game")
|
include(":protocols.game")
|
||||||
include(":server.login")
|
include(":server.login")
|
||||||
include(":server.game")
|
include(":server.game")
|
||||||
include(":maps")
|
include(":codegen")
|
||||||
Reference in new issue
Block a user