added Particles.getParticleProperties() to JS

This commit is contained in:
ZappoMan 2014-01-24 12:56:36 -08:00
parent bcaafb25f0
commit 0b871c80c3
4 changed files with 35 additions and 0 deletions

View file

@ -840,6 +840,8 @@ ParticleProperties::ParticleProperties() :
_inHand(false),
_shouldDie(false),
_id(UNKNOWN_PARTICLE_ID),
_idSet(false),
_lastEdited(usecTimestampNow()),
_positionChanged(false),
_colorChanged(false),
@ -925,6 +927,11 @@ QScriptValue ParticleProperties::copyToScriptValue(QScriptEngine* engine) const
properties.setProperty("script", _script);
properties.setProperty("inHand", _inHand);
properties.setProperty("shouldDie", _shouldDie);
if (_idSet) {
properties.setProperty("id", _id);
properties.setProperty("isKnownID", (_id == UNKNOWN_PARTICLE_ID));
}
return properties;
}
@ -1118,6 +1125,9 @@ void ParticleProperties::copyFromParticle(const Particle& particle) {
_inHand = particle.getInHand();
_shouldDie = particle.getShouldDie();
_id = particle.getID();
_idSet = true;
_positionChanged = false;
_colorChanged = false;
_radiusChanged = false;

View file

@ -94,6 +94,9 @@ public:
void setShouldDie(bool shouldDie) { _shouldDie = shouldDie; _shouldDieChanged = true; }
void setLifetime(float value) { _lifetime = value; _lifetimeChanged = true; }
void setScript(QString updateScript) { _script = updateScript; _scriptChanged = true; }
/// used by ParticleScriptingInterface to return ParticleProperties for unknown particles
void setIsUnknownID() { _id = UNKNOWN_PARTICLE_ID; _idSet = true; }
private:
glm::vec3 _position;
@ -107,6 +110,8 @@ private:
bool _inHand;
bool _shouldDie;
uint32_t _id;
bool _idSet;
uint64_t _lastEdited;
bool _positionChanged;
bool _colorChanged;

View file

@ -49,6 +49,22 @@ ParticleID ParticlesScriptingInterface::identifyParticle(ParticleID particleID)
return particleID;
}
ParticleProperties ParticlesScriptingInterface::getParticleProperties(ParticleID particleID) {
ParticleProperties results;
ParticleID identity = identifyParticle(particleID);
if (!identity.isKnownID) {
results.setIsUnknownID();
return results;
}
if (_particleTree) {
const Particle* particle = _particleTree->findParticleByID(identity.id);
results.copyFromParticle(*particle);
}
return results;
}
ParticleID ParticlesScriptingInterface::editParticle(ParticleID particleID, const ParticleProperties& properties) {
uint32_t actualID = particleID.id;

View file

@ -34,6 +34,10 @@ public slots:
/// identify a recently created particle to determine its true ID
ParticleID identifyParticle(ParticleID particleID);
/// gets the current particle properties for a specific particle
/// this function will not find return results in script engine contexts which don't have access to particles
ParticleProperties getParticleProperties(ParticleID particleID);
/// edits a particle updating only the included properties, will return the identified ParticleID in case of
/// successful edit, if the input particleID is for an unknown particle this function will have no effect
ParticleID editParticle(ParticleID particleID, const ParticleProperties& properties);