mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-20 04:31:09 +02:00
Support custom trainer palettes and base portraits
This commit is contained in:
@@ -188,6 +188,27 @@ local function namedPalette(data, name)
|
|||||||
return { name = key, colors = colors }
|
return { name = key, colors = colors }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Custom trainer portraits can opt into the same Advanced OBJ palette source
|
||||||
|
-- as their overworld walker. Vanilla trainers preserve the hardware-faithful
|
||||||
|
-- MEWMON fallback used during the battle introduction.
|
||||||
|
function BattleState.trainerPalette(data, trainer)
|
||||||
|
local source = trainer and trainer.paletteSource
|
||||||
|
if source then
|
||||||
|
local PaletteFX = require("src.render.PaletteFX")
|
||||||
|
local colors, group = PaletteFX.spriteObp({ paletteSource = source }, trainer.id)
|
||||||
|
if colors then
|
||||||
|
return { name = "trainer:" .. source .. ":" .. tostring(group), colors = colors }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return namedPalette(data, "MEWMON")
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleState.trainerPicPath(data, trainer)
|
||||||
|
if trainer and trainer.pic then return trainer.pic end
|
||||||
|
local base = trainer and trainer.basePic and data.trainers[trainer.basePic]
|
||||||
|
return base and base.pic or nil
|
||||||
|
end
|
||||||
|
|
||||||
-- The battle-BGP fade variant of a pic (AnimationFlashScreen and the
|
-- The battle-BGP fade variant of a pic (AnimationFlashScreen and the
|
||||||
-- SetAnimationBGPalette effects remap the four BG shades; on the SGB
|
-- SetAnimationBGPalette effects remap the four BG shades; on the SGB
|
||||||
-- the colorizer then colors the REMAPPED shade, so a faded pic shows
|
-- the colorizer then colors the REMAPPED shade, so a faded pic shows
|
||||||
@@ -608,7 +629,8 @@ function BattleState.newTrainer(game, oppClass, partyIndex)
|
|||||||
-- MonsterPalettes[0] = PAL_MEWMON -- InitBattleCommon zeroes
|
-- MonsterPalettes[0] = PAL_MEWMON -- InitBattleCommon zeroes
|
||||||
-- wEnemyMonSpecies2 before the intro's SET_PAL_BATTLE
|
-- wEnemyMonSpecies2 before the intro's SET_PAL_BATTLE
|
||||||
-- (engine/battle/core.asm:6682, engine/gfx/palettes.asm SetPal_Battle)
|
-- (engine/battle/core.asm:6682, engine/gfx/palettes.asm SetPal_Battle)
|
||||||
self.trainerPic = getImage(self.trainer.pic, namedPalette(game.data, "MEWMON"))
|
self.trainerPic = getImage(BattleState.trainerPicPath(game.data, self.trainer),
|
||||||
|
BattleState.trainerPalette(game.data, self.trainer))
|
||||||
self.introText = Strings("%s wants\nto fight!", self.trainer.name)
|
self.introText = Strings("%s wants\nto fight!", self.trainer.name)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -561,6 +561,11 @@ R.trainers = {
|
|||||||
index = f.opt(f.int(0, 255)),
|
index = f.opt(f.int(0, 255)),
|
||||||
-- unused vanilla classes ship without a pic, so it cannot be required
|
-- unused vanilla classes ship without a pic, so it cannot be required
|
||||||
pic = f.opt(f.path),
|
pic = f.opt(f.path),
|
||||||
|
-- Optional Advanced-mode OBJ palette source for a custom trainer portrait.
|
||||||
|
-- It follows the same ROM crosswalk form as sprites.paletteSource.
|
||||||
|
paletteSource = f.opt(f.str),
|
||||||
|
-- Reuse a base trainer class's portrait without redistributing its asset.
|
||||||
|
basePic = f.opt(f.id("trainers")),
|
||||||
baseMoney = f.opt(f.int(0)),
|
baseMoney = f.opt(f.int(0)),
|
||||||
parties = f.list(f.list(f.rec{ level = f.int(1),
|
parties = f.list(f.list(f.rec{ level = f.int(1),
|
||||||
species = f.id("pokemon") })),
|
species = f.id("pokemon") })),
|
||||||
@@ -580,6 +585,10 @@ R.sprites = {
|
|||||||
frames = f.int(1),
|
frames = f.int(1),
|
||||||
walker = f.opt(f.bool),
|
walker = f.opt(f.bool),
|
||||||
trueColor = f.opt(f.bool),
|
trueColor = f.opt(f.bool),
|
||||||
|
-- Mod art can opt into an existing ROM sprite's Advanced-mode OBJ
|
||||||
|
-- palette assignment without claiming that the image itself came from
|
||||||
|
-- the ROM (which is what `source` documents on imported records).
|
||||||
|
paletteSource = f.opt(f.str),
|
||||||
},
|
},
|
||||||
example = 'mod.content.sprites:register("SPRITE_HERO", { image = "...", frames = 6 })',
|
example = 'mod.content.sprites:register("SPRITE_HERO", { image = "...", frames = 6 })',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -537,7 +537,7 @@ end
|
|||||||
function PaletteFX.spriteObp(spriteDef, seed)
|
function PaletteFX.spriteObp(spriteDef, seed)
|
||||||
local pack = PaletteFX.gbcPack()
|
local pack = PaletteFX.gbcPack()
|
||||||
local w = pack and pack.world
|
local w = pack and pack.world
|
||||||
local src = spriteDef and spriteDef.source
|
local src = spriteDef and (spriteDef.paletteSource or spriteDef.source)
|
||||||
if not (w and src) then return nil end
|
if not (w and src) then return nil end
|
||||||
local idx = tonumber(src:match("%[(%d+)%]"))
|
local idx = tonumber(src:match("%[(%d+)%]"))
|
||||||
-- RedBikeSprite loads outside SpriteSheetPointerTable
|
-- RedBikeSprite loads outside SpriteSheetPointerTable
|
||||||
|
|||||||
Reference in New Issue
Block a user