More Rubocopping

This commit is contained in:
Maruno17
2021-12-20 17:18:21 +00:00
parent db4acd3369
commit 33fcbf623b
154 changed files with 1388 additions and 1420 deletions

View File

@@ -9,7 +9,7 @@ class Dir
files = []
filters = [filters] if !filters.is_a?(Array)
self.chdir(dir) do
for filter in filters
filters.each do |filter|
self.glob(filter) { |f| files.push(full ? (dir + "/" + f) : f) }
end
end
@@ -22,7 +22,7 @@ class Dir
# sets variables for starting
files = []
subfolders = []
for file in self.get(dir, filters, full)
self.get(dir, filters, full).each do |file|
# engages in recursion to read the entire file tree
if self.safe?(file) # Is a directory
subfolders += self.all(file, filters, full)
@@ -157,7 +157,7 @@ def canonicalize(c)
pos = -1
ret = []
retstr = ""
for x in csplit
csplit.each do |x|
if x == ".."
if pos >= 0
ret.delete_at(pos)
@@ -168,7 +168,7 @@ def canonicalize(c)
pos += 1
end
end
for i in 0...ret.length
ret.length.times do |i|
retstr += "/" if i > 0
retstr += ret[i]
end
@@ -184,7 +184,7 @@ module RTP
return false if nil_or_empty?(filename)
eachPathFor(filename) { |path|
return true if safeExists?(path)
for ext in extensions
extensions.each do |ext|
return true if safeExists?(path + ext)
end
}
@@ -203,7 +203,7 @@ module RTP
return filename if nil_or_empty?(filename)
eachPathFor(filename) { |path|
return path if safeExists?(path)
for ext in extensions
extensions.each do |ext|
file = path + ext
return file if safeExists?(file)
end
@@ -449,7 +449,8 @@ class StringInput
def gets
raise IOError, 'closed stream' if @closed
if idx = @string.index(?\n, @pos)
idx = @string.index("\n", @pos)
if idx
idx += 1 # "\n".size
line = @string[@pos...idx]
@pos = idx

View File

@@ -37,7 +37,7 @@ class String
width -= bitmap.text_size("...").width
string_width = 0
text = []
for char in string.scan(/./)
string.scan(/./).each do |char|
wdh = bitmap.text_size(char).width
next if (wdh + string_width) > width
string_width += wdh
@@ -45,7 +45,7 @@ class String
end
text.push("...") if text.length < string.length
new_string = ""
for char in text
text.each do |char|
new_string += char
end
return new_string
@@ -97,7 +97,7 @@ class Hash
h = self.clone
# failsafe
return h if !hash.is_a?(Hash)
for key in hash.keys
hash.keys.each do |key|
if self[key].is_a?(Hash)
h.deep_merge!(hash[key])
else
@@ -109,7 +109,7 @@ class Hash
def deep_merge!(hash)
return if !hash.is_a?(Hash)
for key in hash.keys
hash.keys.each do |key|
if self[key].is_a?(Hash)
self[key].deep_merge!(hash[key])
else
@@ -139,7 +139,9 @@ class File
data = ""
t = Time.now
File.open(source, 'rb') do |f|
while r = f.read(4096)
loop do
r = f.read(4096)
break if !r
if Time.now - t > 1
Graphics.update
t = Time.now

View File

@@ -24,7 +24,7 @@ def pbSetTextMessages
begin
t = Time.now.to_i
texts = []
for script in $RGSS_SCRIPTS
$RGSS_SCRIPTS.each do |script|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -34,8 +34,8 @@ def pbSetTextMessages
end
if safeExists?("Data/PluginScripts.rxdata")
plugin_scripts = load_data("Data/PluginScripts.rxdata")
for plugin in plugin_scripts
for script in plugin[2]
plugin_scripts.each do |plugin|
plugin[2].each do |script|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -50,7 +50,7 @@ def pbSetTextMessages
commonevents = load_data("Data/CommonEvents.rxdata")
items = []
choices = []
for event in commonevents.compact
commonevents.compact.each do |event|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -58,7 +58,7 @@ def pbSetTextMessages
begin
neednewline = false
lastitem = ""
for j in 0...event.list.size
event.list.size.times do |j|
list = event.list[j]
if neednewline && list.code != 401
if lastitem != ""
@@ -72,7 +72,7 @@ def pbSetTextMessages
lastitem += "#{list.parameters[0]}"
neednewline = true
elsif list.code == 102
for k in 0...list.parameters[0].length
list.parameters[0].length.times do |k|
choices.push(list.parameters[0][k])
end
neednewline = false
@@ -86,7 +86,7 @@ def pbSetTextMessages
pbAddScriptTexts(items, list.parameters[1])
elsif list.code == 209
route = list.parameters[1]
for k in 0...route.list.size
route.list.size.times do |k|
if route.list[k].code == 45
pbAddScriptTexts(items, route.list[k].parameters[0])
end
@@ -110,7 +110,7 @@ def pbSetTextMessages
items.concat(choices)
MessageTypes.setMapMessagesAsHash(0, items)
mapinfos = pbLoadMapInfos
for id in mapinfos.keys
mapinfos.keys.each do |id|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -120,16 +120,16 @@ def pbSetTextMessages
map = load_data(filename)
items = []
choices = []
for event in map.events.values
map.events.values.each do |event|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
end
begin
for i in 0...event.pages.size
event.pages.size.times do |i|
neednewline = false
lastitem = ""
for j in 0...event.pages[i].list.size
event.pages[i].list.size.times do |j|
list = event.pages[i].list[j]
if neednewline && list.code != 401
if lastitem != ""
@@ -143,7 +143,7 @@ def pbSetTextMessages
lastitem += "#{list.parameters[0]}"
neednewline = true
elsif list.code == 102
for k in 0...list.parameters[0].length
list.parameters[0].length.times do |k|
choices.push(list.parameters[0][k])
end
neednewline = false
@@ -157,7 +157,7 @@ def pbSetTextMessages
pbAddScriptTexts(items, list.parameters[1])
elsif list.code == 209
route = list.parameters[1]
for k in 0...route.list.size
route.list.size.times do |k|
if route.list[k].code == 45
pbAddScriptTexts(items, route.list[k].parameters[0])
end
@@ -312,7 +312,7 @@ class OrderedHash < Hash
def inspect
str = "{"
for i in 0...@keys.length
@keys.length.times do |i|
str += ", " if i > 0
str += @keys[i].inspect + "=>" + self[@keys[i]].inspect
end
@@ -330,7 +330,7 @@ class OrderedHash < Hash
@keys |= []
@keys -= [key]
end
return super(key, value)
super(key, value)
end
def self._load(string)
@@ -338,7 +338,7 @@ class OrderedHash < Hash
keysvalues = Marshal.load(string)
keys = keysvalues[0]
values = keysvalues[1]
for i in 0...keys.length
keys.length.times do |i|
ret[keys[i]] = values[i]
end
return ret
@@ -346,7 +346,7 @@ class OrderedHash < Hash
def _dump(_depth = 100)
values = []
for key in @keys
@keys.each do |key|
values.push(self[key])
end
return Marshal.dump([@keys, values])
@@ -415,7 +415,7 @@ class Messages
case msgs
when Array
f.write("[#{secname}]\r\n")
for j in 0...msgs.length
msgs.length.times do |j|
next if nil_or_empty?(msgs[j])
value = Messages.normalizeValue(msgs[j])
origValue = ""
@@ -431,7 +431,7 @@ class Messages
when OrderedHash
f.write("[#{secname}]\r\n")
keys = msgs.keys
for key in keys
keys.each do |key|
next if nil_or_empty?(msgs[key])
value = Messages.normalizeValue(msgs[key])
valkey = Messages.normalizeValue(key)
@@ -456,12 +456,12 @@ class Messages
f.write("# To localize this text for a particular language, please\r\n")
f.write("# translate every second line of this file.\r\n")
if origMessages.messages[0]
for i in 0...origMessages.messages[0].length
origMessages.messages[0].length.times do |i|
msgs = origMessages.messages[0][i]
Messages.writeObject(f, msgs, "Map#{i}", origMessages)
end
end
for i in 1...origMessages.messages.length
(1...origMessages.messages.length).each do |i|
msgs = origMessages.messages[i]
Messages.writeObject(f, msgs, i, origMessages)
end
@@ -471,7 +471,7 @@ class Messages
def setMessages(type, array)
@messages = [] if !@messages
arr = []
for i in 0...array.length
array.length.times do |i|
arr[i] = (array[i]) ? array[i] : ""
end
@messages[type] = arr
@@ -480,7 +480,7 @@ class Messages
def addMessages(type, array)
@messages = [] if !@messages
arr = (@messages[type]) ? @messages[type] : []
for i in 0...array.length
array.length.times do |i|
arr[i] = (array[i]) ? array[i] : (arr[i]) ? arr[i] : ""
end
@messages[type] = arr
@@ -488,7 +488,7 @@ class Messages
def self.createHash(_type, array)
arr = OrderedHash.new
for i in 0...array.length
array.length.times do |i|
if array[i]
key = Messages.stringToKey(array[i])
arr[key] = array[i]
@@ -499,7 +499,7 @@ class Messages
def self.addToHash(_type, array, hash)
hash = OrderedHash.new if !hash
for i in 0...array.length
array.length.times do |i|
if array[i]
key = Messages.stringToKey(array[i])
hash[key] = array[i]
@@ -738,7 +738,7 @@ def _INTL(*arg)
string = arg[0]
end
string = string.clone
for i in 1...arg.length
(1...arg.length).each do |i|
string.gsub!(/\{#{i}\}/, "#{arg[i]}")
end
return string
@@ -754,7 +754,7 @@ def _ISPRINTF(*arg)
string = arg[0]
end
string = string.clone
for i in 1...arg.length
(1...arg.length).each do |i|
string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m|
next sprintf("%" + $1, arg[i])
}
@@ -769,7 +769,7 @@ end
def _MAPINTL(mapid, *arg)
string = MessageTypes.getFromMapHash(mapid, arg[0])
string = string.clone
for i in 1...arg.length
(1...arg.length).each do |i|
string.gsub!(/\{#{i}\}/, "#{arg[i]}")
end
return string
@@ -778,7 +778,7 @@ end
def _MAPISPRINTF(mapid, *arg)
string = MessageTypes.getFromMapHash(mapid, arg[0])
string = string.clone
for i in 1...arg.length
(1...arg.length).each do |i|
string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m|
next sprintf("%" + $1, arg[i])
}

View File

@@ -185,7 +185,7 @@ module PluginManager
idx_b = order.index(b) || order.size
next idx_a <=> idx_b
end
for key in keys
keys.each do |key|
value = options[key]
case key
when :name # Plugin name
@@ -211,7 +211,7 @@ module PluginManager
when :dependencies # Plugin dependencies
dependencies = value
dependencies = [dependencies] if !dependencies.is_a?(Array) || !dependencies[0].is_a?(Array)
for dep in value
value.each do |dep|
case dep
when String # "plugin name"
if !self.installed?(dep)
@@ -238,7 +238,8 @@ module PluginManager
if self.installed?(dep_name) # Have plugin but lower version
msg = "Plugin '#{name}' requires plugin '#{dep_name}' version #{dep_version} or higher, " +
"but the installed version is #{self.version(dep_name)}."
if dep_link = self.link(dep_name)
dep_link = self.link(dep_name)
if dep_link
msg += "\r\nCheck #{dep_link} for an update to plugin '#{dep_name}'."
end
self.error(msg)
@@ -308,7 +309,7 @@ module PluginManager
when :incompatibilities # Plugin incompatibilities
incompats = value
incompats = [incompats] if !incompats.is_a?(Array)
for incompat in incompats
incompats.each do |incompat|
if self.installed?(incompat)
self.error("Plugin '#{name}' is incompatible with '#{incompat}'. " +
"They cannot both be used at the same time.")
@@ -317,7 +318,7 @@ module PluginManager
when :credits # Plugin credits
value = [value] if value.is_a?(String)
if value.is_a?(Array)
for entry in value
value.each do |entry|
if !entry.is_a?(String)
self.error("Plugin '#{name}'s credits array contains a non-string value.")
else
@@ -331,7 +332,7 @@ module PluginManager
self.error("Invalid plugin registry key '#{key}'.")
end
end
for plugin in @@Plugins.values
@@Plugins.values.each do |plugin|
if plugin[:incompatibilities] && plugin[:incompatibilities].include?(name)
self.error("Plugin '#{plugin[:name]}' is incompatible with '#{name}'. " +
"They cannot both be used at the same time.")
@@ -422,7 +423,7 @@ module PluginManager
while d2[-1] == "." # Turn "123." into "123"
d2 = d2[0..-2]
end
for i in 0...[d1.size, d2.size].max # Compare each digit in turn
[d1.size, d2.size].max.times do |i| # Compare each digit in turn
c1 = d1[i]
c2 = d2[i]
if c1
@@ -445,7 +446,7 @@ module PluginManager
message += "Error in Plugin [#{name}]:\r\n"
message += "#{$!.class} occurred.\r\n"
# go through message content
for line in $!.message.split("\r\n")
$!.message.split("\r\n").each do |line|
next if nil_or_empty?(line)
n = line[/\d+/]
err = line.split(":")[-1].strip
@@ -538,7 +539,7 @@ module PluginManager
# be loaded (files listed in the meta file are loaded first)
meta[:scripts] = [] if !meta[:scripts]
# get all script files from plugin Dir
for fl in Dir.all(dir)
Dir.all(dir).each do |fl|
next if !fl.include?(".rb")
meta[:scripts].push(fl.gsub("#{dir}/", ""))
end
@@ -566,7 +567,7 @@ module PluginManager
return nil if !meta[name] || !meta[name][:dependencies]
og = [name] if !og
# go through all dependencies
for dname in meta[name][:dependencies]
meta[name][:dependencies].each do |dname|
# clean the name to a simple string
dname = dname[0] if dname.is_a?(Array) && dname.length == 2
dname = dname[1] if dname.is_a?(Array) && dname.length == 3
@@ -583,10 +584,10 @@ module PluginManager
#-----------------------------------------------------------------------------
def self.sortLoadOrder(order, plugins)
# go through the load order
for o in order
order.each do |o|
next if !plugins[o] || !plugins[o][:dependencies]
# go through all dependencies
for dname in plugins[o][:dependencies]
plugins[o][:dependencies].each do |dname|
optional = false
# clean the name to a simple string
if dname.is_a?(Array)
@@ -615,7 +616,7 @@ module PluginManager
order = []
# Find all plugin folders that have a meta.txt and add them to the list of
# plugins.
for dir in self.listAll
self.listAll.each do |dir|
# skip if there is no meta file
next if !safeExists?(dir + "/meta.txt")
ndx = order.length
@@ -646,11 +647,11 @@ module PluginManager
return true if Input.press?(Input::CTRL)
# analyze whether or not to push recompile
mtime = File.mtime("Data/PluginScripts.rxdata")
for o in order
order.each do |o|
# go through all the registered plugin scripts
scr = plugins[o][:scripts]
dir = plugins[o][:dir]
for sc in scr
scr.each do |sc|
return true if File.mtime("#{dir}/#{sc}") > mtime
end
return true if File.mtime("#{dir}/meta.txt") > mtime
@@ -664,14 +665,14 @@ module PluginManager
Console.echo_li "Compiling plugin scripts..."
scripts = []
# go through the entire order one by one
for o in order
order.each do |o|
# save name, metadata and scripts array
meta = plugins[o].clone
meta.delete(:scripts)
meta.delete(:dir)
dat = [o, meta, []]
# iterate through each file to deflate
for file in plugins[o][:scripts]
plugins[o][:scripts].each do |file|
File.open("#{plugins[o][:dir]}/#{file}", 'rb') do |f|
dat[2].push([file, Zlib::Deflate.deflate(f.read)])
end
@@ -697,7 +698,7 @@ module PluginManager
# load plugins
scripts = load_data("Data/PluginScripts.rxdata")
echoed_plugins = []
for plugin in scripts
scripts.each do |plugin|
# get the required data
name, meta, script = plugin
if !meta[:essentials] || !meta[:essentials].include?(Essentials::VERSION)
@@ -706,7 +707,7 @@ module PluginManager
# register plugin
self.register(meta)
# go through each script and interpret
for scr in script
script.each do |scr|
# turn code into plaintext
code = Zlib::Inflate.inflate(scr[1]).force_encoding(Encoding::UTF_8)
# get rid of tabs

View File

@@ -100,7 +100,7 @@ class SpriteAnimation
sprite.bitmap.dispose
end
end
for sprite in @_animation_sprites
@_animation_sprites.each do |sprite|
sprite.dispose
end
@_animation_sprites = nil
@@ -116,7 +116,7 @@ class SpriteAnimation
sprite.bitmap.dispose
end
end
for sprite in @_loop_animation_sprites
@_loop_animation_sprites.each do |sprite|
sprite.dispose
end
@_loop_animation_sprites = nil
@@ -160,7 +160,7 @@ class SpriteAnimation
position = @_animation.position
animation_set_sprites(@_animation_sprites, cell_data, position, quick_update)
return if quick_update
for timing in @_animation.timings
@_animation.timings.each do |timing|
next if timing.frame != frame_index
animation_process_timing(timing, @_animation_hit)
end
@@ -172,7 +172,7 @@ class SpriteAnimation
position = @_loop_animation.position
animation_set_sprites(@_loop_animation_sprites, cell_data, position, quick_update)
return if quick_update
for timing in @_loop_animation.timings
@_loop_animation.timings.each do |timing|
next if timing.frame != frame_index
animation_process_timing(timing, true)
end
@@ -192,7 +192,7 @@ class SpriteAnimation
sprite_y += self.src_rect.height / 2 if position == 1
sprite_y += self.src_rect.height if position == 2
end
for i in 0..15
16.times do |i|
sprite = sprites[i]
pattern = cell_data[i, 0]
if sprite == nil || pattern == nil || pattern == -1
@@ -247,12 +247,12 @@ class SpriteAnimation
sx = x - self.x
return if sx == 0
if @_animation_sprites != nil
for i in 0..15
16.times do |i|
@_animation_sprites[i].x += sx
end
end
if @_loop_animation_sprites != nil
for i in 0..15
16.times do |i|
@_loop_animation_sprites[i].x += sx
end
end
@@ -262,12 +262,12 @@ class SpriteAnimation
sy = y - self.y
return if sy == 0
if @_animation_sprites != nil
for i in 0..15
16.times do |i|
@_animation_sprites[i].y += sy
end
end
if @_loop_animation_sprites != nil
for i in 0..15
16.times do |i|
@_loop_animation_sprites[i].y += sy
end
end
@@ -376,7 +376,7 @@ module RPG
end
def pushAnimation(array, anim)
for i in 0...array.length
array.length.times do |i|
next if array[i] && array[i].active?
array[i] = anim
return
@@ -405,14 +405,14 @@ module RPG
end
def dispose_animation
for a in @animations
@animations.each do |a|
a.dispose_animation if a
end
@animations.clear
end
def dispose_loop_animation
for a in @loopAnimations
@loopAnimations.each do |a|
a.dispose_loop_animation if a
end
@loopAnimations.clear
@@ -440,7 +440,7 @@ module RPG
return true if @_escape_duration > 0
return true if @_collapse_duration > 0
return true if @_damage_duration > 0
for a in @animations
@animations.each do |a|
return true if a.effect?
end
return false
@@ -481,10 +481,10 @@ module RPG
dispose_damage
end
end
for a in @animations
@animations.each do |a|
a.update
end
for a in @loopAnimations
@loopAnimations.each do |a|
a.update
end
if @_blink
@@ -500,32 +500,32 @@ module RPG
end
def update_animation
for a in @animations
@animations.each do |a|
a.update_animation if a && a.active?
end
end
def update_loop_animation
for a in @loopAnimations
@loopAnimations.each do |a|
a.update_loop_animation if a && a.active?
end
end
def x=(x)
for a in @animations
@animations.each do |a|
a.x = x if a
end
for a in @loopAnimations
@loopAnimations.each do |a|
a.x = x if a
end
super
end
def y=(y)
for a in @animations
@animations.each do |a|
a.y = y if a
end
for a in @loopAnimations
@loopAnimations.each do |a|
a.y = y if a
end
super