Custom appearances for art gallery spriters

This commit is contained in:
chardub
2025-02-21 12:30:56 -05:00
parent 0f416eecaf
commit 80eef3b1c4
25 changed files with 406 additions and 15 deletions

View File

@@ -74,7 +74,7 @@ class PokeBattle_Scene
# Opposing trainer(s) sprites
if @battle.trainerBattle?
@battle.opponent.each_with_index do |p, i|
pbCreateTrainerFrontSprite(i, p.trainer_type, @battle.opponent.length, p.sprite_override)
pbCreateTrainerFrontSprite(i, p.trainer_type, @battle.opponent.length, p.sprite_override, p.custom_appearance)
end
end
# Data boxes and Pokémon sprites
@@ -207,7 +207,7 @@ class PokeBattle_Scene
# trainer.oy = trainer.bitmap.height
end
def pbCreateTrainerFrontSprite(idxTrainer, trainerType, numTrainers = 1, sprite_override = nil)
def pbCreateTrainerFrontSprite(idxTrainer, trainerType, numTrainers = 1, sprite_override = nil, custom_appearance=nil)
trainerFile = GameData::TrainerType.front_sprite_filename(trainerType)
trainerFile = sprite_override if sprite_override
@@ -215,7 +215,7 @@ class PokeBattle_Scene
trainer = pbAddSprite("trainer_#{idxTrainer + 1}", spriteX, spriteY, trainerFile, @viewport)
spriteOverrideBitmap = setTrainerSpriteOverrides(trainerType)
trainer.bitmap = spriteOverrideBitmap if spriteOverrideBitmap
trainer.bitmap = generate_front_trainer_sprite_bitmap_from_appearance(custom_appearance).bitmap if custom_appearance
return if !trainer.bitmap
# Alter position of sprite
trainer.z = 7 + idxTrainer

View File

@@ -567,7 +567,7 @@ end
#party: array of pokemon team
# [[:SPECIES,level], ... ]
#
def customTrainerBattle(trainerName, trainerType, party_array, default_level=50, endSpeech="", sprite_override=nil)
def customTrainerBattle(trainerName, trainerType, party_array, default_level=50, endSpeech="", sprite_override=nil,custom_appearance=nil)
# trainerID= "customTrainer"
@@ -582,7 +582,7 @@ def customTrainerBattle(trainerName, trainerType, party_array, default_level=50,
# trainer_info_hash[:pokemon] = party
#trainer = GameData::Trainer.new(trainer_info_hash)
trainer = NPCTrainer.new(trainerName,trainerType,sprite_override)
trainer = NPCTrainer.new(trainerName,trainerType,sprite_override,custom_appearance)
trainer.lose_text=endSpeech
party = []
party_array.each { |pokemon|

View File

@@ -9,6 +9,7 @@ class Trainer
attr_accessor :party
attr_accessor :quests
attr_accessor :sprite_override
attr_accessor :custom_appearance
attr_accessor :lowest_difficulty
attr_accessor :selected_difficulty
attr_accessor :game_mode
@@ -212,13 +213,14 @@ class Trainer
#=============================================================================
def initialize(name, trainer_type, sprite_override=nil)
def initialize(name, trainer_type, sprite_override=nil, custom_appearance=nil)
@trainer_type = GameData::TrainerType.get(trainer_type).id
@name = name
@id = rand(2 ** 16) | rand(2 ** 16) << 16
@language = pbGetLanguage
@party = []
@sprite_override = sprite_override
@custom_appearance = custom_appearance
@lowest_difficulty=2 #On hard by default, lowered whenever the player selects another difficulty
@selected_difficulty=2 #On hard by default, lowered whenever the player selects another difficulty
@game_mode =0 #classic
@@ -232,7 +234,7 @@ class NPCTrainer < Trainer
attr_accessor :items
attr_accessor :lose_text
def initialize(name, trainer_type, sprite_override=nil)
def initialize(name, trainer_type, sprite_override=nil,custom_appearance=nil)
super
@items = []
@lose_text = nil

View File

@@ -230,9 +230,17 @@ def generateNPCClothedBitmapStatic(trainerAppearance,action = "walk")
hair_color_shift = trainerAppearance.hair_color || 0
hairBitmap = AnimatedBitmap.new(hairFilename, hair_color_shift).bitmap if pbResolveBitmap(hairFilename)
baseBitmap.blt(0, 0, hairBitmap, hairBitmap.rect)
#Hat
hat_color_shift = trainerAppearance.hat_color || 0
hat2_color_shift = trainerAppearance.hat2_color || 0
hatFilename = getOverworldHatFilename(trainerAppearance.hat)
hat2Filename = getOverworldHatFilename(trainerAppearance.hat2)
hatBitmapWrapper = AnimatedBitmap.new(hatFilename, hat_color_shift) if pbResolveBitmap(hatFilename)
hat2BitmapWrapper = AnimatedBitmap.new(hat2Filename, hat2_color_shift) if pbResolveBitmap(hat2Filename)
if hatBitmapWrapper
frame_count = 4 # Assuming 4 frames for hair animation; adjust as needed
hat_frame_bitmap = duplicateHatForFrames(hatBitmapWrapper.bitmap, frame_count)
@@ -247,6 +255,22 @@ def generateNPCClothedBitmapStatic(trainerAppearance,action = "walk")
positionHat(baseBitmap, hat_frame_bitmap, frame_offset, i, frame_width)
end
end
if hat2BitmapWrapper
frame_count = 4 # Assuming 4 frames for hair animation; adjust as needed
hat2_frame_bitmap = duplicateHatForFrames(hat2BitmapWrapper.bitmap, frame_count)
frame_width = baseSprite.bitmap.width / frame_count # Calculate frame width
frame_count.times do |i|
# Calculate offset for each frame
frame_offset = [i * frame_width, 0]
# Adjust Y offset if frame index is odd
frame_offset[1] -= 2 if i.odd?
positionHat(baseBitmap, hat2_frame_bitmap, frame_offset, i, frame_width)
end
end
return baseBitmap
end

View File

@@ -53,12 +53,12 @@ class HatsMartAdapter < OutfitsMartAdapter
def updateTrainerPreview(item, previewWindow)
if item.is_a?(Outfit)
previewWindow.hat = item.id
previewWindow.set_hat(item.id,@is_secondary_hat)
$Trainer.set_hat(item.id,@is_secondary_hat)# unless $Trainer.hat==nil
set_dye_color(item,previewWindow)
else
$Trainer.set_hat(nil,@is_secondary_hat)
previewWindow.hat= nil
previewWindow.set_hat(nil,@is_secondary_hat)
end

View File

@@ -312,6 +312,71 @@ def randomizePlayerOutfitUnlocked()
end
def convert_letter_to_number(letter, max_number = nil)
return letter.ord if !max_number
return letter.ord % max_number
end
def generate_appearance_from_name(name)
name_seed_length = 15
seed = name[0, name_seed_length] # Truncate if longer than 8
seed += seed[0, name_seed_length - seed.length] while seed.length < name_seed_length # Repeat first characters if shorter
echoln seed
hats_list = $PokemonGlobal.hats_data.keys
clothes_list = $PokemonGlobal.clothes_data.keys
hairstyles_list = $PokemonGlobal.hairstyles_data.keys
hat = hats_list[convert_letter_to_number(seed[0],hats_list.length)]
hat2 = hats_list[convert_letter_to_number(seed[1],hats_list.length)]
hat2 = nil if convert_letter_to_number(seed[2]) % 3 == 0 #1/3 chance of no 2nd hat
hat_color = convert_letter_to_number(seed[3],255)
hat_color = 0 if convert_letter_to_number(seed[4]) % 2 == 0 #1/2 chance of no dyed hat
hat2_color = convert_letter_to_number(seed[5],255)
hat2_color = 0 if convert_letter_to_number(seed[6]) % 2 == 0
clothes = clothes_list[convert_letter_to_number(seed[7],clothes_list.length)]
clothes_color = convert_letter_to_number(seed[8],255)
clothes_color = 0 if convert_letter_to_number(seed[9]) % 2 == 0 #1/2 chance of no dyed clothes
hair_base = hairstyles_list[convert_letter_to_number(seed[10],hairstyles_list.length)]
hair_number = [1,2,3,4][convert_letter_to_number(seed[11],3)]
hair=getFullHairId(hair_base,hair_number)
hair_color = convert_letter_to_number(seed[12],255)
hair_color = 0 if convert_letter_to_number(seed[13]) % 2 == 0 #1/2 chance of no dyed hair
skin_tone = [1,2,3,4,5,6][convert_letter_to_number(seed[14],5)]
echoln clothes
return TrainerAppearance.new(skin_tone,hat,clothes, hair,
hair_color, clothes_color, hat_color,hat2,hat2_color)
end
def get_random_appearance()
hat = $PokemonGlobal.hats_data.keys.sample
hat2 = $PokemonGlobal.hats_data.keys.sample
hat2 = nil if(rand(3)==0)
clothes = $PokemonGlobal.clothes_data.keys.sample
hat_color = rand(2)==0 ? rand(255) : 0
hat2_color = rand(2)==0 ? rand(255) : 0
clothes_color = rand(2)==0 ? rand(255) : 0
hair_color = rand(2)==0 ? rand(255) : 0
hair_id = $PokemonGlobal.hairstyles_data.keys.sample
hair_color = [1,2,3,4].sample
skin_tone = [1,2,3,4,5,6].sample
hair = getFullHairId(hair_id,hair_color)
return TrainerAppearance.new(skin_tone,hat,clothes, hair,
hair_color, clothes_color, hat_color,hat2)
end
def randomizePlayerOutfit()
$Trainer.hat = $PokemonGlobal.hats_data.keys.sample
$Trainer.hat2 = $PokemonGlobal.hats_data.keys.sample

View File

@@ -1,21 +1,26 @@
class TrainerAppearance
attr_accessor :skin_color
attr_accessor :hat
attr_accessor :hat2
attr_accessor :clothes
attr_accessor :hair
attr_accessor :hair_color
attr_accessor :clothes_color
attr_accessor :hat_color
attr_accessor :hat2_color
def initialize(skin_color, hat, clothes, hair, hair_color = 0, clothes_color = 0, hat_color = 0)
def initialize(skin_color, hat, clothes, hair, hair_color = 0, clothes_color = 0, hat_color = 0, hat2=nil, hat2_color=0)
@skin_color = skin_color
@hat = hat
@hat2 = hat2
@clothes = clothes
@hair = hair
@hair_color = hair_color
@clothes_color = clothes_color
@hat_color = hat_color
@hat2_color = hat2_color
end
end

View File

@@ -151,12 +151,16 @@ def generateCurrentGalleryBattle(level = nil, number_of_pokemon = 3)
selected_battlers_idx.each { |species| 00
party << Pokemon.new(species, level)
}
custom_appearance = generate_appearance_from_name(spriter_name)
customTrainerBattle(spriter_name,
:PAINTER,
party,
level,
pick_spriter_losing_dialog(spriter_name),
pick_trainer_sprite(spriter_name)
pick_trainer_sprite(spriter_name),
custom_appearance
)
end