Fixed previous commit always causing recompiling if shadow_pokemon.dat doesn't exist, also rubocopping

This commit is contained in:
Maruno17
2023-01-23 22:27:04 +00:00
parent f6213057d8
commit b0b6e675c3
103 changed files with 1099 additions and 1302 deletions

View File

@@ -2,9 +2,7 @@
# Reads files of certain format from a directory
#===============================================================================
class Dir
#-----------------------------------------------------------------------------
# Reads all files in a directory
#-----------------------------------------------------------------------------
# Reads all files in a directory
def self.get(dir, filters = "*", full = true)
files = []
filters = [filters] if !filters.is_a?(Array)
@@ -15,9 +13,8 @@ class Dir
end
return files.sort
end
#-----------------------------------------------------------------------------
# Generates entire file/folder tree from a certain directory
#-----------------------------------------------------------------------------
# Generates entire file/folder tree from a certain directory
def self.all(dir, filters = "*", full = true)
# sets variables for starting
files = []
@@ -33,18 +30,16 @@ class Dir
# returns all found files
return files + subfolders
end
#-----------------------------------------------------------------------------
# Checks for existing directory, gets around accents
#-----------------------------------------------------------------------------
# Checks for existing directory, gets around accents
def self.safe?(dir)
return false if !FileTest.directory?(dir)
ret = false
self.chdir(dir) { ret = true } rescue nil
return ret
end
#-----------------------------------------------------------------------------
# Creates all the required directories for filename path
#-----------------------------------------------------------------------------
# Creates all the required directories for filename path
def self.create(path)
path.gsub!("\\", "/") # Windows compatibility
# get path tree
@@ -56,9 +51,8 @@ class Dir
self.mkdir(full) if !self.safe?(full)
end
end
#-----------------------------------------------------------------------------
# Generates entire folder tree from a certain directory
#-----------------------------------------------------------------------------
# Generates entire folder tree from a certain directory
def self.all_dirs(dir)
# sets variables for starting
dirs = []
@@ -69,45 +63,35 @@ class Dir
# returns all found directories
return dirs.length > 0 ? (dirs + [dir]) : [dir]
end
#-----------------------------------------------------------------------------
# Deletes all the files in a directory and all the sub directories (allows for non-empty dirs)
#-----------------------------------------------------------------------------
# Deletes all the files in a directory and all the sub directories (allows for non-empty dirs)
def self.delete_all(dir)
# delete all files in dir
self.all(dir).each { |f| File.delete(f) }
# delete all dirs in dir
self.all_dirs(dir).each { |f| Dir.delete(f) }
end
#-----------------------------------------------------------------------------
end
#===============================================================================
# extensions for file class
# Extensions for file class
#===============================================================================
class File
#-----------------------------------------------------------------------------
# Checks for existing file, gets around accents
#-----------------------------------------------------------------------------
# Checks for existing file, gets around accents
def self.safe?(file)
ret = false
self.open(file, "rb") { ret = true } rescue nil
return ret
end
#-----------------------------------------------------------------------------
# Checks for existing .rxdata file
#-----------------------------------------------------------------------------
# Checks for existing .rxdata file
def self.safeData?(file)
ret = false
ret = (load_data(file) ? true : false) rescue false
return ret
end
#-----------------------------------------------------------------------------
end
#===============================================================================
# Checking for files and directories
#===============================================================================
@@ -219,8 +203,9 @@ def canonicalize(c)
return retstr
end
#===============================================================================
#
#===============================================================================
module RTP
@rtpPaths = nil
@@ -255,7 +240,7 @@ module RTP
return filename
end
# Gets the absolute RGSS paths for the given file name
# Gets the absolute RGSS paths for the given file name
def self.eachPathFor(filename)
return if !filename
if filename[/^[A-Za-z]\:[\/\\]/] || filename[/^[\/\\]/]
@@ -299,8 +284,9 @@ module RTP
end
end
#===============================================================================
#
#===============================================================================
module FileTest
IMAGE_EXTENSIONS = [".png", ".gif"] # ".jpg", ".jpeg", ".bmp",
AUDIO_EXTENSIONS = [".mid", ".midi", ".ogg", ".wav", ".wma"] # ".mp3"
@@ -314,27 +300,23 @@ module FileTest
end
end
#===============================================================================
#
#===============================================================================
# Used to determine whether a data file exists (rather than a graphics or
# audio file). Doesn't check RTP, but does check encrypted archives.
# NOTE: pbGetFileChar checks anything added in MKXP's RTP setting,
# and matching mount points added through System.mount
# NOTE: pbGetFileChar checks anything added in MKXP's RTP setting, and matching
# mount points added through System.mount.
def pbRgssExists?(filename)
if safeExists?("./Game.rgssad")
return pbGetFileChar(filename) != nil
else
filename = canonicalize(filename)
return safeExists?(filename)
end
return pbGetFileChar(filename) != nil if safeExists?("./Game.rgssad")
filename = canonicalize(filename)
return safeExists?(filename)
end
# Opens an IO, even if the file is in an encrypted archive.
# Doesn't check RTP for the file.
# NOTE: load_data checks anything added in MKXP's RTP setting,
# and matching mount points added through System.mount
# NOTE: load_data checks anything added in MKXP's RTP setting, and matching
# mount points added through System.mount.
def pbRgssOpen(file, mode = nil)
# File.open("debug.txt","ab") { |fw| fw.write([file,mode,Time.now.to_f].inspect+"\r\n") }
if !safeExists?("./Game.rgssad")
@@ -385,9 +367,8 @@ end
# Gets the contents of a file. Doesn't check RTP, but does check
# encrypted archives.
# NOTE: load_data will check anything added in MKXP's RTP setting,
# and matching mount points added through System.mount
# NOTE: load_data will check anything added in MKXP's RTP setting, and matching
# mount points added through System.mount.
def pbGetFileString(file)
file = canonicalize(file)
if !safeExists?("./Game.rgssad")
@@ -407,14 +388,14 @@ def pbGetFileString(file)
return str
end
#===============================================================================
#
#===============================================================================
class StringInput
include Enumerable
attr_reader :lineno, :string
class << self
def new(str)
if block_given?
@@ -438,8 +419,6 @@ class StringInput
@lineno = 0
end
attr_reader :lineno, :string
def inspect
return "#<#{self.class}:#{@closed ? 'closed' : 'open'},src=#{@string[0, 30].inspect}>"
end

View File

@@ -168,8 +168,8 @@ class Color
# New constructor, accepts RGB values as well as a hex number or string value.
def initialize(*args)
pbPrintException("Wrong number of arguments! At least 1 is needed!") if args.length < 1
if args.length == 1
pbPrintException("Wrong number of arguments! At least 1 is needed!") if args.length < 1
if args.length == 1
if args.first.is_a?(Fixnum)
hex = args.first.to_s(16)
elsif args.first.is_a?(String)
@@ -181,11 +181,11 @@ class Color
r = hex[0...2].to_i(16)
g = hex[2...4].to_i(16)
b = hex[4...6].to_i(16)
elsif args.length == 3
elsif args.length == 3
r, g, b = *args
end
return init_original(r, g, b) if r && g && b
return init_original(*args)
end
return init_original(r, g, b) if r && g && b
return init_original(*args)
end
def self.new_from_rgb(param)
@@ -253,7 +253,7 @@ class Color
# @return [Integer] this color in RGB format converted to an integer
def to_i
return self.to_rgb24.to_i(16)
return self.to_rgb24.to_i(16)
end
# @return [Color] the contrasting color to this one
@@ -282,11 +282,11 @@ class Color
# Converts the provided hex string/24-bit integer to RGB values.
def self.hex_to_rgb(hex)
hex = hex.delete("#") if hex.is_a?(String)
hex = hex.to_s(16) if hex.is_a?(Numeric)
r = hex[0...2].to_i(16)
g = hex[2...4].to_i(16)
b = hex[4...6].to_i(16)
return r, g, b
hex = hex.to_s(16) if hex.is_a?(Numeric)
r = hex[0...2].to_i(16)
g = hex[2...4].to_i(16)
b = hex[4...6].to_i(16)
return r, g, b
end
# Parses the input as a Color and returns a Color object made from it.

View File

@@ -267,7 +267,10 @@ module Translator
# existing destination folder
if Dir.safe?(dir_name)
has_files = false
Dir.all(dir_name).each { |f| has_files = true; break }
Dir.all(dir_name).each do |f|
has_files = true
break
end
if has_files && !pbConfirmMessageSerious(_INTL("Replace all text files in folder '{1}'?", dir_name))
pbDisposeMessageWindow(msg_window)
return
@@ -568,14 +571,15 @@ class Translation
def setMapMessagesAsHash(map_id, array)
load_default_messages
@default_game_messages[MessageTypes::EventTexts] ||= []
@default_game_messages[MessageTypes::EventTexts][map_id] = priv_add_to_hash(MessageTypes::EventTexts, array, nil, map_id)
@default_game_messages[MessageTypes::EventTexts][map_id] = priv_add_to_hash(MessageTypes::EventTexts,
array, nil, map_id)
end
def addMapMessagesAsHash(map_id, array)
load_default_messages
@default_game_messages[MessageTypes::EventTexts] ||= []
@default_game_messages[MessageTypes::EventTexts][map_id] = priv_add_to_hash(
MessageTypes::EventTexts, array, @default_game_messages[MessageTypes::EventTexts][map_id], map_id)
@default_game_messages[MessageTypes::EventTexts][map_id] = priv_add_to_hash(MessageTypes::EventTexts,
array, @default_game_messages[MessageTypes::EventTexts][map_id], map_id)
end
def get(type, id)

View File

@@ -106,9 +106,8 @@
module PluginManager
# Holds all registered plugin data.
@@Plugins = {}
#-----------------------------------------------------------------------------
# Registers a plugin and tests its dependencies and incompatibilities.
#-----------------------------------------------------------------------------
def self.register(options)
name = nil
version = nil
@@ -289,9 +288,8 @@ module PluginManager
:credits => credits
}
end
#-----------------------------------------------------------------------------
# Throws a pure error message without stack trace or any other useless info.
#-----------------------------------------------------------------------------
def self.error(msg)
Graphics.update
t = Thread.new do
@@ -304,11 +302,10 @@ module PluginManager
end
Kernel.exit! true
end
#-----------------------------------------------------------------------------
# Returns true if the specified plugin is installed.
# If the version is specified, this version is taken into account.
# If mustequal is true, the version must be a match with the specified version.
#-----------------------------------------------------------------------------
def self.installed?(plugin_name, plugin_version = nil, mustequal = false)
plugin = @@Plugins[plugin_name]
return false if plugin.nil?
@@ -317,41 +314,36 @@ module PluginManager
return true if !mustequal && comparison >= 0
return true if mustequal && comparison == 0
end
#-----------------------------------------------------------------------------
# Returns the string names of all installed plugins.
#-----------------------------------------------------------------------------
def self.plugins
return @@Plugins.keys
end
#-----------------------------------------------------------------------------
# Returns the installed version of the specified plugin.
#-----------------------------------------------------------------------------
def self.version(plugin_name)
return if !installed?(plugin_name)
return @@Plugins[plugin_name][:version]
end
#-----------------------------------------------------------------------------
# Returns the link of the specified plugin.
#-----------------------------------------------------------------------------
def self.link(plugin_name)
return if !installed?(plugin_name)
return @@Plugins[plugin_name][:link]
end
#-----------------------------------------------------------------------------
# Returns the credits of the specified plugin.
#-----------------------------------------------------------------------------
def self.credits(plugin_name)
return if !installed?(plugin_name)
return @@Plugins[plugin_name][:credits]
end
#-----------------------------------------------------------------------------
# Compares two versions given in string form. v1 should be the plugin version
# you actually have, and v2 should be the minimum/desired plugin version.
# Return values:
# 1 if v1 is higher than v2
# 0 if v1 is equal to v2
# -1 if v1 is lower than v2
#-----------------------------------------------------------------------------
def self.compare_versions(v1, v2)
d1 = v1.chars
d1.insert(0, "0") if d1[0] == "." # Turn ".123" into "0.123"
@@ -376,9 +368,8 @@ module PluginManager
end
return 0
end
#-----------------------------------------------------------------------------
# formats the error message
#-----------------------------------------------------------------------------
# Formats the error message
def self.pluginErrorMsg(name, script)
e = $!
# begin message formatting
@@ -415,9 +406,8 @@ module PluginManager
end
end
end
#-----------------------------------------------------------------------------
# Used to read the metadata file
#-----------------------------------------------------------------------------
def self.readMeta(dir, file)
filename = "#{dir}/#{file}"
meta = {}
@@ -480,9 +470,8 @@ module PluginManager
# return meta hash
return meta
end
#-----------------------------------------------------------------------------
# Get a list of all the plugin directories to inspect
#-----------------------------------------------------------------------------
def self.listAll
return [] if !$DEBUG || safeExists?("Game.rgssad") || !Dir.safe?("Plugins")
# get a list of all directories in the `Plugins/` folder
@@ -491,9 +480,8 @@ module PluginManager
# return all plugins
return dirs
end
#-----------------------------------------------------------------------------
# Catch any potential loop with dependencies and raise an error
#-----------------------------------------------------------------------------
def self.validateDependencies(name, meta, og = nil)
# exit if no registered dependency
return nil if !meta[name] || !meta[name][:dependencies]
@@ -511,9 +499,8 @@ module PluginManager
end
return name
end
#-----------------------------------------------------------------------------
# Sort load order based on dependencies (this ends up in reverse order)
#-----------------------------------------------------------------------------
def self.sortLoadOrder(order, plugins)
# go through the load order
order.each do |o|
@@ -540,9 +527,8 @@ module PluginManager
end
return order
end
#-----------------------------------------------------------------------------
# Get the order in which to load plugins
#-----------------------------------------------------------------------------
def self.getPluginOrder
plugins = {}
order = []
@@ -568,9 +554,8 @@ module PluginManager
# sort the load order
return self.sortLoadOrder(order, plugins).reverse, plugins
end
#-----------------------------------------------------------------------------
# Check if plugins need compiling
#-----------------------------------------------------------------------------
def self.needCompiling?(order, plugins)
# fixed actions
return false if !$DEBUG || safeExists?("Game.rgssad")
@@ -590,9 +575,8 @@ module PluginManager
end
return false
end
#-----------------------------------------------------------------------------
# Check if plugins need compiling
#-----------------------------------------------------------------------------
def self.compilePlugins(order, plugins)
Console.echo_li("Compiling plugin scripts...")
scripts = []
@@ -618,9 +602,8 @@ module PluginManager
GC.start
Console.echo_done(true)
end
#-----------------------------------------------------------------------------
# Check if plugins need compiling
#-----------------------------------------------------------------------------
def self.runPlugins
Console.echo_h1("Checking plugins")
# get the order of plugins to interpret
@@ -668,9 +651,8 @@ module PluginManager
Console.echoln_li_done("No plugins found")
end
end
#-----------------------------------------------------------------------------
# Get plugin dir from name based on meta entries
#-----------------------------------------------------------------------------
# Get plugin dir from name based on meta entries
def self.findDirectory(name)
# go through the plugins folder
Dir.get("Plugins").each do |dir|
@@ -683,5 +665,4 @@ module PluginManager
# return nil if no plugin dir found
return nil
end
#-----------------------------------------------------------------------------
end

View File

@@ -1,3 +1,6 @@
#===============================================================================
#
#===============================================================================
class SpriteAnimation
@@_animations = []
@@_reference_count = {}
@@ -262,8 +265,9 @@ class SpriteAnimation
end
end
#===============================================================================
#
#===============================================================================
module RPG
class Sprite < ::Sprite
def initialize(viewport = nil)