KTitleUpdate ACE
#1
KTitleUpdate ACE

by Kyonides

Introduction

Happy with a sweat 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. Winking

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!
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }




Users browsing this thread: 2 Guest(s)