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

@@ -99,7 +99,7 @@ class PokemonEggHatch_Scene
frames = (GameData::Species.cry_length(@pokemon) * Graphics.frame_rate).ceil
@pokemon.play_cry
updateScene(frames + 4)
pbBGMStop()
pbBGMStop
pbMEPlay("Evolution success")
@pokemon.name = nil
pbMessage(_INTL("\\se[]{1} hatched from the Egg!\\wt[80]", @pokemon.name)) { update }
@@ -135,8 +135,8 @@ class PokemonEggHatch_Scene
targets.push(@sprites["pokemon"].x)
targets.each_with_index do |target, i|
loop do
break if i % 2 == 0 && @sprites["pokemon"].x >= target
break if i % 2 == 1 && @sprites["pokemon"].x <= target
break if i.even? && @sprites["pokemon"].x >= target
break if i.odd? && @sprites["pokemon"].x <= target
@sprites["pokemon"].x += speed
@sprites["hatch"].x = @sprites["pokemon"].x
updateScene

View File

@@ -161,7 +161,7 @@ class HallOfFame_Scene
def xpositionformula(battlernumber)
ret = 0
if !SINGLEROW
ret = (battlernumber / 3 % 2 == 0) ? (19 - battlernumber) % 3 : (19 + battlernumber) % 3
ret = (battlernumber / 3).even? ? (19 - battlernumber) % 3 : (19 + battlernumber) % 3
else
ret = battlernumber % 2 * 2
end

View File

@@ -676,7 +676,7 @@ class PokemonPokedex_Scene
end
end
# Draw selected option(s) button graphic
if mode == 3 || mode == 4 # Height, weight
if [3, 4].include?(mode) # Height, weight
xpos1 = xstart + (sel[0] + 1) * xgap
xpos1 = xstart if sel[0] < -1
xpos2 = xstart + (sel[1] + 1) * xgap
@@ -696,11 +696,10 @@ class PokemonPokedex_Scene
textpos.push([txt2, xpos2 + halfwidth, ypos2, 2, base, nil, 1])
else
for i in 0...sel.length
selrect = Rect.new(0, selbuttony, @selbitmap.bitmap.width, selbuttonheight)
if sel[i] >= 0
selrect = Rect.new(0, selbuttony, @selbitmap.bitmap.width, selbuttonheight)
overlay.blt(xstart + (sel[i] % cols) * xgap, ystart + (sel[i] / cols).floor * ygap, @selbitmap.bitmap, selrect)
else
selrect = Rect.new(0, selbuttony, @selbitmap.bitmap.width, selbuttonheight)
overlay.blt(xstart + (cols - 1) * xgap, ystart + (cmds.length / cols).floor * ygap, @selbitmap.bitmap, selrect)
end
end
@@ -903,7 +902,7 @@ class PokemonPokedex_Scene
oldindex = index
minmax = 1
oldminmax = minmax
if mode == 3 || mode == 4
if [3, 4].include?(mode)
index = oldindex = selindex[minmax]
end
@sprites["searchcursor"].mode = mode
@@ -922,7 +921,7 @@ class PokemonPokedex_Scene
end
Graphics.update
Input.update
if mode == 3 || mode == 4
if [3, 4].include?(mode)
if Input.trigger?(Input::UP)
if index < -1 # From OK/Cancel
minmax = 0
@@ -936,10 +935,11 @@ class PokemonPokedex_Scene
pbRefreshDexSearchParam(mode, cmds, selindex, index)
end
elsif Input.trigger?(Input::DOWN)
if minmax == 1
case minmax
when 1
minmax = 0
index = selindex[minmax]
elsif minmax == 0
when 0
minmax = -1
index = -2
end
@@ -1131,7 +1131,7 @@ class PokemonPokedex_Scene
end
pbPlayCursorSE if index != oldindex
elsif Input.trigger?(Input::DOWN)
if index == 4 || index == 6
if [4, 6].include?(index)
index = 8
elsif index < 7
index += 1
@@ -1151,7 +1151,7 @@ class PokemonPokedex_Scene
index = 5
elsif index >= 2 && index <= 4
index = 6
elsif index == 7 || index == 8
elsif [7, 8].include?(index)
index += 1
end
pbPlayCursorSE if index != oldindex

View File

@@ -383,7 +383,7 @@ class PokemonPokedexInfo_Scene
end
textpos = [
[GameData::Species.get(@species).name, Graphics.width / 2, Graphics.height - 94, 2, base, shadow],
[formname, Graphics.width / 2, Graphics.height - 62, 2, base, shadow],
[formname, Graphics.width / 2, Graphics.height - 62, 2, base, shadow]
]
# Draw all text
pbDrawTextPositions(overlay, textpos)
@@ -464,12 +464,13 @@ class PokemonPokedexInfo_Scene
pbPlayCloseMenuSE
break
elsif Input.trigger?(Input::USE)
if @page == 1 # Info
case @page
when 1 # Info
@show_battled_count = !@show_battled_count
dorefresh = true
elsif @page == 2 # Area
when 2 # Area
# dorefresh = true
elsif @page == 3 # Forms
when 3 # Forms
if @available.length > 1
pbPlayDecisionSE
pbChooseForm

View File

@@ -679,7 +679,7 @@ class PokemonParty_Scene
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, bag)
ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).can_hold? })
ret = screen.pbChooseItemScreen(proc { |item| GameData::Item.get(item).can_hold? })
yield if block_given?
}
return ret
@@ -690,7 +690,7 @@ class PokemonParty_Scene
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, bag)
ret = screen.pbChooseItemScreen(Proc.new { |item|
ret = screen.pbChooseItemScreen(proc { |item|
itm = GameData::Item.get(item)
next false if !pbCanUseOnPokemon?(itm)
if itm.is_machine?
@@ -1023,8 +1023,6 @@ class PokemonPartyScreen
addedEntry = false
for i in 0...@party.length
statuses[i] = (ruleset.isPokemonValid?(@party[i])) ? 1 : 2
end
for i in 0...@party.length
annot[i] = ordinals[statuses[i]]
end
@scene.pbStartScene(@party, _INTL("Choose Pokémon and confirm."), annot, true)

View File

@@ -212,14 +212,14 @@ class PokemonSummary_Scene
def pbDisplay(text)
@sprites["messagebox"].text = text
@sprites["messagebox"].visible = true
pbPlayDecisionSE()
pbPlayDecisionSE
loop do
Graphics.update
Input.update
pbUpdate
if @sprites["messagebox"].busy?
if Input.trigger?(Input::USE)
pbPlayDecisionSE() if @sprites["messagebox"].pausing?
pbPlayDecisionSE if @sprites["messagebox"].pausing?
@sprites["messagebox"].resume
end
elsif Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
@@ -393,7 +393,7 @@ class PokemonSummary_Scene
[@pokemon.speciesName, 435, 106, 2, Color.new(64, 64, 64), Color.new(176, 176, 176)],
[_INTL("Type"), 238, 138, 0, base, shadow],
[_INTL("OT"), 238, 170, 0, base, shadow],
[_INTL("ID No."), 238, 202, 0, base, shadow],
[_INTL("ID No."), 238, 202, 0, base, shadow]
]
# Write the Regional/National Dex number
dexnum = 0
@@ -836,7 +836,7 @@ class PokemonSummary_Scene
# Write various bits of text
textpos = [
[_INTL("No. of Ribbons:"), 234, 326, 0, Color.new(64, 64, 64), Color.new(176, 176, 176)],
[@pokemon.numRibbons.to_s, 450, 326, 1, Color.new(64, 64, 64), Color.new(176, 176, 176)],
[@pokemon.numRibbons.to_s, 450, 326, 1, Color.new(64, 64, 64), Color.new(176, 176, 176)]
]
# Draw all text
pbDrawTextPositions(overlay, textpos)
@@ -1097,11 +1097,12 @@ class PokemonSummary_Scene
# Reposition the cursor
@sprites["markingsel"].x = 284 + 58 * (index % 3)
@sprites["markingsel"].y = 144 + 50 * (index / 3)
if index == 6 # OK
case index
when 6 # OK
@sprites["markingsel"].x = 284
@sprites["markingsel"].y = 244
@sprites["markingsel"].src_rect.y = @sprites["markingsel"].bitmap.height / 2
elsif index == 7 # Cancel
when 7 # Cancel
@sprites["markingsel"].x = 284
@sprites["markingsel"].y = 294
@sprites["markingsel"].src_rect.y = @sprites["markingsel"].bitmap.height / 2
@@ -1116,10 +1117,11 @@ class PokemonSummary_Scene
break
elsif Input.trigger?(Input::USE)
pbPlayDecisionSE
if index == 6 # OK
case index
when 6 # OK
ret = markings
break
elsif index == 7 # Cancel
when 7 # Cancel
break
else
markings[index] = ((markings[index] || 0) + 1) % mark_variants
@@ -1197,7 +1199,7 @@ class PokemonSummary_Scene
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, $bag)
item = screen.pbChooseItemScreen(Proc.new { |itm| GameData::Item.get(itm).can_hold? })
item = screen.pbChooseItemScreen(proc { |itm| GameData::Item.get(itm).can_hold? })
}
if item
dorefresh = pbGiveItemToPokemon(item, @pokemon, self, @partyindex)

View File

@@ -42,7 +42,7 @@ class PokegearButton < SpriteWrapper
rect.y = @button.height / 2 if @selected
self.bitmap.blt(0, 0, @button.bitmap, rect)
textpos = [
[@name, self.bitmap.width / 2, 4, 2, Color.new(248, 248, 248), Color.new(40, 40, 40)],
[@name, self.bitmap.width / 2, 4, 2, Color.new(248, 248, 248), Color.new(40, 40, 40)]
]
pbDrawTextPositions(self.bitmap, textpos)
imagepos = [

View File

@@ -408,13 +408,13 @@ class PokemonOption_Scene
@PokemonOptions[i].set(@sprites["option"][i])
end
if $PokemonSystem.textskin != oldTextSkin
@sprites["textbox"].setSkin(MessageConfig.pbGetSpeechFrame())
@sprites["textbox"].setSkin(MessageConfig.pbGetSpeechFrame)
@sprites["textbox"].text = _INTL("Speech frame {1}.", 1 + $PokemonSystem.textskin)
oldTextSkin = $PokemonSystem.textskin
end
if $PokemonSystem.frame != oldSystemSkin
@sprites["title"].setSkin(MessageConfig.pbGetSystemFrame())
@sprites["option"].setSkin(MessageConfig.pbGetSystemFrame())
@sprites["title"].setSkin(MessageConfig.pbGetSystemFrame)
@sprites["option"].setSkin(MessageConfig.pbGetSystemFrame)
oldSystemSkin = $PokemonSystem.frame
end
end

View File

@@ -71,7 +71,7 @@ class ReadyMenuButton < SpriteWrapper
self.bitmap.blt(0, 0, @button.bitmap, rect)
textx = (@command[2]) ? 164 : (GameData::Item.get(@command[0]).is_important?) ? 146 : 124
textpos = [
[@command[1], textx, 16, 2, Color.new(248, 248, 248), Color.new(40, 40, 40), 1],
[@command[1], textx, 16, 2, Color.new(248, 248, 248), Color.new(40, 40, 40), 1]
]
if !@command[2]
if !GameData::Item.get(@command[0]).is_important?
@@ -206,11 +206,12 @@ class PokemonReadyMenu_Scene
oldindex = @index[@index[2]]
@index[@index[2]] = @sprites["cmdwindow"].index
if @index[@index[2]] != oldindex
if @index[2] == 0
case @index[2]
when 0
for i in 0...@commands[0].length
@sprites["movebutton#{i}"].selected = @index[@index[2]]
end
elsif @index[2] == 1
when 1
for i in 0...@commands[1].length
@sprites["itembutton#{i}"].selected = @index[@index[2]]
end

View File

@@ -617,12 +617,11 @@ class PokemonStorageScene
if command != 2
pbSetArrow(@sprites["arrow"], @selection)
pbUpdateOverlay(@selection)
pbSetMosaic(@selection)
else
pbPartySetArrow(@sprites["arrow"], @selection)
pbUpdateOverlay(@selection, @storage.party)
pbSetMosaic(@selection)
end
pbSetMosaic(@selection)
pbSEPlay("PC access")
pbFadeInAndShow(@sprites)
end
@@ -714,22 +713,24 @@ class PokemonStorageScene
def pbChangeSelection(key, selection)
case key
when Input::UP
if selection == -1 # Box name
case selection
when -1 # Box name
selection = -2
elsif selection == -2 # Party
when -2 # Party
selection = PokemonBox::BOX_SIZE - 1 - PokemonBox::BOX_WIDTH * 2 / 3 # 25
elsif selection == -3 # Close Box
when -3 # Close Box
selection = PokemonBox::BOX_SIZE - PokemonBox::BOX_WIDTH / 3 # 28
else
selection -= PokemonBox::BOX_WIDTH
selection = -1 if selection < 0
end
when Input::DOWN
if selection == -1 # Box name
case selection
when -1 # Box name
selection = PokemonBox::BOX_WIDTH / 3 # 2
elsif selection == -2 # Party
when -2 # Party
selection = -1
elsif selection == -3 # Close Box
when -3 # Close Box
selection = -1
else
selection += PokemonBox::BOX_WIDTH
@@ -830,16 +831,17 @@ class PokemonStorageScene
pbPlayCursorSE
selection = pbChangeSelection(key, selection)
pbSetArrow(@sprites["arrow"], selection)
if selection == -4
case selection
when -4
nextbox = (@storage.currentBox + @storage.maxBoxes - 1) % @storage.maxBoxes
pbSwitchBoxToLeft(nextbox)
@storage.currentBox = nextbox
elsif selection == -5
when -5
nextbox = (@storage.currentBox + 1) % @storage.maxBoxes
pbSwitchBoxToRight(nextbox)
@storage.currentBox = nextbox
end
selection = -1 if selection == -4 || selection == -5
selection = -1 if [-4, -5].include?(selection)
pbUpdateOverlay(selection)
pbSetMosaic(selection)
end
@@ -932,9 +934,10 @@ class PokemonStorageScene
if key >= 0
pbPlayCursorSE
newselection = pbPartyChangeSelection(key, selection)
if newselection == -1
case newselection
when -1
return -1 if !depositing
elsif newselection == -2
when -2
selection = lastsel
else
selection = newselection
@@ -1217,7 +1220,7 @@ class PokemonStorageScene
pbFadeOutIn {
scene = PokemonBag_Scene.new
screen = PokemonBagScreen.new(scene, bag)
ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).can_hold? })
ret = screen.pbChooseItemScreen(proc { |item| GameData::Item.get(item).can_hold? })
}
return ret
end
@@ -1352,10 +1355,11 @@ class PokemonStorageScene
break
elsif Input.trigger?(Input::USE)
pbPlayDecisionSE
if index == 6 # OK
case index
when 6 # OK
pokemon.markings = markings
break
elsif index == 7 # Cancel
when 7 # Cancel
break
else
markings[index] = ((markings[index] || 0) + 1) % mark_variants
@@ -1399,7 +1403,7 @@ class PokemonStorageScene
buttonshadow = Color.new(80, 80, 80)
pbDrawTextPositions(overlay, [
[_INTL("Party: {1}", (@storage.party.length rescue 0)), 270, 326, 2, buttonbase, buttonshadow, 1],
[_INTL("Exit"), 446, 326, 2, buttonbase, buttonshadow, 1],
[_INTL("Exit"), 446, 326, 2, buttonbase, buttonshadow, 1]
])
pokemon = nil
if @screen.pbHeldPokemon
@@ -1478,7 +1482,8 @@ class PokemonStorageScreen
def pbStartScreen(command)
$game_temp.in_storage = true
@heldpkmn = nil
if command == 0 # Organise
case command
when 0 # Organise
@scene.pbStartBox(self, command)
loop do
selected = @scene.pbSelectBox(@storage.party)
@@ -1559,7 +1564,7 @@ class PokemonStorageScreen
end
end
@scene.pbCloseBox
elsif command == 1 # Withdraw
when 1 # Withdraw
@scene.pbStartBox(self, command)
loop do
selected = @scene.pbSelectBox(@storage.party)
@@ -1599,7 +1604,7 @@ class PokemonStorageScreen
end
end
@scene.pbCloseBox
elsif command == 2 # Deposit
when 2 # Deposit
@scene.pbStartBox(self, command)
loop do
selected = @scene.pbSelectParty(@storage.party)
@@ -1631,7 +1636,7 @@ class PokemonStorageScreen
end
end
@scene.pbCloseBox
elsif command == 3
when 3
@scene.pbStartBox(self, command)
@scene.pbCloseBox
end
@@ -1921,7 +1926,7 @@ class PokemonStorageScreen
_INTL("Jump"),
_INTL("Wallpaper"),
_INTL("Name"),
_INTL("Cancel"),
_INTL("Cancel")
]
command = pbShowCommands(
_INTL("What do you want to do?"), commands)

View File

@@ -47,12 +47,13 @@ class StorageSystemPC
_INTL("Return to the previous menu.")], -1, command
)
if command >= 0 && command < 3
if command == 1 # Withdraw
case command
when 1 # Withdraw
if $PokemonStorage.party_full?
pbMessage(_INTL("Your party is full!"))
next
end
elsif command == 2 # Deposit
when 2 # Deposit
count = 0
for p in $PokemonStorage.party
count += 1 if p && !p.egg? && p.hp > 0

View File

@@ -291,7 +291,7 @@ module PurifyChamberHelper
return chamber.getShadow(set)
elsif position > 0
position -= 1
if position % 2 == 0
if position.even?
return chamber[set, position / 2]
else # In between two indices
return nil
@@ -305,7 +305,7 @@ module PurifyChamberHelper
return chamber.getShadow(chamber.currentSet)
elsif position > 0
position -= 1
if position % 2 == 0
if position.even?
return chamber[chamber.currentSet, position / 2]
else # In between two indices
return nil
@@ -318,7 +318,7 @@ module PurifyChamberHelper
if position > 0
position -= 1
oldpos = position / 2
if position % 2 == 0
if position.even?
return position + 1
else
return ((oldpos + 1) * 2) + 1
@@ -332,7 +332,7 @@ module PurifyChamberHelper
chamber.setShadow(chamber.currentSet, value)
elsif position > 0
position -= 1
if position % 2 == 0
if position.even?
chamber.insertAt(chamber.currentSet, position / 2, value)
else # In between two indices
chamber.insertAfter(chamber.currentSet, position / 2, value)
@@ -612,11 +612,12 @@ class PurifyChamberScreen
_INTL("What do you want to do?"),
[_INTL("EDIT"), _INTL("SWITCH"), _INTL("CANCEL")]
)
if cmd == 0 # edit
case cmd
when 0 # edit
if !pbOpenSetDetail
break
end
elsif cmd == 1 # switch
when 1 # switch
chamber.currentSet = set
newSet = @scene.pbSwitch(set)
chamber.switch(set, newSet)
@@ -900,19 +901,20 @@ class PurifyChamberSetView < SpriteWrapper
pos /= 2
end
seg = pos * 8 / points
if seg == 7 || seg == 0
case seg
when 7, 0
pos -= 1 if button == Input::LEFT
pos += 1 if button == Input::RIGHT
pos = nil if button == Input::DOWN
elsif seg == 1 || seg == 2
when 1, 2
pos -= 1 if button == Input::UP
pos += 1 if button == Input::DOWN
pos = nil if button == Input::LEFT
elsif seg == 3 || seg == 4
when 3, 4
pos -= 1 if button == Input::RIGHT
pos += 1 if button == Input::LEFT
pos = nil if button == Input::UP
elsif seg == 5 || seg == 6
when 5, 6
pos -= 1 if button == Input::DOWN
pos += 1 if button == Input::UP
pos = nil if button == Input::RIGHT
@@ -986,7 +988,7 @@ class PurifyChamberSetView < SpriteWrapper
setList = @chamber.setList(@set)
refreshFlows
for i in 0...PurifyChamber::SETSIZE * 2
pkmn = (i % 2 == 1 || i >= points) ? nil : setList[i / 2]
pkmn = (i.odd? || i >= points) ? nil : setList[i / 2]
angle = 360 - (i * 360 / points)
angle += 90 # start at 12 not 3 o'clock
if pkmn && @chamber[@set].facing == i / 2

View File

@@ -182,18 +182,19 @@ def pbManageMysteryGifts
_INTL("Delete"),
_INTL("Cancel")]
cmd = pbMessage("\\ts[]" + commands[command], cmds, -1, nil, cmd)
if cmd == -1 || cmd == cmds.length - 1
case cmd
when -1, cmds.length - 1
break
elsif cmd == 0 # Toggle on/offline
when 0 # Toggle on/offline
if online.include?(gift[0])
online.delete(gift[0])
else
online.push(gift[0])
end
elsif cmd == 1 # Edit
when 1 # Edit
newgift = pbEditMysteryGift(gift[1], gift[2], gift[0], gift[3])
master[command] = newgift if newgift
elsif cmd == 2 # Receive
when 2 # Receive
if !$player
pbMessage(_INTL("There is no save file loaded. Cannot receive any gifts."))
next
@@ -207,7 +208,7 @@ def pbManageMysteryGifts
end
$player.mystery_gifts.push(gift) if !replaced
pbReceiveMysteryGift(gift[0])
elsif cmd == 3 # Delete
when 3 # Delete
master.delete_at(command) if pbConfirmMessage(_INTL("Are you sure you want to delete this gift?"))
break
end
@@ -381,13 +382,8 @@ def pbReceiveMysteryGift(id)
gift[2].timeReceived = time.getgm.to_i
gift[2].obtain_method = 4 # Fateful encounter
gift[2].record_first_moves
if $game_map
gift[2].obtain_map = $game_map.map_id
gift[2].obtain_level = gift[2].level
else
gift[2].obtain_map = 0
gift[2].obtain_level = gift[2].level
end
gift[2].obtain_level = gift[2].level
gift[2].obtain_map = $game_map&.map_id || 0
if pbAddPokemonSilent(gift[2])
pbMessage(_INTL("\\me[Pkmn get]{1} received {2}!", $player.name, gift[2].name))
$player.mystery_gifts[index] = [id]

View File

@@ -72,7 +72,7 @@ end
class PokemonEntryScene
@@Characters = [
[("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").scan(/./), "[*]"],
[("0123456789 !@\#$%^&*() ~`-_+={}[] :;'\"<>,.?/ ").scan(/./), "[A]"],
[("0123456789 !@\#$%^&*() ~`-_+={}[] :;'\"<>,.?/ ").scan(/./), "[A]"]
]
USEKEYBOARD = true
@@ -212,28 +212,28 @@ class PokemonEntryScene
if index == -3 # Confirm text
ret = @sprites["entry"].text
if ret.length < @minlength || ret.length > @maxlength
pbPlayBuzzerSE()
pbPlayBuzzerSE
else
pbPlayDecisionSE()
pbPlayDecisionSE
break
end
elsif index == -1 # Insert a space
if @sprites["entry"].insert(" ")
pbPlayDecisionSE()
pbPlayDecisionSE
else
pbPlayBuzzerSE()
pbPlayBuzzerSE
end
elsif index == -2 # Change character set
pbPlayDecisionSE()
pbPlayDecisionSE
@symtype += 1
@symtype = 0 if @symtype >= @@Characters.length
@sprites["entry2"].setCharset(@@Characters[@symtype][0])
@sprites["entry2"].setOtherCharset(@@Characters[@symtype][1])
else # Insert given character
if @sprites["entry"].insert(@sprites["entry2"].character)
pbPlayDecisionSE()
pbPlayDecisionSE
else
pbPlayBuzzerSE()
pbPlayBuzzerSE
end
end
next