Many more Rubocop-inspired code improvements

This commit is contained in:
Maruno17
2021-12-18 19:06:22 +00:00
parent d17fc40a47
commit 13a238cc6a
107 changed files with 651 additions and 652 deletions

View File

@@ -356,7 +356,8 @@ def pbTrainerTypeEditor
]
pbListScreenBlock(_INTL("Trainer Types"), TrainerTypeLister.new(0, true)) { |button, tr_type|
if tr_type
if button == Input::ACTION
case button
when Input::ACTION
if tr_type.is_a?(Symbol)
if pbConfirmMessageSerious("Delete this trainer type?")
GameData::TrainerType::DATA.delete(tr_type)
@@ -365,7 +366,7 @@ def pbTrainerTypeEditor
pbMessage(_INTL("The Trainer type was deleted."))
end
end
elsif button == Input::USE
when Input::USE
if tr_type.is_a?(Symbol)
t_data = GameData::TrainerType.get(tr_type)
data = [
@@ -496,7 +497,8 @@ def pbTrainerBattleEditor
modified = false
pbListScreenBlock(_INTL("Trainer Battles"), TrainerBattleLister.new(0, true)) { |button, trainer_id|
if trainer_id
if button == Input::ACTION
case button
when Input::ACTION
if trainer_id.is_a?(Array)
if pbConfirmMessageSerious("Delete this trainer battle?")
tr_data = GameData::Trainer::DATA[trainer_id]
@@ -505,7 +507,7 @@ def pbTrainerBattleEditor
pbMessage(_INTL("The Trainer battle was deleted."))
end
end
elsif button == Input::USE
when Input::USE
if trainer_id.is_a?(Array) # Edit existing trainer
tr_data = GameData::Trainer::DATA[trainer_id]
old_type = tr_data.trainer_type
@@ -881,7 +883,8 @@ def pbItemEditor
]
pbListScreenBlock(_INTL("Items"), ItemLister.new(0, true)) { |button, item|
if item
if button == Input::ACTION
case button
when Input::ACTION
if item.is_a?(Symbol)
if pbConfirmMessageSerious("Delete this item?")
GameData::Item::DATA.delete(item)
@@ -890,7 +893,7 @@ def pbItemEditor
pbMessage(_INTL("The item was deleted."))
end
end
elsif button == Input::USE
when Input::USE
if item.is_a?(Symbol)
itm = GameData::Item.get(item)
data = [
@@ -1039,7 +1042,8 @@ def pbPokemonEditor
]
pbListScreenBlock(_INTL("Pokémon species"), SpeciesLister.new(0, false)) { |button, species|
if species
if button == Input::ACTION
case button
when Input::ACTION
if species.is_a?(Symbol)
if pbConfirmMessageSerious("Delete this species?")
GameData::Species::DATA.delete(species)
@@ -1048,7 +1052,7 @@ def pbPokemonEditor
pbMessage(_INTL("The species was deleted."))
end
end
elsif button == Input::USE
when Input::USE
if species.is_a?(Symbol)
spec = GameData::Species.get(species)
moves = []
@@ -1448,29 +1452,30 @@ def pbAnimationsOrganiser
refreshlist = false
oldsel = -1
cmd = pbCommands3(cmdwin, commands, -1, cmd[1], true)
if cmd[0] == 1 # Swap animation up
case cmd[0]
when 1 # Swap animation up
if cmd[1] >= 0 && cmd[1] < commands.length - 1
list[cmd[1] + 1], list[cmd[1]] = list[cmd[1]], list[cmd[1] + 1]
refreshlist = true
end
elsif cmd[0] == 2 # Swap animation down
when 2 # Swap animation down
if cmd[1] > 0
list[cmd[1] - 1], list[cmd[1]] = list[cmd[1]], list[cmd[1] - 1]
refreshlist = true
end
elsif cmd[0] == 3 # Delete spot
when 3 # Delete spot
list.delete_at(cmd[1])
cmd[1] = [cmd[1], list.length - 1].min
refreshlist = true
pbWait(Graphics.frame_rate * 2 / 10)
elsif cmd[0] == 4 # Insert spot
when 4 # Insert spot
list.insert(cmd[1], PBAnimation.new)
refreshlist = true
pbWait(Graphics.frame_rate * 2 / 10)
elsif cmd[0] == 0
when 0
cmd2 = pbMessage(_INTL("Save changes?"),
[_INTL("Yes"), _INTL("No"), _INTL("Cancel")], 3)
if cmd2 == 0 || cmd2 == 1
if [0, 1].include?(cmd2)
if cmd2 == 0
# Save animations here
save_data(list, "Data/PkmnAnimations.rxdata")

View File

@@ -20,7 +20,7 @@ class MapSprite
def getXY
return nil if !Input.trigger?(Input::MOUSELEFT)
mouse = Mouse::getMousePos(true)
mouse = Mouse.getMousePos(true)
return nil if !mouse
if mouse[0] < @sprite.x || mouse[0] >= @sprite.x + @sprite.bitmap.width
return nil
@@ -119,7 +119,7 @@ class RegionMapSprite
def getXY
return nil if !Input.trigger?(Input::MOUSELEFT)
mouse = Mouse::getMousePos(true)
mouse = Mouse.getMousePos(true)
return nil if !mouse
if mouse[0] < @sprite.x || mouse[0] >= @sprite.x + @sprite.bitmap.width
return nil
@@ -280,7 +280,7 @@ class MapScreenScene
end
def serializeConnectionData
conndata = generateConnectionData()
conndata = generateConnectionData
save_data(conndata, "Data/map_connections.dat")
Compiler.write_connections
@mapconns = conndata
@@ -477,7 +477,7 @@ class MapScreenScene
end
def update
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
if mousepos
hitmap = hittest(mousepos[0], mousepos[1])
if Input.trigger?(Input::MOUSELEFT)

View File

@@ -121,8 +121,6 @@ def pbChooseFromGameDataList(game_data, default = nil)
name = data.real_name
name = yield(data) if block_given?
next if !name
index = commands.length + 1
index = data.id_number if data.respond_to?("id_number")
commands.push([commands.length + 1, name, data.id])
end
return pbChooseList(commands, default, nil, -1)
@@ -344,9 +342,10 @@ def pbChooseList(commands, default = 0, cancelValue = -1, sortType = 1)
sorting = true
loop do
if sorting
if sortMode == 0
case sortMode
when 0
commands.sort! { |a, b| a[0] <=> b[0] }
elsif sortMode == 1
when 1
commands.sort! { |a, b| a[1] <=> b[1] }
end
if itemID.is_a?(Symbol)
@@ -365,10 +364,11 @@ def pbChooseList(commands, default = 0, cancelValue = -1, sortType = 1)
sorting = false
end
cmd = pbCommandsSortable(cmdwin, realcommands, -1, itemIndex, (sortType < 0))
if cmd[0] == 0 # Chose an option or cancelled
case cmd[0]
when 0 # Chose an option or cancelled
itemID = (cmd[1] < 0) ? cancelValue : (commands[cmd[1]][2] || commands[cmd[1]][0])
break
elsif cmd[0] == 1 # Toggle sorting
when 1 # Toggle sorting
itemID = commands[cmd[1]][2] || commands[cmd[1]][0]
sortMode = (sortMode + 1) % 2
sorting = true

View File

@@ -25,7 +25,7 @@ class Window_Menu < Window_CommandPokemon
end
def hittest
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
return -1 if !mousepos
toprow = self.top_row
for i in toprow...toprow + @item_max
@@ -51,7 +51,7 @@ module Clipboard
def self.data
return nil if !@data
return Marshal::load(@data)
return Marshal.load(@data)
end
def self.typekey
@@ -131,7 +131,7 @@ def pbSpriteHitTest(sprite, x, y, usealpha = true, wholecanvas = false)
end
def pbTrackPopupMenu(commands)
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
return -1 if !mousepos
menuwindow = Window_Menu.new(commands, mousepos[0], mousepos[1])
menuwindow.z = 99999
@@ -250,7 +250,7 @@ class AnimationWindow < SpriteWrapper
end
def update
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
@changed = false
return if !Input.repeat?(Input::MOUSELEFT)
return if !mousepos
@@ -795,7 +795,7 @@ class AnimationCanvas < Sprite
def updateInput
cel = currentCel
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
if mousepos && pbSpriteHitTest(self, mousepos[0], mousepos[1], false, true)
if Input.trigger?(Input::MOUSELEFT) # Left mouse button
selectedcel = -1

View File

@@ -1,9 +1,10 @@
module ShadowText
def shadowtext(bitmap, x, y, w, h, t, disabled = false, align = 0)
width = bitmap.text_size(t).width
if align == 2
case align
when 2
x += (w - width)
elsif align == 1
when 1
x += (w / 2) - (width / 2)
end
pbDrawShadowText(bitmap, x, y, w, h, t,
@@ -120,7 +121,7 @@ class Button < UIControl
end
def update
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
self.changed = false
return if !mousepos
rect = Rect.new(self.x + 1, self.y + 1, self.width - 2, self.height - 2)
@@ -385,7 +386,7 @@ class Slider < UIControl
end
def update
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
self.changed = false
if self.minvalue < self.maxvalue && self.curvalue < self.minvalue
self.curvalue = self.minvalue
@@ -401,14 +402,12 @@ class Slider < UIControl
if left.contains(mousepos[0], mousepos[1])
if repeattime > 2500
self.curvalue -= 10
self.curvalue = self.curvalue.floor
elsif repeattime > 1250
self.curvalue -= 5
self.curvalue = self.curvalue.floor
else
self.curvalue -= 1
self.curvalue = self.curvalue.floor
end
self.curvalue = self.curvalue.floor
self.changed = (self.curvalue != oldvalue)
self.invalidate
end
@@ -416,14 +415,12 @@ class Slider < UIControl
if right.contains(mousepos[0], mousepos[1])
if repeattime > 2500
self.curvalue += 10
self.curvalue = self.curvalue.floor
elsif repeattime > 1250
self.curvalue += 5
self.curvalue = self.curvalue.floor
else
self.curvalue += 1
self.curvalue = self.curvalue.floor
end
self.curvalue = self.curvalue.floor
self.changed = (self.curvalue != oldvalue)
self.invalidate
end
@@ -634,7 +631,7 @@ class TextSlider < UIControl
end
def update
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
self.changed = false
if self.minvalue < self.maxvalue && self.curvalue < self.minvalue
self.curvalue = self.minvalue
@@ -832,7 +829,7 @@ class ControlWindow < SpriteWindow_Base
end
def hittest?(i)
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
return false if !mousepos
return false if i < 0 || i >= @controls.length
rc = Rect.new(

View File

@@ -24,7 +24,7 @@ class ControlPointSprite < SpriteWrapper
@dragging = false
return
end
mouse = Mouse::getMousePos(true)
mouse = Mouse.getMousePos(true)
return if !mouse
self.x = [[mouse[0], 0].max, 512].min
self.y = [[mouse[1], 0].max, 384].min
@@ -32,7 +32,7 @@ class ControlPointSprite < SpriteWrapper
def hittest?
return true if !self.visible
mouse = Mouse::getMousePos(true)
mouse = Mouse.getMousePos(true)
return false if !mouse
return mouse[0] >= self.x && mouse[0] < self.x + 6 &&
mouse[1] >= self.y && mouse[1] < self.y + 6
@@ -294,7 +294,7 @@ def pbDefinePath(canvas)
if Input.trigger?(Input::MOUSELEFT)
for j in 0...4
next if !curve[j].hittest?
if j == 1 || j == 2
if [1, 2].include?(j)
next if !curve[0].visible || !curve[3].visible
end
curve[j].visible = true
@@ -307,7 +307,7 @@ def pbDefinePath(canvas)
for j in 0...4
curve[j].mouseover
end
mousepos = Mouse::getMousePos(true)
mousepos = Mouse.getMousePos(true)
newtext = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
if window.text != newtext
window.text = newtext
@@ -376,11 +376,11 @@ def pbDefinePath(canvas)
if Input.trigger?(Input::MOUSELEFT)
break
end
mousepos = Mouse::getMousePos(true)
mousepos = Mouse.getMousePos(true)
window.text = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
end
while !canceled
mousepos = Mouse::getMousePos(true)
mousepos = Mouse.getMousePos(true)
if mousepos && !pointpath.isEndPoint?(mousepos[0], mousepos[1])
pointpath.addPoint(mousepos[0], mousepos[1])
points.push(PointSprite.new(mousepos[0], mousepos[1], canvas.viewport))

View File

@@ -102,11 +102,12 @@ def pbConvertAnimToNewFormat(textdata)
for j in 0...PBAnimation::MAX_SPRITES
next if !textdata[i][j]
textdata[i][j][AnimFrame::PRIORITY] = 1 if textdata[i][j][AnimFrame::PRIORITY] == nil
if j == 0 # User battler
case j
when 0 # User battler
textdata[i][j][AnimFrame::FOCUS] = 2
textdata[i][j][AnimFrame::X] = Battle::Scene::FOCUSUSER_X
textdata[i][j][AnimFrame::Y] = Battle::Scene::FOCUSUSER_Y
elsif j == 1 # Target battler
when 1 # Target battler
textdata[i][j][AnimFrame::FOCUS] = 1
textdata[i][j][AnimFrame::X] = Battle::Scene::FOCUSTARGET_X
textdata[i][j][AnimFrame::Y] = Battle::Scene::FOCUSTARGET_Y

View File

@@ -158,15 +158,16 @@ def pbAnimList(animations, canvas, animwin)
_INTL("Rename"),
_INTL("Delete")
], -1)
if cmd2 == 0 # Load Animation
case cmd2
when 0 # Load Animation
canvas.loadAnimation(animations[cmdwin.index])
animwin.animbitmap = canvas.animbitmap
animations.selected = cmdwin.index
break
elsif cmd2 == 1 # Rename
when 1 # Rename
pbAnimName(animations[cmdwin.index], cmdwin)
cmdwin.refresh
elsif cmd2 == 2 # Delete
when 2 # Delete
if pbConfirmMessage(_INTL("Are you sure you want to delete this animation?"))
animations[cmdwin.index] = PBAnimation.new
cmdwin.commands[cmdwin.index] = _INTL("{1} {2}", cmdwin.index, animations[cmdwin.index].name)
@@ -683,10 +684,8 @@ def pbEditBG(canvas, timing)
timing.colorBlue = maxsizewindow.value(6)
timing.colorAlpha = maxsizewindow.value(7)
ret = true
break
else
break
end
break
end
if maxsizewindow.changed?(9) # Cancel
break
@@ -1064,7 +1063,7 @@ def animationEditorMain(animation)
end
next
elsif Input.trigger?(Input::MOUSERIGHT) # Right mouse button
mousepos = Mouse::getMousePos
mousepos = Mouse.getMousePos
mousepos = [0, 0] if !mousepos
commands = [
_INTL("Properties..."),
@@ -1187,7 +1186,7 @@ end
# Start
################################################################################
def pbAnimationEditor
pbBGMStop()
pbBGMStop
animation = pbLoadBattleAnimations
if !animation || !animation[0]
animation = PBAnimations.new

View File

@@ -668,7 +668,7 @@ module MapSizeProperty
oldsetting = [0, ""] if !oldsetting
properties = [
[_INTL("Width"), NonzeroLimitProperty.new(30), _INTL("The width of this map in Region Map squares.")],
[_INTL("Valid Squares"), StringProperty, _INTL("A series of 1s and 0s marking which squares are part of this map (1=part, 0=not part).")],
[_INTL("Valid Squares"), StringProperty, _INTL("A series of 1s and 0s marking which squares are part of this map (1=part, 0=not part).")]
]
pbPropertyList(settingname, oldsetting, properties, false)
return oldsetting
@@ -760,10 +760,11 @@ module RegionMapCoordsProperty
def self.set(_settingname, oldsetting)
regions = self.getMapNameList
selregion = -1
if regions.length == 0
case regions.length
when 0
pbMessage(_INTL("No region maps are defined."))
return oldsetting
elsif regions.length == 1
when 1
selregion = regions[0][0]
else
cmds = []
@@ -1335,17 +1336,18 @@ class EvolutionsProperty
refreshlist = false
oldsel = -1
cmd = pbCommands3(cmdwin, commands, -1, cmd[1], true)
if cmd[0] == 1 # Swap evolution up
case cmd[0]
when 1 # Swap evolution up
if cmd[1] > 0 && cmd[1] < realcmds.length - 1
realcmds[cmd[1] + 1][3], realcmds[cmd[1]][3] = realcmds[cmd[1]][3], realcmds[cmd[1] + 1][3]
refreshlist = true
end
elsif cmd[0] == 2 # Swap evolution down
when 2 # Swap evolution down
if cmd[1] > 1
realcmds[cmd[1] - 1][3], realcmds[cmd[1]][3] = realcmds[cmd[1]][3], realcmds[cmd[1] - 1][3]
refreshlist = true
end
elsif cmd[0] == 0
when 0
if cmd[1] >= 0
entry = realcmds[cmd[1]]
if entry[3] == -1 # Add new evolution path
@@ -1450,7 +1452,7 @@ class EvolutionsProperty
else
cmd2 = pbMessage(_INTL("Save changes?"),
[_INTL("Yes"), _INTL("No"), _INTL("Cancel")], 3)
if cmd2 == 0 || cmd2 == 1
if [0, 1].include?(cmd2)
if cmd2 == 0
for i in 0...realcmds.length
realcmds[i].pop

View File

@@ -134,11 +134,12 @@ DebugMenuCommands.register("togglewallpapers", {
end
paperscmd = pbShowCommands(nil, paperscmds, -1, paperscmd)
break if paperscmd < 0
if paperscmd == 0 # Unlock all
case paperscmd
when 0 # Unlock all
for i in PokemonStorage::BASICWALLPAPERQTY...w.length
unlockarray[i] = true
end
elsif paperscmd == 1 # Lock all
when 1 # Lock all
for i in PokemonStorage::BASICWALLPAPERQTY...w.length
unlockarray[i] = false
end
@@ -715,9 +716,10 @@ DebugMenuCommands.register("setbadges", {
end
badgecmd = pbShowCommands(nil, badgecmds, -1, badgecmd)
break if badgecmd < 0
if badgecmd == 0 # Give all
case badgecmd
when 0 # Give all
24.times { |i| $player.badges[i] = true }
elsif badgecmd == 1 # Remove all
when 1 # Remove all
24.times { |i| $player.badges[i] = false }
else
$player.badges[badgecmd - 2] = !$player.badges[badgecmd - 2]

View File

@@ -61,15 +61,17 @@ class SpriteWindow_DebugVariables < Window_DrawableCommand
def shadowtext(x, y, w, h, t, align = 0, colors = 0)
width = self.contents.text_size(t).width
if align == 1 # Right aligned
case align
when 1 # Right aligned
x += (w - width)
elsif align == 2 # Centre aligned
when 2 # Centre aligned
x += (w / 2) - (width / 2)
end
base = Color.new(12 * 8, 12 * 8, 12 * 8)
if colors == 1 # Red
case colors
when 1 # Red
base = Color.new(168, 48, 56)
elsif colors == 2 # Green
when 2 # Green
base = Color.new(0, 144, 0)
end
pbDrawShadowText(self.contents, x, y, [width, w].max, h, t, base, Color.new(26 * 8, 26 * 8, 25 * 8))
@@ -160,14 +162,15 @@ def pbDebugVariables(mode)
break
end
current_id = right_window.index + 1
if mode == 0 # Switches
case mode
when 0 # Switches
if Input.trigger?(Input::USE)
pbPlayDecisionSE
$game_switches[current_id] = !$game_switches[current_id]
right_window.refresh
$game_map.need_refresh = true
end
elsif mode == 1 # Variables
when 1 # Variables
if Input.repeat?(Input::LEFT)
pbDebugSetVariable(current_id, -1)
right_window.refresh
@@ -175,14 +178,17 @@ def pbDebugVariables(mode)
pbDebugSetVariable(current_id, 1)
right_window.refresh
elsif Input.trigger?(Input::ACTION)
if $game_variables[current_id] == 0
case $game_variables[current_id]
when 0
$game_variables[current_id] = ""
elsif $game_variables[current_id] == ""
when ""
$game_variables[current_id] = 0
elsif $game_variables[current_id].is_a?(Numeric)
$game_variables[current_id] = 0
elsif $game_variables[current_id].is_a?(String)
$game_variables[current_id] = ""
else
if $game_variables[current_id].is_a?(Numeric)
$game_variables[current_id] = 0
elsif $game_variables[current_id].is_a?(String)
$game_variables[current_id] = ""
end
end
right_window.refresh
$game_map.need_refresh = true
@@ -366,15 +372,17 @@ class SpriteWindow_DebugRoamers < Window_DrawableCommand
def shadowtext(t, x, y, w, h, align = 0, colors = 0)
width = self.contents.text_size(t).width
if align == 1
case align
when 1
x += (w - width) # Right aligned
elsif align == 2
when 2
x += (w / 2) - (width / 2) # Centre aligned
end
base = Color.new(12 * 8, 12 * 8, 12 * 8)
if colors == 1
case colors
when 1
base = Color.new(168, 48, 56) # Red
elsif colors == 2
when 2
base = Color.new(0, 144, 0) # Green
end
pbDrawShadowText(self.contents, x, y, [width, w].max, h, t, base, Color.new(26 * 8, 26 * 8, 25 * 8))

View File

@@ -64,7 +64,6 @@ module FilenameUpdater
end
next if !changed
mapData.saveMap(id)
any_changed = true
ret.push(_INTL("Map {1}: '{2}' was modified and saved.", id, mapData.mapinfos[id].name))
end
Console.echo_done(true)
@@ -74,7 +73,6 @@ module FilenameUpdater
def rename_files
Console.echo_h1 "Updating file names and locations"
change_record = []
changed = false
# Add underscore to berry plant charsets
if rename_berry_plant_charsets
Console.echo_warn _INTL("Berry plant charset files were renamed.")

View File

@@ -187,9 +187,10 @@ class SpriteWindow_DebugBattleFieldEffects < Window_DrawableCommand
def shadowtext(x, y, w, h, t, align = 0, colors = 0)
width = self.contents.text_size(t).width
if align == 1 # Right aligned
case align
when 1 # Right aligned
x += w - width
elsif align == 2 # Centre aligned
when 2 # Centre aligned
x += (w - width) / 2
end
base_color = BASE_TEXT_COLOR
@@ -213,7 +214,8 @@ class SpriteWindow_DebugBattleFieldEffects < Window_DrawableCommand
rect = drawCursor(index, rect)
# Get value's text to draw
variable_text = variable.to_s
if variable_data[:default] == -1 # Battler
case variable_data[:default]
when -1 # Battler
if variable >= 0
battler_name = @battle.battlers[variable].name
battler_name = "-" if nil_or_empty?(battler_name)
@@ -221,7 +223,7 @@ class SpriteWindow_DebugBattleFieldEffects < Window_DrawableCommand
else
variable_text = _INTL("[None]")
end
elsif variable_data[:default] == nil # Move, item
when nil # Move, item
variable_text = _INTL("[None]") if !variable
end
# Draw text