08-08-2024, 05:47 PM
(This post was last modified: 08-08-2024, 05:49 PM by DerVVulfman.)
(08-05-2024, 07:49 PM)DerVVulfman Wrote: Indeed, this right here can let me open up any script from the database and read it as text IN the game. And I have included a method that 'compresses' any code into the necessary form which can be properly saved.
Yet another followup, and again... with the script database as days before. I now present THIS:
Code:
module Script_list
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def self.main
#
# Define hashes for scripts
@scripts_name = {} # Holds script names
@scripts_list = {} # Holds scripts as an array
#
# Access the script database
script_setup
#
end
#--------------------------------------------------------------------------
# * Search project script database
#--------------------------------------------------------------------------
def self.script_setup
#
path_test = "Data/Scripts.rxdata" # Define scripts database file
scripts_db = load_data(path_test) # Load file into memory
list_size = scripts_db.size # Acquire total number of scripts
#
# Cycle through them all
for i in 0...list_size # Cycle through all scripts
script_setup_hash(i+1, scripts_db[i]) # Put into hash array entries
end
#
p @scripts_name[i+1] # Show the last script's name
p @scripts_list[i+1] # Show the script decoded as array
p @scripts_list[i+1][3] # Show line 4 of the last script
#
end
#--------------------------------------------------------------------------
# * Put each script into its own hash entry
# key_id : key in hash for the script (starts from 1, not 0 as an index)
# script : script contents
#--------------------------------------------------------------------------
def self.script_setup_hash(key_id, script)
#
txt_id = script[0] # Unknown variable for script...
txt_name = script[1] # Script name in editor
txt_decode = tool_inflate(script[2]) # Script converted to text
#
txt_sep = "\r\n" # Define separator between lines
txt_array = txt_decode.split(txt_sep) # Split script into array
#
@scripts_name[key_id] = txt_name # Push the name of the script
@scripts_list[key_id] = txt_array # Push the usable script array
#
end
#--------------------------------------------------------------------------
# * ZLib Tool Inflate
# data_text : text to be inflated/expanded from encryption
#--------------------------------------------------------------------------
def self.tool_inflate(data_text)
#
zlib_tool = Zlib::Inflate.new() # Create the ZLib Inflate tool
new_text = zlib_tool.inflate(data_text) # Decrypt/expand with the tool
zlib_tool.finish # Show work done
zlib_tool.close # Close the tool
return new_text # Return the expanded text
#
end
#--------------------------------------------------------------------------
# * ZLib Tool Deflate
# data_text : text to be compressed/encrypted
# level : a defined compression level (see comments)
#--------------------------------------------------------------------------
def self.deflate(data_text, level = Zlib::BEST_COMPRESSION)
#
# Zlib::DEFAULT_COMPRESSION (-1)
# Zlib::NO_COMPRESSION 0
# Zlib::BEST_SPEED 1
# Zlib::BEST_COMPRESSION 9
#
zlib_tool = Zlib::Deflate.new(level) # Create the ZLib Inflate tool
new_text = zlib_tool.deflate(data_text, Zlib::FINISH) # Encrypt until done
zlib_tool.close # Close the tool
return new_text # Return the expanded text
#
end
end
# This executes at start
Script_list.main
This will store the 'name' of a script from the editor in one hash array, and the script itself in a similar matching hash array. Separate, but they both use the same matching key (numeric value). As defined in the script, the first script would be key #1, the second being Key #2... rather than by index positions that begin from 0 on up.
Ergo, key 7 would get both the name "Game_Picture" and separately the script for Game_Picture as an array. No clumsy illegal characters, and broken into their individual lines.
How can this be adapted for use to read VX or VXAce scripts? Just change the line that reads path_test = "Data/Scripts.rxdata" on line 21. I'm not fond of RPGMaker VX, but I do have it and did test this to confirm.
USEFULNESS?
Well, this COULD be used to generate a script Exporter of sorts, whether to output to a file or series thereof.
Or more comically... to make a FREAKIN SCRIPT TEXT EDITOR. But ya better be pretty dang good at making it possible to edit text that way.