Refactoring and Bugfixes (#127)

* Replacing nil + compact! with delete, delete_at and delete_if wherever possible
* Fixed Terrain Tag editor not setting the correct terrain
* Fixed Text Cursor in Animation Editor not going right
This commit is contained in:
Golisopod-User
2021-08-23 02:55:29 +05:30
committed by GitHub
parent e57e1f4a1e
commit ecc5a040cd
21 changed files with 40 additions and 171 deletions

View File

@@ -322,8 +322,7 @@ def pbEncounterTypeEditor(enc_data, enc_type)
need_refresh = true
when 2 # Delete
if pbConfirmMessage(_INTL("Delete this encounter slot?"))
enc_data.types[enc_type][ret - 2] = nil
enc_data.types[enc_type].compact!
enc_data.types[enc_type].delete_at(ret - 2)
need_refresh = true
end
end
@@ -1298,8 +1297,7 @@ def pbRegionalDexEditorMain
cmd[1] = dex_lists.length
refresh_list = true
when 2 # Delete
dex_lists[cmd[1] - 1] = nil
dex_lists.compact!
dex_lists.delete_at(cmd[1] - 1)
cmd[1] = [cmd[1], dex_lists.length].min
refresh_list = true
end

View File

@@ -215,7 +215,7 @@ class PokemonTilesetScene
end
val = pbMessage(_INTL("\\l[1]\\ts[]Set the terrain tag."), cmds, -1, nil, old_idx)
if val >= 0 && val != old_tag
set_terrain_tag_for_tile_ID(selected, val)
set_terrain_tag_for_tile_ID(selected, ids[val])
draw_overlay
end
end

View File

@@ -218,11 +218,8 @@ class MapScreenScene
return false
end
def removeOldConnections(ret,mapid)
for i in 0...ret.length
ret[i]=nil if ret[i][0]==mapid || ret[i][3]==mapid
end
ret.compact!
def removeOldConnections(ret, mapid)
ret.delete_if { |conn| conn[0] == mapid || conn[3] == mapid}
end
# Returns the maps within _keys_ that are directly connected to this map, _map_.

View File

@@ -271,7 +271,7 @@ class TextField < UIControl
end
return
end
if Input.triggerex?(:LEFT) || Input.repeatex?(:RIGHT)
if Input.triggerex?(:RIGHT) || Input.repeatex?(:RIGHT)
if @cursor < self.text.scan(/./m).length
@cursor+=1
@frame=0

View File

@@ -263,7 +263,6 @@ def pbDefinePath(canvas)
points[j]=nil
end
points.compact!
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
end
elsif sliderwin2.changed?(defcurvebutton)
for point in points

View File

@@ -993,8 +993,7 @@ module MovePoolProperty
havemove = e[2] if e[0] == newlevel && e[1] == entry[1]
end
if havemove >= 0 # Move already known at new level; delete this move
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
oldsel = havemove
else # Apply the new level
entry[0] = newlevel
@@ -1010,8 +1009,7 @@ module MovePoolProperty
havemove = e[2] if e[0] == entry[0] && e[1] == newmove
end
if havemove >= 0 # New move already known at level; delete this move
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
cmd[1] = [cmd[1], realcmds.length - 1].min
oldsel = havemove
else # Apply the new move
@@ -1022,8 +1020,7 @@ module MovePoolProperty
refreshlist = true
end
when 2 # Delete
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
cmd[1] = [cmd[1], realcmds.length - 1].min
refreshlist = true
end
@@ -1111,8 +1108,7 @@ module EggMovesProperty
newmove = pbChooseMoveList(entry[0])
if newmove
if realcmds.any? { |e| e[0] == newmove } # Already have move; delete this one
realcmds[cmd] = nil
realcmds.compact!
realcmds.delete_at(cmd)
cmd = [cmd, realcmds.length - 1].min
else # Change move
realcmds[cmd] = [newmove, GameData::Move.get(newmove).name, 0]
@@ -1121,8 +1117,7 @@ module EggMovesProperty
refreshlist = true
end
when 1 # Delete
realcmds[cmd] = nil
realcmds.compact!
realcmds.delete_at(cmd)
cmd = [cmd, realcmds.length - 1].min
refreshlist = true
end
@@ -1293,8 +1288,7 @@ class EvolutionsProperty
realcmds[i][2]==entry[2]
end
if existing_evo >= 0
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
oldsel = existing_evo
else
entry[0] = newspecies
@@ -1315,8 +1309,7 @@ class EvolutionsProperty
realcmds[i][2]==entry[2]
end
if existing_evo >= 0
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
oldsel = existing_evo
elsif newmethod != entry[1]
entry[1] = newmethod
@@ -1338,8 +1331,7 @@ class EvolutionsProperty
realcmds[i][2]==newparam
end
if existing_evo >= 0
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
oldsel = existing_evo
else
entry[2] = newparam
@@ -1349,8 +1341,7 @@ class EvolutionsProperty
end
end
when 3 # Delete
realcmds[cmd[1]] = nil
realcmds.compact!
realcmds.delete_at(cmd[1])
cmd[1] = [cmd[1],realcmds.length-1].min
refreshlist = true
end

View File

@@ -264,8 +264,7 @@ DebugMenuCommands.register("testwildbattleadvanced", {
scr.pbPokemonDebug(pkmn[pkmnCmd], -1, nil, true)
scr.pbEndScreen
elsif pbConfirmMessage(_INTL("Delete this Pokémon?"))
pkmn[pkmnCmd] = nil
pkmn.compact!
pkmn.delete_at(pkmnCmd)
end
end
end
@@ -366,8 +365,7 @@ DebugMenuCommands.register("testtrainerbattleadvanced", {
trainers[trainerCmd] = [0, tr]
end
elsif pbConfirmMessage(_INTL("Delete this trainer?"))
trainers[trainerCmd] = nil
trainers.compact!
trainers.delete_at(trainerCmd)
end
end
end

View File

@@ -1167,8 +1167,7 @@ PokemonDebugMenuCommands.register("delete", {
"effect" => proc { |pkmn, pkmnid, heldpoke, settingUpBattle, screen|
if screen.pbConfirm(_INTL("Are you sure you want to delete this Pokémon?"))
if screen.is_a?(PokemonPartyScreen)
screen.party[pkmnid] = nil
screen.party.compact!
screen.party.delete_at(pkmnid)
screen.pbHardRefresh
elsif screen.is_a?(PokemonStorageScreen)
screen.scene.pbRelease(pkmnid, heldpoke)