mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 08:44:19 -04:00
ParticlePanel: fixed an issue that prevented saving with Python 3
Since in Python 3 `str == bytes` no longer holds true, I modified the source to write a text file, which it actually is, instead of a binary file. Closes #553 Fixes #543
This commit is contained in:
parent
3875cc8259
commit
33d11dba27
@ -163,44 +163,41 @@ class ParticleEffect(NodePath):
|
|||||||
|
|
||||||
def saveConfig(self, filename):
|
def saveConfig(self, filename):
|
||||||
filename = Filename(filename)
|
filename = Filename(filename)
|
||||||
f = open(filename.toOsSpecific(), 'wb')
|
with open(filename.toOsSpecific(), 'w') as f:
|
||||||
# Add a blank line
|
# Add a blank line
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
|
||||||
# Make sure we start with a clean slate
|
# Make sure we start with a clean slate
|
||||||
f.write('self.reset()\n')
|
f.write('self.reset()\n')
|
||||||
|
|
||||||
pos = self.getPos()
|
pos = self.getPos()
|
||||||
hpr = self.getHpr()
|
hpr = self.getHpr()
|
||||||
scale = self.getScale()
|
scale = self.getScale()
|
||||||
f.write('self.setPos(%0.3f, %0.3f, %0.3f)\n' %
|
f.write('self.setPos(%0.3f, %0.3f, %0.3f)\n' %
|
||||||
(pos[0], pos[1], pos[2]))
|
(pos[0], pos[1], pos[2]))
|
||||||
f.write('self.setHpr(%0.3f, %0.3f, %0.3f)\n' %
|
f.write('self.setHpr(%0.3f, %0.3f, %0.3f)\n' %
|
||||||
(hpr[0], hpr[1], hpr[2]))
|
(hpr[0], hpr[1], hpr[2]))
|
||||||
f.write('self.setScale(%0.3f, %0.3f, %0.3f)\n' %
|
f.write('self.setScale(%0.3f, %0.3f, %0.3f)\n' %
|
||||||
(scale[0], scale[1], scale[2]))
|
(scale[0], scale[1], scale[2]))
|
||||||
|
|
||||||
# Save all the particles to file
|
# Save all the particles to file
|
||||||
num = 0
|
num = 0
|
||||||
for p in list(self.particlesDict.values()):
|
for p in list(self.particlesDict.values()):
|
||||||
target = 'p%d' % num
|
target = 'p%d' % num
|
||||||
num = num + 1
|
num = num + 1
|
||||||
f.write(target + ' = Particles.Particles(\'%s\')\n' % p.getName())
|
f.write(target + ' = Particles.Particles(\'%s\')\n' % p.getName())
|
||||||
p.printParams(f, target)
|
p.printParams(f, target)
|
||||||
f.write('self.addParticles(%s)\n' % target)
|
f.write('self.addParticles(%s)\n' % target)
|
||||||
|
|
||||||
# Save all the forces to file
|
# Save all the forces to file
|
||||||
num = 0
|
num = 0
|
||||||
for fg in list(self.forceGroupDict.values()):
|
for fg in list(self.forceGroupDict.values()):
|
||||||
target = 'f%d' % num
|
target = 'f%d' % num
|
||||||
num = num + 1
|
num = num + 1
|
||||||
f.write(target + ' = ForceGroup.ForceGroup(\'%s\')\n' % \
|
f.write(target + ' = ForceGroup.ForceGroup(\'%s\')\n' % \
|
||||||
fg.getName())
|
fg.getName())
|
||||||
fg.printParams(f, target)
|
fg.printParams(f, target)
|
||||||
f.write('self.addForceGroup(%s)\n' % target)
|
f.write('self.addForceGroup(%s)\n' % target)
|
||||||
|
|
||||||
# Close the file
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def loadConfig(self, filename):
|
def loadConfig(self, filename):
|
||||||
data = vfs.readFile(filename, 1)
|
data = vfs.readFile(filename, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user