6.6 update

This commit is contained in:
chardub
2025-06-07 08:16:50 -04:00
parent 295a71dbcd
commit a393ba1137
467 changed files with 171196 additions and 36566 deletions

View File

@@ -0,0 +1,222 @@
class DoublePreviewScreen
SELECT_ARROW_X_LEFT= 100
SELECT_ARROW_X_RIGHT= 350
SELECT_ARROW_X_CANCEL= 230
SELECT_ARROW_Y_SELECT= 0
SELECT_ARROW_Y_CANCEL= 210
ARROW_GRAPHICS_PATH = "Graphics/Pictures/selHand"
CANCEL_BUTTON_PATH = "Graphics/Pictures/previewScreen_Cancel"
BACKGROUND_PATH = "Graphics/Pictures/shadeFull_"
CANCEL_BUTTON_X= 140
CANCEL_BUTTON_Y= 260
def initialize(species_left, species_right)
@species_left = species_left
@species_right = species_right
@typewindows = []
@picture1 = nil
@picture2 = nil
@draw_types = nil
@draw_level = nil
@draw_sprite_info = nil
@selected = 0
@last_post=0
@sprites = {}
initializeBackground
initializeSelectArrow
initializeCancelButton
end
def getBackgroundPicture
return BACKGROUND_PATH
end
def getSelection
selected = startSelection
@sprites["cancel"].visible=false
#@sprites["arrow"].visible=false
#todo: il y a un fuck en quelque part.... en attendant ca marche inversé ici
return @species_left if selected == 0
return @species_right if selected == 1
return -1
end
def startSelection
loop do
Graphics.update
Input.update
updateSelection
if Input.trigger?(Input::USE)
return @selected
end
if Input.trigger?(Input::BACK)
return -1
end
end
end
def updateSelection
currentSelected = @selected
updateSelectionIndex
if @selected != currentSelected
updateSelectionGraphics
end
end
def updateSelectionIndex
if Input.trigger?(Input::LEFT)
@selected = 0
elsif Input.trigger?(Input::RIGHT)
@selected = 1
end
if @selected == -1
if Input.trigger?(Input::UP)
@selected = @last_post
end
else
if Input.trigger?(Input::DOWN)
@last_post = @selected
@selected = -1
end
end
end
def updateSelectionGraphics
if @selected == 0
@sprites["arrow"].x = SELECT_ARROW_X_LEFT
@sprites["arrow"].y = SELECT_ARROW_Y_SELECT
elsif @selected == 1
@sprites["arrow"].x = SELECT_ARROW_X_RIGHT
@sprites["arrow"].y = SELECT_ARROW_Y_SELECT
else
@sprites["arrow"].x = SELECT_ARROW_X_CANCEL
@sprites["arrow"].y = SELECT_ARROW_Y_CANCEL
end
pbUpdateSpriteHash(@sprites)
end
def draw_window(dexNumber, level, x, y, isShiny=false, bodyShiny = false, headShiny=false)
body_pokemon = getBodyID(dexNumber)
head_pokemon = getHeadID(dexNumber, body_pokemon)
# picturePath = getPicturePath(head_pokemon, body_pokemon)
# bitmap = AnimatedBitmap.new(picturePath)
spriteLoader = BattleSpriteLoader.new
bitmap = GameData::Species.front_sprite_bitmap(dexNumber)
bitmap.shiftAllColors(dexNumber, bodyShiny, headShiny)
bitmap.scale_bitmap(Settings::FRONTSPRITE_SCALE)
pif_sprite = spriteLoader.obtain_fusion_pif_sprite(head_pokemon,body_pokemon)
#hasCustom = picturePath.include?("CustomBattlers")
#hasCustom = customSpriteExistsBase(body_pokemon,head_pokemon)
hasCustom = customSpriteExists(body_pokemon,head_pokemon)
previewwindow = PictureWindow.new(bitmap)
previewwindow.x = x
previewwindow.y = y
previewwindow.z = 100000
drawFusionInformation(dexNumber, level, x)
if !$Trainer.seen?(dexNumber)
if pif_sprite.local_path()
previewwindow.picture.pbSetColor(170, 200, 250, 200) #blue
elsif hasCustom
previewwindow.picture.pbSetColor(150, 255, 150, 200) #green
else
previewwindow.picture.pbSetColor(255, 255, 255, 200) #white
end
end
return previewwindow
end
def drawFusionInformation(fusedDexNum, level, x = 0)
viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@typewindows << drawPokemonType(fusedDexNum, viewport, x + 55, 220) if @draw_types
drawFusionPreviewText(viewport, "Lv. " + level.to_s, x + 80, 40,) if @draw_level
drawSpriteInfoIcons(getPokemon(fusedDexNum),viewport) if @draw_sprite_info
end
def initializeSelectArrow
@sprites["arrow"] = IconSprite.new(0, 0, @viewport)
@sprites["arrow"].setBitmap(ARROW_GRAPHICS_PATH)
@sprites["arrow"].x = SELECT_ARROW_X_LEFT
@sprites["arrow"].y = SELECT_ARROW_Y_SELECT
@sprites["arrow"].z = 100001
end
def initializeCancelButton()
@sprites["cancel"] = IconSprite.new(0, 0, @viewport)
@sprites["cancel"].setBitmap(CANCEL_BUTTON_PATH)
@sprites["cancel"].x = CANCEL_BUTTON_X
@sprites["cancel"].y = CANCEL_BUTTON_Y
@sprites["cancel"].z = 100000
end
def initializeBackground()
@sprites["background"] = IconSprite.new(0, 0, @viewport)
@sprites["background"].setBitmap(getBackgroundPicture)
@sprites["background"].x = 0
@sprites["background"].y = 0
@sprites["background"].z = 99999
end
def drawFusionPreviewText(viewport, text, x, y)
label_base_color = Color.new(248, 248, 248)
label_shadow_color = Color.new(104, 104, 104)
overlay = BitmapSprite.new(Graphics.width, Graphics.height, viewport).bitmap
textpos = [[text, x, y, 0, label_base_color, label_shadow_color]]
pbDrawTextPositions(overlay, textpos)
end
#todo
# Adds the icons indicating if the fusion has alt sprites and if the final evo has a custom sprite
# also add a second icon to indidcate if the final evolution has a custom
def drawSpriteInfoIcons(fusedPokemon, viewport)
#pokedexUtils = PokedexUtils.new
#hasAltSprites = pokedexUtils.pbGetAvailableAlts(fusedPokemon).size>1
#pokedexUtils.getFinalEvolution(fusedPokemon).real_name
#todo
end
def dispose
@picture1.dispose
@picture2.dispose
for typeWindow in @typewindows
typeWindow.dispose
end
pbDisposeSpriteHash(@sprites)
end
def drawPokemonType(pokemon_id, viewport, x_pos = 192, y_pos = 264)
width = 66
viewport.z = 1000001
overlay = BitmapSprite.new(Graphics.width, Graphics.height, viewport).bitmap
pokemon = GameData::Species.get(pokemon_id)
typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
type1_number = GameData::Type.get(pokemon.type1).id_number
type2_number = GameData::Type.get(pokemon.type2).id_number
type1rect = Rect.new(0, type1_number * 28, 64, 28)
type2rect = Rect.new(0, type2_number * 28, 64, 28)
if pokemon.type1 == pokemon.type2
overlay.blt(x_pos + (width / 2), y_pos, typebitmap.bitmap, type1rect)
else
overlay.blt(x_pos, y_pos, typebitmap.bitmap, type1rect)
overlay.blt(x_pos + width, y_pos, typebitmap.bitmap, type2rect)
end
return viewport
end
end

View File

@@ -0,0 +1,432 @@
module GameData
class FusedSpecies < GameData::Species
attr_reader :growth_rate
attr_reader :body_pokemon
attr_reader :head_pokemon
def initialize(id)
if id.is_a?(Integer)
body_id = getBodyID(id)
head_id = getHeadID(id, body_id)
pokemon_id = getFusedPokemonIdFromDexNum(body_id, head_id)
return GameData::FusedSpecies.new(pokemon_id)
end
id = normalize_id(id)
body_id = get_body_number_from_symbol(id)
head_id = get_head_number_from_symbol(id)
@body_pokemon = GameData::Species.get(body_id)
@head_pokemon = GameData::Species.get(head_id)
@id = id
@id_number = calculate_dex_number()
@species = @id
@form = 0
@real_name = calculate_name()
@real_form_name = nil
@type1 = calculate_type1()
@type2 = calculate_type2()
#Stats
@base_stats = calculate_base_stats()
@evs = calculate_evs()
adjust_stats_with_evs()
@base_exp = calculate_base_exp()
@growth_rate = calculate_growth_rate()
@gender_ratio = calculate_gender() #todo
@catch_rate = calculate_catch_rate()
@happiness = calculate_base_happiness()
#Moves
@moves = calculate_moveset()
@tutor_moves = calculate_tutor_moves() # hash[:tutor_moves] || []
@egg_moves = calculate_egg_moves() # hash[:egg_moves] || []
#Abilities
@abilities = calculate_abilities() # hash[:abilities] || []
@hidden_abilities = calculate_hidden_abilities() # hash[:hidden_abilities] || []
#wild held items
@wild_item_common = get_wild_item(@head_pokemon.wild_item_common, @body_pokemon.wild_item_common) # hash[:wild_item_common]
@wild_item_uncommon = get_wild_item(@head_pokemon.wild_item_uncommon, @body_pokemon.wild_item_uncommon) # hash[:wild_item_uncommon]
@wild_item_rare = get_wild_item(@head_pokemon.wild_item_rare, @body_pokemon.wild_item_rare) # hash[:wild_item_rare]
@evolutions = calculate_evolutions() # hash[:evolutions] || []
#breeding
@egg_groups = [:Undiscovered] #calculate_egg_groups() # hash[:egg_groups] || [:Undiscovered]
@hatch_steps = calculate_hatch_steps() # hash[:hatch_steps] || 1
@incense = nil #hash[:incense]
#pokedex
@pokedex_form = @form #ignored
@real_category = calculate_category()
@real_pokedex_entry = calculate_dex_entry()
@height = average_values(@head_pokemon.height, @body_pokemon.height)
@weight = average_values(@head_pokemon.weight, @body_pokemon.weight)
@color = @head_pokemon.color
@shape = @body_pokemon.shape
#sprite positioning
@back_sprite_x = @body_pokemon.back_sprite_x
@back_sprite_y = @body_pokemon.back_sprite_y
@front_sprite_x = @body_pokemon.front_sprite_x
@front_sprite_y = @body_pokemon.front_sprite_y
@front_sprite_altitude = @body_pokemon.front_sprite_altitude
@shadow_x = @body_pokemon.shadow_x
@shadow_size = @body_pokemon.shadow_size
# #unused attributes from Species class
#
# @shape = :Head
# @habitat = :None
# @generation = 0
# @mega_stone = nil
# @mega_move = nil
# @unmega_form = 0
# @mega_message = 0
end
#Input formats:
# :1_x_2
# :BULBASAUR_x_IVYSAUR
# :B2H1
#
# Output: :B2H1
def normalize_id(id)
if id.to_s.include?("/")
full_id_split = id.to_s.split("/")
# Detect if both sides are numeric
if full_id_split[0] =~ /^\d+$/ && full_id_split[1] =~ /^\d+$/
head_dex = full_id_split[0].to_i
body_dex = full_id_split[1].to_i
else
head_species = full_id_split[0].to_sym
body_species = full_id_split[1].to_sym
head_dex = getDexNumberForSpecies(head_species)
body_dex = getDexNumberForSpecies(body_species)
end
return "B#{body_dex}H#{head_dex}".to_sym
else #Passed internal ID directly, just return it
return id
end
end
def get_body_number_from_symbol(id)
return id.to_s.match(/\d+/)[0].to_i
end
def get_head_number_from_symbol(id)
return id.to_s.match(/(?<=H)\d+/)[0].to_i
end
def get_body_species
return @body_pokemon.id_number
end
def get_head_species
return @head_pokemon.id_number
end
def get_body_species_symbol
return @body_pokemon.id
end
def get_head_species_symbol
return @head_pokemon.id
end
def adjust_stats_with_evs
GameData::Stat.each_main do |s|
@base_stats[s.id] = 1 if !@base_stats[s.id] || @base_stats[s.id] <= 0
@evs[s.id] = 0 if !@evs[s.id] || @evs[s.id] < 0
end
end
#FUSION CALCULATIONS
def calculate_dex_number()
return (@body_pokemon.id_number * NB_POKEMON) + @head_pokemon.id_number
end
def calculate_type1()
return @head_pokemon.type2 if @head_pokemon.type1 == :NORMAL && @head_pokemon.type2 == :FLYING
return @head_pokemon.type1
end
def calculate_type2()
return @body_pokemon.type1 if @body_pokemon.type2 == @type1
return @body_pokemon.type2
end
def calculate_base_stats()
head_stats = @head_pokemon.base_stats
body_stats = @body_pokemon.base_stats
fused_stats = {}
#Head dominant stats
fused_stats[:HP] = calculate_fused_stats(head_stats[:HP], body_stats[:HP])
fused_stats[:SPECIAL_DEFENSE] = calculate_fused_stats(head_stats[:SPECIAL_DEFENSE], body_stats[:SPECIAL_DEFENSE])
fused_stats[:SPECIAL_ATTACK] = calculate_fused_stats(head_stats[:SPECIAL_ATTACK], body_stats[:SPECIAL_ATTACK])
#Body dominant stats
fused_stats[:ATTACK] = calculate_fused_stats(body_stats[:ATTACK], head_stats[:ATTACK])
fused_stats[:DEFENSE] = calculate_fused_stats(body_stats[:DEFENSE], head_stats[:DEFENSE])
fused_stats[:SPEED] = calculate_fused_stats(body_stats[:SPEED], head_stats[:SPEED])
return fused_stats
end
def calculate_base_exp()
head_exp = @head_pokemon.base_exp
body_exp = @body_pokemon.base_exp
return average_values(head_exp, body_exp)
end
def calculate_catch_rate
return get_lowest_value(@body_pokemon.catch_rate, @head_pokemon.catch_rate)
end
def calculate_base_happiness
return @head_pokemon.happiness
end
def calculate_moveset
return combine_arrays(@body_pokemon.moves, @head_pokemon.moves)
end
def calculate_egg_moves
return combine_arrays(@body_pokemon.egg_moves, @head_pokemon.egg_moves)
end
def calculate_tutor_moves
return combine_arrays(@body_pokemon.tutor_moves, @head_pokemon.tutor_moves)
end
def get_wild_item(body_item, head_item)
rand_num = rand(2)
if rand_num == 0
return body_item
else
return head_item
end
end
def calculate_abilities()
abilities_hash = []
ability1 = @body_pokemon.abilities[0]
ability2 = @head_pokemon.abilities[0]
abilities_hash << ability1
abilities_hash << ability2
return abilities_hash
end
# def calculate_abilities(pokemon1, pokemon2)
# abilities_hash = []
#
# ability1 = pokemon1.abilities[0]
# ability2 = pokemon2.abilities[1]
# if !ability2
# ability2 = pokemon2.abilities[0]
# end
# abilities_hash << ability1
# abilities_hash << ability2
# return abilities_hash
# end
def calculate_hidden_abilities()
abilities_hash = []
#First two spots are the other abilities of the two pokemon
ability1 = @body_pokemon.abilities[1]
ability2 = @head_pokemon.abilities[1]
ability1 = @body_pokemon.abilities[0] if !ability1
ability2 = @head_pokemon.abilities[0] if !ability2
abilities_hash << ability1
abilities_hash << ability2
#add the hidden ability for the two base pokemon
hiddenAbility1 = @body_pokemon.hidden_abilities[0]
hiddenAbility1 = ability1 if !hiddenAbility1
hiddenAbility2 = @head_pokemon.hidden_abilities[0]
hiddenAbility2 = ability2 if !hiddenAbility2
abilities_hash << hiddenAbility1
abilities_hash << hiddenAbility2
return abilities_hash
end
def calculate_name()
body_nat_dex = GameData::NAT_DEX_MAPPING[@body_pokemon.id_number] ? GameData::NAT_DEX_MAPPING[@body_pokemon.id_number] : @body_pokemon.id_number
head_nat_dex = GameData::NAT_DEX_MAPPING[@head_pokemon.id_number] ? GameData::NAT_DEX_MAPPING[@head_pokemon.id_number] : @head_pokemon.id_number
begin
prefix = GameData::SPLIT_NAMES[head_nat_dex][0]
suffix = GameData::SPLIT_NAMES[body_nat_dex][1]
if prefix[-1] == suffix[0]
prefix = prefix[0..-2]
end
suffix = suffix.capitalize if prefix.end_with?(" ")
return prefix + suffix
rescue
print("species with error: " + @species.to_s)
end
end
def calculate_evolutions()
body_evolutions = @body_pokemon.evolutions
head_evolutions = @head_pokemon.evolutions
fused_evolutions = []
#body
for evolution in body_evolutions
evolutionSpecies = evolution[0]
evolutionSpecies_dex = GameData::Species.get(evolutionSpecies).id_number
fused_species = _INTL("B{1}H{2}", evolutionSpecies_dex, @head_pokemon.id_number)
fused_evolutions << build_evolution_array(evolution, fused_species)
end
#head
for evolution in head_evolutions
evolutionSpecies = evolution[0]
evolutionSpecies_dex = GameData::Species.get(evolutionSpecies).id_number
fused_species = _INTL("B{1}H{2}", @body_pokemon.id_number, evolutionSpecies_dex)
fused_evolutions << build_evolution_array(evolution, fused_species)
end
return fused_evolutions
end
#Change the evolution species depending if head & body and keep the rest of the data the same
def build_evolution_array(evolution_data, new_species)
fused_evolution_array = []
fused_evolution_array << new_species.to_sym
#add the rest
for data in evolution_data
next if evolution_data.index(data) == 0
fused_evolution_array << data
end
return fused_evolution_array
end
def calculate_dex_entry
body_entry = @body_pokemon.real_pokedex_entry.gsub(@body_pokemon.real_name, @real_name)
head_entry = @head_pokemon.real_pokedex_entry.gsub(@head_pokemon.real_name, @real_name)
return split_and_combine_text(body_entry, head_entry, ".")
end
def get_random_dex_entry()
begin
file_path = Settings::POKEDEX_ENTRIES_PATH
json_data = File.read(file_path)
all_body_entries = HTTPLite::JSON.parse(json_data)
body_entry = all_body_entries[@body_pokemon.id_number.to_s].sample
body_entry = body_entry.gsub(/#{@body_pokemon.real_name}/i, @real_name)
body_entry = clean_json_string(body_entry).gsub(@body_pokemon.real_name, @real_name)
head_entry = all_body_entries[@head_pokemon.id_number.to_s].sample
head_entry = head_entry.gsub(/#{@head_pokemon.real_name}/i, @real_name)
head_entry = clean_json_string(head_entry).gsub(@head_pokemon.real_name, @real_name)
rescue
body_entry = @body_pokemon.real_pokedex_entry.gsub(@body_pokemon.real_name, @real_name)
head_entry = @head_pokemon.real_pokedex_entry.gsub(@head_pokemon.real_name, @real_name)
end
echoln body_entry
echoln head_entry
combined_entry = split_and_combine_text(body_entry, head_entry, ".")
combined_entry += "." unless combined_entry.end_with?(".")
return combined_entry
end
def calculate_egg_groups
body_egg_groups = @body_pokemon.egg_groups
head_egg_groups = @head_pokemon.egg_groups
return :Undiscovered if body_egg_groups.include?(:Undiscovered) || head_egg_groups.include?(:Undiscovered)
return combine_arrays(body_egg_groups, head_egg_groups)
end
def calculate_hatch_steps
return average_values(@head_pokemon.hatch_steps, @body_pokemon.hatch_steps)
end
def calculate_evs()
return average_map_values(@body_pokemon.evs, @head_pokemon.evs)
end
def calculate_category
return split_and_combine_text(@body_pokemon.category, @head_pokemon.category, " ")
end
def calculate_growth_rate
growth_rate_priority = [:Fast, :Medium, :Parabolic, :Fluctuating, :Erratic, :Slow] #todo rearrange order for balance?
body_growth_rate = @body_pokemon.growth_rate
head_growth_rate = @head_pokemon.growth_rate
base_growth_rates = [body_growth_rate, head_growth_rate]
for rate in growth_rate_priority
return rate if base_growth_rates.include?(rate)
end
return :Medium
end
#TODO
# ################## UNFINISHED ####################
def calculate_gender
return :Genderless
end
############################# UTIL METHODS ###############################
#Takes 2 strings, splits and combines them using the beginning of the first one and the end of the second one
# (for example for pokedex entries)
def split_and_combine_text(beginingText_full, endText_full, separator)
beginingText_split = beginingText_full.split(separator, 2)
endText_split = endText_full.split(separator, 2)
beginningText = beginingText_split[0]
endText = endText_split[1] && endText_split[1] != "" ? endText_split[1] : endText_split[0]
return beginningText + separator + " " + endText
end
def calculate_fused_stats(dominantStat, otherStat)
return ((2 * dominantStat) / 3) + (otherStat / 3).floor
end
def average_values(value1, value2)
return ((value1 + value2) / 2).floor
end
def average_map_values(map1, map2)
averaged_map = map1.merge(map2) do |key, value1, value2|
((value1 + value2) / 2.0).floor
end
return averaged_map
end
def get_highest_value(value1, value2)
return value1 > value2 ? value1 : value2
end
def get_lowest_value(value1, value2)
return value1 < value2 ? value1 : value2
end
def combine_arrays(array1, array2)
return array1 + array2
end
end
end

View File

@@ -0,0 +1,38 @@
# class PokemonFusionScene
# HEAD_SPRITE_STARTING_POS = Graphics.width / 2
#
#
# def pbStartScreen(pokemon_head,pokemon_body,pokemon_fused)
#
# @pokemon_head = pokemon_head
# @pokemon_body = pokemon_body
#
# @pokemon_fused = pokemon_fused
#
# @sprites = {}
# @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
# @viewport.z = 99999
#
# initialize_background()
# initialize_sprites()
# end
#
# def initialize_background()
# addBackgroundOrColoredPlane(@sprites, "background", "DNAbg",
# Color.new(248, 248, 248), @viewport)
# end
#
# def initialize_sprites()
# pokeHead_number = GameData::Species.get(@pokemon_head.species).id_number
# pokeBody_number = GameData::Species.get(@pokemon_body.species).id_number
#
# @sprites["poke_head"] = PokemonSprite.new(@viewport)
# @sprites["poke_head"].setPokemonBitmapFromId(pokeHead_number, false, @pokemon_head.shiny?)
#
# @sprites["poke_head"].ox = @sprites["rsprite1"].bitmap.width / 2
# @sprites["poke_head"].x = Graphics.width / 2
# @sprites["poke_head"].zoom_x = Settings::FRONTSPRITE_SCALE
#
# end
#
# end

View File

@@ -0,0 +1,115 @@
class FusionSelectOptionsScene < PokemonOption_Scene
attr_accessor :selectedAbility
attr_accessor :selectedNature
attr_accessor :hasNickname
attr_accessor :nickname
def initialize(abilityList,natureList, pokemon1, pokemon2)
@abilityList = abilityList
@natureList = natureList
@selectedAbility=nil
@selectedNature=nil
@selBaseColor = Color.new(48,96,216)
@selShadowColor = Color.new(32,32,32)
@show_frame=false
@hasNickname = false
@nickname = nil
@pokemon1=pokemon1
@pokemon2=pokemon2
end
def initUIElements
@sprites["title"] = Window_UnformattedTextPokemon.newWithSize(
_INTL("Select your Pokémon's ability and nature"), 0, 0, Graphics.width, 64, @viewport)
@sprites["textbox"] = pbCreateMessageWindow
@sprites["textbox"].letterbyletter = false
pbSetSystemFont(@sprites["textbox"].contents)
@sprites["title"].opacity=0
end
def pbStartScene(inloadscreen = nil)
super
@sprites["option"].opacity=0
end
def getAbilityName(ability)
return GameData::Ability.get(ability.id).real_name
end
def getAbilityDescription(ability)
return GameData::Ability.get(ability.id).real_description
end
def getNatureName(nature)
return GameData::Nature.get(nature.id).real_name
end
def getNatureDescription(nature)
change= GameData::Nature.get(nature.id).stat_changes
return "Neutral nature" if change.empty?
positiveChange = change[0]
negativeChange = change[1]
return _INTL("+ {1}\n- {2}",GameData::Stat.get(positiveChange[0]).name,GameData::Stat.get(negativeChange[0]).name)
end
def shouldSelectNickname
if @pokemon1.nicknamed? && @pokemon2.nicknamed?
@hasNickname=true
return true
end
if @pokemon1.nicknamed? && !@pokemon2.nicknamed?
@hasNickname=true
@nickname = @pokemon1.name
return false
end
if !@pokemon1.nicknamed? && @pokemon2.nicknamed?
@hasNickname=true
@nickname = @pokemon2.name
return false
end
@hasNickname=false
return false
end
def pbGetOptions(inloadscreen = false)
options = []
if shouldSelectNickname
options << EnumOption.new(_INTL("Nickname"), [_INTL(@pokemon1.name), _INTL(@pokemon2.name)],
proc { 0 },
proc { |value|
if value ==0
@nickname = @pokemon1.name
else
@nickname = @pokemon2.name
end
}, "Select the Pokémon's nickname")
end
options << EnumOption.new(_INTL("Ability"), [_INTL(getAbilityName(@abilityList[0])), _INTL(getAbilityName(@abilityList[1]))],
proc { 0 },
proc { |value|
@selectedAbility=@abilityList[value]
}, [getAbilityDescription(@abilityList[0]), getAbilityDescription(@abilityList[1])]
)
options << EnumOption.new(_INTL("Nature"), [_INTL(getNatureName(@natureList[0])), _INTL(getNatureName(@natureList[1]))],
proc { 0 },
proc { |value|
@selectedNature=@natureList[value]
}, [getNatureDescription(@natureList[0]), getNatureDescription(@natureList[1])]
)
return options
end
def isConfirmedOnKeyPress
return true
end
end

View File

@@ -0,0 +1,240 @@
class FusionMovesOptionsScene < PokemonOption_Scene
attr_accessor :move1
attr_accessor :move2
attr_accessor :move3
attr_accessor :move4
def initialize(poke1, poke2)
@poke1 = poke1
@poke2 = poke2
@move1 = @poke1.moves[0]
@move2 = @poke1.moves[1]
@move3 = @poke1.moves[2]
@move4 = @poke1.moves[3]
@index1=0
@index2=0
@index3=0
@index4=0
@selBaseColor = Color.new(48,96,216)
@selShadowColor = Color.new(32,32,32)
end
def initUIElements
@sprites["title"] = Window_UnformattedTextPokemon.newWithSize(
_INTL(""), 0, 0, Graphics.width, 64, @viewport)
@sprites["textbox"] = pbCreateMessageWindow
@sprites["textbox"].letterbyletter = false
pbSetSystemFont(@sprites["textbox"].contents)
end
def pbStartScene(inloadscreen = false)
super
@typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
@sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
@sprites["overlay"].z = 9999
pbSetSystemFont(@sprites["overlay"].bitmap)
@sprites["option"].nameBaseColor = MessageConfig::BLUE_TEXT_MAIN_COLOR
@sprites["option"].nameShadowColor = MessageConfig::BLUE_TEXT_SHADOW_COLOR
@changedColor = true
for i in 0...@PokemonOptions.length
@sprites["option"][i] = (@PokemonOptions[i].get || 0)
end
@sprites["title"] = Window_UnformattedTextPokemon.newWithSize(
_INTL("Select moves"), 0, 0, Graphics.width, 64, @viewport)
@sprites["title"].setSkin("Graphics/Windowskins/invisible")
@sprites["option"].setSkin("Graphics/Windowskins/invisible")
@sprites["textbox"].setSkin("Graphics/Windowskins/invisible")
# @sprites["textbox"].text = _INTL("Select moves")
updateDescription(0)
pbFadeInAndShow(@sprites) { pbUpdate }
end
def draw_empty_move_info
# code here
end
def draw_move_info(pokemonMove)
move = GameData::Move.get(pokemonMove.id)
move_base_color = Color.new(50, 40, 230)
move_base_shadow = Color.new(14, 14, 114)
label_base_color = Color.new(248, 248, 248)
label_shadow_color = Color.new(104, 104, 104)
value_base_color = Color.new(248, 248, 248)
value_shadow_color = Color.new(104, 104, 104)
@sprites["title"].text = _INTL("{1}", move.real_name)
damage = move.base_damage == 0 ? "-" : move.base_damage.to_s
accuracy = move.accuracy == 0 ? "100" : move.accuracy.to_s
pp = move.total_pp.to_s
if !move
damage="-"
accuracy="-"
pp="-"
end
textpos = [
[_INTL("Type"), 20, 84, 0, label_base_color, label_shadow_color],
[_INTL("Category"), 20, 116, 0, label_base_color, label_shadow_color],
[_INTL("Power"), 20, 148, 0, label_base_color, label_shadow_color],
[_INTL("{1}", damage), 140, 148, 0, value_base_color, value_shadow_color],
[_INTL("Accuracy"), 20, 180, 0, label_base_color, label_shadow_color],
[_INTL("{1}%", accuracy), 140, 180, 0, value_base_color, value_shadow_color],
[_INTL("PP"), 20, 212, 0, label_base_color, label_shadow_color], #move.total_pp
[_INTL("{1}", pp), 140, 212, 0, value_base_color, value_shadow_color] #move.total_pp
]
imagepos = []
yPos = 90
type_number = GameData::Type.get(move.type).id_number
category = move.category
imagepos.push(["Graphics/Pictures/types", 120, 94, 0, type_number * 28, 64, 28]) #248
imagepos.push(["Graphics/Pictures/category", 120, 124, 0, category * 28, 64, 28])
if !move
imagepos=[]
end
@sprites["overlay"].bitmap.clear
pbDrawTextPositions(@sprites["overlay"].bitmap, textpos)
pbDrawImagePositions(@sprites["overlay"].bitmap, imagepos)
end
def draw_pokemon_type
type1_number = GameData::Type.get(@poke1.type1).id_number
type2_number = GameData::Type.get(@poke1.type2).id_number
type1rect = Rect.new(0, type1_number * 28, 64, 28)
type2rect = Rect.new(0, type2_number * 28, 64, 28)
if @poke1.type1 == @poke1.type2
overlay.blt(130, 78, @typebitmap.bitmap, type1rect)
else
overlay.blt(96, 78, @typebitmap.bitmap, type1rect)
overlay.blt(166, 78, @typebitmap.bitmap, type2rect)
end
end
def updateDescription(index)
index = 0 if !index
begin
move = getMoveForIndex(index)
draw_move_info(move)
new_description = getMoveDescription(move)
@sprites["textbox"].text = _INTL(new_description)
rescue
@sprites["textbox"].text = getDefaultDescription
end
end
def getDefaultDescription
return _INTL("No move selected")
end
def getMoveForIndex(index)
case index
when 0
return @move1
when 1
return @move2
when 2
return @move3
when 3
return @move4
end
return nil
end
def pbFadeInAndShow(sprites, visiblesprites = nil)
return if !@changedColor
super
end
def getMoveName(move)
return " - " if !@sprites["option"] && !move
move = @poke1.moves[@sprites["option"].index] if !move
return GameData::Move.get(move.id).real_name
end
def getMoveDescription(move)
return " - " if !@sprites["option"] && !move
move = @poke1.moves[@sprites["option"].index] if !move
return GameData::Move.get(move.id).real_description
end
def pbGetOptions(inloadscreen = false)
options = [
EnumOption.new(_INTL(""), [_INTL(getMoveName(@poke1.moves[0])), _INTL(getMoveName(@poke2.moves[0]))],
proc { 0 },
proc { |value|
@move1 = value == 0 ? @poke1.moves[0] : @poke2.moves[0]
}, [getMoveDescription(@poke1.moves[0]), getMoveDescription(@poke2.moves[0])]
),
EnumOption.new(_INTL(""), [_INTL(getMoveName(@poke1.moves[1])), _INTL(getMoveName(@poke2.moves[1]))],
proc { 0 },
proc { |value|
@move2 = value == 0 ? @poke1.moves[1] : @poke2.moves[1]
}, [getMoveDescription(@poke1.moves[1]), getMoveDescription(@poke2.moves[1])]
),
EnumOption.new(_INTL(""), [_INTL(getMoveName(@poke1.moves[2])), _INTL(getMoveName(@poke2.moves[2]))],
proc { 0 },
proc { |value|
@move3 = value == 0 ? @poke1.moves[2] : @poke2.moves[2]
}, [getMoveDescription(@poke1.moves[2]), getMoveDescription(@poke2.moves[2])]
),
EnumOption.new(_INTL(""), [_INTL(getMoveName(@poke1.moves[3])), _INTL(getMoveName(@poke2.moves[3]))],
proc { 0 },
proc { |value|
@move4 = value == 0 ? @poke1.moves[3] : @poke2.moves[3]
}, [getMoveDescription(@poke1.moves[3]), getMoveDescription(@poke2.moves[3])]
)
]
return options
end
def isConfirmedOnKeyPress
return true
end
def initOptionsWindow
optionsWindow = Window_PokemonOptionFusionMoves.new(@PokemonOptions, 0,
@sprites["title"].height, Graphics.width,
Graphics.height - @sprites["title"].height - @sprites["textbox"].height)
optionsWindow.viewport = @viewport
optionsWindow.visible = true
return optionsWindow
end
end
class Window_PokemonOptionFusionMoves < Window_PokemonOption
def initialize(options, x, y, width, height)
super
@mustUpdateOptions=true
@mustUpdateDescription=true
@confirmed=false
end
def drawCursor(index,rect)
if self.index==index
pbCopyBitmap(self.contents, @selarrow.bitmap,rect.x+175,rect.y)
end
return Rect.new(rect.x+16,rect.y,rect.width-16,rect.height)
end
def dont_draw_item(index)
return index == @options.length
end
end

View File

@@ -0,0 +1,50 @@
class FusionPreviewScreen < DoublePreviewScreen
attr_reader :poke1
attr_reader :poke2
attr_reader :fusedPokemon
attr_reader :fusedPokemon
attr_writer :draw_types
attr_writer :draw_level
BACKGROUND_PATH = "Graphics/Pictures/DNAbg"
def initialize(poke1,poke2, usingSuperSplicers=false)
super(poke1,poke2)
@draw_types = true
@draw_level = true
@draw_sprite_info=true
#@viewport = viewport
@poke1 = poke1
@poke2 = poke2
@fusedPokemon=nil
if poke1.isShiny?
shiny = true
poke1_shiny = true
end
if poke2.isShiny?
shiny = true
poke2_shiny = true
end
new_level = calculateFusedPokemonLevel(poke1.level, poke2.level, usingSuperSplicers)
fusion_left = (poke1.species_data.id_number) * NB_POKEMON + poke2.species_data.id_number
fusion_right = (poke2.species_data.id_number) * NB_POKEMON + poke1.species_data.id_number
@picture1 = draw_window(fusion_left,new_level,20,30,shiny,poke1_shiny,poke2_shiny)
@picture2 = draw_window(fusion_right,new_level,270,30,shiny,poke2_shiny,poke1_shiny)
@sprites["picture1"] = @picture1
@sprites["picture2"] = @picture2
end
def getBackgroundPicture
super
end
end

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
class SpritesBitmapCache
@@cache = {} # Cache storage for individual sprites
@@usage_order = [] # Tracks usage order for LRU eviction
def getCache()
return @@cache
end
def get_bitmap(pif_sprite)
sprite_key = get_cache_key(pif_sprite)
if @@cache.key?(sprite_key)
mark_key_as_recently_used(sprite_key)
return @@cache[sprite_key].clone
end
return nil
end
def mark_key_as_recently_used(sprite_key)
@@usage_order.delete(sprite_key)
@@usage_order << sprite_key
end
#Keys format: [type]_B[body]H[head]_letter
# ex:
# AUTOGEN_B12H12_
# CUSTOM_B12H12_a
# BASE_BH12_a
# etc.
def get_cache_key(pif_sprite)
return "#{pif_sprite.type.to_s}_B#{pif_sprite.body_id}H#{pif_sprite.head_id}_#{pif_sprite.alt_letter}".to_sym
end
#Keys format: AUTOGEN_B12H12_a
def add(pif_sprite,bitmap)
sprite_key = get_cache_key(pif_sprite)
echoln "adding key #{sprite_key} to cache"
@@cache[sprite_key] = bitmap.clone
if @@cache.size >= Settings::SPRITE_CACHE_MAX_NB
# Evict least recently used (first in order)
oldest_key = @@usage_order.shift
@@cache.delete(oldest_key)
echoln "Evicted: #{oldest_key} from sprite cache"
end
@@usage_order << sprite_key
end
def clear
@@cache = {}
@@usage_order = []
end
end

View File

@@ -0,0 +1,98 @@
class PIFSpriteExtracter
COLUMNS = 20 # Number of columns in the spritesheet
@@spritesheet_cache = SpritesBitmapCache.new
#factor by which the sprite needs to be resized to get it to base game resolution (288x288)
def get_resize_scale
return 1
end
def load_sprite(pif_sprite,download_allowed=true)
begin
start_time = Time.now
bitmap = @@spritesheet_cache.get_bitmap(pif_sprite)
loaded_from_spritesheet=false
if !bitmap
download_new_spritesheet(pif_sprite) if should_update_spritesheet?(pif_sprite) && download_allowed
if pbResolveBitmap(getSpritesheetPath(pif_sprite))
bitmap = load_bitmap_from_spritesheet(pif_sprite)
loaded_from_spritesheet=true
@@spritesheet_cache.add(pif_sprite, bitmap)
else
return nil
end
end
sprite_bitmap = AnimatedBitmap.from_bitmap(bitmap)
sprite_bitmap.scale_bitmap(get_resize_scale())
end_time = Time.now
source = loaded_from_spritesheet ? :"spritesheet" : "cache"
echoln "Loaded sprite for <head:#{pif_sprite.head_id}, body: #{pif_sprite.body_id}, variant: #{pif_sprite.alt_letter}> from #{source} in #{end_time - start_time} seconds"
return sprite_bitmap
rescue Exception
e = $!
echoln "Error loading sprite: #{e}" if bitmap
end
end
def download_new_spritesheet(pif_sprite)
spritesheet_file = getSpritesheetPath(pif_sprite)
if download_spritesheet(pif_sprite,spritesheet_file)
$updated_spritesheets << spritesheet_file
update_downloaded_spritesheets_list()
return true
end
return false
end
def update_downloaded_spritesheets_list()
File.open(Settings::UPDATED_SPRITESHEETS_CACHE, "w") do |file|
$updated_spritesheets.each { |line| file.puts(line) }
end
end
def get_sprite_position_on_spritesheet(body_id,sprite_size,nb_column)
row = body_id / nb_column
col = body_id % nb_column
# echoln "(#{col},#{row})"
# Define the area of the sprite on the spritesheet
sprite_x_position = col * sprite_size
sprite_y_position = row * sprite_size
return sprite_x_position, sprite_y_position
end
def extract_bitmap_to_file(pif_sprite, dest_folder)
# Create the directory if it doesn't exist
Dir.mkdir(dest_folder) unless Dir.exist?(dest_folder)
single_sprite_bitmap=load_sprite(pif_sprite)
# Save the single sprite bitmap to a file
file_path = "#{dest_folder}/#{head_id}.#{body_id}.png"
single_sprite_bitmap.save_to_png(file_path)
# Dispose of the single sprite bitmap
single_sprite_bitmap.dispose
# Return the path to the saved PNG file
return file_path
end
#Implemented for base and custom, not autogen
def should_update_spritesheet?(spritesheet_file)
return false
end
def getSpritesheetPath(pif_sprite)
return nil #implement in subclasses
end
def clear_cache()
@@spritesheet_cache.clear
end
end
class PokemonGlobalMetadata
attr_accessor :current_spritepack_date
end

View File

@@ -0,0 +1,160 @@
class AutogenExtracter < PIFSpriteExtracter
SPRITESHEET_FOLDER_PATH = "Graphics\\Battlers\\spritesheets_autogen\\"
SPRITE_SIZE = 96 # Size of each sprite in the spritesheet
COLUMNS = 10 # Number of columns in the spritesheet
SHEET_WIDTH = SPRITE_SIZE * COLUMNS # 2880 pixels wide spritesheet
@instance = new
def self.instance
@@instance ||= new # If @@instance is nil, create a new instance
@@instance # Return the existing or new instance
end
def load_bitmap_from_spritesheet(pif_sprite)
body_id = pif_sprite.body_id
spritesheet_file = getSpritesheetPath(pif_sprite)
spritesheet_bitmap = AnimatedBitmap.new(spritesheet_file).bitmap
# Extract individual sprite
sprite_x_position, sprite_y_position = get_sprite_position_on_spritesheet(body_id, SPRITE_SIZE, COLUMNS)
src_rect = Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE)
bitmap = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
bitmap.blt(0, 0, spritesheet_bitmap, src_rect)
# Dispose of spritesheet if it's no longer needed
spritesheet_bitmap.dispose
return bitmap
end
def getSpritesheetPath(pif_sprite)
head_id = pif_sprite.head_id
return "#{SPRITESHEET_FOLDER_PATH}#{head_id}.png"
end
def get_resize_scale
return 3
end
#
# # Check cache before loading from disk
# sprite_bitmap = @@spritesheet_cache.fetch(pif_sprite) do
# # Load spritesheet from disk if necessary
# echoln "Loading spritesheet from disk: #{spritesheet_file}"
# spritesheet_bitmap = AnimatedBitmap.new(spritesheet_file).bitmap
#
# # Extract individual sprite
# sprite_x_position, sprite_y_position = get_sprite_position_on_spritesheet(body_id, SPRITE_SIZE, COLUMNS)
# src_rect = Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE)
#
# sprite = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
# sprite.blt(0, 0, spritesheet_bitmap, src_rect)
#
# # Dispose of spritesheet if it's no longer needed
# spritesheet_bitmap.dispose
#
# sprite
# end
# animatedBitmap = AnimatedBitmap.from_bitmap(sprite_bitmap)
#
# end_time = Time.now
# echoln "finished load sprite in #{end_time - start_time} seconds"
# echoln animatedBitmap
# return animatedBitmap
# end
def load_sprite_with_spritesheet_cache(pif_sprite)
start_time = Time.now
head_id = pif_sprite.head_id
body_id = pif_sprite.body_id
spritesheet_file = "#{SPRITESHEET_FOLDER_PATH}#{head_id}.png"
# Check cache before loading from disk
spritesheet_bitmap = @@spritesheet_cache.fetch(spritesheet_file) do
echoln "Loading spritesheet from disk: #{spritesheet_file}"
AnimatedBitmap.new(spritesheet_file).bitmap
end
sprite_x_position, sprite_y_position = get_sprite_position_on_spritesheet(body_id, SPRITE_SIZE, COLUMNS)
src_rect = Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE)
sprite_bitmap = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
sprite_bitmap.blt(0, 0, spritesheet_bitmap, src_rect)
#spritesheet_bitmap.dispose # Dispose since not needed
animatedBitmap = AnimatedBitmap.from_bitmap(sprite_bitmap)
end_time = Time.now
echoln "finished load sprite in #{end_time - start_time} seconds"
return animatedBitmap
end
end
# def extract_bitmap_to_file(head_id, body_id, folder)
# # Create the directory if it doesn't exist
# Dir.mkdir(folder) unless Dir.exist?(folder)
#
# # Load the entire spritesheet
# spritesheet_file = "#{SPRITESHEET_FOLDER_PATH}#{head_id}.png"
# spritesheet_bitmap = AnimatedBitmap.new(spritesheet_file).bitmap
#
# # Calculate the 0-based row and column from the sprite index
# zero_index = body_id - 1
# row = zero_index / COLUMNS
# col = zero_index % COLUMNS
#
# # Define the area of the sprite on the spritesheet
# sprite_x_position = col * SPRITE_SIZE
# sprite_y_position = row * SPRITE_SIZE
#
# # Create a new bitmap for the single sprite
# single_sprite_bitmap = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
# single_sprite_bitmap.blt(0, 0, spritesheet_bitmap, Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE))
#
# # Dispose of the spritesheet bitmap if its no longer needed
# spritesheet_bitmap.dispose
#
# # Save the single sprite bitmap to a file
# file_path = "#{folder}/#{head_id}.#{body_id}.png"
# single_sprite_bitmap.save_to_png(file_path)
#
# # Dispose of the single sprite bitmap
# single_sprite_bitmap.dispose
#
# # Return the path to the saved PNG file
# return file_path
# end
#end
#
#
# class SpritesBitmapCache
# @@cache = {} # Cache storage for individual sprites
# @@usage_order = [] # Tracks usage order for LRU eviction
#
# def self.fetch(pif_sprite)
# sprite_key = "B#{pif_sprite.body_id}H#{pif_sprite.head_id}".to_sym
# if @@cache.key?(sprite_key)
# # Move key to the end to mark it as recently used
# @@usage_order.delete(sprite_key)
# @@usage_order << sprite_key
# return @@cache[sprite_key]
# end
#
# # Load sprite via block if not found in cache
# sprite_bitmap = yield
#
# if @@cache.size >= Settings::SPRITE_CACHE_MAX_NB
# # Evict least recently used (first in order)
# oldest_key = @@usage_order.shift
# @@cache.delete(oldest_key)
# echoln "Evicted: #{oldest_key} from sprite cache"
# end
#
# # Add new sprite to cache and track its usage
# @@cache[sprite_key] = sprite_bitmap
# @@usage_order << sprite_key
# sprite_bitmap
# echoln @@cache
# end
# end

View File

@@ -0,0 +1,61 @@
class BaseSpriteExtracter < PIFSpriteExtracter
@instance = new
def self.instance
@@instance ||= new # If @@instance is nil, create a new instance
@@instance # Return the existing or new instance
end
SPRITESHEET_FOLDER_PATH = "Graphics/CustomBattlers/spritesheets/spritesheets_base/"
SPRITE_SIZE = 96 # Original sprite size
NB_COLUMNS_BASESPRITES = 10
SHEET_WIDTH = SPRITE_SIZE * NB_COLUMNS_BASESPRITES # 2880 pixels wide spritesheet
def load_bitmap_from_spritesheet(pif_sprite)
alt_letter = pif_sprite.alt_letter
spritesheet_file = getSpritesheetPath(pif_sprite)
spritesheet_bitmap = AnimatedBitmap.new(spritesheet_file).bitmap
letter_index = letters_to_index(alt_letter)
sprite_x_position, sprite_y_position = get_sprite_position_on_spritesheet(letter_index, SPRITE_SIZE, NB_COLUMNS_BASESPRITES)
src_rect = Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE)
sprite_bitmap = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
sprite_bitmap.blt(0, 0, spritesheet_bitmap, src_rect)
spritesheet_bitmap.dispose # Dispose since not needed
return sprite_bitmap
end
def letters_to_index(letters)
letters = letters.downcase # Ensure input is case-insensitive
index = 0
letters.each_char do |char|
index = index * 26 + (char.ord - 'a'.ord + 1)
end
#echoln "index: #{index}"
return index
end
def load_sprite_directly(head_id, body_id, alt_letter = "")
load_sprite(PIFSprite.new(:CUSTOM, head_id, body_id, alt_letter))
end
def getSpritesheetPath(pif_sprite)
dex_number = getDexNumberForSpecies(pif_sprite.head_id)
return "#{SPRITESHEET_FOLDER_PATH}#{dex_number}.png"
end
def should_update_spritesheet?(pif_sprite)
return false if !$updated_spritesheets
return false if !downloadAllowed?()
return false if requestRateExceeded?(Settings::CUSTOMSPRITES_RATE_LOG_FILE,Settings::CUSTOMSPRITES_ENTRIES_RATE_TIME_WINDOW,Settings::CUSTOMSPRITES_RATE_MAX_NB_REQUESTS,false)
spritesheet_file = getSpritesheetPath(pif_sprite)
return true if !pbResolveBitmap(spritesheet_file)
return !$updated_spritesheets.include?(spritesheet_file)
end
def get_resize_scale
return 3
end
end

View File

@@ -0,0 +1,279 @@
class BattleSpriteLoader
def initialize
@download_allowed = true
end
def load_pif_sprite_directly(pif_sprite)
if pif_sprite.local_path && pbResolveBitmap(pif_sprite.local_path)
return AnimatedBitmap.new(pif_sprite.local_path)
end
extractor = get_sprite_extractor_instance(pif_sprite.type)
return extractor.load_sprite(pif_sprite)
end
#random alt
def load_pif_sprite(pif_sprite)
case pif_sprite.type
when :CUSTOM, :AUTOGEN
load_fusion_sprite(pif_sprite.head_id, pif_sprite.body_id)
when :BASE
load_base_sprite(pif_sprite.head_id)
end
end
# Only preloads if the pokemon's sprite has been assigned an alt letter
def preload_sprite_from_pokemon(pokemon)
return if !pokemon
substitution_id = get_sprite_substitution_id_from_dex_number(pokemon.species)
# echoln substitution_id
# echoln $PokemonGlobal.alt_sprite_substitutions
pif_sprite = $PokemonGlobal.alt_sprite_substitutions[substitution_id] if $PokemonGlobal
if !pif_sprite
pif_sprite = get_pif_sprite_from_species(pokemon.species)
end
preload(pif_sprite)
end
#loads a sprite into cache without actually returning it
# Does not download spritesheet
def preload(pif_sprite)
echoln "preloading"
previous_download_allowed = @download_allowed
@download_allowed = false
load_pif_sprite(pif_sprite)
@download_allowed = previous_download_allowed
end
def clear_sprites_cache(type)
extractor = get_sprite_extractor_instance(type)
extractor.clear_cache
end
def load_from_dex_number(dex_number)
if dex_number > NB_POKEMON
if dex_number > ZAPMOLCUNO_NB #Triple Fusion
return load_triple_fusion_sprite(dex_number)
else
#Regular fusion
body_id = getBodyID(dex_number)
head_id = getHeadID(dex_number, body_id)
return load_fusion_sprite(head_id, body_id)
end
else
#base pokemon
return load_base_sprite(dex_number)
end
end
def registerSpriteSubstitution(pif_sprite)
substitution_id = get_sprite_substitution_id_from_dex_number(pif_sprite.species)
$PokemonGlobal.alt_sprite_substitutions[substitution_id] = pif_sprite
end
def obtain_fusion_pif_sprite(head_id,body_id)
substitution_id = get_sprite_substitution_id_for_fusion(head_id, body_id)
pif_sprite = $PokemonGlobal.alt_sprite_substitutions[substitution_id] if $PokemonGlobal
#pif_sprite.dump_info if pif_sprite
if !pif_sprite
pif_sprite = select_new_pif_fusion_sprite(head_id, body_id)
local_path = check_for_local_sprite(pif_sprite)
if local_path
pif_sprite.local_path = local_path
pif_sprite.type = :CUSTOM
end
substitution_id = get_sprite_substitution_id_for_fusion(head_id, body_id)
$PokemonGlobal.alt_sprite_substitutions[substitution_id] = pif_sprite if $PokemonGlobal
end
return pif_sprite
end
def load_fusion_sprite(head_id, body_id)
pif_sprite = obtain_fusion_pif_sprite(head_id,body_id)
if pif_sprite.local_path
return AnimatedBitmap.new(pif_sprite.local_path)
end
extractor = get_sprite_extractor_instance(pif_sprite.type)
loaded_sprite = extractor.load_sprite(pif_sprite, @download_allowed)
if !loaded_sprite
loaded_sprite = handle_unloaded_sprites(extractor,pif_sprite)
end
return loaded_sprite
end
def load_base_sprite(dex_number)
substitution_id = get_sprite_substitution_id_from_dex_number(dex_number)
pif_sprite = $PokemonGlobal.alt_sprite_substitutions[substitution_id] if $PokemonGlobal
if !pif_sprite
pif_sprite = select_new_pif_base_sprite(dex_number)
$PokemonGlobal.alt_sprite_substitutions[substitution_id] = pif_sprite if $PokemonGlobal
end
if pif_sprite.local_path
return AnimatedBitmap.new(pif_sprite.local_path)
end
extractor = get_sprite_extractor_instance(pif_sprite.type)
loaded_sprite = extractor.load_sprite(pif_sprite)
if !loaded_sprite
loaded_sprite = handle_unloaded_sprites(extractor,pif_sprite)
end
return loaded_sprite
end
def handle_unloaded_sprites(extractor,pif_sprite)
if(extractor.is_a?(CustomSpriteExtracter)) #Custom failed to load, load an autogen (which should always be there)
new_extractor = get_sprite_extractor_instance(:AUTOGEN)
return new_extractor.load_sprite(pif_sprite)
else
$Trainer.seen_qmarks_sprite=true if $Trainer
#If autogen or base sprite aren't able to load a sprite then we have nothing else to load -> show a ? instead.
return AnimatedBitmap.new(Settings::DEFAULT_SPRITE_PATH)
end
end
#Always loaded from local individual sprites
def load_triple_fusion_sprite(dex_number)
sprite_path = getSpecialSpriteName(dex_number)
return AnimatedBitmap.new(sprite_path)
end
def get_sprite_extractor_instance(type)
case type
when :AUTOGEN
return AutogenExtracter.instance
when :CUSTOM
return CustomSpriteExtracter.instance
when :BASE
return BaseSpriteExtracter.instance
else
raise ArgumentError, "Unknown sprite type: #{type}"
end
end
def check_for_local_sprite(pif_sprite)
return pif_sprite.local_path if pif_sprite.local_path
if pif_sprite.type == :BASE
sprite_path = "#{Settings::CUSTOM_BASE_SPRITES_FOLDER}#{pif_sprite.head_id}#{pif_sprite.alt_letter}.png"
else
sprite_path = "#{Settings::CUSTOM_BATTLERS_FOLDER_INDEXED}#{pif_sprite.head_id}/#{pif_sprite.head_id}.#{pif_sprite.body_id}#{pif_sprite.alt_letter}.png"
end
return pbResolveBitmap(sprite_path)
end
def get_pif_sprite_from_species(species)
substitution_id = get_sprite_substitution_id_from_dex_number(species)
pif_sprite = $PokemonGlobal.alt_sprite_substitutions[substitution_id] if $PokemonGlobal
return pif_sprite if pif_sprite
species_data = GameData::Species.get(species)
if species_data.id_number <= NB_POKEMON #base pokemon
return select_new_pif_base_sprite(species_data.id_number)
else #isFusion
return select_new_pif_fusion_sprite(species_data.get_head_species, species_data.get_body_species)
end
end
#
# Flow:
# # if none found, look for custom sprite in custom spritesheet (download if can't find spritesheet or new spritepack released)
# if none found, load from autogen spritesheet
def select_new_pif_fusion_sprite(head_id, body_id)
species_symbol = "B#{body_id}H#{head_id}".to_sym
spritename = get_fusion_spritename(head_id,body_id)
customSpritesList = $game_temp.custom_sprites_list[species_symbol]
alt_letter = ""
if customSpritesList
alt_letter = get_random_alt_letter_for_custom(head_id,body_id,true)
type = :CUSTOM
type = :AUTOGEN if !alt_letter
else
type = :AUTOGEN
end
if $PokemonTemp.forced_alt_sprites && $PokemonTemp.forced_alt_sprites.include?(spritename)
alt_letter = $PokemonTemp.forced_alt_sprites[spritename]
end
return PIFSprite.new(type, head_id, body_id, alt_letter)
end
def select_new_pif_base_sprite(dex_number)
random_alt = get_random_alt_letter_for_unfused(dex_number, true) #nil if no main
random_alt = "" if !random_alt
return PIFSprite.new(:BASE, dex_number, nil, random_alt)
end
#todo refactor by using get_triple_fusion_components()
def getSpecialSpriteName(dexNum)
base_path = "Graphics/Battlers/special/"
case dexNum
when Settings::ZAPMOLCUNO_NB
return sprintf(base_path + "144.145.146")
when Settings::ZAPMOLCUNO_NB + 1
return sprintf(base_path + "144.145.146")
when Settings::ZAPMOLCUNO_NB + 2
return sprintf(base_path + "243.244.245")
when Settings::ZAPMOLCUNO_NB + 3
return sprintf(base_path +"340.341.342")
when Settings::ZAPMOLCUNO_NB + 4
return sprintf(base_path +"343.344.345")
when Settings::ZAPMOLCUNO_NB + 5
return sprintf(base_path +"349.350.351")
when Settings::ZAPMOLCUNO_NB + 6
return sprintf(base_path +"151.251.381")
when Settings::ZAPMOLCUNO_NB + 11
return sprintf(base_path +"150.348.380")
#starters
when Settings::ZAPMOLCUNO_NB + 7
return sprintf(base_path +"3.6.9")
when Settings::ZAPMOLCUNO_NB + 8
return sprintf(base_path +"154.157.160")
when Settings::ZAPMOLCUNO_NB + 9
return sprintf(base_path +"278.281.284")
when Settings::ZAPMOLCUNO_NB + 10
return sprintf(base_path +"318.321.324")
#starters prevos
when Settings::ZAPMOLCUNO_NB + 12
return sprintf(base_path +"1.4.7")
when Settings::ZAPMOLCUNO_NB + 13
return sprintf(base_path +"2.5.8")
when Settings::ZAPMOLCUNO_NB + 14
return sprintf(base_path +"152.155.158")
when Settings::ZAPMOLCUNO_NB + 15
return sprintf(base_path +"153.156.159")
when Settings::ZAPMOLCUNO_NB + 16
return sprintf(base_path +"276.279.282")
when Settings::ZAPMOLCUNO_NB + 17
return sprintf(base_path +"277.280.283")
when Settings::ZAPMOLCUNO_NB + 18
return sprintf(base_path +"316.319.322")
when Settings::ZAPMOLCUNO_NB + 19
return sprintf(base_path +"317.320.323")
when Settings::ZAPMOLCUNO_NB + 20 #birdBoss Left
return sprintf(base_path +"invisible")
when Settings::ZAPMOLCUNO_NB + 21 #birdBoss middle
return sprintf(base_path + "144.145.146")
when Settings::ZAPMOLCUNO_NB + 22 #birdBoss right
return sprintf(base_path +"invisible")
when Settings::ZAPMOLCUNO_NB + 23 #sinnohboss left
return sprintf(base_path +"invisible")
when Settings::ZAPMOLCUNO_NB + 24 #sinnohboss middle
return sprintf(base_path +"343.344.345")
when Settings::ZAPMOLCUNO_NB + 25 #sinnohboss right
return sprintf(base_path +"invisible")
when Settings::ZAPMOLCUNO_NB + 25 #cardboard
return sprintf(base_path +"invisible")
when Settings::ZAPMOLCUNO_NB + 26 #cardboard
return sprintf(base_path + "cardboard")
when Settings::ZAPMOLCUNO_NB + 27 #Triple regi
return sprintf(base_path + "447.448.449")
#Triple Kalos 1
when Settings::ZAPMOLCUNO_NB + 28
return sprintf(base_path + "479.482.485")
when Settings::ZAPMOLCUNO_NB + 29
return sprintf(base_path + "480.483.486")
when Settings::ZAPMOLCUNO_NB + 30
return sprintf(base_path + "481.484.487")
else
return sprintf(base_path + "000")
end
end
end

View File

@@ -0,0 +1,106 @@
class CustomSpriteExtracter < PIFSpriteExtracter
@instance = new
def self.instance
@@instance ||= new # If @@instance is nil, create a new instance
@@instance # Return the existing or new instance
end
SPRITESHEET_FOLDER_PATH = "Graphics/CustomBattlers/spritesheets/spritesheets_custom/"
SPRITE_SIZE = 96 # Original sprite size
SHEET_WIDTH = SPRITE_SIZE * COLUMNS # 2880 pixels wide spritesheet
def load_bitmap_from_spritesheet(pif_sprite)
body_id = pif_sprite.body_id
spritesheet_file = getSpritesheetPath(pif_sprite)
spritesheet_bitmap = AnimatedBitmap.new(spritesheet_file).bitmap
sprite_x_position,sprite_y_position =get_sprite_position_on_spritesheet(body_id,SPRITE_SIZE,COLUMNS)
src_rect = Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE)
sprite_bitmap = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
sprite_bitmap.blt(0, 0, spritesheet_bitmap, src_rect)
spritesheet_bitmap.dispose # Dispose since not needed
return sprite_bitmap
end
def load_sprite_to_file(pif_sprite)
head_id = pif_sprite.head_id
body_id = pif_sprite.body_id
alt_letter = pif_sprite.alt_letter
base_folder = "#{Settings::CUSTOM_BATTLERS_FOLDER_INDEXED}#{head_id}/"
individualSpriteFile = "#{base_folder}#{head_id}.#{body_id}#{alt_letter}.png"
if !pbResolveBitmap(individualSpriteFile)
animatedBitmap = load_sprite_from_spritesheet(pif_sprite)
Dir.mkdir(base_folder) unless Dir.exist?(base_folder)
animatedBitmap.bitmap.save_to_png(individualSpriteFile)
end
return AnimatedBitmap.new(individualSpriteFile)
end
def getSpritesheetPath(pif_sprite)
alt_letter = pif_sprite.alt_letter
head_id = pif_sprite.head_id
return "#{SPRITESHEET_FOLDER_PATH}#{head_id}/#{head_id}#{alt_letter}.png"
end
def should_update_spritesheet?(pif_sprite)
return false if !$updated_spritesheets
return false if !downloadAllowed?()
return false if requestRateExceeded?(Settings::CUSTOMSPRITES_RATE_LOG_FILE,Settings::CUSTOMSPRITES_ENTRIES_RATE_TIME_WINDOW,Settings::CUSTOMSPRITES_RATE_MAX_NB_REQUESTS,false)
spritesheet_file = getSpritesheetPath(pif_sprite)
return true if !pbResolveBitmap(spritesheet_file)
return !$updated_spritesheets.include?(spritesheet_file)
end
def load_sprite_directly(head_id,body_id,alt_letter="")
load_sprite(PIFSprite.new(:CUSTOM,head_id,body_id,alt_letter))
end
def get_resize_scale
return 3
end
#
# def extract_bitmap_to_file(head_id, body_id, alt_letter, folder)
# # Create the directory if it doesn't exist
# Dir.mkdir(folder) unless Dir.exist?(folder)
#
# # Load the entire spritesheet
# spritesheet_file = "#{SPRITESHEET_FOLDER_PATH}#{head_id}\\#{head_id}#{alt_letter}.png"
# spritesheet_bitmap = AnimatedBitmap.new(spritesheet_file).bitmap
#
# # Calculate the 0-based row and column from the sprite index
# index = body_id
# row = index / COLUMNS
# col = index % COLUMNS
#
# # Define the area of the sprite on the spritesheet
# sprite_x_position = col * SPRITE_SIZE
# sprite_y_position = row * SPRITE_SIZE
#
# # Create a new bitmap for the sprite at its original size
# sprite_bitmap = Bitmap.new(SPRITE_SIZE, SPRITE_SIZE)
#
# # Copy the sprite from the spritesheet to the new bitmap
# src_rect = Rect.new(sprite_x_position, sprite_y_position, SPRITE_SIZE, SPRITE_SIZE)
# sprite_bitmap.blt(0, 0, spritesheet_bitmap, src_rect)
#
# # Dispose of the spritesheet bitmap if its no longer needed
# spritesheet_bitmap.dispose
#
# # Save the sprite bitmap to a file
# file_path = "#{folder}/#{head_id}.#{body_id}.png"
# sprite_bitmap.save_to_png(file_path)
#
# # Dispose of the sprite bitmap
# sprite_bitmap.dispose
#
# # Return the path to the saved PNG file
# return file_path
# end
end

View File

@@ -0,0 +1,122 @@
# object representing a sprite which saves its position in the tileset
class PIFSprite
attr_accessor :type
attr_accessor :head_id
attr_accessor :body_id
attr_accessor :alt_letter
attr_accessor :local_path
# types:
# :AUTOGEN, :CUSTOM, :BASE
def initialize(type, head_id, body_id, alt_letter = "")
@type = type
@head_id = head_id
@body_id = body_id
@alt_letter = alt_letter
@local_path = nil
end
def dump_info()
echoln "Type: #{@type}"
echoln "Head: #{@head_id}"
echoln "Body: #{@body_id}"
echoln "Alt letter: #{@alt_letter}"
echoln "Local path: #{@local_path}"
end
def species
if @type == :BASE
return GameData::Species.get(@head_id).species
else
return "B#{@body_id}H#{@head_id}".to_sym
end
end
def exists()
filename = get_spritesheet_path()
echoln filename
return File.file?(filename)
end
def get_spritesheet_path()
case @type
when :BASE
path = "#{BaseSpriteExtracter::SPRITESHEET_FOLDER_PATH}#{@head_id}.png"
when :CUSTOM
path = "#{CustomSpriteExtracter::SPRITESHEET_FOLDER_PATH}#{@head_id}/#{@head_id}#{@alt_letter}.png"
when :AUTOGEN
path = "#{AutogenExtracter::SPRITESHEET_FOLDER_PATH}#{@head_id}.png"
else
return nil
end
echoln path
return path
end
end
def equals(other_pif_sprite)
return @type == other_pif_sprite.type &&
@head_id == other_pif_sprite.head_id &&
@body_id == other_pif_sprite.body_id &&
@alt_letter == other_pif_sprite.alt_letter &&
@local_path == other_pif_sprite.local_path
end
# little hack for old methods that expect a filename for a sprite
def to_filename()
case @type
when :CUSTOM
return "#{@head_id}.#{@body_id}#{@alt_letter}.png"
when :AUTOGEN
return "#{@head_id}.#{@body_id}.png"
when :BASE
return "#{@head_id}#{@alt_letter}.png"
end
end
def setup_from_spritename(spritename, type)
@type = type
cleaned_name = spritename.gsub(".png", "")
if cleaned_name =~ /(\d+)\.(\d+)([a-zA-Z]*)/
head_id = $1
body_id = $2
alt_letter = $3
end
@head_id = head_id
@body_id = body_id
@alt_letter = alt_letter
end
def self.from_spritename(spritename, type)
obj = allocate
obj.send(:setup_from_spritename, spritename, type)
obj
end
def new_pif_sprite_from_dex_num(type, dexNum, alt_letter)
body_id = getBodyID(dexNum)
head_id = getHeadID(dexNum, body_id)
return PIFSprite.new(type, head_id, body_id, alt_letter)
end
def pif_sprite_from_spritename(spritename, autogen = false)
spritename = spritename.split(".png")[0] # remove the extension
if spritename =~ /^(\d+)\.(\d+)([a-zA-Z]*)$/ # Two numbers with optional letters
type = :CUSTOM
head_id = $1.to_i # Head (e.g., "1" in "1.2.png")
body_id = $2.to_i # Body (e.g., "2" in "1.2.png")
alt_letter = $3 # Optional trailing letter (e.g., "a" in "1.2a.png")
elsif spritename =~ /^(\d+)([a-zA-Z]*)$/ # One number with optional letters
type = :BASE
head_id = $1.to_i # Head (e.g., "1" in "1.png")
alt_letter = $2 # Optional trailing letter (e.g., "a" in "1a.png")
else
echoln "Invalid sprite format: #{spritename}"
return nil
end
type = :AUTOGEN if autogen
return PIFSprite.new(type, head_id, body_id, alt_letter)
end

View File

@@ -0,0 +1,89 @@
def setSpriteSubstitution(pif_sprite)
end
def getSpriteSubstitutionForDex(dex_num)
end
def setSpriteSubstitution(head,body)
end
def set_updated_spritesheets
echoln
end
def initialize_alt_sprite_substitutions()
$PokemonGlobal.alt_sprite_substitutions = {} if !$PokemonGlobal.alt_sprite_substitutions
migrate_sprites_substitutions()
end
def get_sprite_substitution_id_for_fusion(head_id, body_id)
species_symbol = "B#{body_id}H#{head_id}".to_sym
return get_sprite_substitution_id_from_dex_number(species_symbol)
end
def get_sprite_substitution_id_from_dex_number(species_symbol)
species = GameData::Species.get(species_symbol)
if species.is_fusion
substitution_id = [species.get_head_species,species.get_body_species]
else
substitution_id= species.id_number
end
return substitution_id
end
def migrate_sprites_substitutions
return if $game_switches[SWITCH_UPDATED_TO_SPRITESHEETS_SPRITES]
new_substitutions = {}
old_number_pokemon = 470
for dex_number_key in $PokemonGlobal.alt_sprite_substitutions.keys
if $PokemonGlobal.alt_sprite_substitutions[dex_number_key].is_a?(String) && can_convert_to_int?(dex_number_key)
old_dex_number = dex_number_key.to_i
if old_dex_number > old_number_pokemon #fusion
body_id = getBodyID(old_dex_number,old_number_pokemon)
head_id = getHeadID(old_dex_number,body_id,old_number_pokemon)
new_id = [head_id,body_id]
type = :CUSTOM
else
new_id = old_dex_number
head_id = old_dex_number
body_id= nil
type = :BASE
end
file_path = $PokemonGlobal.alt_sprite_substitutions[dex_number_key]
alt_letter =get_alt_letter_from_path(file_path)
pif_sprite = PIFSprite.new(type,head_id,body_id,alt_letter)
new_substitutions[new_id] = pif_sprite
end
end
$PokemonGlobal.alt_sprite_substitutions = new_substitutions
$game_switches[SWITCH_UPDATED_TO_SPRITESHEETS_SPRITES] = true
end
def can_convert_to_int?(str)
Integer(str)
true
rescue ArgumentError
false
end
def get_alt_letter_from_path(filename)
# Remove the extension
base_name = filename.sub(/\.png$/, '')
# Check the last character
last_char = base_name[-1]
if last_char.match?(/\d/) # Check if the last character is a number
alt_letter = ""
else
# Reverse the base name and capture all letters until the first number
alt_letter = base_name.reverse[/[a-zA-Z]+/].reverse
end
return alt_letter
end