KTitleUpdate ACE - kyonides - 06-17-2023
KTitleUpdate ACE
by Kyonides
Introduction
Well, I think the title is pretty much self descriptive, but here we go!
Did you ever need to dynamically change your Title Scene but couldn't do it on your own?
Then use this scriptlet and you will be able to do it by yourself!
This is NOT a Plug and Play Script, yet, it will work from the very beginning if you are using the default assets in your game project.
Please read the instructions embedded in my script.
Code: # * KTitleUpdate ACE * #
# Scripter : Kyonides Arkanthes
# 2023-06-16
# This scriptlet lets you change the Background and Foreground Titles of your
# game project based on the value of a predefined Game Variable.
# You must configure 7 CONSTANTS to tell it which Title will be displayed on
# screen at that specific point.
# * Warning! * #
# If you don't use the Scene_End menu scene, delete that part from this script.
module KTitleUpdate
# For the Game's Root Save Directory the String might be "Save*"
# For a Custom Save Directory the String might be "CustomDir/Save*"
DIR_N_SAVE_FILENAME = "Save*"
TITLE_VAR_ID = 1
# Load Data Types: :var_max or :recent
LOAD_DATA_TYPE = :var_max
USE_BACKGROUNDS = true
USE_FOREGROUNDS = true
# Manually List All of Your Background and Foreground Titles
BACKGROUNDS = ["Book", "Fountain", "Island", "Sword"]
FOREGROUNDS = ["Metal", "Heroes", "Mist", "Mountains"]
extend self
def sort_save_files
Dir[DIR_N_SAVE_FILENAME].sort
end
def find_bg_fg(index)
[BACKGROUNDS[index], FOREGROUNDS[index]]
end
end
module DataManager
extend self
attr_accessor :titles, :total_save_files
def load_vars_only(fn)
File.open(fn, "rb") do |file|
Marshal.load(file)
data = Marshal.load(file)
variables = data[:variables]
@titles << variables[KTitleUpdate::TITLE_VAR_ID]
@make_times << File.mtime(fn) rescue Time.at(0)
end
end
def check_save_files
@titles = []
@make_times = []
filenames = KTitleUpdate.sort_save_files
filenames.each {|fn| load_vars_only(fn) }
@total_save_files = filenames.size
end
def highest_titles
KTitleUpdate.find_bg_fg(@titles.max - 1)
end
def latest_titles
time_max = @make_times.max
title_index = @make_times.index(time_max)
title_index = @titles[title_index] - 1
KTitleUpdate.find_bg_fg(title_index)
end
def default_title?
@titles.empty? or @titles.max == 0
end
check_save_files
end
class Scene_Title
alias :kyon_title_change_scn_ttl_create_backgr :create_background
def create_background
if DataManager.default_title?
kyon_title_change_scn_ttl_create_backgr
else
custom_background
end
end
def custom_background
case KTitleUpdate::LOAD_DATA_TYPE
when :var_max
background, foreground = DataManager.highest_titles
when :recent
background, foreground = DataManager.latest_titles
end
@sprite1 = Sprite.new
@sprite1.bitmap = Cache.title1(background)
@sprite2 = Sprite.new
@sprite2.z = 25
@sprite2.bitmap = Cache.title2(foreground)
center_sprite(@sprite1)
center_sprite(@sprite2)
end
end
class Scene_End
alias :kyon_title_change_scn_end_comm_ttl :command_to_title
def command_to_title
kyon_title_change_scn_end_comm_ttl
DataManager.check_save_files
end
end
Side Note
Usually, I would not make this kind of simple scripts, still, an unknown forumer was desperate to get another one work the way he expected and it made me flex my scripting muscles once again.
Terms & Conditions
Free for use in any game
Due credit is optional but appreciated.
That's it!
|