Changed: PokemonMessages --- Left +++ Right @@ -1320,5 +1320,5 @@ facewindow.dispose if facewindow facewindow=PictureWindow.new("Graphics/Pictures/#{param}") - elsif control=="se" && i==0 + elsif control=="se" && controls[i][2]==0 startSE=param controls[i]=nil Changed: PokemonEntry --- Left +++ Right @@ -180,4 +180,13 @@ end return 0 + end + def self.release?(button) + rc=0 + for btn in self.buttonToKey(button) + c=self.repeatcount(btn) + return false if c>0 + rc+=1 if self.releaseex?(btn) + end + return rc>0 end def self.trigger?(button) Changed: SpriteWindow --- Left +++ Right @@ -285,4 +285,56 @@ return val end + @@folder=nil + def self.isDirWritable(dir) + return false if !dir || dir=="" + loop do + name=dir.gsub(/[\/\\]$/,"")+"/writetest" + for i in 0...12 + name+=sprintf("%02X",rand(256)) + end + name+=".tmp" + if !FileTest.exist?(name) + retval=false + begin; File.open(name,"wb"){retval=true}; + rescue Errno::EINVAL, Errno::EACCES, Errno::ENOENT + ensure; File.delete(name) rescue nil; end + return retval + end + end + end + def self.ensureGameDir(dir) + title=RTP.getGameIniValue("Game","Title") + title="RGSS Game" if title=="" + title=title.gsub(/[^\w ]/,"_") + newdir=dir.gsub(/[\/\\]$/,"")+"/"+title + Dir.mkdir(newdir) rescue nil + ret=FileTest.directory?(newdir) ? newdir : dir + return ret + end + def self.getSaveFileName(fileName) + return getSaveFolder().gsub(/[\/\\]$/,"")+"/"+fileName + end + def self.getSaveFolder + if !@@folder + pwd=Dir.pwd + if isDirWritable(pwd) + @@folder=pwd + else + appdata=ENV["LOCALAPPDATA"] + if isDirWritable(appdata) + appdata=ensureGameDir(appdata) + else + appdata=ENV["APPDATA"] + if isDirWritable(appdata) + appdata=ensureGameDir(appdata) + else + appdata=pwd + end + end + @@folder=appdata + end + end + return @@folder + end end Changed: DrawText --- Left +++ Right @@ -141,34 +141,31 @@ def shadowctagFromRgb(param) - color=RgbToColor(param) - shadow=nil - maxval=[color.red,color.green,color.blue].max - minval=[color.red,color.green,color.blue].min - lightness=(maxval+minval)/510 - if lightness<=112.0 # brighten - r=color.red+(255-color.red)/2 - g=color.green+(255-color.green)/2 - b=color.blue+(255-color.blue)/2 - shadow=Color.new(r,g,b,color.alpha) - else # darken - shadow=Color.new(color.red/2,color.green/2,color.blue/2,color.alpha) - end - return shadowctag(color,shadow) + return shadowctagFromColor(RgbToColor(param)) end + +def getContrastColor(color) + raise "No color given" if !color + r=color.red; g=color.green; b=color.blue + yuv=[ + r * 0.299 + g * 0.587 + b * 0.114, + r * -0.1687 + g * -0.3313 + b * 0.500 + 0.5, + r * 0.500 + g * -0.4187 + b * -0.0813 + 0.5 + ] + if yuv[0]<127.5 + yuv[0]+=(255-yuv[0])/2 + else + yuv[0]=yuv[0]/2 + end + return Color.new( + yuv[0] + 1.4075 * (yuv[2] - 0.5), + yuv[0] - 0.3455 * (yuv[1] - 0.5) - 0.7169 * (yuv[2] - 0.5), + yuv[0] + 1.7790 * (yuv[1] - 0.5), + color.alpha + ) +end + def shadowctagFromColor(color) - shadow=nil - maxval=[color.red,color.green,color.blue].max - minval=[color.red,color.green,color.blue].min - lightness=(maxval+minval)/510 - if lightness<=112.0 # brighten - r=color.red+(255-color.red)/2 - g=color.green+(255-color.green)/2 - b=color.blue+(255-color.blue)/2 - shadow=Color.new(r,g,b,color.alpha) - else # darken - shadow=Color.new(color.red/2,color.green/2,color.blue/2,color.alpha) - end - return shadowctag(color,shadow) + return shadowctag(color,getContrastColor(color)) end @@ -305,21 +302,10 @@ havenl=false position=0;while position20 + errorlogline="\r\n"+errorlogline + end if !e.is_a?(Hangup) - print("#{message}\r\nThis exception was logged in errorlog.txt.\r\nPress Ctrl+C to copy this message to the clipboard.") + print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nPress Ctrl+C to copy this message to the clipboard.") end - File.open("errorlog.txt","ab"){|f| f.write(message) } + File.open(errorlog,"ab"){|f| f.write(message) } end @@ -715,5 +745,5 @@ record.push(linerecord[8]) if linerecord[9]!="" && linerecord[9] - record.push(PBMoves.const_get(linerecord[9])) + record.push(parseMove(linerecord[9])) else record.push(0) @@ -823,6 +853,6 @@ clonitem.sub!(/^\s*/){} clonitem.sub!(/\s*$/){} - return pbGetConst(PBItems,item, - _INTL("Undefined item constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}", + return pbGetConst(PBItems,clonitem, + _INTL("Undefined item conzstant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}", FileLineData.linereport)) end @@ -830,9 +860,9 @@ def parseSpecies(item) clonitem=item.upcase - clonitem.sub!(/^\s*/){} - clonitem.sub!(/\s*$/){} + clonitem.gsub!(/^[\s\n]*/){} + clonitem.gsub!(/[\s\n]*$/){} clonitem="NIDORANmA" if clonitem=="NIDORANMA" clonitem="NIDORANfE" if clonitem=="NIDORANFE" - return pbGetConst(PBSpecies,item,_INTL("Undefined species constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}",FileLineData.linereport)) + return pbGetConst(PBSpecies,clonitem,_INTL("Undefined species constant name: [%s]\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}",FileLineData.linereport)) end @@ -841,5 +871,5 @@ clonitem.sub!(/^\s*/){} clonitem.sub!(/\s*$/){} - return pbGetConst(PBMoves,item,_INTL("Undefined move constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}",FileLineData.linereport)) + return pbGetConst(PBMoves,clonitem,_INTL("Undefined move constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}",FileLineData.linereport)) end @@ -848,5 +878,5 @@ clonitem.sub!(/^\s*/){} clonitem.sub!(/\s*$/){} - return pbGetConst(PBTrainers,item,_INTL("Undefined Trainer constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\n{1}",FileLineData.linereport)) + return pbGetConst(PBTrainers,clonitem,_INTL("Undefined Trainer constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\nIn addition, the name must be defined\r\nin trainernames.txt.\r\n{1}",FileLineData.linereport)) end @@ -939,8 +969,8 @@ maxlevel=PBExperience::MAXLEVEL if splitarr[1]<=0 || splitarr[1]>maxlevel - raise _INTL("Invalid level number: {1}\r\n{2}",splitarr[1],FileLineData.linereport) + raise _INTL("Level number is not valid: {1}\r\n{2}",splitarr[1],FileLineData.linereport) end if splitarr[2]<=0 || splitarr[2]>maxlevel - raise _INTL("Invalid level number: {1}\r\n{2}",splitarr[2],FileLineData.linereport) + raise _INTL("Level number is not valid: {1}\r\n{2}",splitarr[2],FileLineData.linereport) end if splitarr[1]>splitarr[2] @@ -1371,5 +1401,5 @@ if !line[/^\#/] && !line[/^\s*$/] if line[/^\s*\[\s*(.*)\s*\]\s*$/] - sectionname=PBMoves.const_get($~[1]) + sectionname=parseMove($~[1]) sections[sectionname]=WordArray.new havesection=true @@ -1380,10 +1410,6 @@ specieslist=line.split(",") for species in specieslist - species.sub!(/^\s+/,"") - species.sub!(/\s+$/,"") sec=sections[sectionname] - if constDef?(PBSpecies,species) - sec[sec.length]=PBSpecies.const_get(species) - end + sec[sec.length]=parseSpecies(species) end end @@ -1970,5 +1996,5 @@ end rescue NameError - raise _INTL("Invalid value {1} in {2}\r\n{3}",ret,enumer.name,FileLineData.linereport) + raise _INTL("Incorrect value {1} in {2}\r\n{3}",ret,enumer.name,FileLineData.linereport) end return enumer.const_get(ret.to_sym) @@ -2140,5 +2166,5 @@ else if sectionname==nil - raise _INTL("Expected a section at the beginning of the file (line {1})",lineno) + raise _INTL("Expected a section at the beginning of the file (line {1}). Sections begin with '[name of section]'",lineno) end lastsection.push(line.gsub(/^\s+/,"").gsub(/\s+$/,"")) Changed: AudioUtilities --- Left +++ Right @@ -472,6 +472,6 @@ t1=0 t1=1209 if "14ghi7pqrs*".include?(tone) - t1=1336 if "2abc5jkl7tuv0".include?(tone) - t1=1477 if "3def6mno7wxyz#".include?(tone) + t1=1336 if "2abc5jkl8tuv0".include?(tone) + t1=1477 if "3def6mno9wxyz#".include?(tone) t1=1633 if "ABCD".include?(tone) t2=0 Changed: Interpreter --- Left +++ Right @@ -238,48 +238,39 @@ result = eval(script) return result - rescue SyntaxError + rescue Exception + e=$! event=get_character(0) - message=$!.message - # Analyze script to make error message more helpful - script.each_line {|line| + s="" + message=pbGetExceptionMessage(e) + if e.is_a?(SyntaxError) + script.each_line {|line| line.gsub!(/\s+$/,"") if line[/\:\:\s*$/] - message+="\r\n***Line '#{line}' can't begin with '::', try putting the next\r\nword on the same line, e.g.: 'PBSpecies::MEW'" + message+="\r\n***Line '#{line}' can't begin with '::', try putting the next\r\n" + message+="word on the same line, e.g.: 'PBSpecies::MEW'" end if line[/^\s*\(/] - message+="\r\n***Line '#{line}' shouldn't begin with '(', try putting '(' at\r\nthe end of the last line" + message+="\r\n***Line '#{line}' shouldn't begin with '(', try putting '(' at\r\n" + message+="the end of the last line" end - } - message+="\r\n***Full script:\r\n#{script}" - s="" - if event && $game_map - mapname="???" - mapname=$game_map.name rescue nil - raise "Script error within event #{event.id}, map #{$game_map.map_id} (#{mapname}):\r\n#{message}\r\n" - elsif $game_map - mapname="???" - mapname=$game_map.name rescue nil - raise "Script error within map #{$game_map.map_id} (#{mapname}):\r\n#{message}\r\n" + } else - raise "Script error in interpreter:\r\n#{message}\r\n" + for bt in e.backtrace[0,10] + s+=bt+"\r\n" + end + s.gsub!(/Section(\d+)/){$RGSS_SCRIPTS[$1.to_i][1]} end - return false - rescue - event=get_character(0) - s="" - for bt in $!.backtrace[0,10] - s+=bt+"\r\n" - end - s.gsub!(/Section(\d+)/){$RGSS_SCRIPTS[$1.to_i][1]} - message=$!.message + message="Exception: #{e.class}\r\nMessage: "+message message+="\r\n***Full script:\r\n#{script}" if event && $game_map mapname="???" mapname=$game_map.name rescue nil - raise "Script error within event #{event.id}, map #{$game_map.map_id} (#{mapname}):\r\n#{message}\r\n#{s}" + raise "Script error within event #{event.id}, map #{$game_map.map_id} ".concat( + "(#{mapname}):\r\n#{message}\r\n#{s}") elsif $game_map mapname="???" mapname=$game_map.name rescue nil - raise "Script error within map #{$game_map.map_id} (#{mapname}):\r\n#{message}\r\n#{s}" + raise "Script error within map #{$game_map.map_id} ".concat( + "(#{mapname}):\r\n#{message}\r\n#{s}") else raise "Script error in interpreter:\r\n#{message}\r\n#{s}" Changed: PokemonLoad --- Left +++ Right @@ -225,5 +225,5 @@ def pbStartDeleteScreen - savefile="Game.rxdata" + savefile=RTP.getSaveFileName("Game.rxdata") @scene.pbStartScene if FileTest.exist?(savefile) @@ -255,5 +255,5 @@ cmdLanguage=-1 commands=[] - savefile="Game.rxdata" + savefile=RTP.getSaveFileName("Game.rxdata") FontInstaller.install data_system = pbLoadRxData("Data/System") @@ -360,5 +360,5 @@ savedata[3]=$PokemonSystem begin - File.open("Game.rxdata","wb"){|f| + File.open(RTP.getSaveFileName("Game.rxdata"),"wb"){|f| 14.times {|i| Marshal.dump(savedata[i],f) } }