Skip to content
Permalink
Browse files

particles: add snake-case aliases to Python particle classes

  • Loading branch information
rdb committed Nov 10, 2019
1 parent ccca3cc commit f47fd8875cf1e9a4ecb636b54b30d74944c9ede5
Showing with 52 additions and 5 deletions.
  1. +11 −1 direct/src/particles/ForceGroup.py
  2. +27 −4 direct/src/particles/ParticleEffect.py
  3. +14 −0 direct/src/particles/Particles.py
@@ -6,13 +6,14 @@
from direct.directnotify import DirectNotifyGlobal
import sys


class ForceGroup(DirectObject):

notify = DirectNotifyGlobal.directNotify.newCategory('ForceGroup')
id = 1

def __init__(self, name=None):
if (name == None):
if name is None:
self.name = 'ForceGroup-%d' % ForceGroup.id
ForceGroup.id += 1
else:
@@ -60,9 +61,12 @@ def removeForce(self, force):

# Get/set
def getName(self):
"""Deprecated: access .name directly instead."""
return self.name

def getNode(self):
return self.node

def getNodePath(self):
return self.nodePath

@@ -124,3 +128,9 @@ def printParams(self, file = sys.stdout, targ = 'self'):
file.write(fname + ' = AngularVectorForce(Quat(%.4f, %.4f, %.4f))\n' % (vec[0], vec[1], vec[2], vec[3]))
file.write(fname + '.setActive(%d)\n' % f.getActive())
file.write(targ + '.addForce(%s)\n' % fname)

is_enabled = isEnabled
get_node = getNode
get_node_path = getNodePath
as_list = asList
print_params = printParams
@@ -8,12 +8,13 @@

from direct.directnotify import DirectNotifyGlobal


class ParticleEffect(NodePath):
notify = DirectNotifyGlobal.directNotify.newCategory('ParticleEffect')
pid = 1

def __init__(self, name=None, particles=None):
if name == None:
if name is None:
name = 'particle-effect-%d' % ParticleEffect.pid
ParticleEffect.pid += 1
NodePath.__init__(self, name)
@@ -25,7 +26,7 @@ def __init__(self, name=None, particles=None):
self.particlesDict = {}
self.forceGroupDict = {}
# The effect's particle system
if particles != None:
if particles is not None:
self.addParticles(particles)
self.renderParent = None

@@ -55,7 +56,7 @@ def start(self, parent=None, renderParent=None):
assert self.notify.debug('start() - name: %s' % self.name)
self.renderParent = renderParent
self.enable()
if parent != None:
if parent is not None:
self.reparentTo(parent)

def enable(self):
@@ -128,7 +129,7 @@ def addParticles(self, particles):
particles.addForce(fg[i])

def removeParticles(self, particles):
if particles == None:
if particles is None:
self.notify.warning('removeParticles() - particles == None!')
return
particles.nodePath.detachNode()
@@ -232,3 +233,25 @@ def softStart(self):
def __isValid(self):
return hasattr(self, 'forceGroupDict') and \
hasattr(self, 'particlesDict')

# Snake-case aliases.
is_enabled = isEnabled
add_force_group = addForceGroup
add_force = addForce
remove_force_group = removeForceGroup
remove_force = removeForce
remove_all_forces = removeAllForces
add_particles = addParticles
remove_particles = removeParticles
remove_all_particles = removeAllParticles
get_particles_list = getParticlesList
get_particles_named = getParticlesNamed
get_particles_dict = getParticlesDict
get_force_group_list = getForceGroupList
get_force_group_named = getForceGroupNamed
get_force_group_dict = getForceGroupDict
save_config = saveConfig
load_config = loadConfig
clear_to_initial = clearToInitial
soft_stop = softStop
soft_start = softStart
@@ -600,3 +600,17 @@ def accelerate(self,time,stepCount = 1,stepTime=0.0):
base.physicsMgr.doPhysics(remainder,self)

self.render()

# Snake-case aliases.
is_enabled = isEnabled
set_factory = setFactory
set_renderer = setRenderer
set_emitter = setEmitter
add_force = addForce
remove_force = removeForce
set_render_node_path = setRenderNodePath
get_factory = getFactory
get_emitter = getEmitter
get_renderer = getRenderer
print_params = printParams
get_pool_size_ranges = getPoolSizeRanges

0 comments on commit f47fd88

Please sign in to comment.
You can’t perform that action at this time.