Refactoring and tidying

This commit is contained in:
Maruno17
2021-01-11 19:30:45 +00:00
parent a5d1359dfe
commit 2586c09c3c
37 changed files with 5288 additions and 5966 deletions

View File

@@ -896,7 +896,7 @@ DebugMenuCommands.register("setencounters", {
end
save_data(encdata, "Data/encounters.dat")
$PokemonTemp.encountersData = nil
pbSaveEncounterData # Rewrite PBS file encounters.txt
Compiler.write_encounters # Rewrite PBS file encounters.txt
}
})

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,945 @@
module ShadowText
def shadowtext(bitmap,x,y,w,h,t,disabled=false,align=0)
width=bitmap.text_size(t).width
if align==2
x+=(w-width)
elsif align==1
x+=(w/2)-(width/2)
end
pbDrawShadowText(bitmap,x,y+6,w,h,t,
disabled ? Color.new(26*8,26*8,25*8) : Color.new(12*8,12*8,12*8),
Color.new(26*8,26*8,25*8))
end
end
class UIControl
include ShadowText
attr_accessor :bitmap
attr_accessor :label
attr_accessor :x
attr_accessor :y
attr_accessor :width
attr_accessor :height
attr_accessor :changed
attr_accessor :parent
attr_accessor :disabled
def text
return self.label
end
def text=(value)
self.label=value
end
def initialize(label)
@label=label
@x=0
@y=0
@width=0
@height=0
@changed=false
@disabled=false
@invalid=true
end
def toAbsoluteRect(rc)
return Rect.new(
rc.x+self.parentX,
rc.y+self.parentY,
rc.width,rc.height)
end
def parentX
return 0 if !self.parent
return self.parent.x+self.parent.leftEdge if self.parent.is_a?(SpriteWindow)
return self.parent.x+16 if self.parent.is_a?(Window)
return self.parent.x
end
def parentY
return 0 if !self.parent
return self.parent.y+self.parent.topEdge if self.parent.is_a?(SpriteWindow)
return self.parent.y+16 if self.parent.is_a?(Window)
return self.parent.y
end
def invalid?
return @invalid
end
def invalidate # Marks that the control must be redrawn to reflect current logic
@invalid=true
end
def update # Updates the logic on the control, invalidating it if necessary
end
def refresh # Redraws the control
end
def validate # Makes the control no longer invalid
@invalid=false
end
def repaint # Redraws the control only if it is invalid
if self.invalid?
self.refresh
self.validate
end
end
end
class Label < UIControl
def text=(value)
self.label=value
refresh
end
def refresh
bitmap=self.bitmap
bitmap.fill_rect(self.x,self.y,self.width,self.height,Color.new(0,0,0,0))
size=bitmap.text_size(self.label).width
shadowtext(bitmap,self.x+4,self.y,size,self.height,self.label,@disabled)
end
end
class Button < UIControl
attr_accessor :label
def initialize(label)
super
@captured=false
@label=label
end
def update
mousepos=Mouse::getMousePos
self.changed=false
return if !mousepos
rect=Rect.new(self.x+1,self.y+1,self.width-2,self.height-2)
rect=toAbsoluteRect(rect)
if Input.triggerex?(Input::LeftMouseKey) &&
rect.contains(mousepos[0],mousepos[1]) && !@captured
@captured=true
self.invalidate
end
if Input.releaseex?(Input::LeftMouseKey) && @captured
self.changed=true if rect.contains(mousepos[0],mousepos[1])
@captured=false
self.invalidate
end
end
def refresh
bitmap=self.bitmap
x=self.x
y=self.y
width=self.width
height=self.height
color=Color.new(120,120,120)
bitmap.fill_rect(x+1,y+1,width-2,height-2,color)
ret=Rect.new(x+1,y+1,width-2,height-2)
if !@captured
bitmap.fill_rect(x+2,y+2,width-4,height-4,Color.new(0,0,0,0))
else
bitmap.fill_rect(x+2,y+2,width-4,height-4,Color.new(120,120,120,80))
end
size=bitmap.text_size(self.label).width
shadowtext(bitmap,x+4,y,size,height,self.label,@disabled)
return ret
end
end
class Checkbox < Button
attr_reader :checked
def curvalue
return self.checked
end
def curvalue=(value)
self.checked=value
end
def checked=(value)
@checked=value
invalidate
end
def initialize(label)
super
@checked=false
end
def update
super
if self.changed
@checked=!@checked
self.invalidate
end
end
def refresh
bitmap=self.bitmap
x=self.x
y=self.y
width=[self.width,32].min
height=[self.height,32].min
color=Color.new(120,120,120)
bitmap.fill_rect(x+2,y+2,self.width-4,self.height-4,Color.new(0,0,0,0))
bitmap.fill_rect(x+1,y+1,width-2,height-2,color)
ret=Rect.new(x+1,y+1,width-2,height-2)
if !@captured
bitmap.fill_rect(x+2,y+2,width-4,height-4,Color.new(0,0,0,0))
else
bitmap.fill_rect(x+2,y+2,width-4,height-4,Color.new(120,120,120,80))
end
if self.checked
shadowtext(bitmap,x,y,32,32,"X",@disabled,1)
end
size=bitmap.text_size(self.label).width
shadowtext(bitmap,x+36,y,size,height,self.label,@disabled)
return ret
end
end
class TextField < UIControl
attr_accessor :label
attr_reader :text
def text=(value)
@text=value
self.invalidate
end
def initialize(label,text)
super(label)
@frame=0
@label=label
@text=text
@cursor=text.scan(/./m).length
end
def insert(ch)
chars=self.text.scan(/./m)
chars.insert(@cursor,ch)
@text=""
for ch in chars
@text+=ch
end
@cursor+=1
@frame=0
self.changed=true
self.invalidate
end
def delete
chars=self.text.scan(/./m)
chars.delete_at(@cursor-1)
@text=""
for ch in chars
@text+=ch
end
@cursor-=1
@frame=0
self.changed=true
self.invalidate
end
def update
@frame+=1
@frame%=20
self.changed=false
self.invalidate if ((@frame%10)==0)
# Moving cursor
if Input.repeat?(Input::LEFT)
if @cursor > 0
@cursor-=1
@frame=0
self.invalidate
end
return
end
if Input.repeat?(Input::RIGHT)
if @cursor < self.text.scan(/./m).length
@cursor+=1
@frame=0
self.invalidate
end
return
end
# Backspace
if Input.repeat?(Input::BACKSPACE) || Input.repeat?(Input::DELETE)
self.delete if @cursor > 0
return
end
# Letter keys
for i in 65..90
if Input.repeatex?(i)
shift=(Input.press?(Input::SHIFT)) ? 0x41 : 0x61
insert((shift+i-65).chr)
return
end
end
# Number keys
shifted=")!@\#$%^&*("
unshifted="0123456789"
for i in 48..57
if Input.repeatex?(i)
insert((Input.press?(Input::SHIFT)) ? shifted[i-48].chr : unshifted[i-48].chr)
return
end
end
keys=[
[32," "," "],
[106,"*","*"],
[107,"+","+"],
[109,"-","-"],
[111,"/","/"],
[186,";",":"],
[187,"=","+"],
[188,",","<"],
[189,"-","_"],
[190,".",">"],
[191,"/","?"],
[219,"[","{"],
[220,"\\","|"],
[221,"]","}"],
[222,"\"","'"]
]
for i in keys
if Input.repeatex?(i[0])
insert((Input.press?(Input::SHIFT)) ? i[2] : i[1])
return
end
end
end
def refresh
bitmap=self.bitmap
x=self.x
y=self.y
width=self.width
height=self.height
color=Color.new(120,120,120)
bitmap.font.color=color
bitmap.fill_rect(x,y,width,height,Color.new(0,0,0,0))
size=bitmap.text_size(self.label).width
shadowtext(bitmap,x,y,size,height,self.label)
x+=size
width-=size
bitmap.fill_rect(x+1,y+1,width-2,height-2,color)
ret=Rect.new(x+1,y+1,width-2,height-2)
if !@captured
bitmap.fill_rect(x+2,y+2,width-4,height-4,Color.new(0,0,0,0))
else
bitmap.fill_rect(x+2,y+2,width-4,height-4,Color.new(120,120,120,80))
end
x+=4
textscan=self.text.scan(/./m)
scanlength=textscan.length
@cursor=scanlength if @cursor>scanlength
@cursor=0 if @cursor<0
startpos=@cursor
fromcursor=0
while (startpos>0)
c=textscan[startpos-1]
fromcursor+=bitmap.text_size(c).width
break if fromcursor>width-4
startpos-=1
end
for i in startpos...scanlength
c=textscan[i]
textwidth=bitmap.text_size(c).width
next if c=="\n"
# Draw text
shadowtext(bitmap,x,y, textwidth+4, 32, c)
# Draw cursor if necessary
if ((@frame/10)&1) == 0 && i==@cursor
bitmap.fill_rect(x,y+4,2,24,Color.new(120,120,120))
end
# Add x to drawn text width
x += textwidth
end
if ((@frame/10)&1) == 0 && textscan.length==@cursor
bitmap.fill_rect(x,y+4,2,24,Color.new(120,120,120))
end
return ret
end
end
class Slider < UIControl
attr_reader :minvalue
attr_reader :maxvalue
attr_reader :curvalue
attr_accessor :label
def curvalue=(value)
@curvalue=value
@curvalue=self.minvalue if self.minvalue && @curvalue<self.minvalue
@curvalue=self.maxvalue if self.maxvalue && @curvalue>self.maxvalue
self.invalidate
end
def minvalue=(value)
@minvalue=value
@curvalue=self.minvalue if self.minvalue && @curvalue<self.minvalue
@curvalue=self.maxvalue if self.maxvalue && @curvalue>self.maxvalue
self.invalidate
end
def maxvalue=(value)
@maxvalue=value
@curvalue=self.minvalue if self.minvalue && @curvalue<self.minvalue
@curvalue=self.maxvalue if self.maxvalue && @curvalue>self.maxvalue
self.invalidate
end
def initialize(label,minvalue,maxvalue,curval)
super(label)
@minvalue=minvalue
@maxvalue=maxvalue
@curvalue=curval
@label=label
@leftarrow=Rect.new(0,0,0,0)
@rightarrow=Rect.new(0,0,0,0)
self.minvalue=minvalue
self.maxvalue=maxvalue
self.curvalue=curval
end
def update
mousepos=Mouse::getMousePos
self.changed=false
if self.minvalue<self.maxvalue && self.curvalue<self.minvalue
self.curvalue=self.minvalue
end
return false if self.disabled
return false if !Input.repeatex?(Input::LeftMouseKey)
return false if !mousepos
left=toAbsoluteRect(@leftarrow)
right=toAbsoluteRect(@rightarrow)
oldvalue=self.curvalue
# Left arrow
if left.contains(mousepos[0],mousepos[1])
if Input.repeatcount(Input::LeftMouseKey)>100
self.curvalue-=10
self.curvalue=self.curvalue.floor
elsif Input.repeatcount(Input::LeftMouseKey)>50
self.curvalue-=5
self.curvalue=self.curvalue.floor
else
self.curvalue-=1
self.curvalue=self.curvalue.floor
end
self.changed=(self.curvalue!=oldvalue)
self.invalidate
end
#Right arrow
if right.contains(mousepos[0],mousepos[1])
if Input.repeatcount(Input::LeftMouseKey)>100
self.curvalue+=10
self.curvalue=self.curvalue.floor
elsif Input.repeatcount(Input::LeftMouseKey)>50
self.curvalue+=5
self.curvalue=self.curvalue.floor
else
self.curvalue+=1
self.curvalue=self.curvalue.floor
end
self.changed=(self.curvalue!=oldvalue)
self.invalidate
end
end
def refresh
bitmap=self.bitmap
x=self.x
y=self.y
width=self.width
height=self.height
color=Color.new(120,120,120)
bitmap.fill_rect(x,y,width,height,Color.new(0,0,0,0))
size=bitmap.text_size(self.label).width
leftarrows=bitmap.text_size(_INTL(" << "))
numbers=bitmap.text_size(" XXXX ").width
rightarrows=bitmap.text_size(_INTL(" >> "))
bitmap.font.color=color
shadowtext(bitmap,x,y,size,height,self.label)
x+=size
shadowtext(bitmap,x,y,leftarrows.width,height,_INTL(" << "),
self.disabled || self.curvalue==self.minvalue)
@leftarrow=Rect.new(x,y,leftarrows.width,height)
x+=leftarrows.width
if !self.disabled
bitmap.font.color=color
shadowtext(bitmap,x,y,numbers,height," #{self.curvalue} ",false,1)
end
x+=numbers
shadowtext(bitmap,x,y,rightarrows.width,height,_INTL(" >> "),
self.disabled || self.curvalue==self.maxvalue)
@rightarrow=Rect.new(x,y,rightarrows.width,height)
end
end
class OptionalSlider < Slider
def initialize(label,minvalue,maxvalue,curvalue)
@slider=Slider.new(label,minvalue,maxvalue,curvalue)
@checkbox=Checkbox.new("")
end
def curvalue
return @checkbox.checked ? @slider.curvalue : nil
end
def curvalue=(value)
slider.curvalue=value
end
def checked
return @checkbox.checked
end
def checked=(value)
@checkbox.checked=value
end
def invalid?
return @slider.invalid? || @checkbox.invalid?
end
def invalidate
@slider.invalidate
@checkbox.invalidate
end
def validate?
@slider.validate
@checkbox.validate
end
def changed
return @slider.changed || @checkbox.changed
end
def minvalue
return @slider.minvalue
end
def minvalue=(value)
slider.minvalue=value
end
def maxvalue
return @slider.maxvalue
end
def maxvalue=(value)
slider.maxvalue=value
end
def update
updatedefs
@slider.update
@checkbox.update
end
def refresh
updatedefs
@slider.refresh
@checkbox.refresh
end
private
def updatedefs
checkboxwidth=32
@slider.bitmap=self.bitmap
@slider.parent=self.parent
@checkbox.x=self.x
@checkbox.y=self.y
@checkbox.width=checkboxwidth
@checkbox.height=self.height
@checkbox.bitmap=self.bitmap
@checkbox.parent=self.parent
@slider.x=self.x+checkboxwidth+4
@slider.y=self.y
@slider.width=self.width-checkboxwidth
@slider.height=self.height
@slider.disabled=!@checkbox.checked
end
end
class ArrayCountSlider < Slider
def maxvalue
return @array.length-1
end
def initialize(array,label)
@array=array
super(label,0,canvas.animation.length-1,0)
end
end
class FrameCountSlider < Slider
def maxvalue
return @canvas.animation.length
end
def initialize(canvas)
@canvas=canvas
super(_INTL("Frame:"),1,canvas.animation.length,0)
end
end
class FrameCountButton < Button
def label
return _INTL("Total Frames: {1}",@canvas.animation.length)
end
def initialize(canvas)
@canvas=canvas
super(self.label)
end
end
class TextSlider < UIControl
attr_reader :minvalue
attr_reader :maxvalue
attr_reader :curvalue
attr_accessor :label
attr_accessor :options
attr_accessor :maxoptionwidth
def curvalue=(value)
@curvalue=value
@curvalue=self.minvalue if self.minvalue && @curvalue<self.minvalue
@curvalue=self.maxvalue if self.maxvalue && @curvalue>self.maxvalue
self.invalidate
end
def minvalue=(value)
@minvalue=value
@curvalue=self.minvalue if self.minvalue && @curvalue<self.minvalue
@curvalue=self.maxvalue if self.maxvalue && @curvalue>self.maxvalue
self.invalidate
end
def maxvalue=(value)
@maxvalue=value
@curvalue=self.minvalue if self.minvalue && @curvalue<self.minvalue
@curvalue=self.maxvalue if self.maxvalue && @curvalue>self.maxvalue
self.invalidate
end
def initialize(label,options,curval)
super(label)
@label=label
@options=options
@minvalue=0
@maxvalue=options.length-1
@curvalue=curval
@leftarrow=Rect.new(0,0,0,0)
@rightarrow=Rect.new(0,0,0,0)
self.minvalue=@minvalue
self.maxvalue=@maxvalue
self.curvalue=@curvalue
end
def update
mousepos=Mouse::getMousePos
self.changed=false
if self.minvalue<self.maxvalue && self.curvalue<self.minvalue
self.curvalue=self.minvalue
end
return false if self.disabled
return false if !Input.repeatex?(Input::LeftMouseKey)
return false if !mousepos
left=toAbsoluteRect(@leftarrow)
right=toAbsoluteRect(@rightarrow)
oldvalue=self.curvalue
# Left arrow
if left.contains(mousepos[0],mousepos[1])
if Input.repeatcount(Input::LeftMouseKey)>100
self.curvalue-=10
elsif Input.repeatcount(Input::LeftMouseKey)>50
self.curvalue-=5
else
self.curvalue-=1
end
self.changed=(self.curvalue!=oldvalue)
self.invalidate
end
# Right arrow
if right.contains(mousepos[0],mousepos[1])
if Input.repeatcount(Input::LeftMouseKey)>100
self.curvalue+=10
elsif Input.repeatcount(Input::LeftMouseKey)>50
self.curvalue+=5
else
self.curvalue+=1
end
self.changed=(self.curvalue!=oldvalue)
self.invalidate
end
end
def refresh
bitmap=self.bitmap
if @maxoptionwidth==nil
for i in 0...@options.length
w=self.bitmap.text_size(" "+@options[i]+" ").width
@maxoptionwidth=w if !@maxoptionwidth || @maxoptionwidth<w
end
end
x=self.x
y=self.y
width=self.width
height=self.height
color=Color.new(120,120,120)
bitmap.fill_rect(x,y,width,height,Color.new(0,0,0,0))
size=bitmap.text_size(self.label).width
leftarrows=bitmap.text_size(_INTL(" << "))
rightarrows=bitmap.text_size(_INTL(" >> "))
bitmap.font.color=color
shadowtext(bitmap,x,y,size,height,self.label)
x+=size
shadowtext(bitmap,x,y,leftarrows.width,height,_INTL(" << "),
self.disabled || self.curvalue==self.minvalue)
@leftarrow=Rect.new(x,y,leftarrows.width,height)
x+=leftarrows.width
if !self.disabled
bitmap.font.color=color
shadowtext(bitmap,x,y,@maxoptionwidth,height," #{@options[self.curvalue]} ",false,1)
end
x+=@maxoptionwidth
shadowtext(bitmap,x,y,rightarrows.width,height,_INTL(" >> "),
self.disabled || self.curvalue==self.maxvalue)
@rightarrow=Rect.new(x,y,rightarrows.width,height)
end
end
class OptionalTextSlider < TextSlider
def initialize(label,options,curval)
@slider=TextSlider.new(label,options,curval)
@checkbox=Checkbox.new("")
end
def curvalue
return @checkbox.checked ? @slider.curvalue : nil
end
def curvalue=(value)
slider.curvalue=value
end
def checked
return @checkbox.checked
end
def checked=(value)
@checkbox.checked=value
end
def invalid?
return @slider.invalid? || @checkbox.invalid?
end
def invalidate
@slider.invalidate
@checkbox.invalidate
end
def validate?
@slider.validate
@checkbox.validate
end
def changed
return @slider.changed || @checkbox.changed
end
def minvalue
return @slider.minvalue
end
def minvalue=(value)
slider.minvalue=value
end
def maxvalue
return @slider.maxvalue
end
def maxvalue=(value)
slider.maxvalue=value
end
def update
updatedefs
@slider.update
@checkbox.update
end
def refresh
updatedefs
@slider.refresh
@checkbox.refresh
end
private
def updatedefs
checkboxwidth=32
@slider.bitmap=self.bitmap
@slider.parent=self.parent
@checkbox.x=self.x
@checkbox.y=self.y
@checkbox.width=checkboxwidth
@checkbox.height=self.height
@checkbox.bitmap=self.bitmap
@checkbox.parent=self.parent
@slider.x=self.x+checkboxwidth+4
@slider.y=self.y
@slider.width=self.width-checkboxwidth
@slider.height=self.height
@slider.disabled=!@checkbox.checked
end
end
class ControlWindow < SpriteWindow_Base
attr_reader :controls
def initialize(x,y,width,height)
super(x,y,width,height)
self.contents=Bitmap.new(width-32,height-32)
pbSetNarrowFont(self.contents)
@controls=[]
end
def dispose
self.contents.dispose
super
end
def refresh
for i in 0...@controls.length
@controls[i].refresh
end
end
def repaint
for i in 0...@controls.length
@controls[i].repaint
end
end
def invalidate
for i in 0...@controls.length
@controls[i].invalidate
end
end
def hittest?(i)
mousepos=Mouse::getMousePos
return false if !mousepos
return false if i<0 || i>=@controls.length
rc=Rect.new(
@controls[i].parentX,
@controls[i].parentY,
@controls[i].width,
@controls[i].height
)
return rc.contains(mousepos[0],mousepos[1])
end
def addControl(control)
i=@controls.length
@controls[i]=control
@controls[i].x=0
@controls[i].y=i*32
@controls[i].width=self.contents.width
@controls[i].height=32
@controls[i].parent=self
@controls[i].bitmap=self.contents
@controls[i].invalidate
refresh
return i
end
def addLabel(label)
return addControl(Label.new(label))
end
def addButton(label)
return addControl(Button.new(label))
end
def addSlider(label,minvalue,maxvalue,curvalue)
return addControl(Slider.new(label,minvalue,maxvalue,curvalue))
end
def addOptionalSlider(label,minvalue,maxvalue,curvalue)
return addControl(OptionalSlider.new(label,minvalue,maxvalue,curvalue))
end
def addTextSlider(label,options,curvalue)
return addControl(TextSlider.new(label,options,curvalue))
end
def addOptionalTextSlider(label,options,curvalue)
return addControl(OptionalTextSlider.new(label,options,curvalue))
end
def addCheckbox(label)
return addControl(Checkbox.new(label))
end
def addSpace
return addControl(UIControl.new(""))
end
def update
super
for i in 0...@controls.length
@controls[i].update
end
repaint
end
def changed?(i)
return false if i<0
return @controls[i].changed
end
def value(i)
return false if i<0
return @controls[i].curvalue
end
end

View File

@@ -0,0 +1,444 @@
################################################################################
# Paths and interpolation
################################################################################
class ControlPointSprite < SpriteWrapper
attr_accessor :dragging
def initialize(red,viewport=nil)
super(viewport)
self.bitmap=Bitmap.new(6,6)
self.bitmap.fill_rect(0,0,6,1,Color.new(0,0,0))
self.bitmap.fill_rect(0,0,1,6,Color.new(0,0,0))
self.bitmap.fill_rect(0,5,6,1,Color.new(0,0,0))
self.bitmap.fill_rect(5,0,1,6,Color.new(0,0,0))
color=(red) ? Color.new(255,0,0) : Color.new(0,0,0)
self.bitmap.fill_rect(2,2,2,2,color)
self.x=-6
self.y=-6
self.visible=false
@dragging=false
end
def mouseover
if Input.repeatcount(Input::LeftMouseKey)==0 || !@dragging
@dragging=false
return
end
mouse=Mouse::getMousePos(true)
return if !mouse
self.x=[[mouse[0],0].max,512].min
self.y=[[mouse[1],0].max,384].min
end
def hittest?
return true if !self.visible
mouse=Mouse::getMousePos(true)
return false if !mouse
return mouse[0]>=self.x && mouse[0]<self.x+6 &&
mouse[1]>=self.y && mouse[1]<self.y+6
end
def inspect
return "[#{self.x},#{self.y}]"
end
def dispose
self.bitmap.dispose
super
end
end
class PointSprite < SpriteWrapper
def initialize(x,y,viewport=nil)
super(viewport)
self.bitmap=Bitmap.new(2,2)
self.bitmap.fill_rect(0,0,2,2,Color.new(0,0,0))
self.x=x
self.y=y
end
def dispose
self.bitmap.dispose
super
end
end
class PointPath
include Enumerable
def initialize
@points=[]
@distances=[]
@totaldist=0
end
def [](x)
return @points[x].clone
end
def each
@points.each { |o| yield o.clone }
end
def size
return @points.size
end
def length
return @points.length
end
def totalDistance
return @totaldist
end
def inspect
p=[]
for point in @points
p.push([point[0].to_i,point[1].to_i])
end
return p.inspect
end
def isEndPoint?(x,y)
return false if @points.length==0
index=@points.length-1
return @points[index][0]==x &&
@points[index][1]==y
end
def addPoint(x,y)
@points.push([x,y])
if @points.length>1
len=@points.length
dx=@points[len-2][0]-@points[len-1][0]
dy=@points[len-2][1]-@points[len-1][1]
dist=Math.sqrt(dx*dx+dy*dy)
@distances.push(dist)
@totaldist+=dist
end
end
def clear
@points.clear
@distances.clear
@totaldist=0
end
def smoothPointPath(frames,roundValues=false)
if frames<0
raise ArgumentError.new("frames out of range: #{frames}")
end
ret=PointPath.new
if @points.length==0
return ret
end
step=1.0/frames
t=0.0
(frames+2).times do
point=pointOnPath(t)
if roundValues
ret.addPoint(point[0].round,point[1].round)
else
ret.addPoint(point[0],point[1])
end
t+=step
t=[1.0,t].min
end
return ret
end
def pointOnPath(t)
if t<0 || t>1
raise ArgumentError.new("t out of range for pointOnPath: #{t}")
end
return nil if @points.length==0
ret=@points[@points.length-1].clone
if @points.length==1
return ret
end
curdist=0
distForT=@totaldist*t
i=0
for dist in @distances
curdist+=dist
if dist>0.0
if curdist>=distForT
distT=1.0-((curdist-distForT)/dist)
dx=@points[i+1][0]-@points[i][0]
dy=@points[i+1][1]-@points[i][1]
ret=[@points[i][0]+dx*distT,
@points[i][1]+dy*distT]
break
end
end
i+=1
end
return ret
end
end
def catmullRom(p1,p2,p3,p4,t)
# p1=prevPoint, p2=startPoint, p3=endPoint, p4=nextPoint, t is from 0 through 1
t2=t*t
t3=t2*t
return 0.5*(2*p2+t*(p3-p1) +
t2*(2*p1-5*p2+4*p3-p4)+
t3*(p4-3*p3+3*p2-p1))
end
def getCatmullRomPoint(src,t)
x=0,y=0
t*=3.0
if t<1.0
x=catmullRom(src[0].x,src[0].x,src[1].x,src[2].x,t)
y=catmullRom(src[0].y,src[0].y,src[1].y,src[2].y,t)
elsif t<2.0
t-=1.0
x=catmullRom(src[0].x,src[1].x,src[2].x,src[3].x,t)
y=catmullRom(src[0].y,src[1].y,src[2].y,src[3].y,t)
else
t-=2.0
x=catmullRom(src[1].x,src[2].x,src[3].x,src[3].x,t)
y=catmullRom(src[1].y,src[2].y,src[3].y,src[3].y,t)
end
return [x,y]
end
def getCurvePoint(src,t)
return getCatmullRomPoint(src,t)
end
def curveToPointPath(curve,numpoints)
if numpoints<2
return nil
end
path=PointPath.new
step=1.0/(numpoints-1)
t=0.0
numpoints.times do
point=getCurvePoint(curve,t)
path.addPoint(point[0],point[1])
t+=step
end
return path
end
def pbDefinePath(canvas)
sliderwin2=ControlWindow.new(0,0,320,320)
sliderwin2.viewport=canvas.viewport
sliderwin2.addSlider(_INTL("Number of frames:"),2,500,20)
sliderwin2.opacity=200
defcurvebutton=sliderwin2.addButton(_INTL("Define Smooth Curve"))
defpathbutton=sliderwin2.addButton(_INTL("Define Freehand Path"))
okbutton=sliderwin2.addButton(_INTL("OK"))
cancelbutton=sliderwin2.addButton(_INTL("Cancel"))
points=[]
path=nil
loop do
Graphics.update
Input.update
sliderwin2.update
if sliderwin2.changed?(0) # Number of frames
if path
path=path.smoothPointPath(sliderwin2.value(0),false)
i=0
for point in path
if i<points.length
points[i].x=point[0]
points[i].y=point[1]
else
points.push(PointSprite.new(point[0],point[1],canvas.viewport))
end
i+=1
end
for j in i...points.length
points[j].dispose
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
point.dispose
end
points.clear
30.times do
point=PointSprite.new(0,0,canvas.viewport)
point.visible=false
points.push(point)
end
curve=[
ControlPointSprite.new(true,canvas.viewport),
ControlPointSprite.new(false,canvas.viewport),
ControlPointSprite.new(false,canvas.viewport),
ControlPointSprite.new(true,canvas.viewport)
]
showline=false
sliderwin2.visible=false
# This window displays the mouse's current position
window=Window_UnformattedTextPokemon.new("")
window.x=0
window.y=320-64
window.width=128
window.height=64
window.viewport=canvas.viewport
loop do
Graphics.update
Input.update
if Input.trigger?(Input::B)
break
end
if Input.triggerex?(Input::LeftMouseKey)
for j in 0...4
next if !curve[j].hittest?
if j==1||j==2
next if !curve[0].visible || !curve[3].visible
end
curve[j].visible=true
for k in 0...4
curve[k].dragging=(k==j)
end
break
end
end
for j in 0...4
curve[j].mouseover
end
mouse = Mouse::getMousePos(true)
newtext = (mouse) ? sprintf("(%d,%d)",mouse[0],mouse[1]) : "(??,??)"
if window.text!=newtext
window.text=newtext
end
if curve[0].visible && curve[3].visible &&
!curve[0].dragging && !curve[3].dragging
for point in points
point.visible=true
end
if !showline
curve[1].visible=true
curve[2].visible=true
curve[1].x=curve[0].x+0.3333*(curve[3].x-curve[0].x)
curve[1].y=curve[0].y+0.3333*(curve[3].y-curve[0].y)
curve[2].x=curve[0].x+0.6666*(curve[3].x-curve[0].x)
curve[2].y=curve[0].y+0.6666*(curve[3].y-curve[0].y)
end
showline=true
end
if showline
step=1.0/(points.length-1)
t=0.0
for i in 0...points.length
point=getCurvePoint(curve,t)
points[i].x=point[0]
points[i].y=point[1]
t+=step
end
end
end
window.dispose
# dispose temporary path
for point in points
point.dispose
end
points.clear
if showline
path=curveToPointPath(curve,sliderwin2.value(0))
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
for point in path
points.push(PointSprite.new(point[0],point[1],canvas.viewport))
end
end
for point in curve
point.dispose
end
sliderwin2.visible=true
next
elsif sliderwin2.changed?(defpathbutton)
canceled=false
pointpath=PointPath.new
for point in points
point.dispose
end
points.clear
window=Window_UnformattedTextPokemon.newWithSize("",
0, 320-64, 128, 64, canvas.viewport)
sliderwin2.visible=false
loop do
Graphics.update
Input.update
if Input.trigger?(Input::ESC)
canceled=true
break
end
if Input.triggerex?(Input::LeftMouseKey)
break
end
mousepos=Mouse::getMousePos(true)
window.text = (mousepos) ? sprintf("(%d,%d)",mousepos[0],mousepos[1]) : "(??,??)"
end
while !canceled
mousepos=Mouse::getMousePos(true)
if mouse && !pointpath.isEndPoint?(mousepos[0],mousepos[1])
pointpath.addPoint(mousepos[0],mousepos[1])
points.push(PointSprite.new(mousepos[0],mousepos[1],canvas.viewport))
end
window.text = (mousepos) ? sprintf("(%d,%d)",mousepos[0],mousepos[1]) : "(??,??)"
Graphics.update
Input.update
if Input.trigger?(Input::ESC) || Input.repeatcount(Input::LeftMouseKey)==0
break
end
end
window.dispose
# dispose temporary path
for point in points
point.dispose
end
points.clear
# generate smooth path from temporary path
path=pointpath.smoothPointPath(sliderwin2.value(0),true)
# redraw path from smooth path
for point in path
points.push(PointSprite.new(point[0],point[1],canvas.viewport))
end
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
sliderwin2.visible=true
next
elsif sliderwin2.changed?(okbutton) && path
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
neededsize=canvas.currentframe+sliderwin2.value(0)
if neededsize>canvas.animation.length
canvas.animation.resize(neededsize)
end
thiscel=canvas.currentCel
celnumber=canvas.currentcel
for i in canvas.currentframe...neededsize
cel=canvas.animation[i][celnumber]
if !canvas.animation[i][celnumber]
cel=pbCreateCel(0,0,thiscel[AnimFrame::PATTERN],canvas.animation.position)
canvas.animation[i][celnumber]=cel
end
cel[AnimFrame::X]=path[i-canvas.currentframe][0]
cel[AnimFrame::Y]=path[i-canvas.currentframe][1]
end
break
elsif sliderwin2.changed?(cancelbutton) || Input.trigger?(Input::B)
break
end
end
# dispose all points
for point in points
point.dispose
end
points.clear
sliderwin2.dispose
return
end

View File

@@ -0,0 +1,144 @@
################################################################################
# Importing and exporting
################################################################################
def pbRgssChdir(dir)
RTP.eachPathFor(dir) { |path| Dir.chdir(path) { yield } }
end
def tryLoadData(file)
begin
return load_data(file)
rescue
return nil
end
end
def dumpBase64Anim(s)
return [Zlib::Deflate.deflate(Marshal.dump(s))].pack("m").gsub(/\n/,"\r\n")
end
def loadBase64Anim(s)
return Marshal.restore(StringInput.new(Zlib::Inflate.inflate(s.unpack("m")[0])))
end
def pbExportAnim(animations)
filename=pbMessageFreeText(_INTL("Enter a filename."),"",false,32)
if filename!=""
begin
filename+=".anm"
File.open(filename,"wb") { |f|
f.write(dumpBase64Anim(animations[animations.selected]))
}
failed=false
rescue
pbMessage(_INTL("Couldn't save the animation to {1}.",filename))
failed=true
end
if !failed
pbMessage(_INTL("Animation was saved to {1} in the game folder.",filename))
pbMessage(_INTL("It's a text file, so it can be transferred to others easily."))
end
end
end
def pbImportAnim(animations,canvas,animwin)
animfiles=[]
pbRgssChdir(".") {
animfiles.concat(Dir.glob("*.anm"))
}
cmdwin=pbListWindow(animfiles,320)
cmdwin.opacity=200
cmdwin.height=480
cmdwin.viewport=canvas.viewport
loop do
Graphics.update
Input.update
cmdwin.update
if (Input.trigger?(Input::C) || (cmdwin.doubleclick? rescue false)) && animfiles.length>0
begin
textdata=loadBase64Anim(IO.read(animfiles[cmdwin.index]))
throw "Bad data" if !textdata.is_a?(PBAnimation)
textdata.id=-1 # this is not an RPG Maker XP animation
pbConvertAnimToNewFormat(textdata)
animations[animations.selected]=textdata
rescue
pbMessage(_INTL("The animation is invalid or could not be loaded."))
next
end
graphic=animations[animations.selected].graphic
graphic="Graphics/Animations/#{graphic}"
if graphic && graphic!="" && !FileTest.image_exist?(graphic)
pbMessage(_INTL("The animation file {1} was not found. The animation will load anyway.",graphic))
end
canvas.loadAnimation(animations[animations.selected])
animwin.animbitmap=canvas.animbitmap
break
end
if Input.trigger?(Input::B)
break
end
end
cmdwin.dispose
return
end
################################################################################
# Format conversion
################################################################################
def pbConvertAnimToNewFormat(textdata)
needconverting=false
for i in 0...textdata.length
next if !textdata[i]
for j in 0...PBAnimation::MAX_SPRITES
next if !textdata[i][j]
needconverting=true if textdata[i][j][AnimFrame::FOCUS]==nil
break if needconverting
end
break if needconverting
end
if needconverting
for i in 0...textdata.length
next if !textdata[i]
for j in 0...PBAnimation::MAX_SPRITES
next if !textdata[i][j]
textdata[i][j][AnimFrame::PRIORITY]=1 if textdata[i][j][AnimFrame::PRIORITY]==nil
if j==0 # User battler
textdata[i][j][AnimFrame::FOCUS]=2
textdata[i][j][AnimFrame::X]=PokeBattle_SceneConstants::FOCUSUSER_X
textdata[i][j][AnimFrame::Y]=PokeBattle_SceneConstants::FOCUSUSER_Y
elsif j==1 # Target battler
textdata[i][j][AnimFrame::FOCUS]=1
textdata[i][j][AnimFrame::X]=PokeBattle_SceneConstants::FOCUSTARGET_X
textdata[i][j][AnimFrame::Y]=PokeBattle_SceneConstants::FOCUSTARGET_Y
else
textdata[i][j][AnimFrame::FOCUS]=(textdata.position || 4)
if textdata.position==1
textdata[i][j][AnimFrame::X]+=PokeBattle_SceneConstants::FOCUSTARGET_X
textdata[i][j][AnimFrame::Y]+=PokeBattle_SceneConstants::FOCUSTARGET_Y-2
end
end
end
end
end
return needconverting
end
def pbConvertAnimsToNewFormat
pbMessage(_INTL("Will convert animations now."))
count=0
animations=pbLoadBattleAnimations
if !animations || !animations[0]
pbMessage(_INTL("No animations exist."))
return
end
for k in 0...animations.length
next if !animations[k]
ret=pbConvertAnimToNewFormat(animations[k])
count+=1 if ret
end
if count>0
save_data(animations,"Data/PkmnAnimations.rxdata")
$PokemonTemp.battleAnims = nil
end
pbMessage(_INTL("{1} animations converted to new format.",count))
end

File diff suppressed because it is too large Load Diff

View File

@@ -626,7 +626,7 @@ def pbEditMetadata(map_id = 0)
GameData::MapMetadata::DATA[map_id] = GameData::MapMetadata.new(metadata_hash)
GameData::MapMetadata.save
end
pbSaveMetadata
Compiler.write_metadata
end
end
@@ -671,7 +671,7 @@ def pbItemEditor
GameData::Item::DATA.delete(item)
GameData::Item::DATA.delete(id_number)
GameData::Item.save
pbSaveItems
Compiler.write_items
pbMessage(_INTL("The item was deleted."))
end
end
@@ -708,7 +708,7 @@ def pbItemEditor
# Add item's data to records
GameData::Item::DATA[itm.id_number] = GameData::Item::DATA[itm.id] = GameData::Item.new(item_hash)
GameData::Item.save
pbSaveItems
Compiler.write_items
end
else # Add a new item
pbItemEditorNew(nil)
@@ -772,7 +772,7 @@ def pbItemEditorNew(default_name)
# Add item's data to records
GameData::Item::DATA[id_number] = GameData::Item::DATA[id.to_sym] = GameData::Item.new(item_hash)
GameData::Item.save
pbSaveItems
Compiler.write_items
pbMessage(_INTL("The item {1} was created (ID: {2}).", name, id.to_s))
pbMessage(_ISPRINTF("Put the item's graphic (item{1:s}.png or item{2:03d}.png) in Graphics/Icons, or it will be blank.",
id, id_number))
@@ -857,7 +857,7 @@ def pbPokemonEditor
GameData::Species::DATA.delete(species)
GameData::Species::DATA.delete(id_number)
GameData::Species.save
pbSavePokemonData
Compiler.write_pokemon
pbMessage(_INTL("The species was deleted."))
end
end
@@ -971,7 +971,7 @@ def pbPokemonEditor
# Add species' data to records
GameData::Species::DATA[spec.id_number] = GameData::Species::DATA[spec.id] = GameData::Species.new(species_hash)
GameData::Species.save
pbSavePokemonData
Compiler.write_pokemon
pbMessage(_INTL("Data saved."))
end
else
@@ -1178,7 +1178,7 @@ def pbRegionalDexEditorMain
when 0 # Save all changes to Dexes
save_data(dex_lists, "Data/regional_dexes.dat")
$PokemonTemp.regionalDexes = nil
pbSaveRegionalDexes
Compiler.write_regional_dexes
pbMessage(_INTL("Data saved."))
break
when 1 # Just quit

View File

@@ -1,870 +0,0 @@
#===============================================================================
# Save type data to PBS file
#===============================================================================
def pbSaveTypes
File.open("PBS/types.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
# Write each type in turn
GameData::Type.each do |type|
f.write("\#-------------------------------\r\n")
f.write("[#{type.id_number}]\r\n")
f.write("Name = #{type.real_name}\r\n")
f.write("InternalName = #{type.id.to_s}\r\n")
f.write("IsPseudoType = true\r\n") if type.pseudo_type
f.write("IsSpecialType = true\r\n") if type.special?
f.write("Weaknesses = #{type.weaknesses.join(",")}\r\n") if type.weaknesses.length > 0
f.write("Resistances = #{type.resistances.join(",")}\r\n") if type.resistances.length > 0
f.write("Immunities = #{type.immunities.join(",")}\r\n") if type.immunities.length > 0
end
}
end
#===============================================================================
# Save ability data to PBS file
#===============================================================================
def pbSaveAbilities
File.open("PBS/abilities.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
GameData::Ability.each do |a|
f.write(sprintf("%d,%s,%s,%s\r\n",
a.id_number,
csvQuote(a.id.to_s),
csvQuote(a.real_name),
csvQuoteAlways(a.real_description)
))
end
}
end
#===============================================================================
# Save move data to PBS file
#===============================================================================
def pbSaveMoveData
File.open("PBS/moves.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
current_type = -1
GameData::Move.each do |m|
if current_type != m.type
current_type = m.type
f.write("\#-------------------------------\r\n")
end
f.write(sprintf("%d,%s,%s,%s,%d,%s,%s,%d,%d,%d,%s,%d,%s,%s\r\n",
m.id_number,
csvQuote(m.id.to_s),
csvQuote(m.real_name),
csvQuote(m.function_code),
m.base_damage,
m.type.to_s,
["Physical", "Special", "Status"][m.category],
m.accuracy,
m.total_pp,
m.effect_chance,
(getConstantName(PBTargets, m.target) rescue sprintf("%d", m.target)),
m.priority,
csvQuote(m.flags),
csvQuoteAlways(m.real_description)
))
end
}
end
#===============================================================================
# Save map connection data to PBS file
#===============================================================================
def normalizeConnectionPoint(conn)
ret = conn.clone
if conn[1]<0 && conn[4]<0
elsif conn[1]<0 || conn[4]<0
ret[4] = -conn[1]
ret[1] = -conn[4]
end
if conn[2]<0 && conn[5]<0
elsif conn[2]<0 || conn[5]<0
ret[5] = -conn[2]
ret[2] = -conn[5]
end
return ret
end
def writeConnectionPoint(map1,x1,y1,map2,x2,y2)
dims1 = MapFactoryHelper.getMapDims(map1)
dims2 = MapFactoryHelper.getMapDims(map2)
if x1==0 && x2==dims2[0]
return sprintf("%d,West,%d,%d,East,%d",map1,y1,map2,y2)
elsif y1==0 && y2==dims2[1]
return sprintf("%d,North,%d,%d,South,%d",map1,x1,map2,x2)
elsif x1==dims1[0] && x2==0
return sprintf("%d,East,%d,%d,West,%d",map1,y1,map2,y2)
elsif y1==dims1[1] && y2==0
return sprintf("%d,South,%d,%d,North,%d",map1,x1,map2,x2)
end
return sprintf("%d,%d,%d,%d,%d,%d",map1,x1,y1,map2,x2,y2)
end
def pbSerializeConnectionData(conndata,mapinfos)
File.open("PBS/connections.txt","wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
for conn in conndata
if mapinfos
# Skip if map no longer exists
next if !mapinfos[conn[0]] || !mapinfos[conn[3]]
f.write(sprintf("# %s (%d) - %s (%d)\r\n",
mapinfos[conn[0]] ? mapinfos[conn[0]].name : "???",conn[0],
mapinfos[conn[3]] ? mapinfos[conn[3]].name : "???",conn[3]))
end
if conn[1].is_a?(String) || conn[4].is_a?(String)
f.write(sprintf("%d,%s,%d,%d,%s,%d",conn[0],conn[1],
conn[2],conn[3],conn[4],conn[5]))
else
ret = normalizeConnectionPoint(conn)
f.write(writeConnectionPoint(ret[0],ret[1],ret[2],ret[3],ret[4],ret[5]))
end
f.write("\r\n")
end
}
save_data(conndata,"Data/map_connections.dat")
end
def pbSaveConnectionData
data = load_data("Data/map_connections.dat") rescue nil
return if !data
pbSerializeConnectionData(data,pbLoadRxData("Data/MapInfos"))
end
#===============================================================================
# Save metadata data to PBS file
#===============================================================================
def pbSaveMetadata
File.open("PBS/metadata.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
# Write global metadata
f.write("\#-------------------------------\r\n")
f.write("[000]\r\n")
metadata = GameData::Metadata.get
schema = GameData::Metadata::SCHEMA
keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] }
for key in keys
record = metadata.property_from_string(key)
next if record.nil?
f.write(sprintf("%s = ", key))
pbWriteCsvRecord(record, f, schema[key])
f.write("\r\n")
end
# Write map metadata
map_infos = pbLoadRxData("Data/MapInfos")
schema = GameData::MapMetadata::SCHEMA
keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] }
GameData::MapMetadata.each do |map_data|
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%03d]\r\n", map_data.id))
if map_infos && map_infos[map_data.id]
f.write(sprintf("# %s\r\n", map_infos[map_data.id].name))
end
for key in keys
record = map_data.property_from_string(key)
next if record.nil?
f.write(sprintf("%s = ", key))
pbWriteCsvRecord(record, f, schema[key])
f.write("\r\n")
end
end
}
end
#===============================================================================
# Save item data to PBS file
#===============================================================================
def pbSaveItems
File.open("PBS/items.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
current_pocket = 0
GameData::Item.each do |i|
if current_pocket != i.pocket
current_pocket = i.pocket
f.write("\#-------------------------------\r\n")
end
move_name = (i.move) ? GameData::Move.get(i.move).id.to_s : ""
sprintf_text = "%d,%s,%s,%s,%d,%d,%s,%d,%d,%d\r\n"
sprintf_text = "%d,%s,%s,%s,%d,%d,%s,%d,%d,%d,%s\r\n" if move_name != ""
f.write(sprintf(sprintf_text,
i.id_number,
csvQuote(i.id.to_s),
csvQuote(i.real_name),
csvQuote(i.real_name_plural),
i.pocket,
i.price,
csvQuoteAlways(i.real_description),
i.field_use,
i.battle_use,
i.type,
csvQuote(move_name)
))
end
}
end
#===============================================================================
# Save berry plant data to PBS file
#===============================================================================
def pbSaveBerryPlants
File.open("PBS/berryplants.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
GameData::BerryPlant.each do |bp|
f.write(sprintf("%s = %d,%d,%d,%d\r\n",
csvQuote(bp.id.to_s),
bp.hours_per_stage,
bp.drying_per_hour,
bp.minimum_yield,
bp.maximum_yield
))
end
}
end
#===============================================================================
# Save trainer list data to PBS file
#===============================================================================
def pbSaveTrainerLists
trainerlists = load_data("Data/trainer_lists.dat") rescue nil
return if !trainerlists
File.open("PBS/trainerlists.txt","wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
for tr in trainerlists
f.write("\#-------------------------------\r\n")
f.write(((tr[5]) ? "[DefaultTrainerList]" : "[TrainerList]")+"\r\n")
f.write("Trainers = "+tr[3]+"\r\n")
f.write("Pokemon = "+tr[4]+"\r\n")
f.write("Challenges = "+tr[2].join(",")+"\r\n") if !tr[5]
pbSaveBTTrainers(tr[0],"PBS/"+tr[3])
pbSaveBattlePokemon(tr[1],"PBS/"+tr[4])
end
}
end
#===============================================================================
# Save wild encounter data to PBS file
#===============================================================================
def pbSaveEncounterData
encdata = pbLoadEncountersData
return if !encdata
mapinfos = pbLoadRxData("Data/MapInfos")
File.open("PBS/encounters.txt","wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
sortedkeys = encdata.keys.sort
for i in sortedkeys
next if !encdata[i]
e = encdata[i]
mapname = ""
if mapinfos[i]
map = mapinfos[i].name
mapname = " # #{map}"
end
f.write("\#-------------------------------\r\n")
f.write(sprintf("%03d%s\r\n",i,mapname))
f.write(sprintf("%d,%d,%d\r\n",e[0][EncounterTypes::Land],
e[0][EncounterTypes::Cave],e[0][EncounterTypes::Water]))
for j in 0...e[1].length
enc = e[1][j]
next if !enc
f.write(sprintf("%s\r\n",EncounterTypes::Names[j]))
for k in 0...EncounterTypes::EnctypeChances[j].length
next if !enc[k]
encentry = enc[k]
if encentry[1]==encentry[2]
f.write(sprintf(" %s,%d\r\n",encentry[0],encentry[1]))
else
f.write(sprintf(" %s,%d,%d\r\n",encentry[0],encentry[1],encentry[2]))
end
end
end
end
}
end
#===============================================================================
# Save trainer type data to PBS file
#===============================================================================
def pbSaveTrainerTypes
File.open("PBS/trainertypes.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
GameData::TrainerType.each do |t|
f.write(sprintf("%d,%s,%s,%d,%s,%s,%s,%s,%s,%s\r\n",
t.id_number,
csvQuote(t.id.to_s),
csvQuote(t.real_name),
t.base_money,
csvQuote(t.battle_BGM),
csvQuote(t.victory_ME),
csvQuote(t.intro_ME),
["Male", "Female", "Mixed"][t.gender],
(t.skill_level == t.base_money) ? "" : t.skill_level.to_s,
csvQuote(t.skill_code)
))
end
}
end
#===============================================================================
# Save individual trainer data to PBS file
#===============================================================================
def pbSaveTrainerBattles
data = pbLoadTrainersData
return if !data
File.open("PBS/trainers.txt","wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
for trainer in data
trtypename = trainer[0].to_s
next if !trtypename
f.write("\#-------------------------------\r\n")
# Section
trainername = trainer[1] ? trainer[1].gsub(/,/,";") : "???"
if trainer[4]==0
f.write(sprintf("[%s,%s]\r\n",trtypename,trainername))
else
f.write(sprintf("[%s,%s,%d]\r\n",trtypename,trainername,trainer[4]))
end
# Trainer's items
if trainer[2] && trainer[2].length>0
itemstring = ""
for i in 0...trainer[2].length
itemstring.concat(",") if i > 0
itemstring.concat(trainer[2][i].to_s)
end
f.write(sprintf("Items = %s\r\n",itemstring)) if itemstring!=""
end
# Lose texts
if trainer[5] && trainer[5]!=""
f.write(sprintf("LoseText = %s\r\n",csvQuoteAlways(trainer[5])))
end
# Pokémon
for poke in trainer[3]
f.write(sprintf("Pokemon = %s,%d\r\n",poke[TrainerData::SPECIES],poke[TrainerData::LEVEL]))
if poke[TrainerData::NAME] && poke[TrainerData::NAME]!=""
f.write(sprintf(" Name = %s\r\n",poke[TrainerData::NAME]))
end
if poke[TrainerData::FORM]
f.write(sprintf(" Form = %d\r\n",poke[TrainerData::FORM]))
end
if poke[TrainerData::GENDER]
f.write(sprintf(" Gender = %s\r\n",(poke[TrainerData::GENDER]==1) ? "female" : "male"))
end
if poke[TrainerData::SHINY]
f.write(" Shiny = yes\r\n")
end
if poke[TrainerData::SHADOW]
f.write(" Shadow = yes\r\n")
end
if poke[TrainerData::MOVES] && poke[TrainerData::MOVES].length>0
movestring = ""
for i in 0...poke[TrainerData::MOVES].length
movename = GameData::Move.get(poke[TrainerData::MOVES][i]).id.to_s
next if !movename
movestring.concat(",") if i>0
movestring.concat(movename)
end
f.write(sprintf(" Moves = %s\r\n",movestring)) if movestring!=""
end
if poke[TrainerData::ABILITY]
f.write(sprintf(" Ability = %s\r\n",poke[TrainerData::ABILITY].to_s))
end
if poke[TrainerData::ITEM]
f.write(sprintf(" Item = %s\r\n",poke[TrainerData::ITEM].to_s))
end
if poke[TrainerData::NATURE]
nature = getConstantName(PBNatures,poke[TrainerData::NATURE]) rescue nil
f.write(sprintf(" Nature = %s\r\n",nature)) if nature
end
if poke[TrainerData::IV] && poke[TrainerData::IV].length>0
f.write(sprintf(" IV = %d",poke[TrainerData::IV][0]))
if poke[TrainerData::IV].length>1
for i in 1...6
f.write(sprintf(",%d",(i<poke[TrainerData::IV].length) ? poke[TrainerData::IV][i] : poke[TrainerData::IV][0]))
end
end
f.write("\r\n")
end
if poke[TrainerData::EV] && poke[TrainerData::EV].length>0
f.write(sprintf(" EV = %d",poke[TrainerData::EV][0]))
if poke[TrainerData::EV].length>1
for i in 1...6
f.write(sprintf(",%d",(i<poke[TrainerData::EV].length) ? poke[TrainerData::EV][i] : poke[TrainerData::EV][0]))
end
end
f.write("\r\n")
end
if poke[TrainerData::HAPPINESS]
f.write(sprintf(" Happiness = %d\r\n",poke[TrainerData::HAPPINESS]))
end
if poke[TrainerData::BALL]
f.write(sprintf(" Ball = %d\r\n",poke[TrainerData::BALL]))
end
end
end
}
end
#===============================================================================
# Save Town Map data to PBS file
#===============================================================================
def pbSaveTownMap
mapdata = pbLoadTownMapData
return if !mapdata
File.open("PBS/townmap.txt","wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
for i in 0...mapdata.length
map = mapdata[i]
next if !map
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%d]\r\n",i))
rname = pbGetMessage(MessageTypes::RegionNames,i)
f.write(sprintf("Name = %s\r\nFilename = %s\r\n",
(rname && rname!="") ? rname : _INTL("Unnamed"),
csvQuote((map[1].is_a?(Array)) ? map[1][0] : map[1])))
for loc in map[2]
f.write("Point = ")
pbWriteCsvRecord(loc,f,[nil,"uussUUUU"])
f.write("\r\n")
end
end
}
end
#===============================================================================
# Save phone message data to PBS file
#===============================================================================
def pbSavePhoneData
data = load_data("Data/phone.dat") rescue nil
return if !data
File.open("PBS/phone.txt","wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<Generics>]\r\n")
f.write(data.generics.join("\r\n")+"\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<BattleRequests>]\r\n")
f.write(data.battleRequests.join("\r\n")+"\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<GreetingsMorning>]\r\n")
f.write(data.greetingsMorning.join("\r\n")+"\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<GreetingsEvening>]\r\n")
f.write(data.greetingsEvening.join("\r\n")+"\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<Greetings>]\r\n")
f.write(data.greetings.join("\r\n")+"\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<Bodies1>]\r\n")
f.write(data.bodies1.join("\r\n")+"\r\n")
f.write("\#-------------------------------\r\n")
f.write("[<Bodies2>]\r\n")
f.write(data.bodies2.join("\r\n")+"\r\n")
}
end
#===============================================================================
# Save Pokémon data to PBS file
#===============================================================================
def pbSavePokemonData
File.open("PBS/pokemon.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
GameData::Species.each do |species|
next if species.form != 0
pbSetWindowText(_INTL("Writing species {1}...", species.id_number))
Graphics.update if species.id_number % 50 == 0
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%d]\r\n", species.id_number))
f.write(sprintf("Name = %s\r\n", species.real_name))
f.write(sprintf("InternalName = %s\r\n", species.species))
f.write(sprintf("Type1 = %s\r\n", species.type1))
f.write(sprintf("Type2 = %s\r\n", species.type2)) if species.type2 != species.type1
f.write(sprintf("BaseStats = %s\r\n", species.base_stats.join(",")))
f.write(sprintf("GenderRate = %s\r\n", getConstantName(PBGenderRates, species.gender_rate)))
f.write(sprintf("GrowthRate = %s\r\n", getConstantName(PBGrowthRates, species.growth_rate)))
f.write(sprintf("BaseEXP = %d\r\n", species.base_exp))
f.write(sprintf("EffortPoints = %s\r\n", species.evs.join(",")))
f.write(sprintf("Rareness = %d\r\n", species.catch_rate))
f.write(sprintf("Happiness = %d\r\n", species.happiness))
if species.abilities.length > 0
f.write(sprintf("Abilities = %s\r\n", species.abilities.join(",")))
end
if species.hidden_abilities.length > 0
f.write(sprintf("HiddenAbility = %s\r\n", species.hidden_abilities.join(",")))
end
if species.moves.length > 0
f.write(sprintf("Moves = %s\r\n", species.moves.join(",")))
end
if species.tutor_moves.length > 0
f.write(sprintf("TutorMoves = %s\r\n", species.tutor_moves.join(",")))
end
if species.egg_moves.length > 0
f.write(sprintf("EggMoves = %s\r\n", species.egg_moves.join(",")))
end
if species.egg_groups.length > 0
f.write("Compatibility = ")
species.egg_groups.each_with_index do |group, i|
f.write(",") if i > 0
f.write(getConstantName(PBEggGroups, group))
end
f.write("\r\n")
end
f.write(sprintf("StepsToHatch = %d\r\n", species.hatch_steps))
f.write(sprintf("Height = %.1f\r\n", species.height / 10.0))
f.write(sprintf("Weight = %.1f\r\n", species.weight / 10.0))
f.write(sprintf("Color = %s\r\n", getConstantName(PBColors, species.color)))
f.write(sprintf("Shape = %d\r\n", species.shape))
f.write(sprintf("Habitat = %s\r\n", getConstantName(PBHabitats, species.habitat))) if species.habitat != PBHabitats::None
f.write(sprintf("Kind = %s\r\n", species.real_category))
f.write(sprintf("Pokedex = %s\r\n", species.real_pokedex_entry))
f.write(sprintf("FormName = %s\r\n", species.real_form_name)) if species.real_form_name && !species.real_form_name.empty?
f.write(sprintf("Generation = %d\r\n", species.generation)) if species.generation != 0
f.write(sprintf("WildItemCommon = %s\r\n", species.wild_item_common)) if species.wild_item_common
f.write(sprintf("WildItemUncommon = %s\r\n", species.wild_item_uncommon)) if species.wild_item_uncommon
f.write(sprintf("WildItemRare = %s\r\n", species.wild_item_rare)) if species.wild_item_rare
f.write(sprintf("BattlerPlayerX = %d\r\n", species.back_sprite_x))
f.write(sprintf("BattlerPlayerY = %d\r\n", species.back_sprite_y))
f.write(sprintf("BattlerEnemyX = %d\r\n", species.front_sprite_x))
f.write(sprintf("BattlerEnemyY = %d\r\n", species.front_sprite_y))
f.write(sprintf("BattlerAltitude = %d\r\n", species.front_sprite_altitude)) if species.front_sprite_altitude != 0
f.write(sprintf("BattlerShadowX = %d\r\n", species.shadow_x))
f.write(sprintf("BattlerShadowSize = %d\r\n", species.shadow_size))
if species.evolutions.any? { |evo| !evo[3] }
f.write("Evolutions = ")
need_comma = false
species.evolutions.each do |evo|
next if evo[3] # Skip prevolution entries
f.write(",") if need_comma
need_comma = true
f.write(sprintf("%s,%s,", evo[0], getConstantName(PBEvolution, evo[1])))
param_type = PBEvolution.getFunction(evo[1], "parameterType")
has_param = !PBEvolution.hasFunction?(evo[1], "parameterType") || param_type != nil
next if !has_param
if param_type
if GameData.const_defined?(param_type.to_sym)
f.write(evo[2].to_s)
else
f.write(getConstantName(param_type, evo[2]))
end
else
f.write(evo[2].to_s)
end
end
f.write("\r\n")
end
f.write(sprintf("Incense = %s\r\n", species.incense)) if species.incense
end
}
Graphics.update
end
#===============================================================================
# Save Pokémon forms data to PBS file
#===============================================================================
def pbSavePokemonFormsData
File.open("PBS/pokemonforms.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
GameData::Species.each do |species|
next if species.form == 0
base_species = GameData::Species.get(species.species)
pbSetWindowText(_INTL("Writing species {1}...", species.id_number))
Graphics.update if species.id_number % 50 == 0
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%s,%d]\r\n", species.species, species.form))
f.write(sprintf("FormName = %s\r\n", species.real_form_name)) if species.real_form_name && !species.real_form_name.empty?
f.write(sprintf("PokedexForm = %d\r\n", species.pokedex_form)) if species.pokedex_form != species.form
f.write(sprintf("MegaStone = %s\r\n", species.mega_stone)) if species.mega_stone
f.write(sprintf("MegaMove = %s\r\n", species.mega_move)) if species.mega_move
f.write(sprintf("UnmegaForm = %d\r\n", species.unmega_form)) if species.unmega_form != 0
f.write(sprintf("MegaMessage = %d\r\n", species.mega_message)) if species.mega_message != 0
if species.type1 != base_species.type1 || species.type2 != base_species.type2
f.write(sprintf("Type1 = %s\r\n", species.type1))
f.write(sprintf("Type2 = %s\r\n", species.type2)) if species.type2 != species.type1
end
f.write(sprintf("BaseStats = %s\r\n", species.base_stats.join(","))) if species.base_stats != base_species.base_stats
f.write(sprintf("BaseEXP = %d\r\n", species.base_exp)) if species.base_exp != base_species.base_exp
f.write(sprintf("EffortPoints = %s\r\n", species.evs.join(","))) if species.evs != base_species.evs
f.write(sprintf("Rareness = %d\r\n", species.catch_rate)) if species.catch_rate != base_species.catch_rate
f.write(sprintf("Happiness = %d\r\n", species.happiness)) if species.happiness != base_species.happiness
if species.abilities.length > 0 && species.abilities != base_species.abilities
f.write(sprintf("Abilities = %s\r\n", species.abilities.join(",")))
end
if species.hidden_abilities.length > 0 && species.hidden_abilities != base_species.hidden_abilities
f.write(sprintf("HiddenAbility = %s\r\n", species.hidden_abilities.join(",")))
end
if species.moves.length > 0 && species.moves != base_species.moves
f.write(sprintf("Moves = %s\r\n", species.moves.join(",")))
end
if species.tutor_moves.length > 0 && species.tutor_moves != base_species.tutor_moves
f.write(sprintf("TutorMoves = %s\r\n", species.tutor_moves.join(",")))
end
if species.egg_moves.length > 0 && species.egg_moves != base_species.egg_moves
f.write(sprintf("EggMoves = %s\r\n", species.egg_moves.join(",")))
end
if species.egg_groups.length > 0 && species.egg_groups != base_species.egg_groups
f.write("Compatibility = ")
species.egg_groups.each_with_index do |group, i|
f.write(",") if i > 0
f.write(getConstantName(PBEggGroups, group))
end
f.write("\r\n")
end
f.write(sprintf("StepsToHatch = %d\r\n", species.hatch_steps)) if species.hatch_steps != base_species.hatch_steps
f.write(sprintf("Height = %.1f\r\n", species.height / 10.0)) if species.height != base_species.height
f.write(sprintf("Weight = %.1f\r\n", species.weight / 10.0)) if species.weight != base_species.weight
f.write(sprintf("Color = %s\r\n", getConstantName(PBColors, species.color))) if species.color != base_species.color
f.write(sprintf("Shape = %d\r\n", species.shape)) if species.shape != base_species.shape
if species.habitat != PBHabitats::None && species.habitat != base_species.habitat
f.write(sprintf("Habitat = %s\r\n", getConstantName(PBHabitats, species.habitat)))
end
f.write(sprintf("Kind = %s\r\n", species.real_category)) if species.real_category != base_species.real_category
f.write(sprintf("Pokedex = %s\r\n", species.real_pokedex_entry)) if species.real_pokedex_entry != base_species.real_pokedex_entry
f.write(sprintf("Generation = %d\r\n", species.generation)) if species.generation != base_species.generation
if species.wild_item_common != base_species.wild_item_common ||
species.wild_item_uncommon != base_species.wild_item_uncommon ||
species.wild_item_rare != base_species.wild_item_rare
f.write(sprintf("WildItemCommon = %s\r\n", species.wild_item_common)) if species.wild_item_common
f.write(sprintf("WildItemUncommon = %s\r\n", species.wild_item_uncommon)) if species.wild_item_uncommon
f.write(sprintf("WildItemRare = %s\r\n", species.wild_item_rare)) if species.wild_item_rare
end
f.write(sprintf("BattlerPlayerX = %d\r\n", species.back_sprite_x)) if species.back_sprite_x != base_species.back_sprite_x
f.write(sprintf("BattlerPlayerY = %d\r\n", species.back_sprite_y)) if species.back_sprite_y != base_species.back_sprite_y
f.write(sprintf("BattlerEnemyX = %d\r\n", species.front_sprite_x)) if species.front_sprite_x != base_species.front_sprite_x
f.write(sprintf("BattlerEnemyY = %d\r\n", species.front_sprite_y)) if species.front_sprite_y != base_species.front_sprite_y
f.write(sprintf("BattlerAltitude = %d\r\n", species.front_sprite_altitude)) if species.front_sprite_altitude != base_species.front_sprite_altitude
f.write(sprintf("BattlerShadowX = %d\r\n", species.shadow_x)) if species.shadow_x != base_species.shadow_x
f.write(sprintf("BattlerShadowSize = %d\r\n", species.shadow_size)) if species.shadow_size != base_species.shadow_size
if species.evolutions != base_species.evolutions && species.evolutions.any? { |evo| !evo[3] }
f.write("Evolutions = ")
need_comma = false
species.evolutions.each do |evo|
next if evo[3] # Skip prevolution entries
f.write(",") if need_comma
need_comma = true
f.write(sprintf("%s,%s,", evo[0], getConstantName(PBEvolution, evo[1])))
param_type = PBEvolution.getFunction(evo[1], "parameterType")
has_param = !PBEvolution.hasFunction?(evo[1], "parameterType") || param_type != nil
next if !has_param
if param_type
if GameData.const_defined?(param_type.to_sym)
f.write(evo[2].to_s)
else
f.write(getConstantName(param_type, evo[2]))
end
else
f.write(evo[2].to_s)
end
end
f.write("\r\n")
end
end
}
Graphics.update
end
#===============================================================================
# Save Shadow move data to PBS file
#===============================================================================
def pbSaveShadowMoves
shadow_movesets = pbLoadShadowMovesets
File.open("PBS/shadowmoves.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
GameData::Species.each do |species_data|
moveset = shadow_movesets[species_data.id]
next if !moveset || moveset.length == 0
f.write(sprintf("%s = %s\r\n", species_data.id, moveset.join(",")))
end
}
end
#===============================================================================
# Save Regional Dexes data to PBS file
#===============================================================================
def pbSaveRegionalDexes
dex_lists = pbLoadRegionalDexes
File.open("PBS/regionaldexes.txt", "wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
# Write each Dex list in turn
dex_lists.each_with_index do |list, index|
f.write("\#-------------------------------\r\n")
f.write("[#{index}]")
comma = false
current_family = nil
list.each do |species|
next if !species
if current_family && current_family.include?(species)
f.write(",") if comma
else
current_family = EvolutionHelper.all_related_species(species)
comma = false
f.write("\r\n")
end
f.write(species)
comma = true
end
f.write("\r\n")
end
}
end
#===============================================================================
# Save Battle Tower trainer data to PBS file
#===============================================================================
def pbSaveBTTrainers(bttrainers,filename)
return if !bttrainers || !filename
btTrainersRequiredTypes = {
"Type" => [0,"e",nil], # Specifies a trainer
"Name" => [1,"s"],
"BeginSpeech" => [2,"s"],
"EndSpeechWin" => [3,"s"],
"EndSpeechLose" => [4,"s"],
"PokemonNos" => [5,"*u"]
}
File.open(filename,"wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
for i in 0...bttrainers.length
next if !bttrainers[i]
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%03d]\r\n",i))
for key in btTrainersRequiredTypes.keys
schema = btTrainersRequiredTypes[key]
record = bttrainers[i][schema[0]]
next if record==nil
f.write(sprintf("%s = ",key))
if key=="Type"
f.write(record.to_s)
elsif key=="PokemonNos"
f.write(record.join(",")) # pbWriteCsvRecord somehow won't work here
else
pbWriteCsvRecord(record,f,schema)
end
f.write(sprintf("\r\n"))
end
end
}
end
#===============================================================================
# Save Battle Tower Pokémon data to PBS file
#===============================================================================
def pbSaveBattlePokemon(btpokemon,filename)
return if !btpokemon || !filename
species = {0=>""}
moves = {0=>""}
items = {0=>""}
natures = {}
File.open(filename,"wb") { |f|
f.write(0xEF.chr)
f.write(0xBB.chr)
f.write(0xBF.chr)
f.write("\# " + _INTL("See the documentation on the wiki to learn how to edit this file.") + "\r\n")
f.write("\#-------------------------------\r\n")
for i in 0...btpokemon.length
Graphics.update if i%500==0
pkmn = btpokemon[i]
f.write(pbFastInspect(pkmn,moves,species,items,natures))
f.write("\r\n")
end
}
end
def pbFastInspect(pkmn,moves,species,items,natures)
c1 = (species[pkmn.species]) ? species[pkmn.species] : (species[pkmn.species] = GameData::Species.get(pkmn.species).species.to_s)
c2 = (items[pkmn.item]) ? items[pkmn.item] : (items[pkmn.item] = GameData::Item.get(pkmn.item).id.to_s)
c3 = (natures[pkmn.nature]) ? natures[pkmn.nature] :
(natures[pkmn.nature] = getConstantName(PBNatures,pkmn.nature))
evlist = ""
ev = pkmn.ev
evs = ["HP","ATK","DEF","SPD","SA","SD"]
for i in 0...ev
if ((ev&(1<<i))!=0)
evlist += "," if evlist.length>0
evlist += evs[i]
end
end
c4 = (moves[pkmn.move1]) ? moves[pkmn.move1] : (moves[pkmn.move1] = GameData::Move.get(pkmn.move1).id.to_s)
c5 = (moves[pkmn.move2]) ? moves[pkmn.move2] : (moves[pkmn.move2] = GameData::Move.get(pkmn.move2).id.to_s)
c6 = (moves[pkmn.move3]) ? moves[pkmn.move3] : (moves[pkmn.move3] = GameData::Move.get(pkmn.move3).id.to_s)
c7 = (moves[pkmn.move4]) ? moves[pkmn.move4] : (moves[pkmn.move4] = GameData::Move.get(pkmn.move4).id.to_s)
return "#{c1};#{c2};#{c3};#{evlist};#{c4},#{c5},#{c6},#{c7}"
end
#===============================================================================
# Save all data to PBS files
#===============================================================================
def pbSaveAllData
pbSaveTypes; Graphics.update
pbSaveAbilities; Graphics.update
pbSaveMoveData; Graphics.update
pbSaveConnectionData; Graphics.update
pbSaveMetadata; Graphics.update
pbSaveItems; Graphics.update
pbSaveBerryPlants; Graphics.update
pbSaveTrainerLists; Graphics.update
pbSaveEncounterData; Graphics.update
pbSaveTrainerTypes; Graphics.update
pbSaveTrainerBattles; Graphics.update
pbSaveTownMap; Graphics.update
pbSavePhoneData; Graphics.update
pbSavePokemonData; Graphics.update
pbSavePokemonFormsData; Graphics.update
pbSaveShadowMoves; Graphics.update
pbSaveRegionalDexes; Graphics.update
end

View File

@@ -1,116 +0,0 @@
#===============================================================================
# String formatting, conversion of value to string
#===============================================================================
def csvQuote(str,always=false)
return "" if !str || str==""
if always || str[/[,\"]/] # || str[/^\s/] || str[/\s$/] || str[/^#/]
str = str.gsub(/[\"]/,"\\\"")
str = "\"#{str}\""
end
return str
end
def csvQuoteAlways(str)
return csvQuote(str,true)
end
def pbWriteCsvRecord(record,file,schema)
rec = (record.is_a?(Array)) ? record.clone : [record]
for i in 0...schema[1].length
chr = schema[1][i,1]
file.write(",") if i>0
if rec[i].nil?
# do nothing
elsif rec[i].is_a?(String)
file.write(csvQuote(rec[i]))
elsif rec[i].is_a?(Symbol)
file.write(csvQuote(rec[i].to_s))
elsif rec[i]==true
file.write("true")
elsif rec[i]==false
file.write("false")
elsif rec[i].is_a?(Numeric)
case chr
when "e", "E" # Enumerable
enumer = schema[2+i]
if enumer.is_a?(Array)
file.write(enumer[rec[i]])
elsif enumer.is_a?(Symbol) || enumer.is_a?(String)
mod = Object.const_get(enumer.to_sym)
file.write(getConstantName(mod,rec[i]))
elsif enumer.is_a?(Module)
file.write(getConstantName(enumer,rec[i]))
elsif enumer.is_a?(Hash)
for key in enumer.keys
if enumer[key]==rec[i]
file.write(key)
break
end
end
end
when "y", "Y" # Enumerable or integer
enumer = schema[2+i]
if enumer.is_a?(Array)
if enumer[rec[i]]!=nil
file.write(enumer[rec[i]])
else
file.write(rec[i])
end
elsif enumer.is_a?(Symbol) || enumer.is_a?(String)
mod = Object.const_get(enumer.to_sym)
file.write(getConstantNameOrValue(mod,rec[i]))
elsif enumer.is_a?(Module)
file.write(getConstantNameOrValue(enumer,rec[i]))
elsif enumer.is_a?(Hash)
hasenum = false
for key in enumer.keys
if enumer[key]==rec[i]
file.write(key)
hasenum = true; break
end
end
file.write(rec[i]) unless hasenum
end
else # Any other record type
file.write(rec[i].inspect)
end
else
file.write(rec[i].inspect)
end
end
return record
end
#===============================================================================
# Enum const manipulators and parsers
#===============================================================================
def getConstantName(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
return c if mod.const_get(c.to_sym)==value
end
raise _INTL("Value {1} not defined by a constant in {2}",value,mod.name)
end
def getConstantNameOrValue(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
return c if mod.const_get(c.to_sym)==value
end
return value.inspect
end
def setConstantName(mod,value,name)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
mod.send(:remove_const,c.to_sym) if mod.const_get(c.to_sym)==value
end
mod.const_set(name,value)
end
def removeConstantValue(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
mod.send(:remove_const,c.to_sym) if mod.const_get(c.to_sym)==value
end
end

View File

@@ -108,110 +108,6 @@ def pbMapTree
return retarray
end
#===============================================================================
# Make up internal names for things based on their actual names
#===============================================================================
module MakeshiftConsts
@@consts = []
def self.get(c,i,modname=nil)
@@consts[c] = [] if !@@consts[c]
return @@consts[c][i] if @@consts[c][i]
if modname
v = getConstantName(modname,i) rescue nil
if v
@@consts[c][i] = v
return v
end
end
trname = pbGetMessage(c,i)
trconst = trname.gsub(/é/,"e")
trconst = trconst.upcase
trconst = trconst.gsub(//,"fE")
trconst = trconst.gsub(//,"mA")
trconst = trconst.gsub(/[^A-Za-z0-9_]/,"")
if trconst.length==0
return nil if trname.length==0
trconst = sprintf("T_%03d",i)
elsif !trconst[0,1][/[A-Z]/]
trconst = "T_"+trconst
end
while @@consts[c].include?(trconst)
trconst = sprintf("%s_%03d",trconst,i)
end
@@consts[c][i] = trconst
return trconst
end
end
def pbGetEvolutionConst(i)
ret = MakeshiftConsts.get(50,i,PBEvolution)
if !ret
ret = ["None",
"Happiness","HappinessDay","HappinessNight","Level","Trade",
"TradeItem","Item","AttackGreater","AtkDefEqual","DefenseGreater",
"Silcoon","Cascoon","Ninjask","Shedinja","Beauty",
"ItemMale","ItemFemale","DayHoldItem","NightHoldItem","HasMove",
"HasInParty","LevelMale","LevelFemale","Location","TradeSpecies",
"Custom1","Custom2","Custom3","Custom4","Custom5"]
i = 0 if i>=ret.length || i<0
ret = ret[i]
end
return ret
end
def pbGetEggGroupConst(i)
ret = MakeshiftConsts.get(51,i,PBEggGroups)
if !ret
ret = ["Undiscovered",
"Monster","Water1","Bug","Flying","Field",
"Fairy","Grass","Humanlike","Water3","Mineral",
"Amorphous","Water2","Ditto","Dragon"][i]
i = 0 if i>=ret.length || i<0
ret = ret[i]
end
return ret
end
def pbGetColorConst(i)
ret = MakeshiftConsts.get(52,i,PBColors)
if !ret
ret = ["Red","Blue","Yellow","Green","Black","Brown","Purple","Gray","White","Pink"]
i = 0 if i>=ret.length || i<0
ret = ret[i]
end
return ret
end
def pbGetGenderConst(i)
ret = MakeshiftConsts.get(53,i,PBGenderRates)
if !ret
ret = ["Genderless","AlwaysMale","FemaleOneEighth","Female25Percent",
"Female50Percent","Female75Percent","FemaleSevenEighths",
"AlwaysFemale"]
i = 0 if i>=ret.length || i<0
ret = ret[i]
end
return ret
end
def pbGetHabitatConst(i)
ret = MakeshiftConsts.get(54,i,PBHabitats)
if !ret
ret = ["","Grassland","Forest","WatersEdge","Sea","Cave","Mountain",
"RoughTerrain","Urban","Rare"]
i = 0 if i>=ret.length || i<0
ret = ret[i]
end
return ret
end
#===============================================================================
# List all members of a class
#===============================================================================

View File

@@ -284,7 +284,8 @@ class MapScreenScene
def serializeConnectionData
conndata=generateConnectionData()
pbSerializeConnectionData(conndata,@mapinfos)
save_data(conndata, "Data/map_connections.dat")
Compiler.write_connections
@mapconns=conndata
end
@@ -575,7 +576,7 @@ class MapScreenScene
MapFactoryHelper.clear
save_data(@encdata,"Data/encounters.dat")
$PokemonTemp.encountersData = nil
pbSaveEncounterData
Compiler.write_encounters
end
break if pbConfirmMessage(_INTL("Exit from the editor?"))
end

View File

@@ -32,8 +32,8 @@ def pbAutoPositionAll
bitmap2.dispose if bitmap2
end
GameData::Species.save
pbSavePokemonData
pbSavePokemonFormsData
Compiler.write_pokemon
Compiler.write_pokemon_forms
end
#===============================================================================
@@ -97,8 +97,8 @@ class SpritePositioner
def pbSaveMetrics
GameData::Species.save
pbSavePokemonData
pbSavePokemonFormsData
Compiler.write_pokemon
Compiler.write_pokemon_forms
end
def update

File diff suppressed because it is too large Load Diff