More Rubocop changes

This commit is contained in:
Maruno17
2022-02-13 00:57:54 +00:00
parent cca5989746
commit f68e699cc9
108 changed files with 708 additions and 808 deletions

View File

@@ -77,8 +77,8 @@ module Console
# list item
def echo_li(msg, pad = 0, color = :brown)
echo markup_style(' -> ', text: color)
pad = (pad - msg.length) > 0 ? '.' * (pad - msg.length) : ''
echo markup_style(" -> ", text: color)
pad = (pad - msg.length) > 0 ? "." * (pad - msg.length) : ""
echo markup(msg + pad)
end
@@ -106,18 +106,18 @@ module Console
# status output
def echo_status(status)
if status
echoln markup_style('OK', text: :green)
echoln markup_style("OK", text: :green)
else
echoln markup_style('FAIL', text: :red)
echoln markup_style("FAIL", text: :red)
end
end
# completion output
def echo_done(status)
if status
echoln markup_style('done', text: :green)
echoln markup_style("done", text: :green)
else
echoln markup_style('error', text: :red)
echoln markup_style("error", text: :red)
end
end
@@ -126,39 +126,39 @@ module Console
#-----------------------------------------------------------------------------
def string_colors
{
default: '38', black: '30', red: '31', green: '32', brown: '33',
blue: '34', purple: '35', cyan: '36', gray: '37',
dark_gray: '1;30', light_red: '1;31', light_green: '1;32', yellow: '1;33',
light_blue: '1;34', light_purple: '1;35', light_cyan: '1;36', white: '1;37'
default: "38", black: "30", red: "31", green: "32", brown: "33",
blue: "34", purple: "35", cyan: "36", gray: "37",
dark_gray: "1;30", light_red: "1;31", light_green: "1;32", yellow: "1;33",
light_blue: "1;34", light_purple: "1;35", light_cyan: "1;36", white: "1;37"
}
end
def background_colors
{
default: '0', black: '40', red: '41', green: '42', brown: '43',
blue: '44', purple: '45', cyan: '46', gray: '47',
dark_gray: '100', light_red: '101', light_green: '102', yellow: '103',
light_blue: '104', light_purple: '105', light_cyan: '106', white: '107'
default: "0", black: "40", red: "41", green: "42", brown: "43",
blue: "44", purple: "45", cyan: "46", gray: "47",
dark_gray: "100", light_red: "101", light_green: "102", yellow: "103",
light_blue: "104", light_purple: "105", light_cyan: "106", white: "107"
}
end
def font_options
{
bold: '1', dim: '2', italic: '3', underline: '4', reverse: '7',
hidden: '8'
bold: "1", dim: "2", italic: "3", underline: "4", reverse: "7",
hidden: "8"
}
end
# Text markup that turns text between them a certain color
def markup_colors
{
'`' => :cyan, '"' => :purple, "'" => :purple, '$' => :green, '~' => :red
"`" => :cyan, '"' => :purple, "'" => :purple, "$" => :green, "~" => :red
}
end
def markup_options
{
'__' => :underline, '*' => :bold, '|' => :italic
"__" => :underline, "*" => :bold, "|" => :italic
}
end
@@ -169,9 +169,9 @@ module Console
code_bg = background_colors[bg]
# get options
options_pool = options.select { |key, val| font_options.key?(key) && val }
markup_pool = options_pool.keys.map { |opt| font_options[opt] }.join(';').squeeze
markup_pool = options_pool.keys.map { |opt| font_options[opt] }.join(";").squeeze
# return formatted string
"\e[#{code_bg};#{markup_pool};#{code_text}m#{string}\e[0m".squeeze(';')
"\e[#{code_bg};#{markup_pool};#{code_text}m#{string}\e[0m".squeeze(";")
end
#-----------------------------------------------------------------------------

View File

@@ -40,11 +40,11 @@ class Module
raise ArgumentError, "#{class_name} does not have method #{aliased_method} defined"
end
delimiter = class_method ? '.' : '#'
delimiter = class_method ? "." : "#"
target.define_method(name) do |*args, **kvargs|
alias_name = sprintf('%s%s%s', class_name, delimiter, name)
aliased_method_name = sprintf('%s%s%s', class_name, delimiter, aliased_method)
alias_name = sprintf("%s%s%s", class_name, delimiter, name)
aliased_method_name = sprintf("%s%s%s", class_name, delimiter, aliased_method)
Deprecation.warn_method(alias_name, removal_in, aliased_method_name)
method(aliased_method).call(*args, **kvargs)
end

View File

@@ -56,7 +56,7 @@ class File
#-----------------------------------------------------------------------------
def self.safe?(file)
ret = false
self.open(file, 'rb') { ret = true } rescue nil
self.open(file, "rb") { ret = true } rescue nil
return ret
end
#-----------------------------------------------------------------------------
@@ -258,8 +258,8 @@ end
module FileTest
IMAGE_EXTENSIONS = ['.png', '.gif'] # '.jpg', '.jpeg', '.bmp',
AUDIO_EXTENSIONS = ['.mid', '.midi', '.ogg', '.wav', '.wma'] # '.mp3'
IMAGE_EXTENSIONS = [".png", ".gif"] # ".jpg", ".jpeg", ".bmp",
AUDIO_EXTENSIONS = [".mid", ".midi", ".ogg", ".wav", ".wma"] # ".mp3"
def self.audio_exist?(filename)
return RTP.exists?(filename, AUDIO_EXTENSIONS)
@@ -318,7 +318,7 @@ def pbGetFileChar(file)
canon_file = canonicalize(file)
if !safeExists?("./Game.rgssad")
return nil if !safeExists?(canon_file)
return nil if file.last == '/' # Is a directory
return nil if file.last == "/" # Is a directory
begin
File.open(canon_file, "rb") { |f| return f.read(1) } # read one byte
rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES, Errno::EISDIR
@@ -336,7 +336,7 @@ end
def pbTryString(x)
ret = pbGetFileChar(x)
return (ret != nil && ret != "") ? x : nil
return nil_or_empty?(ret) ? nil : x
end
# Gets the contents of a file. Doesn't check RTP, but does check
@@ -401,7 +401,7 @@ class StringInput
end
def close
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
@pos = nil
@closed = true
end
@@ -409,7 +409,7 @@ class StringInput
def closed?; @closed; end
def pos
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
[@pos, @string.size].min
end
@@ -420,7 +420,7 @@ class StringInput
def pos=(value); seek(value); end
def seek(offset, whence = IO::SEEK_SET)
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
case whence
when IO::SEEK_SET then @pos = offset
when IO::SEEK_CUR then @pos += offset
@@ -434,12 +434,12 @@ class StringInput
end
def eof?
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
@pos > @string.size
end
def each(&block)
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
begin
@string.each(&block)
ensure
@@ -448,7 +448,7 @@ class StringInput
end
def gets
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
idx = @string.index("\n", @pos)
if idx
idx += 1 # "\n".size
@@ -464,7 +464,7 @@ class StringInput
end
def getc
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
ch = @string[@pos]
@pos += 1
@pos += 1 if @pos == @string.size
@@ -472,7 +472,7 @@ class StringInput
end
def read(len = nil)
raise IOError, 'closed stream' if @closed
raise IOError, "closed stream" if @closed
if !len
return nil if eof?
rest = @string[@pos...@string.size]

View File

@@ -12,10 +12,10 @@ def pbPostData(url, postdata, filename = nil, depth = 0)
body = postdata.map { |key, value|
keyString = key.to_s
valueString = value.to_s
keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf('%%%02x', s[0]) }
valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf('%%%02x', s[0]) }
keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf("%%%02x", s[0]) }
valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf("%%%02x", s[0]) }
next "#{keyString}=#{valueString}"
}.join('&')
}.join("&")
ret = HTTPLite.post_body(
url,
body,

View File

@@ -23,7 +23,7 @@ end
#===============================================================================
class String
def starts_with_vowel?
return ['a', 'e', 'i', 'o', 'u'].include?(self[0, 1].downcase)
return ["a", "e", "i", "o", "u"].include?(self[0, 1].downcase)
end
def first(n = 1); return self[0...n]; end
@@ -97,7 +97,7 @@ class Hash
h = self.clone
# failsafe
return h if !hash.is_a?(Hash)
hash.keys.each do |key|
hash.each_key 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)
hash.keys.each do |key|
hash.each_key do |key|
if self[key].is_a?(Hash)
self[key].deep_merge!(hash[key])
else
@@ -138,7 +138,7 @@ class File
def self.copy(source, destination)
data = ""
t = Time.now
File.open(source, 'rb') do |f|
File.open(source, "rb") do |f|
loop do
r = f.read(4096)
break if !r
@@ -150,7 +150,7 @@ class File
end
end
File.delete(destination) if File.file?(destination)
f = File.new(destination, 'wb')
f = File.new(destination, "wb")
f.write data
f.close
end

View File

@@ -108,7 +108,7 @@ def pbSetTextMessages
items.concat(choices)
MessageTypes.setMapMessagesAsHash(0, items)
mapinfos = pbLoadMapInfos
mapinfos.keys.each do |id|
mapinfos.each_key do |id|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -118,7 +118,7 @@ def pbSetTextMessages
map = load_data(filename)
items = []
choices = []
map.events.values.each do |event|
map.events.each_value do |event|
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update

View File

@@ -332,7 +332,7 @@ module PluginManager
self.error("Invalid plugin registry key '#{key}'.")
end
end
@@Plugins.values.each do |plugin|
@@Plugins.each_value do |plugin|
if plugin[:incompatibilities]&.include?(name)
self.error("Plugin '#{plugin[:name]}' is incompatible with '#{name}'. " +
"They cannot both be used at the same time.")
@@ -488,14 +488,14 @@ module PluginManager
raise _INTL("Bad line syntax (expected syntax like XXX=YYY)\r\n{1}", FileLineData.linereport)
end
property = $~[1].upcase
data = $~[2].split(',')
data = $~[2].split(",")
data.each_with_index { |value, i| data[i] = value.strip }
# begin formatting data hash
case property
when 'ESSENTIALS'
when "ESSENTIALS"
meta[:essentials] = [] if !meta[:essentials]
data.each { |ver| meta[:essentials].push(ver) }
when 'REQUIRES'
when "REQUIRES"
meta[:dependencies] = [] if !meta[:dependencies]
if data.length < 2 # No version given, just push name of plugin dependency
meta[:dependencies].push(data[0])
@@ -505,23 +505,23 @@ module PluginManager
else # Push dependency type, name and version of plugin dependency
meta[:dependencies].push([data[2].downcase.to_sym, data[0], data[1]])
end
when 'EXACT'
when "EXACT"
next if data.length < 2 # Exact dependencies must have a version given; ignore if not
meta[:dependencies] = [] if !meta[:dependencies]
meta[:dependencies].push([:exact, data[0], data[1]])
when 'OPTIONAL'
when "OPTIONAL"
next if data.length < 2 # Optional dependencies must have a version given; ignore if not
meta[:dependencies] = [] if !meta[:dependencies]
meta[:dependencies].push([:optional, data[0], data[1]])
when 'CONFLICTS'
when "CONFLICTS"
meta[:incompatibilities] = [] if !meta[:incompatibilities]
data.each { |value| meta[:incompatibilities].push(value) if value && !value.empty? }
when 'SCRIPTS'
when "SCRIPTS"
meta[:scripts] = [] if !meta[:scripts]
data.each { |scr| meta[:scripts].push(scr) }
when 'CREDITS'
when "CREDITS"
meta[:credits] = data
when 'LINK', 'WEBSITE'
when "LINK", "WEBSITE"
meta[:link] = data[0]
else
meta[property.downcase.to_sym] = data[0]
@@ -665,7 +665,7 @@ module PluginManager
dat = [o, meta, []]
# iterate through each file to deflate
plugins[o][:scripts].each do |file|
File.open("#{plugins[o][:dir]}/#{file}", 'rb') do |f|
File.open("#{plugins[o][:dir]}/#{file}", "rb") do |f|
dat[2].push([file, Zlib::Deflate.deflate(f.read)])
end
end
@@ -673,7 +673,7 @@ module PluginManager
scripts.push(dat)
end
# save to main `PluginScripts.rxdata` file
File.open("Data/PluginScripts.rxdata", 'wb') { |f| Marshal.dump(scripts, f) }
File.open("Data/PluginScripts.rxdata", "wb") { |f| Marshal.dump(scripts, f) }
# collect garbage
GC.start
Console.echo_done(true)

View File

@@ -92,7 +92,7 @@ class SpriteAnimation
def dispose_animation
return if @_animation_sprites.nil?
sprite = @_animation_sprites[0]
if sprite != nil
if sprite
@@_reference_count[sprite.bitmap] -= 1
if @@_reference_count[sprite.bitmap] == 0
sprite.bitmap.dispose
@@ -108,7 +108,7 @@ class SpriteAnimation
def dispose_loop_animation
return if @_loop_animation_sprites.nil?
sprite = @_loop_animation_sprites[0]
if sprite != nil
if sprite
@@_reference_count[sprite.bitmap] -= 1
if @@_reference_count[sprite.bitmap] == 0
sprite.bitmap.dispose
@@ -122,7 +122,7 @@ class SpriteAnimation
end
def active?
return @_loop_animation_sprites != nil || @_animation_sprites != nil
return @_loop_animation_sprites || @_animation_sprites
end
def effect?
@@ -130,7 +130,7 @@ class SpriteAnimation
end
def update
if @_animation != nil
if @_animation
quick_update = true
if Graphics.frame_count % @_animation_frame_skip == 0
@_animation_duration -= 1
@@ -138,7 +138,7 @@ class SpriteAnimation
end
update_animation(quick_update)
end
if @_loop_animation != nil
if @_loop_animation
quick_update = (Graphics.frame_count % @_loop_animation_frame_skip != 0)
update_loop_animation(quick_update)
if !quick_update
@@ -180,7 +180,7 @@ class SpriteAnimation
sprite_x = 320
sprite_y = 240
if position == 3
if self.viewport != nil
if self.viewport
sprite_x = self.viewport.rect.width / 2
sprite_y = self.viewport.rect.height - 160
end
@@ -194,7 +194,7 @@ class SpriteAnimation
sprite = sprites[i]
pattern = cell_data[i, 0]
if sprite.nil? || pattern.nil? || pattern == -1
sprite.visible = false if sprite != nil
sprite.visible = false if sprite
next
end
sprite.x = sprite_x + cell_data[i, 1]
@@ -232,9 +232,7 @@ class SpriteAnimation
when 1
self.flash(timing.flash_color, timing.flash_duration * 2)
when 2
if self.viewport != nil
self.viewport.flash(timing.flash_color, timing.flash_duration * 2)
end
self.viewport.flash(timing.flash_color, timing.flash_duration * 2) if self.viewport
when 3
self.flash(nil, timing.flash_duration * 2)
end
@@ -244,30 +242,22 @@ class SpriteAnimation
def x=(x)
sx = x - self.x
return if sx == 0
if @_animation_sprites != nil
16.times do |i|
@_animation_sprites[i].x += sx
end
if @_animation_sprites
16.times { |i| @_animation_sprites[i].x += sx }
end
if @_loop_animation_sprites != nil
16.times do |i|
@_loop_animation_sprites[i].x += sx
end
if @_loop_animation_sprites
16.times { |i| @_loop_animation_sprites[i].x += sx }
end
end
def y=(y)
sy = y - self.y
return if sy == 0
if @_animation_sprites != nil
16.times do |i|
@_animation_sprites[i].y += sy
end
if @_animation_sprites
16.times { |i| @_animation_sprites[i].y += sy }
end
if @_loop_animation_sprites != nil
16.times do |i|
@_loop_animation_sprites[i].y += sy
end
if @_loop_animation_sprites
16.times { |i| @_loop_animation_sprites[i].y += sy }
end
end
end