feat(game): run a map's on-transition script when a player enters it

This commit is contained in:
Fiereu committed 2026-07-26 14:36:07 +02:00
1 parent 023f4eb305
commit c06aff99d3
12 files changed
+176 -32

No files matched your search

@@ -45,4 +45,5 @@ internal val ${objectName}: MapDef =
warps = ${RenderUtil.INSTANCE.warps(map.getWarps())},
npcs = ${RenderUtil.INSTANCE.npcs(map.getVisibleNpcs())},
bgEvents = ${RenderUtil.INSTANCE.bgEvents(map.getBgEvents())},
onTransitionScript = "${map.getOnTransitionScript()}",
)
@@ -26,6 +26,8 @@ data class ParsedMap(
val warps: List<ParsedWarp>,
val visibleNpcs: List<ParsedNpc>,
val bgEvents: List<ParsedBgEvent>,
// Decomp label of the map's ON_TRANSITION script, or "" when the map has none.
val onTransitionScript: String,
)
data class ParsedConnection(
@@ -192,9 +192,20 @@ class PretGbaParser(
warps = parseWarps(mapJson, ctx),
visibleNpcs = parseNpcs(mapJson, mapDirName, ctx),
bgEvents = parseBgEvents(mapJson),
onTransitionScript = parseOnTransitionScript(mapDirName),
)
}
// The map's ON_TRANSITION script runs whenever the player enters the map. It sits in the map's
// scripts.inc _MapScripts table as a direct label, unlike the ON_FRAME/ON_WARP conditional
// tables.
private fun parseOnTransitionScript(mapDirName: String): String {
val file = File(rootDir, "data/maps/$mapDirName/scripts.inc")
if (!file.exists()) return ""
val re = Regex("""map_script\s+MAP_SCRIPT_ON_TRANSITION\s*,\s*(\w+)""")
return re.find(file.readText())?.groupValues?.get(1) ?: ""
}
private fun parseConnections(mapJson: JsonObject, ctx: Context): List<ParsedConnection> =
mapJson["connections"]?.jsonArrayOrNull()?.mapNotNull { conn ->
val obj = conn.jsonObject
@@ -32,6 +32,8 @@ class MapDef(
val warps: List<WarpTile> = emptyList(),
val npcs: List<NpcDef> = emptyList(),
val bgEvents: List<BgEventDef> = emptyList(),
/** Decomp label of the script that runs when a player enters this map, or "" if none. */
val onTransitionScript: String = "",
private val blockData: String = "",
private val behaviorData: String = "",
) {