Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Sound.js
function Sound() {} | function Sound() {} | ||||
Sound.prototype.Schema = | Sound.prototype.Schema = | ||||
"<a:help>Lists the sound groups associated with this unit.</a:help>" + | "<a:help>Lists the sound groups associated with this unit.</a:help>" + | ||||
"<a:example>" + | "<a:example>" + | ||||
"<SoundGroups>" + | "<SoundGroups>" + | ||||
"<walk>actor/human/movement/walk.xml</walk>" + | "<walk>actor/human/movement/walk.xml</walk>" + | ||||
"<run>actor/human/movement/walk.xml</run>" + | "<run>actor/human/movement/walk.xml</run>" + | ||||
"<attack_melee>attack/weapon/sword.xml</attack_melee>" + | "<attack_melee>attack/weapon/sword.xml</attack_melee>" + | ||||
"<death>actor/human/death/death.xml</death>" + | "<death>actor/human/death/death.xml</death>" + | ||||
"<ambientEmitter>ambient/water/river_slow.xml</ambientEmitter>" + | |||||
"</SoundGroups>" + | "</SoundGroups>" + | ||||
"</a:example>" + | "</a:example>" + | ||||
"<element name='SoundGroups'>" + | "<element name='SoundGroups'>" + | ||||
"<zeroOrMore>" + /* TODO: make this more specific, like a list of specific elements */ | "<zeroOrMore>" + /* TODO: make this more specific, like a list of specific elements */ | ||||
"<element>" + | "<element>" + | ||||
"<anyName/>" + | "<anyName/>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</zeroOrMore>" + | "</zeroOrMore>" + | ||||
"</element>"; | "</element>"; | ||||
Sound.prototype.Init = function() | Sound.prototype.Init = function() | ||||
{ | { | ||||
this.hasAmbientEmitter = !!this.template.SoundGroups.ambientEmitter; | |||||
}; | }; | ||||
Sound.prototype.Serialize = null; // we have no dynamic state to save | Sound.prototype.Serialize = null; // we have no dynamic state to save | ||||
Sound.prototype.GetSoundGroup = function(name) | Sound.prototype.GetSoundGroup = function(name) | ||||
{ | { | ||||
return this.template.SoundGroups[name] || ""; | return this.template.SoundGroups[name] || ""; | ||||
}; | }; | ||||
Show All 13 Lines | if (name in this.template.SoundGroups) | ||||
let soundName = this.template.SoundGroups[name].replace(/\{lang\}/g, lang) | let soundName = this.template.SoundGroups[name].replace(/\{lang\}/g, lang) | ||||
.replace(/\{phenotype\}/g, phenotype); | .replace(/\{phenotype\}/g, phenotype); | ||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | ||||
if (cmpSoundManager) | if (cmpSoundManager) | ||||
cmpSoundManager.PlaySoundGroup(soundName, this.entity); | cmpSoundManager.PlaySoundGroup(soundName, this.entity); | ||||
} | } | ||||
}; | }; | ||||
Sound.prototype.OnOwnershipChanged = function(msg) | |||||
{ | |||||
if (!this.hasAmbientEmitter || msg.to != INVALID_PLAYER) | |||||
return; | |||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | |||||
cmpSoundManager.RemoveAmbientEmitter(this.entity); | |||||
this.emitsAmbientSound = false; | |||||
}; | |||||
// This may be performace-intensive for moving ents with ambient emitters | |||||
Freagarach: Perhaps we can use a timer? | |||||
Done Inline ActionsWould sound a bit weird to have a unit making an ambient sound at a different place :) Stan: Would sound a bit weird to have a unit making an ambient sound at a different place :) | |||||
Sound.prototype.OnPositionChanged = function(msg) | |||||
{ | |||||
if (!this.hasAmbientEmitter || !msg.inWorld) | |||||
return; | |||||
if (this.emitsAmbientSound) { | |||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | |||||
cmpSoundManager.UpdateAmbientEmitterPosition(this.entity); | |||||
} | |||||
else | |||||
this.AddAmbientEmitter(); | |||||
}; | |||||
Sound.prototype.AddAmbientEmitter = function() | |||||
{ | |||||
let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | |||||
this.emitsAmbientSound = cmpSoundManager.AddAmbientEmitter(this.template.SoundGroups.ambientEmitter, this.entity); | |||||
} | |||||
Engine.RegisterComponentType(IID_Sound, "Sound", Sound); | Engine.RegisterComponentType(IID_Sound, "Sound", Sound); |
Wildfire Games · Phabricator
Perhaps we can use a timer?