mirror of
https://github.com/AverageConsumer/kanto-gear.git
synced 2026-08-28 18:24:42 +02:00
fix(gen2): mirror level-up and clear battle exit
This commit is contained in:
+58
-14
@@ -670,7 +670,6 @@ assert(mirroredBattleMenu({ screenId = "Gen2PackMenu" })
|
||||
and mirroredBattleMenu({ screenId = "Gen2PartyMenu" })
|
||||
and not mirroredBattleMenu({ screenId = "Gen2PackMenu", message = {} }),
|
||||
"safe Gen 2 battle menu mirroring")
|
||||
|
||||
assert(not choiceReady(0.31, 0.32) and choiceReady(0.32, 0.32),
|
||||
"choice quiet gate")
|
||||
assert(caughtWild("wild", true) and caughtWild("safari", true)
|
||||
@@ -1202,6 +1201,32 @@ return function(mod)
|
||||
itemPc = { PlayerPC = true, Gen2ItemPcMenu = true },
|
||||
trainerCard = { TrainerCard = true, Gen2TrainerCard = true },
|
||||
} }
|
||||
|
||||
function compat.levelUpMon(state)
|
||||
if state and state.mon and state.mon.stats and not state.screenId then
|
||||
return state.mon
|
||||
end
|
||||
if state and state.screenId == "Gen2BattleState"
|
||||
and state.phase == "stats-box" then
|
||||
local mon = state.statsBoxMon
|
||||
return mon and mon.stats and mon or nil
|
||||
end
|
||||
end
|
||||
|
||||
function compat.isBattleScreen(state)
|
||||
return state and (state.isBattleState
|
||||
or state.screenId == "Gen2BattleState") or false
|
||||
end
|
||||
|
||||
do
|
||||
local mon = { stats = {} }
|
||||
assert(compat.levelUpMon({ screenId = "Gen2BattleState",
|
||||
phase = "stats-box", statsBoxMon = mon }) == mon
|
||||
and not compat.levelUpMon({ screenId = "Gen2BattleState",
|
||||
phase = "menu", statsBoxMon = mon })
|
||||
and compat.isBattleScreen({ screenId = "Gen2BattleState" }),
|
||||
"shared level-up and battle-screen detection")
|
||||
end
|
||||
compat.summary = assert(load(mod:read("summary.lua"),
|
||||
"@kanto_gear/summary.lua"))()
|
||||
|
||||
@@ -1873,8 +1898,7 @@ return function(mod)
|
||||
local function battleState()
|
||||
local states = game and game.stack and game.stack.states or {}
|
||||
for i = #states, 1, -1 do
|
||||
if states[i].isBattleState
|
||||
or states[i].screenId == "Gen2BattleState" then return states[i] end
|
||||
if compat.isBattleScreen(states[i]) then return states[i] end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2053,21 +2077,30 @@ return function(mod)
|
||||
end
|
||||
end
|
||||
|
||||
local function drawLevelUpStats(state)
|
||||
local mon, stats = state.mon, state.mon.stats
|
||||
local function drawLevelUpStats(mon)
|
||||
local stats = mon.stats
|
||||
local def = game.data.pokemon[mon.species] or {}
|
||||
header("LEVEL UP")
|
||||
centered(fit(THEME:format("%s L%d",
|
||||
mon.nickname or def.name or mon.species or "POKEMON",
|
||||
mon.level or 0), 24), 27, DARK)
|
||||
local rows = { { "ATTACK", stats.attack },
|
||||
{ "DEFENSE", stats.defense }, { "SPEED", stats.speed },
|
||||
{ "SPECIAL", stats.special } }
|
||||
local splitSpecial = stats.specialAttack ~= nil
|
||||
or stats.specialDefense ~= nil
|
||||
local rows = splitSpecial and {
|
||||
{ "ATTACK", stats.attack }, { "DEFENSE", stats.defense },
|
||||
{ "SPCL.ATK", stats.specialAttack },
|
||||
{ "SPCL.DEF", stats.specialDefense }, { "SPEED", stats.speed },
|
||||
} or {
|
||||
{ "ATTACK", stats.attack }, { "DEFENSE", stats.defense },
|
||||
{ "SPEED", stats.speed }, { "SPECIAL", stats.special },
|
||||
}
|
||||
local firstY, step = splitSpecial and 39 or 44, splitSpecial and 13 or 15
|
||||
for i, row in ipairs(rows) do
|
||||
text(row[1], 24, 44 + (i - 1) * 15, INK)
|
||||
text(tostring(row[2] or 0), 119, 44 + (i - 1) * 15, DARK)
|
||||
local y = firstY + (i - 1) * step
|
||||
text(row[1], 24, y, INK)
|
||||
text(tostring(row[2] or 0), 119, y, DARK)
|
||||
end
|
||||
button(24, 108, 112, 27, "CONTINUE", false)
|
||||
button(24, splitSpecial and 111 or 108, 112, 27, "CONTINUE", false)
|
||||
end
|
||||
|
||||
local function drawMapFallback()
|
||||
@@ -3413,7 +3446,7 @@ return function(mod)
|
||||
local choice, labels, choiceField = dialogueChoice()
|
||||
local naming = not compat.isGen2()
|
||||
and compat.isScreen(top, "naming") and top
|
||||
local levelStats = battle and levelUpStatBox(top) and top
|
||||
local levelStats = battle and compat.levelUpMon(top)
|
||||
if learn then
|
||||
drawLearnMove(learn, top)
|
||||
elseif naming then
|
||||
@@ -4102,8 +4135,11 @@ return function(mod)
|
||||
return
|
||||
end
|
||||
local battleTop = game and game.stack and game.stack:top()
|
||||
if battle and levelUpStatBox(battleTop) then
|
||||
if inside(x, y, 24, 108, 112, 27) then press("a") end
|
||||
local levelMon = battle and compat.levelUpMon(battleTop)
|
||||
if levelMon then
|
||||
local buttonY = levelMon.stats and (levelMon.stats.specialAttack ~= nil
|
||||
or levelMon.stats.specialDefense ~= nil) and 111 or 108
|
||||
if inside(x, y, 24, buttonY, 112, 27) then press("a") end
|
||||
return
|
||||
end
|
||||
local choice, labels, field = dialogueChoice()
|
||||
@@ -4667,6 +4703,14 @@ return function(mod)
|
||||
end
|
||||
end)
|
||||
|
||||
mod.events:on("screen.popped", function(payload)
|
||||
if compat.isBattleScreen(payload and payload.state) then
|
||||
battle = nil
|
||||
moveInfo = nil
|
||||
dirty = true
|
||||
end
|
||||
end)
|
||||
|
||||
for _, event in ipairs({
|
||||
"battle.started", "battle.turn_started", "battle.move_used",
|
||||
"battle.damage_dealt", "battle.status_inflicted",
|
||||
|
||||
@@ -199,6 +199,51 @@ T.check(sawChasedHp,
|
||||
run.loader.game = nil
|
||||
screen.phase, screen.message, screen.hpAnim = "menu", nil, nil
|
||||
|
||||
screen.statsBoxMon = game.save.party[1]
|
||||
screen.statsBoxMon.stats = { hp = 22, attack = 12, defense = 11,
|
||||
specialAttack = 13, specialDefense = 14, speed = 15 }
|
||||
screen.phase = "stats-box"
|
||||
rectangles = {}
|
||||
now = 2
|
||||
run.loader.hooks:call("render.compose", function() return false end, {}, {
|
||||
secondScreen = companion,
|
||||
})
|
||||
local sawLevelContinue = false
|
||||
for _, call in ipairs(rectangles) do
|
||||
local _, x, y, w, h = unpack(call)
|
||||
if x == 24 and y == 111 and w == 112 and h == 27 then
|
||||
sawLevelContinue = true
|
||||
end
|
||||
end
|
||||
T.check(sawLevelContinue,
|
||||
"Gold level-up stats render on the companion screen")
|
||||
T.eq(run.loader.hooks:call("screen.render_visible",
|
||||
function() return true end, screen), true,
|
||||
"Gold level-up keeps the native battle scene visible")
|
||||
|
||||
screen.phase, screen.statsBoxMon = "resolving", nil
|
||||
screen.message = "FIXMON_A gained 12 EXP. Points!"
|
||||
now = 3
|
||||
run.loader.hooks:call("render.compose", function() return false end, {}, {
|
||||
secondScreen = companion,
|
||||
})
|
||||
game.stack.states = {}
|
||||
run.loader.events:emit("screen.popped", { state = screen })
|
||||
rectangles = {}
|
||||
run.loader.hooks:call("render.compose", function() return false end, {}, {
|
||||
secondScreen = companion,
|
||||
})
|
||||
local staleBattlePanel = false
|
||||
for _, call in ipairs(rectangles) do
|
||||
local _, x, y, w, h = unpack(call)
|
||||
if x == 4 and y == 3 and w == 152 and h == 40 then
|
||||
staleBattlePanel = true
|
||||
end
|
||||
end
|
||||
T.check(not staleBattlePanel,
|
||||
"popping Gold's battle screen clears the cached EXP view immediately")
|
||||
screen.phase, screen.message = "menu", nil
|
||||
|
||||
local pack = {
|
||||
screenId = "Gen2PackMenu", battle = true, pocketIndex = 1, index = 1,
|
||||
rows = { { id = "POTION", name = "POTION", count = 2,
|
||||
|
||||
@@ -94,6 +94,8 @@ return {
|
||||
["DEFENSE"] = "ABWEHR",
|
||||
["SPEED"] = "INITIATIVE",
|
||||
["SPECIAL"] = "SPEZIAL",
|
||||
["SPCL.ATK"] = "SP.ANGR.",
|
||||
["SPCL.DEF"] = "SP.ABW.",
|
||||
["ATK"] = "ANG",
|
||||
["DEF"] = "VERT",
|
||||
["SP.ATK"] = "SP.ANG",
|
||||
|
||||
Reference in New Issue
Block a user