3 Commits

Author SHA1 Message Date
chardub
bbd5ba09ea More migration 2025-04-26 22:03:51 -04:00
chardub
90c0e51e88 Caches expanded autotiles to reduce stutter caused by map connections 2025-04-26 22:01:12 -04:00
chardub
85d5f6206c custom autotile replacements 2025-04-26 21:35:28 -04:00
9 changed files with 1788 additions and 101 deletions

View File

@@ -137,12 +137,28 @@ class TilemapRenderer
set_current_frame(filename)
end
EXPANDED_AUTOTILES_FOLDER = "Graphics/Autotiles/ExpandedAutotiles/"
def add(filename)
return if nil_or_empty?(filename)
if @bitmaps[filename]
@load_counts[filename] += 1
return
end
# Try to load expanded autotile from cache first
cached_path = File.join("Graphics", "Autotiles/ExpandedAutotiles", "#{filename}.png")
if FileTest.exist?(cached_path)
echoln "Loading cached expanded autotile for #{filename}"
bitmap = RPG::Cache.load_bitmap(EXPANDED_AUTOTILES_FOLDER, filename)
duration = AUTOTILE_FRAME_DURATION
if filename[/\[\s*(\d+?)\s*\]\s*$/]
duration = $~[1].to_i
end
@frame_durations[filename] = duration.to_f / 20
else
orig_bitmap = pbGetAutotile(filename)
@bitmap_wraps[filename] = false
duration = AUTOTILE_FRAME_DURATION
@@ -150,12 +166,20 @@ class TilemapRenderer
duration = $~[1].to_i
end
@frame_durations[filename] = duration.to_f / 20
bitmap = AutotileExpander.expand(orig_bitmap)
expanded_bitmap = AutotileExpander.expand(orig_bitmap)
# Save expanded bitmap to cache for next time
Dir.mkdir(EXPANDED_AUTOTILES_FOLDER) unless Dir.exist?(EXPANDED_AUTOTILES_FOLDER)
expanded_bitmap.save_to_png(cached_path)
bitmap = expanded_bitmap
orig_bitmap.dispose if orig_bitmap != expanded_bitmap
end
self[filename] = bitmap
if bitmap.height > SOURCE_TILE_HEIGHT && bitmap.height < TILES_PER_AUTOTILE * SOURCE_TILE_HEIGHT
@bitmap_wraps[filename] = true
end
orig_bitmap.dispose if orig_bitmap != bitmap
@load_counts[filename] = 1
end
@@ -382,7 +406,8 @@ class TilemapRenderer
filename = map.autotile_names[(tile_id / TILES_PER_AUTOTILE) - 1]
elsif tile_id < single_autotile_start_id # Large extra autotiles
filename = extra_autotile_arrays[0][(tile_id - TILESET_START_ID) / TILES_PER_AUTOTILE]
else # Single extra autotiles
else
# Single extra autotiles
filename = extra_autotile_arrays[1][tile_id - single_autotile_start_id]
end
tile.set_bitmap(filename, tile_id, true, @autotiles.animated?(filename),

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
class TilemapRenderer
alias original_tilemapRenderer_initialize initialize
def initialize(viewport)
original_tilemapRenderer_initialize(viewport)
@custom_autotile_ids = {} # key: tile_id, value: filename
end
# Examples:
# 1 => [["Sand shore"], ["Flowers2"]],
# 2 => [[], ["Flowers2", "Waterfall", "Waterfall crest", "Waterfall bottom"]],
# 6 => [["Water rock", "Sea deep"], []]
EXTRA_AUTOTILES = {
1 => { #route-field
996 => "flowers_orange[10]",
991 => "flowers_pink[10]",
999 => "flowers_yellow[10]",
1007 => "flowers_blue[10]",
1015 => "flowers_purple[10]",
1023 => "flowers_red[10]",
1031 => "flowers_grey[10]",
1039 => "flowers_white[10]",
},
2 => { #small-town
996 => "flowers_orange[10]",
991 => "flowers_pink[10]",
999 => "flowers_yellow[10]",
1007 => "flowers_blue[10]",
1015 => "flowers_purple[10]",
1023 => "flowers_red[10]",
1031 => "flowers_grey[10]",
1039 => "flowers_white[10]",
}
}
def add_extra_autotiles(tileset_id)
overrides = EXTRA_AUTOTILES[tileset_id]
return unless overrides
overrides.each do |tile_id, filename|
@autotiles.add(filename)
@custom_autotile_ids[tile_id] = filename
end
end
def remove_extra_autotiles(tileset_id)
return if !EXTRA_AUTOTILES[tileset_id]
EXTRA_AUTOTILES[tileset_id].each do |arr|
arr.each { |filename| remove_autotile(filename) }
end
end
def refresh_tile_bitmap(tile, map, tile_id)
tile.tile_id = tile_id
if tile_id < TILES_PER_AUTOTILE
tile.set_bitmap("", tile_id, false, false, 0, nil)
tile.shows_reflection = false
tile.bridge = false
else
terrain_tag = map.terrain_tags[tile_id] || 0
terrain_tag_data = GameData::TerrainTag.try_get(terrain_tag)
priority = map.priorities[tile_id] || 0
single_autotile_start_id = TILESET_START_ID
true_tileset_start_id = TILESET_START_ID
filename = nil
extra_autotile_hash = EXTRA_AUTOTILES[map.tileset_id]
if extra_autotile_hash && extra_autotile_hash[tile_id]
# Custom tile_id override
filename = extra_autotile_hash[tile_id]
tile.set_bitmap(filename, tile_id, true, @autotiles.animated?(filename),
priority, @autotiles[filename])
elsif tile_id < true_tileset_start_id
# Default behavior
if tile_id < TILESET_START_ID # Real autotiles
filename = map.autotile_names[(tile_id / TILES_PER_AUTOTILE) - 1]
elsif tile_id < single_autotile_start_id # Large extra autotiles
filename = extra_autotile_arrays[0][(tile_id - TILESET_START_ID) / TILES_PER_AUTOTILE]
else
# Single extra autotiles
filename = extra_autotile_arrays[1][tile_id - single_autotile_start_id]
end
tile.set_bitmap(filename, tile_id, true, @autotiles.animated?(filename),
priority, @autotiles[filename])
else
filename = map.tileset_name
tile.set_bitmap(filename, tile_id, false, false, priority, @tilesets[filename])
end
tile.shows_reflection = terrain_tag_data&.shows_reflections
tile.bridge = terrain_tag_data&.bridge
end
refresh_tile_src_rect(tile, tile_id)
end
end

View File

@@ -0,0 +1,59 @@
#TODO
# attr_accessor :quicksurf
# attr_accessor :level_caps
# attr_accessor :battle_type
# attr_accessor :download_sprites
# attr_accessor :speedup
# attr_accessor :speedup_speed
# attr_accessor :max_nb_sprites_download
# attr_accessor :on_mobile
# attr_accessor :type_icons
# attr_accessor :use_generated_dex_entries
# attr_accessor :use_custom_eggs
#
#
#
# #===============================================================================#
# # Options menu handlers
# #===============================================================================#
# MenuHandlers.add(:options_menu, :only_speedup_battles, {
# "name" => _INTL("Speed Up Settings"),
# "order" => 25,
# "type" => EnumOption,
# "parameters" => [_INTL("Always"), _INTL("Only Battles")],
# "description" => _INTL("Choose which aspect is sped up."),
# "get_proc" => proc { next $PokemonSystem.only_speedup_battles },
# "set_proc" => proc { |value, scene|
# $GameSpeed = 0 if value != $PokemonSystem.only_speedup_battles
# $PokemonSystem.only_speedup_battles = value
# $CanToggle = value == 0
# }
# })
#
# MenuHandlers.add(:options_menu, :speedup_type, {
# "name" => _INTL("Speed-up type"),
# "order" => 25,
# "type" => EnumOption,
# "parameters" => [_INTL("Hold"), _INTL("Toggle")],
# "description" => _INTL("Pick how you want speed-up to be enabled."),
# "get_proc" => proc { next $PokemonSystem.speedup_type },
# "set_proc" => proc { |value, scene|
# $PokemonSystem.speedup_type = value
# }
# })
#
# MenuHandlers.add(:options_menu, :speedup_speed, {
# "name" => _INTL("Speed-up speed"),
# "order" => 27,
# "type" => SliderOption,
# "parameters" => [0, 10, 0.5], # [minimum_value, maximum_value, interval]
# "description" => _INTL("Sets by how much to speed up the game."),
# "get_proc" => proc { next $PokemonSystem.speedup_speed },
# "set_proc" => proc { |value, scene|
# next if $PokemonSystem.speedup_speed == value
# $PokemonSystem.speedup_speed = value
# }
# })# frozen_string_literal: true
#

View File

@@ -0,0 +1,31 @@
# frozen_string_literal: true
class PokemonSystem
attr_accessor :quicksurf
attr_accessor :level_caps
attr_accessor :battle_type
attr_accessor :download_sprites
attr_accessor :speedup
attr_accessor :speedup_speed
attr_accessor :max_nb_sprites_download
attr_accessor :on_mobile
attr_accessor :type_icons
attr_accessor :use_generated_dex_entries
attr_accessor :use_custom_eggs
unless method_defined?(:initialize_with_new_options)
alias_method :initialize_with_new_options, :initialize
def initialize
initialize_with_new_options
@quicksurf = 0
@battle_type = 0
@download_sprites = 0
@max_nb_sprites_download = 5
@on_mobile = false
@type_icons = true
@use_generated_dex_entries = true
@use_custom_eggs = true
end
end
end

View File

@@ -21,20 +21,6 @@ $GameSpeed = 0
$CanToggle = true
$RefreshEventsForTurbo = false
#===============================================================================#
# Set $CanToggle depending on the saved setting
#===============================================================================#
module Game
class << self
alias_method :original_load, :load unless method_defined?(:original_load)
end
def self.load(save_data)
original_load(save_data)
# echoln "UNSCALED #{System.unscaled_uptime} * #{SPEEDUP_STAGES[$GameSpeed]} - #{$GameSpeed}"
$CanToggle = true #$PokemonSystem.only_speedup_battles == 0
end
end
#===============================================================================#
# Handle incrementing speed stages if $CanToggle allows it
#===============================================================================#
module Input
@@ -238,7 +224,6 @@ end
# PokemonSystem Accessors
#===============================================================================#
class PokemonSystem
alias_method :original_initialize, :initialize unless method_defined?(:original_initialize)
attr_accessor :only_speedup_battles
attr_accessor :battle_speed
@@ -246,8 +231,9 @@ class PokemonSystem
attr_accessor :speedup_speed
attr_accessor :speedup_enabled
alias_method :original_initialize_forSpeedup, :initialize unless method_defined?(:original_initialize_forSpeedup)
def initialize
original_initialize
original_initialize_forSpeedup
@only_speedup_battles = 0 # Speed up setting (0=always, 1=battle_only)
@battle_speed = 0 # Depends on the SPEEDUP_STAGES array size
@speedup_type = SPEED_UP_TYPE_HOLD

View File

@@ -13,11 +13,8 @@ module Game
end
def onLoadSaveFile
# Essentials 21 renamed the global variable $Trainer
# It's still used everywhere in events, global events so this makes things simpler
$Trainer = $player
$PokemonBag = $bag
initializeGlobalVariables
copyOldGlobalVariables()
migrateOldSavesToCharacterCustomization()
clear_all_images()
loadDateSpecificChanges()
@@ -26,6 +23,19 @@ module Game
end
def initializeGlobalVariables()
$CanToggle = true #$PokemonSystem.only_speedup_battles == 0
end
# Essentials 21 renamed the global variable $Trainer
# It's still used everywhere in events, global events
# so this is a little hack to prevent all the old stuff
# from breaking
def copyOldGlobalVariables()
$Trainer = $player
$PokemonBag = $bag
end
def loadDateSpecificChanges()
current_date = Time.new

View File

@@ -0,0 +1,187 @@
def pbGetTerrainTag()
return $game_player.pbTerrainTag().id
end
def getLevelAtWhichSpeciesEvolved(species)
levelAtWhichCurrentSpeciesEvolved=1
evosArray = species.get_family_evolutions
for entry in evosArray
if entry[0] == species.id && entry[1] == :Level
if entry[2] && entry[2] < levelAtWhichCurrentSpeciesEvolved
levelAtWhichCurrentSpeciesEvolved = entry[2]
end
end
end
end
def getNextEvolutions(species, evolutions)
if !evolutions
evolutions = species.get_evolutions
end
nextEvolutions = []
currentLowestEvolution = nil
for evolution in evolutions
if evolution[1]== :Level
evoLevel = evolution[2]
currentLowestLevel = currentLowestEvolution ? currentLowestEvolution[2] : Settings::MAXIMUM_LEVEL
if evoLevel < currentLowestLevel
currentLowestEvolution = evolution
end
else
nextEvolutions << evolution
end
end
if currentLowestEvolution != nil
nextEvolutions << currentLowestEvolution
end
return nextEvolutions
end
def extract_custom_sprites_that_evolve_into_non_customs(includeOnlyNextEvos=true)
outfile = "nonCustomEvos.txt"
customSpecies = getCustomSpeciesList()
alreadyWritten = []
File.open(outfile,"wb") { |f|
for dexNum in customSpecies
species = GameData::Species.get(dexNum)
dex_body = getBodyID(species)
dex_head = getHeadID(species,dex_body)
evolutions = species.get_evolutions
nextEvolutions=evolutions
if includeOnlyNextEvos
nextEvolutions = getNextEvolutions(species,evolutions)
end
next if nextEvolutions.empty?
for evolution in nextEvolutions
evoSpecies = evolution[0]
if !customSpriteExistsSpecies(evoSpecies) && !alreadyWritten.include?(evoSpecies)
body = getBodyID(evoSpecies)
head = getHeadID(evoSpecies,body)
f.write((evoSpecies.to_s) +";")
f.write((head.to_s) +";")
f.write(".;")
f.write((body.to_s) +";")
f.write("evolves from ;")
f.write(species.id.to_s) + ";"
f.write((dex_head.to_s) +";")
f.write(".;")
f.write((dex_body.to_s) +";")
f.write("\n")
alreadyWritten << evoSpecies
end
end
end
}
end
def extract_pokes_with_non_custom_final_evos(includeOnlyNextEvos=true)
outfile = "nonCustomFinals.csv"
customSpecies = getCustomSpeciesList()
alreadyWritten = []
File.open(outfile,"wb") { |f|
for dexNum in customSpecies
species = GameData::Species.get(dexNum)
dex_body = getBodyID(species)
dex_head = getHeadID(species,dex_body)
evolutions = species.get_evolutions
nextEvolutions=evolutions
if includeOnlyNextEvos
nextEvolutions = getNextEvolutions(species,evolutions)
end
next if nextEvolutions.empty?
for evolution in nextEvolutions
evoSpecies = evolution[0]
isFinalEvo = GameData::Species.get(evoSpecies).get_evolutions.empty?
if !customSpriteExistsSpecies(evoSpecies) && !alreadyWritten.include?(evoSpecies) && isFinalEvo
body = getBodyID(evoSpecies)
head = getHeadID(evoSpecies,body)
f.write((evoSpecies.to_s) +";")
f.write((head.to_s) +";")
f.write(".;")
f.write((body.to_s) +";")
f.write("evolves from ;")
f.write(species.id.to_s) + ";"
f.write((dex_head.to_s) +";")
f.write(".;")
f.write((dex_body.to_s) +";")
f.write("\n")
alreadyWritten << evoSpecies
end
end
end
}
end
def extract_incomplete_evolution_lines
outfile = "incompleteLines.txt"
pokeList = []
for i in NB_POKEMON+1..PBSpecies.maxValue
pokeList << i
end
to_skip=[]
File.open(outfile,"wb") { |f|
for i in pokeList
next if to_skip.include?(i)
species = GameData::Species.get(i)
evolutions = []
for evoArray in species.get_family_evolutions
evolutions << evoArray[1]
end
non_customs = []
nbCustoms=0
for stage in evolutions
if !customSpriteExistsSpecies(stage)
non_customs << stage
else
nbCustoms+=1
end
end
#write non customs
if !non_customs.empty? && nbCustoms > 0
for missing_sprite in non_customs
f.write((missing_sprite.to_s) +";")
end
f.write((missing_sprite.to_s) +"\n")
end
#remove evos from list
for evo in evolutions
species = GameData::Species.get(evo)
to_skip << species.id_number
end
end
}
end

Binary file not shown.