08-06-2024, 09:05 PM
Keeping sharp, I decided... why not make a reversal of my Missing Resources script. Instead of checking your project to see if any files are missing... check the resources to see if it is even being USED!
This is an extreme BETA edition, only focusing on the Audio folder. So indeed, I do plan to continue this... which is why it is not in the Scripts Database. its not done!
Code:
#==============================================================================
# ** Resource Sifter
#------------------------------------------------------------------------------
# by DerVVulfman
# version 0.1 (beta - incomplete early stage)
# 08-06-2024 (MM-DD-YYYY)
# RGSS / RPGMaker XP
#------------------------------------------------------------------------------
# Place below Scene_Debug and above Main, and it should search your game's
# project folder for "Audio" not used in your game. That is to say, it will
# find if you have any extra/unnecessary audio files.
#
# Output of resources unused will appear in your game's root folder.
#
# This is a beta as I am continuing development.
#==============================================================================
module Resource_Sifter
#--------------------------------------------------------------------------
# * Invariables
#--------------------------------------------------------------------------
GFX = ['@system_l.gameover_name', '@system_l.title_name',
'@system_l.battle_transition', '@system_l.windowskin_name',
'@system_l.title_bgm.name', '@system_l.battle_bgm.name',
'@system_l.battle_end_me.name', '@system_l.gameover_me.name']
SFX = ['@system_l.cursor_se.name', '@system_l.decision_se.name',
'@system_l.cancel_se.name', '@system_l.buzzer_se.name',
'@system_l.equip_se.name', '@system_l.shop_se.name',
'@system_l.save_se.name', '@system_l.load_se.name',
'@system_l.battle_start_se.name', '@system_l.escape_se.name',
'@system_l.actor_collapse_se.name', '@system_l.enemy_collapse_se.name']
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def self.main
#
setup # Setup data
update # Update/Process tests
output # Output result(s)
#
end
#--------------------------------------------------------------------------
# * Setup
#--------------------------------------------------------------------------
def self.setup
#
# Load database data
@system_l = load_data("Data/System.rxdata")
@common_l = load_data("Data/CommonEvents.rxdata")
@map_l = load_data("Data/MapInfos.rxdata")
#
@root_bgm = []
@root_bgs = []
@root_me = []
@root_se = []
#
setup_files(@root_bgm, "Audio/BGM/*") # Setup test for BGM files
setup_files(@root_bgs, "Audio/BGS/*") # Setup test for BGS files
setup_files(@root_me, "Audio/ME/*") # Setup test for ME files
setup_files(@root_se, "Audio/SE/*") # Setup test for SE files
#
end
#--------------------------------------------------------------------------
# * Update and perform searches
#--------------------------------------------------------------------------
def self.update
#
search_system # Search system database
search_common # Search common events
search_map # Search map content
#
end
#--------------------------------------------------------------------------
# * Output Content
#--------------------------------------------------------------------------
def self.output
#
output_to_file(@root_bgm, "BGMs.txt") # Print BGM test results
output_to_file(@root_bgs, "BGSs.txt") # Print BGS test results
output_to_file(@root_me, "MEs.txt") # Print ME test results
output_to_file(@root_se, "SEs.txt") # Print SE test results
#
end
#--------------------------------------------------------------------------
# * Setup (when acquiring files from a game resource folder)
# pathway_list : pathway specific resource array
# path_test : the folder path for a resource
#--------------------------------------------------------------------------
def self.setup_files(pathway_list, path_test)
#
path_len = (path_test.length) -1 # Get pathway length (minus *)
#
for name in Dir[path_test] # Cycle through root folder
next if File.stat(name).directory? # If NOT a subfolder
name_len = name.length # Get filename's length
name_len -= path_len # Shorten length by path length
name_len -= 4 # Shorten length by ext length
name = name.slice(path_len, name_len) # Trim the audio name
pathway_list.push(name) # Push into the root path list
end
#
end
#--------------------------------------------------------------------------
# * Perform search of the System Database
#--------------------------------------------------------------------------
def self.search_system
#
# Testing BGM and ME
test_bgm(eval(GFX[4])) # Test Title Screen BGM
test_bgm(eval(GFX[5])) # Test Battle BGM
test_me(eval(GFX[6])) # Test Battle End ME
test_me(eval(GFX[7])) # Test Gameover ME
#
for item in SFX # Cycle through all System Sfx
test_se(eval(item)) # Test each Sound Effect
end
#
end
#--------------------------------------------------------------------------
# * Perform search of the Common Events Database
#--------------------------------------------------------------------------
def self.search_common
#
for event in @common_l # Cycle through all common events
next if event.nil? # Skip invalid event
list = event.list # Get list of commands
search_event_item(list) #`Search every item in the event
end
#
end
#--------------------------------------------------------------------------
# * Perform search through every project map
#--------------------------------------------------------------------------
def self.search_map
#
for map in @map_l # Cycle through all maps
#
id = map[0] # Get the map ID
text = "Data/Map%03d.rxdata" # Define the Map file structure
filename = sprintf(text, id) # Get the formatted map filename
map_data = load_data(filename) # Get the map data
#
search_map_params(map_data) # Search through map parameters
search_map_events(map_data) # Search through map events
#
end
#
end
#--------------------------------------------------------------------------
# * Map Database Search (when getting map param data)
# map_data : data acquired from a single map
#--------------------------------------------------------------------------
def self.search_map_params(map_data)
#
test_bgm(map_data.bgm.name) # Test the map's auto-run BGM
test_bgs(map_data.bgs.name) # Test the map's auto-run BGS
#
end
#--------------------------------------------------------------------------
# * Map Database Search (when getting map event data)
# map_data : data acquired from a single map
#--------------------------------------------------------------------------
def self.search_map_events(map_data)
#
events = {} # Create the Event hash array
for i in map_data.events.keys # Sort through map events
events[i] = map_data.events[i] # Fill testable Event hash array
end
#
for event in events # Sort through the Event array
for page in event[1].pages.reverse # Sort through Event Pages
list = page.list # Get the list of commands
search_event_item(list) # Execute resource item search
end
end
#
end
#--------------------------------------------------------------------------
# * Map Database Search (when sifting through each event command)
#--------------------------------------------------------------------------
def self.search_event_item(list)
#
for list_item in list # Cycle through all items in list
item_0 = list_item.parameters[0] # Get the item
case list_item.code # Branch by item's event code
#
when 132 ; test_bgm(item_0.name) # Change Battle BGM
when 133 ; test_me(item_0.name) # Change Battle End ME
when 209 ; self.search_mr(list_item) # Set Move Route
when 241 ; test_bgm(item_0.name) # Play BGM
when 245 ; test_bgs(item_0.name) # Play BGS
when 249 ; test_me(item_0.name) # Play ME
when 250 ; test_se(item_0.name) # Play SE
#
end
end
end
#--------------------------------------------------------------------------
# * Map Database Search (when sifting through the move route command)
#--------------------------------------------------------------------------
def self.search_mr(list_item)
#
move_l = list_item.parameters[1].list # Get the move route command list
for move_item in move_l # Cycle through
item_0 = move_item.parameters[0] # Get the item
case move_item.code # Branch by item's event code
when 44 ; test_se(item_0.name) # Play SE
end
end
#
end
#--------------------------------------------------------------------------
# * Test BGM Audio resource and remove from list
# filename : name of the resource to test
#--------------------------------------------------------------------------
def self.test_bgm(filename)
#
return if filename.nil? # Exit if no file
return if filename. == '' # Exit if empty filename
test_resource(@root_bgm, filename) # Perform resource test
#
end
#--------------------------------------------------------------------------
# * Test BGS Audio resource and remove from list
# filename : name of the resource to test
#--------------------------------------------------------------------------
def self.test_bgs(filename)
#
return if filename.nil? # Exit if no file
return if filename. == '' # Exit if empty filename
test_resource(@root_bgs, filename) # Perform resource test
#
end
#--------------------------------------------------------------------------
# * Test ME Audio resource and remove from list
# filename : name of the resource to test
#--------------------------------------------------------------------------
def self.test_me(filename)
#
return if filename.nil? # Exit if no file
return if filename. == '' # Exit if empty filename
test_resource(@root_me, filename) # Perform resource test
#
end
#--------------------------------------------------------------------------
# * Test SE Audio resource and remove from list
# filename : name of the resource to test
#--------------------------------------------------------------------------
def self.test_se(filename)
#
return if filename.nil? # Exit if no file
return if filename. == '' # Exit if empty filename
test_resource(@root_se, filename) # Perform resource test
#
end
#--------------------------------------------------------------------------
# * Test resource and remove from list
# pathway_list : pathway specific resource array
# filename : name of the resource to test
#--------------------------------------------------------------------------
def self.test_resource(pathway_list, filename)
#
unless pathway_list.include?(filename) # If file is not found
return pathway_list # Exit method with pathway list
end
#
jeff = pathway_list.index(filename) # Get index position
pathway_list.delete_at(jeff) # Delete at index position
return pathway_list # Exit with updated pathway list
#
end
#--------------------------------------------------------------------------
# * Output Content to a file
# pathway_list : pathway specific resource array
# filename : name of the output file
#--------------------------------------------------------------------------
def self.output_to_file(pathway_list, filename="Unnecessary")
#
return if pathway_list.nil? # Exit if no list
return if pathway_list == [] # Exit if empty list
#
f = File.new(filename, "w+") # Create and open the file
for resource_name in pathway_list # Cycle through all resources
f.puts resource_name # Print resource name to file
end
f.close # Close the file
#
end
end
Resource_Sifter.main
This is an extreme BETA edition, only focusing on the Audio folder. So indeed, I do plan to continue this... which is why it is not in the Scripts Database. its not done!