Resolved many Rubocop warnings

This commit is contained in:
Maruno17
2020-09-06 17:31:12 +01:00
parent 6c4670eaa3
commit 681a8331ab
137 changed files with 921 additions and 1200 deletions

View File

@@ -6,7 +6,7 @@ end
def pbGetExceptionMessage(e,script="")
def pbGetExceptionMessage(e,_script="")
emessage = e.message
if e.is_a?(Hangup)
emessage = "The script is taking too long. The game will restart."
@@ -37,7 +37,7 @@ def pbGetExceptionMessage(e,script="")
end
def pbPrintException(e)
premessage = "\r\n=================\r\n\r\n[#{Time.now.to_s}]\r\n"
premessage = "\r\n=================\r\n\r\n[#{Time.now}]\r\n"
emessage = ""
if $EVENTHANGUPMSG && $EVENTHANGUPMSG!=""
emessage = $EVENTHANGUPMSG # Message with map/event ID generated elsewhere
@@ -365,19 +365,17 @@ def csvfield!(str)
return ret
end
def csvBoolean!(str,line=-1)
def csvBoolean!(str,_line=-1)
field = csvfield!(str)
if field[/^1|[Tt][Rr][Uu][Ee]|[Yy][Ee][Ss]|[Yy]$/]
return true
elsif field[/^0|[Ff][Aa][Ll][Ss][Ee]|[Nn][Oo]|[Nn]$/]
return false
else
raise _INTL("Field {1} is not a Boolean value (true, false, 1, 0)\r\n{2}",field,FileLineData.linereport)
return false
end
raise _INTL("Field {1} is not a Boolean value (true, false, 1, 0)\r\n{2}",field,FileLineData.linereport)
end
def csvInt!(str,line=-1)
def csvInt!(str,_line=-1)
ret = csvfield!(str)
if !ret[/^\-?\d+$/]
raise _INTL("Field {1} is not an integer\r\n{2}",ret,FileLineData.linereport)
@@ -385,7 +383,7 @@ def csvInt!(str,line=-1)
return ret.to_i
end
def csvPosInt!(str,line=-1)
def csvPosInt!(str,_line=-1)
ret = csvfield!(str)
if !ret[/^\d+$/]
raise _INTL("Field {1} is not a positive integer\r\n{2}",ret,FileLineData.linereport)
@@ -393,17 +391,17 @@ def csvPosInt!(str,line=-1)
return ret.to_i
end
def csvFloat!(str,line=-1)
def csvFloat!(str,_line=-1)
ret = csvfield!(str)
return Float(ret) rescue raise _INTL("Field {1} is not a number\r\n{2}",ret,FileLineData.linereport)
end
def csvEnumField!(value,enumer,key,section)
def csvEnumField!(value,enumer,_key,_section)
ret = csvfield!(value)
return checkEnumField(ret,enumer)
end
def csvEnumFieldOrInt!(value,enumer,key,section)
def csvEnumFieldOrInt!(value,enumer,_key,_section)
ret = csvfield!(value)
return ret.to_i if ret[/\-?\d+/]
return checkEnumField(ret,enumer)
@@ -885,8 +883,8 @@ def pbAddScript(script,sectionname)
rescue
scripts = []
end
s = pbFindScript(scripts,sectionname)
if false#s
if false # s
s = pbFindScript(scripts,sectionname)
s[2]+=Zlib::Deflate.deflate("#{script}\r\n")
else
scripts.push([rand(100000000),sectionname,Zlib::Deflate.deflate("#{script}\r\n")])
@@ -967,7 +965,7 @@ def readSerialRecords(filename)
pbRgssOpen(filename,"rb") { |file|
numrec = file.fgetdw>>3
curpos = 0
for i in 0...numrec
numrec.times do
file.pos = curpos
offset = file.fgetdw
length = file.fgetdw
@@ -1026,7 +1024,7 @@ class ByteArray
return self.new(str)
end
def _dump(depth=100)
def _dump(_depth=100)
return @a.pack("C*")
end
end
@@ -1060,7 +1058,7 @@ class WordArray
return self.new(str)
end
def _dump(depth=100)
def _dump(_depth=100)
return @a.pack("v*")
end
end
@@ -1101,7 +1099,7 @@ class SignedWordArray
return self.new(str)
end
def _dump(depth=100)
def _dump(_depth=100)
return @a.pack("v*")
end
end

View File

@@ -98,8 +98,6 @@ end
#===============================================================================
def pbCompileConnections
records = []
constants = ""
itemnames = []
pbCompilerEachPreppedLine("PBS/connections.txt") { |line,lineno|
hashenum = {
"N" => "N","North" => "N",
@@ -141,7 +139,7 @@ end
def pbCompileBerryPlants
sections = []
if File.exists?("PBS/berryplants.txt")
pbCompilerEachCommentedLine("PBS/berryplants.txt") { |line,lineno|
pbCompilerEachCommentedLine("PBS/berryplants.txt") { |line,_lineno|
if line[ /^\s*(\w+)\s*=\s*(.*)$/ ]
key = $1
value = $2
@@ -335,10 +333,8 @@ end
def pbCompileTypes
pbWriteDefaultTypes
sections = []
typechart = []
types = []
nameToType = {}
requiredtypes = {
"Name" => [1, "s"],
"InternalName" => [2, "s"],
@@ -428,7 +424,8 @@ def pbCompileTypes
count = maxValue+1
for i in 0...count
type = typehash[i]
j = 0; k = i; while j<count
j = 0; k = i
while j<count
typechart[k] = PBTypeEffectiveness::NORMAL_EFFECTIVE_ONE
atype = typehash[j]
if type && atype
@@ -526,7 +523,7 @@ def readItemList(filename)
pbRgssOpen(filename,"rb") { |file|
numrec = file.fgetdw>>3
curpos = 0
for i in 0...numrec
numrec.times do
file.pos = curpos
offset = file.fgetdw
length = file.fgetdw
@@ -601,7 +598,6 @@ def pbCompileMoves
maxValue = 0
count = 0
pbCompilerEachPreppedLine("PBS/moves.txt") { |line,lineno|
thisline = line.clone
record = []
lineRecord = pbGetCsvRecord(line,lineno,[0,"vnssueeuuuyiss",
nil,nil,nil,nil,nil,PBTypes,["Physical","Special","Status"],
@@ -939,11 +935,9 @@ def pbCompilePokemonForms
# Ensure this is a valid form and not a duplicate.
if form==0
raise _INTL("Form {1} is invalid (PBS/pokemonforms.txt). Form 0 data should be defined in \"PBS/pokemon.txt\".",sectionName)
next
end
if formToSpecies[baseSpeciesID] && formToSpecies[baseSpeciesID][form]
raise _INTL("Form {1} is defined at least twice (PBS/pokemonforms.txt). It should only be defined once.",sectionName)
next
end
# Record new species number in formToSpecies.
speciesID = baseSpeciesID
@@ -1160,7 +1154,7 @@ def pbTMRS # Backup Gen 3 TM list
:CUT,:FLY,:SURF,:STRENGTH,:FLASH,:ROCKSMASH,:WATERFALL,:DIVE
]
ret = []
for i in 0...rstm.length
rstm.length.times do
ret.push((parseMove(rstm.to_s) rescue 0))
end
return ret
@@ -1231,7 +1225,7 @@ end
def pbCompileShadowMoves
sections = []
if File.exists?("PBS/shadowmoves.txt")
pbCompilerEachCommentedLine("PBS/shadowmoves.txt") { |line,lineno|
pbCompilerEachCommentedLine("PBS/shadowmoves.txt") { |line,_lineno|
if line[ /^\s*(\w+)\s*=\s*(.*)$/ ]
key = $1
value = $2
@@ -1272,11 +1266,10 @@ def pbCompileEncounters
}
encounters = {}
thisenc = nil
lastenc = -1
lastenclen = 0
needdensity = false
lastmapid = -1
i = 0; while i<lines.length
i = 0
while i<lines.length
line = lines[i]
FileLineData.setLine(line,linenos[i])
mapid = line[/^\d+$/]
@@ -1301,7 +1294,8 @@ def pbCompileEncounters
needdensity = false
enclines = EncounterTypes::EnctypeChances[enc].length
encarray = []
j = i+1; k = 0; while j<lines.length && k<enclines
j = i+1; k = 0
while j<lines.length && k<enclines
line = lines[j]
FileLineData.setLine(lines[j],linenos[j])
splitarr = strsplit(line,/\s*,\s*/)
@@ -1360,7 +1354,6 @@ def pbCompileTrainerTypes
# Trainer types
records = []
trainernames = []
count = 0
maxValue = 0
pbCompilerEachPreppedLine("PBS/trainertypes.txt") { |line,lineno|
record=pbGetCsvRecord(line,lineno,[0,"unsUSSSeUS", # ID can be 0
@@ -1674,7 +1667,6 @@ def pbCompileTrainerLists
f.write("Pokemon = btpokemon.txt\r\n")
}
end
database = []
sections = []
MessageTypes.setMessagesAsHash(MessageTypes::BeginSpeech,[])
MessageTypes.setMessagesAsHash(MessageTypes::EndSpeechWin,[])
@@ -1709,7 +1701,7 @@ def pbCompileTrainerLists
if safeExists?("PBS/"+rsection[1])
filename = "PBS/"+rsection[1]
rsection[1] = []
pbCompilerEachCommentedLine(filename) { |line,lineno|
pbCompilerEachCommentedLine(filename) { |line,_lineno|
rsection[1].push(PBPokemon.fromInspected(line))
}
else

View File

@@ -56,7 +56,8 @@ def pbGenerateMoveRoute(commands)
route.repeat = false
route.skippable = true
route.list.clear
i = 0; while i<commands.length
i = 0
while i<commands.length
case commands[i]
when PBMoveRoute::Wait, PBMoveRoute::SwitchOn, PBMoveRoute::SwitchOff,
PBMoveRoute::ChangeSpeed, PBMoveRoute::ChangeFreq, PBMoveRoute::Opacity,
@@ -224,7 +225,8 @@ def pbEventId(event)
list = event.pages[0].list
return nil if list.length==0
codes = []
i = 0; while i<list.length
i = 0
while i<list.length
codes.push(list[i].code)
i += 1
end
@@ -726,19 +728,16 @@ def pbConvertToItemEvent(event)
ret.name = event.name
ret.id = event.id
ret.pages = []
itemid = nil
itemName = ""
hidden = false
if name[/^HiddenItem\:\s*(\w+)\s*$/]
itemName = $1
return nil if !hasConst?(PBItems,itemName)
itemid = PBItems.const_get(itemName)
ret.name = "HiddenItem"
hidden = true
elsif name[/^Item\:\s*(\w+)\s*$/]
itemName = $1
return nil if !hasConst?(PBItems,itemName)
itemid = PBItems.const_get(itemName)
ret.name = "Item"
else
return nil
@@ -885,7 +884,7 @@ def pbChangeScripts(script)
return changed
end
def pbFixEventUse(event,mapID,mapData)
def pbFixEventUse(event,_mapID,mapData)
return nil if pbEventIsEmpty?(event)
changed = false
trainerMoneyRE = /^\s*\$Trainer\.money\s*(<|<=|>|>=)\s*(\d+)\s*$/
@@ -1033,22 +1032,22 @@ def pbFixEventUse(event,mapID,mapData)
changed = true
end
deletedRoute = nil
deleteMoveRouteAt = proc { |list,_i|
deleteMoveRouteAt = proc { |list,i|
arr = []
if list[_i] && list[_i].code==209 # Set Move Route
arr.push(list[_i]); list.delete_at(_i)
while _i<list.length
break if !list[_i] || list[_i].code!=509 # Set Move Route (continuation line)
arr.push(list[_i]); list.delete_at(_i)
if list[i] && list[i].code==209 # Set Move Route
arr.push(list[i]); list.delete_at(i)
while i<list.length
break if !list[i] || list[i].code!=509 # Set Move Route (continuation line)
arr.push(list[i]); list.delete_at(i)
end
end
next arr
}
insertMoveRouteAt = proc { |list,_i,route|
_j = route.length-1
while _j>=0
list.insert(_i,route[_j])
_j -= 1
insertMoveRouteAt = proc { |list,i,route|
j = route.length-1
while j>=0
list.insert(i,route[j])
j -= 1
end
}
# If the next event command is a Move Route that moves the player,
@@ -1163,7 +1162,8 @@ def pbFixEventUse(event,mapID,mapData)
# Split Show Text commands with 5+ lines into multiple Show Text
# commands each with a maximum of 4 lines
lines = 1
j = i+1; while j<list.length
j = i+1
while j<list.length
break if list[j].code!=401 # Show Text (continuation line)
if lines%4==0
list[j].code = 101 # Show Text
@@ -1189,7 +1189,8 @@ def pbFixEventUse(event,mapID,mapData)
lastLine = list[i+lines-1].parameters[0].sub(/\s+$/,"")
if lastLine.length>0 && !lastLine[/[\\<]/] && lastLine[/[^\.,\!\?\;\-\"]$/]
message = list[i].parameters[0]
j = i+1; while j<list.length
j = i+1
while j<list.length
break if list[j].code!=401 # Show Text (continuation line)
message += "\n"+list[j].parameters[0]
j += 1
@@ -1207,11 +1208,13 @@ def pbFixEventUse(event,mapID,mapData)
nextMessage = message[punct+1,message.length].sub(/^\s+/,"").split("\n")
list[i+lines].code = 401
lines.times { list.delete_at(i) }
j = nextMessage.length-1; while j>=0
j = nextMessage.length-1
while j>=0
list.insert(i,RPG::EventCommand.new((j==0) ? 101 : 401,indent,[nextMessage[j]]))
j-=1
end
j = newMessage.length-1; while j>=0
j = newMessage.length-1
while j>=0
list.insert(i,RPG::EventCommand.new((j==0) ? 101 : 401,indent,[newMessage[j]]))
j -= 1
end
@@ -1404,7 +1407,7 @@ end
#===============================================================================
# Main compiler method for events
#===============================================================================
def pbCompileTrainerEvents(mustcompile)
def pbCompileTrainerEvents(_mustcompile)
mapData = MapData.new
t = Time.now.to_i
Graphics.update
@@ -1443,10 +1446,7 @@ def pbCompileTrainerEvents(mustcompile)
end
end
changed = false
if Time.now.to_i-t>=5
Graphics.update
t = Time.now.to_i
end
Graphics.update
commonEvents = pbLoadRxData("Data/CommonEvents")
Win32API.SetWindowText(_INTL("Processing common events"))
for key in 0...commonEvents.length