Made more use of nil_or_empty?, fixed incorrect default species body shape, fixed Illusion, fixed potential foreign Pokémon with blank names

This commit is contained in:
Maruno17
2021-05-03 17:34:19 +01:00
parent 8e6ee21c20
commit 474281712b
30 changed files with 71 additions and 73 deletions

View File

@@ -1,4 +1,4 @@
# Using mkxp-z v2.1.1 - https://gitlab.com/mkxp-z/mkxp-z/-/releases/v2.1.1 # Using mkxp-z v2.1.2 - https://gitlab.com/mkxp-z/mkxp-z/-/releases/v2.1.2
$VERBOSE = nil $VERBOSE = nil
Font.default_shadow = false if Font.respond_to?(:default_shadow) Font.default_shadow = false if Font.respond_to?(:default_shadow)
Graphics.frame_rate = 40 Graphics.frame_rate = 40

View File

@@ -181,7 +181,7 @@ module RTP
@rtpPaths = nil @rtpPaths = nil
def self.exists?(filename,extensions=[]) def self.exists?(filename,extensions=[])
return false if !filename || filename=="" return false if nil_or_empty?(filename)
eachPathFor(filename) { |path| eachPathFor(filename) { |path|
return true if safeExists?(path) return true if safeExists?(path)
for ext in extensions for ext in extensions
@@ -200,7 +200,7 @@ module RTP
end end
def self.getPath(filename,extensions=[]) def self.getPath(filename,extensions=[])
return filename if !filename || filename=="" return filename if nil_or_empty?(filename)
eachPathFor(filename) { |path| eachPathFor(filename) { |path|
return path if safeExists?(path) return path if safeExists?(path)
for ext in extensions for ext in extensions

View File

@@ -405,7 +405,7 @@ class Messages
if msgs.is_a?(Array) if msgs.is_a?(Array)
f.write("[#{secname}]\r\n") f.write("[#{secname}]\r\n")
for j in 0...msgs.length for j in 0...msgs.length
next if msgs[j]==nil || msgs[j]=="" next if nil_or_empty?(msgs[j])
value=Messages.normalizeValue(msgs[j]) value=Messages.normalizeValue(msgs[j])
origValue="" origValue=""
if origMessages if origMessages
@@ -421,7 +421,7 @@ class Messages
f.write("[#{secname}]\r\n") f.write("[#{secname}]\r\n")
keys=msgs.keys keys=msgs.keys
for key in keys for key in keys
next if msgs[key]==nil || msgs[key]=="" next if nil_or_empty?(msgs[key])
value=Messages.normalizeValue(msgs[key]) value=Messages.normalizeValue(msgs[key])
valkey=Messages.normalizeValue(key) valkey=Messages.normalizeValue(key)
# key is already serialized # key is already serialized

View File

@@ -438,7 +438,7 @@ module PluginManager
message += "#{$!.class} occurred.\r\n" message += "#{$!.class} occurred.\r\n"
# go through message content # go through message content
for line in $!.message.split("\r\n") for line in $!.message.split("\r\n")
next if !line || line == "" next if nil_or_empty?(line)
n = line[/\d+/] n = line[/\d+/]
err = line.split(":")[-1].strip err = line.split(":")[-1].strip
lms = line.split(":")[0].strip lms = line.split(":")[0].strip

View File

@@ -423,7 +423,7 @@ def pbGetPlayerCharset(meta,charset,trainer=nil,force=false)
end end
$game_player.charsetData = [$Trainer.character_ID,charset,outfit] if $game_player $game_player.charsetData = [$Trainer.character_ID,charset,outfit] if $game_player
ret = meta[charset] ret = meta[charset]
ret = meta[1] if !ret || ret=="" ret = meta[1] if nil_or_empty?(ret)
if pbResolveBitmap("Graphics/Characters/"+ret+"_"+outfit.to_s) if pbResolveBitmap("Graphics/Characters/"+ret+"_"+outfit.to_s)
ret = ret+"_"+outfit.to_s ret = ret+"_"+outfit.to_s
end end

View File

@@ -81,15 +81,15 @@ module MessageConfig
if skin && skin!="" if skin && skin!=""
skin=pbResolveBitmap("Graphics/Windowskins/"+skin) || "" skin=pbResolveBitmap("Graphics/Windowskins/"+skin) || ""
end end
skin=pbResolveBitmap("Graphics/System/Window") if !skin || skin=="" skin=pbResolveBitmap("Graphics/System/Window") if nil_or_empty?(skin)
skin=pbResolveBitmap("Graphics/Windowskins/001-Blue01") if !skin || skin=="" skin=pbResolveBitmap("Graphics/Windowskins/001-Blue01") if nil_or_empty?(skin)
return skin || "" return skin || ""
end end
def self.pbGetSystemFrame def self.pbGetSystemFrame
if !@@systemFrame if !@@systemFrame
skin=MessageConfig.pbDefaultSystemFrame skin=MessageConfig.pbDefaultSystemFrame
skin=MessageConfig.pbDefaultWindowskin if !skin || skin=="" skin=MessageConfig.pbDefaultWindowskin if nil_or_empty?(skin)
@@systemFrame=skin || "" @@systemFrame=skin || ""
end end
return @@systemFrame return @@systemFrame
@@ -98,7 +98,7 @@ module MessageConfig
def self.pbGetSpeechFrame def self.pbGetSpeechFrame
if !@@defaultTextSkin if !@@defaultTextSkin
skin=MessageConfig.pbDefaultSpeechFrame skin=MessageConfig.pbDefaultSpeechFrame
skin=MessageConfig.pbDefaultWindowskin if !skin || skin=="" skin=MessageConfig.pbDefaultWindowskin if nil_or_empty?(skin)
@@defaultTextSkin=skin || "" @@defaultTextSkin=skin || ""
end end
return @@defaultTextSkin return @@defaultTextSkin

View File

@@ -868,7 +868,7 @@ class SpriteWindow_Base < SpriteWindow
@customskin.dispose if @customskin @customskin.dispose if @customskin
@customskin=nil @customskin=nil
resolvedName=pbResolveBitmap(skin) resolvedName=pbResolveBitmap(skin)
return if !resolvedName || resolvedName=="" return if nil_or_empty?(resolvedName)
@customskin=AnimatedBitmap.new(resolvedName) @customskin=AnimatedBitmap.new(resolvedName)
RPG::Cache.retain(resolvedName) RPG::Cache.retain(resolvedName)
__setWindowskin(@customskin.bitmap) __setWindowskin(@customskin.bitmap)

View File

@@ -164,7 +164,7 @@ module GameData
@height = hash[:height] || 1 @height = hash[:height] || 1
@weight = hash[:weight] || 1 @weight = hash[:weight] || 1
@color = hash[:color] || :Red @color = hash[:color] || :Red
@shape = hash[:shape] || :Body @shape = hash[:shape] || :Head
@habitat = hash[:habitat] || :None @habitat = hash[:habitat] || :None
@generation = hash[:generation] || 0 @generation = hash[:generation] || 0
@mega_stone = hash[:mega_stone] @mega_stone = hash[:mega_stone]

View File

@@ -125,7 +125,7 @@ module GameData
end end
def self.icon_bitmap(species, form = 0, gender = 0, shiny = false, shadow = false) def self.icon_bitmap(species, form = 0, gender = 0, shiny = false, shadow = false)
filename = self.icon_filename(species, form, gender,shiny, shadow) filename = self.icon_filename(species, form, gender, shiny, shadow)
return (filename) ? AnimatedBitmap.new(filename).deanimate : nil return (filename) ? AnimatedBitmap.new(filename).deanimate : nil
end end

View File

@@ -344,7 +344,7 @@ class PokeBattle_Battler
def hasActiveAbility?(check_ability, ignore_fainted = false) def hasActiveAbility?(check_ability, ignore_fainted = false)
return false if !abilityActive?(ignore_fainted) return false if !abilityActive?(ignore_fainted)
return check_ability.include?(@ability_id) if check_ability.is_a?(Array) return check_ability.include?(@ability_id) if check_ability.is_a?(Array)
return check_ability == self.ability return self.ability == check_ability
end end
alias hasWorkingAbility hasActiveAbility? alias hasWorkingAbility hasActiveAbility?

View File

@@ -37,7 +37,7 @@ class PokeBattle_Battler
@battle.pbHideAbilitySplash(target) @battle.pbHideAbilitySplash(target)
pbItemHPHealCheck pbItemHPHealCheck
else else
msg = _INTL("{1} had its energy drained!",target.pbThis) if !msg || msg=="" msg = _INTL("{1} had its energy drained!",target.pbThis) if nil_or_empty?(msg)
@battle.pbDisplay(msg) @battle.pbDisplay(msg)
if canHeal? if canHeal?
amt = (amt*1.3).floor if hasActiveItem?(:BIGROOT) amt = (amt*1.3).floor if hasActiveItem?(:BIGROOT)

View File

@@ -484,7 +484,7 @@ class PokeBattle_Battler
def pbConfuse(msg=nil) def pbConfuse(msg=nil)
@effects[PBEffects::Confusion] = pbConfusionDuration @effects[PBEffects::Confusion] = pbConfusionDuration
@battle.pbCommonAnimation("Confusion",self) @battle.pbCommonAnimation("Confusion",self)
msg = _INTL("{1} became confused!",pbThis) if !msg || msg=="" msg = _INTL("{1} became confused!",pbThis) if nil_or_empty?(msg)
@battle.pbDisplay(msg) @battle.pbDisplay(msg)
PBDebug.log("[Lingering effect] #{pbThis}'s confusion count is #{@effects[PBEffects::Confusion]}") PBDebug.log("[Lingering effect] #{pbThis}'s confusion count is #{@effects[PBEffects::Confusion]}")
# Confusion cures # Confusion cures
@@ -551,7 +551,7 @@ class PokeBattle_Battler
def pbAttract(user,msg=nil) def pbAttract(user,msg=nil)
@effects[PBEffects::Attract] = user.index @effects[PBEffects::Attract] = user.index
@battle.pbCommonAnimation("Attract",self) @battle.pbCommonAnimation("Attract",self)
msg = _INTL("{1} fell in love!",pbThis) if !msg || msg=="" msg = _INTL("{1} fell in love!",pbThis) if nil_or_empty?(msg)
@battle.pbDisplay(msg) @battle.pbDisplay(msg)
# Destiny Knot # Destiny Knot
if hasActiveItem?(:DESTINYKNOT) && user.pbCanAttract?(self,false) if hasActiveItem?(:DESTINYKNOT) && user.pbCanAttract?(self,false)

View File

@@ -401,7 +401,7 @@ class PokeBattle_Battle
party.each_with_index do |pkmn,i| party.each_with_index do |pkmn,i|
next if i<idxPartyStart || i>=idxPartyEnd # Check the team only next if i<idxPartyStart || i>=idxPartyEnd # Check the team only
next if !pkmn || !pkmn.able? # Can't copy a non-fainted Pokémon or egg next if !pkmn || !pkmn.able? # Can't copy a non-fainted Pokémon or egg
ret = i if partyOrders[i]>partyOrders[ret] ret = i if ret < 0 || partyOrders[i] > partyOrders[ret]
end end
return ret return ret
end end

View File

@@ -170,7 +170,7 @@ class PokeBattle_Battle
enemyParty = pbParty(idxBattler) enemyParty = pbParty(idxBattler)
if enemyParty[idxPartyNew].ability == :ILLUSION if enemyParty[idxPartyNew].ability == :ILLUSION
new_index = pbLastInTeam(idxBattler) new_index = pbLastInTeam(idxBattler)
idxPartyForName = new_index if new_index >= 0 idxPartyForName = new_index if new_index >= 0 && new_index != idxPartyNew
end end
if pbDisplayConfirm(_INTL("{1} is about to send in {2}. Will you switch your Pokémon?", if pbDisplayConfirm(_INTL("{1} is about to send in {2}. Will you switch your Pokémon?",
opponent.full_name, enemyParty[idxPartyForName].name)) opponent.full_name, enemyParty[idxPartyForName].name))
@@ -257,7 +257,7 @@ class PokeBattle_Battle
newPkmnName = party[idxParty].name newPkmnName = party[idxParty].name
if party[idxParty].ability == :ILLUSION if party[idxParty].ability == :ILLUSION
new_index = pbLastInTeam(idxBattler) new_index = pbLastInTeam(idxBattler)
newPkmnName = party[new_index].name if new_index >= 0 newPkmnName = party[new_index].name if new_index >= 0 && new_index != idxParty
end end
if pbOwnedByPlayer?(idxBattler) if pbOwnedByPlayer?(idxBattler)
opposing = @battlers[idxBattler].pbDirectOpposing opposing = @battlers[idxBattler].pbDirectOpposing

View File

@@ -147,9 +147,7 @@ class PokeBattle_Battle
@scene.pbRefreshOne(idxBattler) @scene.pbRefreshOne(idxBattler)
pbCommonAnimation("MegaEvolution2",battler) pbCommonAnimation("MegaEvolution2",battler)
megaName = battler.pokemon.megaName megaName = battler.pokemon.megaName
if !megaName || megaName=="" megaName = _INTL("Mega {1}", battler.pokemon.speciesName) nil_or_empty?(megaName)
megaName = _INTL("Mega {1}", battler.pokemon.speciesName)
end
pbDisplay(_INTL("{1} has Mega Evolved into {2}!",battler.pbThis,megaName)) pbDisplay(_INTL("{1} has Mega Evolved into {2}!",battler.pbThis,megaName))
side = battler.idxOwnSide side = battler.idxOwnSide
owner = pbGetOwnerIndexFromBattlerIndex(idxBattler) owner = pbGetOwnerIndexFromBattlerIndex(idxBattler)

View File

@@ -538,7 +538,7 @@ class TargetMenuDisplay < BattleMenuBase
@overlay.bitmap.clear @overlay.bitmap.clear
textpos = [] textpos = []
@buttons.each_with_index do |button,i| @buttons.each_with_index do |button,i|
next if !button || @texts[i].nil? || @texts[i]=="" next if !button || nil_or_empty?(@texts[i])
x = button.x-self.x+button.src_rect.width/2 x = button.x-self.x+button.src_rect.width/2
y = button.y-self.y+2 y = button.y-self.y+2
textpos.push([@texts[i],x,y,2,TEXT_BASE_COLOR,TEXT_SHADOW_COLOR]) textpos.push([@texts[i],x,y,2,TEXT_BASE_COLOR,TEXT_SHADOW_COLOR])

View File

@@ -480,7 +480,7 @@ class PokeBattle_Scene
# Plays a common animation. # Plays a common animation.
def pbCommonAnimation(animName,user=nil,target=nil) def pbCommonAnimation(animName,user=nil,target=nil)
return if !animName || animName=="" return if nil_or_empty?(animName)
target = target[0] if target && target.is_a?(Array) target = target[0] if target && target.is_a?(Array)
animations = pbLoadBattleAnimations animations = pbLoadBattleAnimations
return if !animations return if !animations

View File

@@ -946,7 +946,7 @@ ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc { |item,pkmn,scene|
next false next false
end end
# Fusing # Fusing
if pkmn.fused==nil if pkmn.fused.nil?
chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?")) chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
next false if chosen<0 next false if chosen<0
poke2 = $Trainer.party[chosen] poke2 = $Trainer.party[chosen]
@@ -999,7 +999,7 @@ ItemHandlers::UseOnPokemon.add(:NSOLARIZER,proc { |item,pkmn,scene|
next false next false
end end
# Fusing # Fusing
if pkmn.fused==nil if pkmn.fused.nil?
chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?")) chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
next false if chosen<0 next false if chosen<0
poke2 = $Trainer.party[chosen] poke2 = $Trainer.party[chosen]
@@ -1048,7 +1048,7 @@ ItemHandlers::UseOnPokemon.add(:NLUNARIZER,proc { |item,pkmn,scene|
next false next false
end end
# Fusing # Fusing
if pkmn.fused==nil if pkmn.fused.nil?
chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?")) chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
next false if chosen<0 next false if chosen<0
poke2 = $Trainer.party[chosen] poke2 = $Trainer.party[chosen]

View File

@@ -554,7 +554,7 @@ class PokemonSummary_Scene
# Write map name Pokémon was received on # Write map name Pokémon was received on
mapname = pbGetMapNameFromId(@pokemon.obtain_map) mapname = pbGetMapNameFromId(@pokemon.obtain_map)
mapname = @pokemon.obtain_text if @pokemon.obtain_text && !@pokemon.obtain_text.empty? mapname = @pokemon.obtain_text if @pokemon.obtain_text && !@pokemon.obtain_text.empty?
mapname = _INTL("Faraway place") if !mapname || mapname=="" mapname = _INTL("Faraway place") if nil_or_empty?(mapname)
memo += sprintf("<c3=F83820,E09890>%s\n",mapname) memo += sprintf("<c3=F83820,E09890>%s\n",mapname)
# Write how Pokémon was obtained # Write how Pokémon was obtained
mettext = [_INTL("Met at Lv. {1}.",@pokemon.obtain_level), mettext = [_INTL("Met at Lv. {1}.",@pokemon.obtain_level),
@@ -573,7 +573,7 @@ class PokemonSummary_Scene
memo += _INTL("<c3=404040,B0B0B0>{1} {2}, {3}\n",date,month,year) memo += _INTL("<c3=404040,B0B0B0>{1} {2}, {3}\n",date,month,year)
end end
mapname = pbGetMapNameFromId(@pokemon.hatched_map) mapname = pbGetMapNameFromId(@pokemon.hatched_map)
mapname = _INTL("Faraway place") if !mapname || mapname=="" mapname = _INTL("Faraway place") if nil_or_empty?(mapname)
memo += sprintf("<c3=F83820,E09890>%s\n",mapname) memo += sprintf("<c3=F83820,E09890>%s\n",mapname)
memo += _INTL("<c3=404040,B0B0B0>Egg hatched.\n") memo += _INTL("<c3=404040,B0B0B0>Egg hatched.\n")
else else

View File

@@ -248,7 +248,7 @@ end
def pbGetStorageCreator def pbGetStorageCreator
creator = Settings.storage_creator_name creator = Settings.storage_creator_name
creator = _INTL("Bill") if !creator || creator=="" creator = _INTL("Bill") if nil_or_empty?(creator)
return creator return creator
end end

View File

@@ -138,7 +138,7 @@ def pbManageMysteryGifts
pbMessageDisplay(msgwindow,_INTL("Searching for online gifts...\\wtnp[0]")) pbMessageDisplay(msgwindow,_INTL("Searching for online gifts...\\wtnp[0]"))
online = pbDownloadToString(MysteryGift::URL) online = pbDownloadToString(MysteryGift::URL)
pbDisposeMessageWindow(msgwindow) pbDisposeMessageWindow(msgwindow)
if online=="" if nil_or_empty?(online)
pbMessage(_INTL("No online Mystery Gifts found.\\wtnp[20]")) pbMessage(_INTL("No online Mystery Gifts found.\\wtnp[20]"))
online=[] online=[]
else else
@@ -245,7 +245,7 @@ def pbDownloadMysteryGift(trainer)
sprites["msgwindow"]=pbCreateMessageWindow sprites["msgwindow"]=pbCreateMessageWindow
pbMessageDisplay(sprites["msgwindow"],_INTL("Searching for a gift.\nPlease wait...\\wtnp[0]")) pbMessageDisplay(sprites["msgwindow"],_INTL("Searching for a gift.\nPlease wait...\\wtnp[0]"))
string = pbDownloadToString(MysteryGift::URL) string = pbDownloadToString(MysteryGift::URL)
if string=="" if nil_or_empty?(string)
pbMessageDisplay(sprites["msgwindow"],_INTL("No new gifts are available.")) pbMessageDisplay(sprites["msgwindow"],_INTL("No new gifts are available."))
else else
online=pbMysteryGiftDecrypt(string) online=pbMysteryGiftDecrypt(string)
@@ -334,7 +334,7 @@ def pbMysteryGiftEncrypt(gift)
end end
def pbMysteryGiftDecrypt(gift) def pbMysteryGiftDecrypt(gift)
return [] if gift=="" return [] if nil_or_empty?(gift)
ret = Marshal.restore(Zlib::Inflate.inflate(gift.unpack("m")[0])) ret = Marshal.restore(Zlib::Inflate.inflate(gift.unpack("m")[0]))
if ret if ret
ret.each do |gift| ret.each do |gift|

View File

@@ -80,7 +80,7 @@ class PBPokemon
end end
for i in 1..maxconst for i in 1..maxconst
val=mod.getName(i) val=mod.getName(i)
next if !val || val=="" next if nil_or_empty?(val)
return i if val==str return i if val==str
end end
return 0 return 0

View File

@@ -89,19 +89,19 @@ end
# Unused # Unused
def hasConst?(mod,constant) def hasConst?(mod,constant)
return false if !mod || !constant || constant=="" return false if !mod || nil_or_empty?(constant)
return mod.const_defined?(constant.to_sym) rescue false return mod.const_defined?(constant.to_sym) rescue false
end end
# Unused # Unused
def getConst(mod,constant) def getConst(mod,constant)
return nil if !mod || !constant || constant=="" return nil if !mod || nil_or_empty?(constant)
return mod.const_get(constant.to_sym) rescue nil return mod.const_get(constant.to_sym) rescue nil
end end
# Unused # Unused
def getID(mod,constant) def getID(mod,constant)
return nil if !mod || !constant || constant=="" return nil if !mod || nil_or_empty?(constant)
if constant.is_a?(Symbol) || constant.is_a?(String) if constant.is_a?(Symbol) || constant.is_a?(String)
if (mod.const_defined?(constant.to_sym) rescue false) if (mod.const_defined?(constant.to_sym) rescue false)
return mod.const_get(constant.to_sym) rescue 0 return mod.const_get(constant.to_sym) rescue 0

View File

@@ -120,7 +120,7 @@ def pbAddForeignPokemon(pkmn, level = 1, owner_name = nil, nickname = nil, owner
# Set original trainer to a foreign one # Set original trainer to a foreign one
pkmn.owner = Pokemon::Owner.new_foreign(owner_name || "", owner_gender) pkmn.owner = Pokemon::Owner.new_foreign(owner_name || "", owner_gender)
# Set nickname # Set nickname
pkmn.name = nickname[0, Pokemon::MAX_NAME_SIZE] pkmn.name = nickname[0, Pokemon::MAX_NAME_SIZE] if !nil_or_empty?(nickname)
# Recalculate stats # Recalculate stats
pkmn.calc_stats pkmn.calc_stats
if owner_name if owner_name

View File

@@ -68,7 +68,7 @@ end
#=============================================================================== #===============================================================================
def pbPlayTrainerIntroME(trainer_type) def pbPlayTrainerIntroME(trainer_type)
trainer_type_data = GameData::TrainerType.get(trainer_type) trainer_type_data = GameData::TrainerType.get(trainer_type)
return if !trainer_type_data.intro_ME || trainer_type_data.intro_ME == "" return if nil_or_empty?(trainer_type_data.intro_ME)
bgm = pbStringToAudioFile(trainer_type_data.intro_ME) bgm = pbStringToAudioFile(trainer_type_data.intro_ME)
pbMEPlay(bgm) pbMEPlay(bgm)
end end

View File

@@ -416,7 +416,7 @@ def pbTrainerTypeEditorNew(default_name)
# Choose a name # Choose a name
name = pbMessageFreeText(_INTL("Please enter the trainer type's name."), name = pbMessageFreeText(_INTL("Please enter the trainer type's name."),
(default_name) ? default_name.gsub(/_+/, " ") : "", false, 30) (default_name) ? default_name.gsub(/_+/, " ") : "", false, 30)
if name == "" if nil_or_empty?(name)
return nil if !default_name return nil if !default_name
name = default_name name = default_name
end end
@@ -585,7 +585,7 @@ def pbTrainerBattleEditor
end end
next if !tr_type next if !tr_type
tr_name = pbMessageFreeText(_INTL("Now enter the trainer's name."), "", false, 30) tr_name = pbMessageFreeText(_INTL("Now enter the trainer's name."), "", false, 30)
next if tr_name == "" next if nil_or_empty?(tr_name)
tr_version = pbGetFreeTrainerParty(tr_type, tr_name) tr_version = pbGetFreeTrainerParty(tr_type, tr_name)
if tr_version < 0 if tr_version < 0
pbMessage(_INTL("There is no room to create a trainer of that type and name.")) pbMessage(_INTL("There is no room to create a trainer of that type and name."))
@@ -891,7 +891,7 @@ def pbItemEditorNew(default_name)
# Choose a name # Choose a name
name = pbMessageFreeText(_INTL("Please enter the item's name."), name = pbMessageFreeText(_INTL("Please enter the item's name."),
(default_name) ? default_name.gsub(/_+/, " ") : "", false, 30) (default_name) ? default_name.gsub(/_+/, " ") : "", false, 30)
if name == "" if nil_or_empty?(name)
return if !default_name return if !default_name
name = default_name name = default_name
end end

View File

@@ -840,12 +840,12 @@ DebugMenuCommands.register("renameplayer", {
"description" => _INTL("Rename the player."), "description" => _INTL("Rename the player."),
"effect" => proc { "effect" => proc {
trname = pbEnterPlayerName("Your name?", 0, Settings::MAX_PLAYER_NAME_SIZE, $Trainer.name) trname = pbEnterPlayerName("Your name?", 0, Settings::MAX_PLAYER_NAME_SIZE, $Trainer.name)
if trname == "" && pbConfirmMessage(_INTL("Give yourself a default name?")) if nil_or_empty?(trname) && pbConfirmMessage(_INTL("Give yourself a default name?"))
trainertype = $Trainer.trainer_type trainertype = $Trainer.trainer_type
gender = pbGetTrainerTypeGender(trainertype) gender = pbGetTrainerTypeGender(trainertype)
trname = pbSuggestTrainerName(gender) trname = pbSuggestTrainerName(gender)
end end
if trname == "" if nil_or_empty?(trname)
pbMessage(_INTL("The player's name remained {1}.", $Trainer.name)) pbMessage(_INTL("The player's name remained {1}.", $Trainer.name))
else else
$Trainer.name = trname $Trainer.name = trname
@@ -865,11 +865,11 @@ DebugMenuCommands.register("randomid", {
}) })
#=============================================================================== #===============================================================================
# Information options # Information editors
#=============================================================================== #===============================================================================
DebugMenuCommands.register("editorsmenu", { DebugMenuCommands.register("editorsmenu", {
"parent" => "main", "parent" => "main",
"name" => _INTL("Information options..."), "name" => _INTL("Information editors..."),
"description" => _INTL("Edit information in the PBS files, terrain tags, battle animations, etc."), "description" => _INTL("Edit information in the PBS files, terrain tags, battle animations, etc."),
"always_show" => true "always_show" => true
}) })

View File

@@ -82,21 +82,21 @@ class SpriteWindow_DebugVariables < Window_DrawableCommand
name = $data_system.switches[index+1] name = $data_system.switches[index+1]
codeswitch = (name[/^s\:/]) codeswitch = (name[/^s\:/])
val = (codeswitch) ? (eval($~.post_match) rescue nil) : $game_switches[index+1] val = (codeswitch) ? (eval($~.post_match) rescue nil) : $game_switches[index+1]
if val==nil if val.nil?
status = "[-]" status = "[-]"
colors = 0 colors = 0
codeswitch = true codeswitch = true
elsif val elsif val # true
status = "[ON]" status = "[ON]"
colors = 2 colors = 2
else else # false
status = "[OFF]" status = "[OFF]"
colors = 1 colors = 1
end end
else else
name = $data_system.variables[index+1] name = $data_system.variables[index+1]
status = $game_variables[index+1].to_s status = $game_variables[index+1].to_s
status = "\"__\"" if !status || status=="" status = "\"__\"" if nil_or_empty?(status)
end end
name = '' if name==nil name = '' if name==nil
id_text = sprintf("%04d:",index+1) id_text = sprintf("%04d:",index+1)

View File

@@ -77,7 +77,7 @@ module Compiler
end end
def csvQuote(str,always=false) def csvQuote(str,always=false)
return "" if !str || str=="" return "" if nil_or_empty?(str)
if always || str[/[,\"]/] # || str[/^\s/] || str[/\s$/] || str[/^#/] if always || str[/[,\"]/] # || str[/^\s/] || str[/\s$/] || str[/^#/]
str = str.gsub(/[\"]/,"\\\"") str = str.gsub(/[\"]/,"\\\"")
str = "\"#{str}\"" str = "\"#{str}\""
@@ -316,7 +316,7 @@ module Compiler
def checkEnumField(ret,enumer) def checkEnumField(ret,enumer)
if enumer.is_a?(Module) if enumer.is_a?(Module)
begin begin
if ret=="" || !enumer.const_defined?(ret) if nil_or_empty?(ret) || !enumer.const_defined?(ret)
raise _INTL("Undefined value {1} in {2}\r\n{3}",ret,enumer.name,FileLineData.linereport) raise _INTL("Undefined value {1} in {2}\r\n{3}",ret,enumer.name,FileLineData.linereport)
end end
rescue NameError rescue NameError
@@ -327,7 +327,7 @@ module Compiler
if !Kernel.const_defined?(enumer.to_sym) && GameData.const_defined?(enumer.to_sym) if !Kernel.const_defined?(enumer.to_sym) && GameData.const_defined?(enumer.to_sym)
enumer = GameData.const_get(enumer.to_sym) enumer = GameData.const_get(enumer.to_sym)
begin begin
if ret == "" || !enumer.exists?(ret.to_sym) if nil_or_empty?(ret) || !enumer.exists?(ret.to_sym)
raise _INTL("Undefined value {1} in {2}\r\n{3}", ret, enumer.name, FileLineData.linereport) raise _INTL("Undefined value {1} in {2}\r\n{3}", ret, enumer.name, FileLineData.linereport)
end end
rescue NameError rescue NameError
@@ -337,7 +337,7 @@ module Compiler
end end
enumer = Object.const_get(enumer.to_sym) enumer = Object.const_get(enumer.to_sym)
begin begin
if ret=="" || !enumer.const_defined?(ret) if nil_or_empty?(ret) || !enumer.const_defined?(ret)
raise _INTL("Undefined value {1} in {2}\r\n{3}",ret,enumer.name,FileLineData.linereport) raise _INTL("Undefined value {1} in {2}\r\n{3}",ret,enumer.name,FileLineData.linereport)
end end
rescue NameError rescue NameError
@@ -362,16 +362,16 @@ module Compiler
def checkEnumFieldOrNil(ret,enumer) def checkEnumFieldOrNil(ret,enumer)
if enumer.is_a?(Module) if enumer.is_a?(Module)
return nil if ret=="" || !(enumer.const_defined?(ret) rescue false) return nil if nil_or_empty?(ret) || !(enumer.const_defined?(ret) rescue false)
return enumer.const_get(ret.to_sym) return enumer.const_get(ret.to_sym)
elsif enumer.is_a?(Symbol) || enumer.is_a?(String) elsif enumer.is_a?(Symbol) || enumer.is_a?(String)
if GameData.const_defined?(enumer.to_sym) if GameData.const_defined?(enumer.to_sym)
enumer = GameData.const_get(enumer.to_sym) enumer = GameData.const_get(enumer.to_sym)
return nil if ret == "" || !enumer.exists?(ret.to_sym) return nil if nil_or_empty?(re) || !enumer.exists?(ret.to_sym)
return ret.to_sym return ret.to_sym
end end
enumer = Object.const_get(enumer.to_sym) enumer = Object.const_get(enumer.to_sym)
return nil if ret=="" || !(enumer.const_defined?(ret) rescue false) return nil if nil_or_empty?(ret) || !(enumer.const_defined?(ret) rescue false)
return enumer.const_get(ret.to_sym) return enumer.const_get(ret.to_sym)
elsif enumer.is_a?(Array) elsif enumer.is_a?(Array)
idx = findIndex(enumer) { |item| ret==item } idx = findIndex(enumer) { |item| ret==item }
@@ -402,7 +402,7 @@ module Compiler
record.push(csvInt!(rec,lineno)) record.push(csvInt!(rec,lineno))
when "I" # Optional integer when "I" # Optional integer
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif !field[/^\-?\d+$/] elsif !field[/^\-?\d+$/]
raise _INTL("Field {1} is not an integer\r\n{2}",field,FileLineData.linereport) raise _INTL("Field {1} is not an integer\r\n{2}",field,FileLineData.linereport)
@@ -413,7 +413,7 @@ module Compiler
record.push(csvPosInt!(rec,lineno)) record.push(csvPosInt!(rec,lineno))
when "U" # Optional positive integer or zero when "U" # Optional positive integer or zero
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif !field[/^\d+$/] elsif !field[/^\d+$/]
raise _INTL("Field '{1}' must be 0 or greater\r\n{2}",field,FileLineData.linereport) raise _INTL("Field '{1}' must be 0 or greater\r\n{2}",field,FileLineData.linereport)
@@ -426,7 +426,7 @@ module Compiler
record.push(field) record.push(field)
when "V" # Optional positive integer when "V" # Optional positive integer
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif !field[/^\d+$/] elsif !field[/^\d+$/]
raise _INTL("Field '{1}' must be greater than 0\r\n{2}",field,FileLineData.linereport) raise _INTL("Field '{1}' must be greater than 0\r\n{2}",field,FileLineData.linereport)
@@ -443,7 +443,7 @@ module Compiler
record.push(field.hex) record.push(field.hex)
when "X" # Optional hexadecimal number when "X" # Optional hexadecimal number
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif !field[/^[A-Fa-f0-9]+$/] elsif !field[/^[A-Fa-f0-9]+$/]
raise _INTL("Field '{1}' is not a hexadecimal number\r\n{2}",field,FileLineData.linereport) raise _INTL("Field '{1}' is not a hexadecimal number\r\n{2}",field,FileLineData.linereport)
@@ -454,7 +454,7 @@ module Compiler
record.push(csvFloat!(rec,lineno)) record.push(csvFloat!(rec,lineno))
when "F" # Optional floating point number when "F" # Optional floating point number
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif !field[/^\-?^\d*\.?\d*$/] elsif !field[/^\-?^\d*\.?\d*$/]
raise _INTL("Field {1} is not a floating point number\r\n{2}",field,FileLineData.linereport) raise _INTL("Field {1} is not a floating point number\r\n{2}",field,FileLineData.linereport)
@@ -465,7 +465,7 @@ module Compiler
record.push(csvBoolean!(rec,lineno)) record.push(csvBoolean!(rec,lineno))
when "B" # Optional Boolean when "B" # Optional Boolean
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif field[/^1|[Tt][Rr][Uu][Ee]|[Yy][Ee][Ss]|[Tt]|[Yy]$/] elsif field[/^1|[Tt][Rr][Uu][Ee]|[Yy][Ee][Ss]|[Tt]|[Yy]$/]
record.push(true) record.push(true)
@@ -480,7 +480,7 @@ module Compiler
record.push(field) record.push(field)
when "N" # Optional name when "N" # Optional name
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif !field[/^(?![0-9])\w+$/] elsif !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\r\nunderscores and can't begin with a number.\r\n{2}",field,FileLineData.linereport) raise _INTL("Field '{1}' must contain only letters, digits, and\r\nunderscores and can't begin with a number.\r\n{2}",field,FileLineData.linereport)
@@ -491,12 +491,12 @@ module Compiler
record.push(csvfield!(rec)) record.push(csvfield!(rec))
when "S" # Optional string when "S" # Optional string
field = csvfield!(rec) field = csvfield!(rec)
record.push((field=="") ? nil : field) record.push((nil_or_empty?(field)) ? nil : field)
when "q" # Unformatted text when "q" # Unformatted text
record.push(rec) record.push(rec)
rec = "" rec = ""
when "Q" # Optional unformatted text when "Q" # Optional unformatted text
if !rec || rec=="" if nil_or_empty?(rec)
record.push(nil) record.push(nil)
else else
record.push(rec) record.push(rec)
@@ -512,7 +512,7 @@ module Compiler
record.push(csvEnumFieldOrInt!(field,schema[2+i-start],"",FileLineData.linereport)) record.push(csvEnumFieldOrInt!(field,schema[2+i-start],"",FileLineData.linereport))
when "Y" # Optional enumerable or integer when "Y" # Optional enumerable or integer
field = csvfield!(rec) field = csvfield!(rec)
if field=="" if nil_or_empty?(field)
record.push(nil) record.push(nil)
elsif field[/^\-?\d+$/] elsif field[/^\-?\d+$/]
record.push(field.to_i) record.push(field.to_i)
@@ -521,7 +521,7 @@ module Compiler
end end
end end
end end
break if repeat && rec=="" break if repeat && nil_or_empty?(rec)
end while repeat end while repeat
return (schema[1].length==1) ? record[0] : record return (schema[1].length==1) ? record[0] : record
end end

View File

@@ -398,7 +398,7 @@ module Compiler
for key in schema.keys for key in schema.keys
# Skip empty properties, or raise an error if a required property is # Skip empty properties, or raise an error if a required property is
# empty # empty
if contents[key].nil? || contents[key] == "" if nil_or_empty?(contents[key])
if ["Name", "InternalName"].include?(key) if ["Name", "InternalName"].include?(key)
raise _INTL("The entry {1} is required in PBS/pokemon.txt section {2}.", key, species_number) raise _INTL("The entry {1} is required in PBS/pokemon.txt section {2}.", key, species_number)
end end
@@ -583,7 +583,7 @@ module Compiler
# Go through schema hash of compilable data and compile this section # Go through schema hash of compilable data and compile this section
for key in schema.keys for key in schema.keys
# Skip empty properties (none are required) # Skip empty properties (none are required)
if contents[key].nil? || contents[key] == "" if nil_or_empty?(contents[key])
contents[key] = nil contents[key] = nil
next next
end end
@@ -922,7 +922,7 @@ module Compiler
end end
new_format = true new_format = true
values = $~[1].split(',').collect! { |v| v.strip.to_i } values = $~[1].split(',').collect! { |v| v.strip.to_i }
values[1] = 0 if !values[1] || values[1] == "" values[1] = 0 if nil_or_empty?(values[1])
map_number = values[0] map_number = values[0]
map_version = values[1] map_version = values[1]
# Add map encounter's data to records # Add map encounter's data to records