Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Sound.js
/** | /** | |||||||||||
* Simple wrapper function for playing sounds that are associated with entities | * Simple wrapper function for playing sounds that are associated with entities | |||||||||||
* @param name Typically one of 'walk', 'run', 'attack', 'death', 'build', | * @param name Typically one of 'walk', 'run', 'attack', 'death', 'build', | |||||||||||
* 'gather_fruit', 'gather_grain', 'gather_wood', 'gather_stone', 'gather_metal' | * 'gather_fruit', 'gather_grain', 'gather_wood', 'gather_stone', 'gather_metal' | |||||||||||
*/ | */ | |||||||||||
function PlaySound(name, ent) | function PlaySound(name, ent) | |||||||||||
{ | { | |||||||||||
var cmpSound = Engine.QueryInterface(ent, IID_Sound); | var cmpSound = Engine.QueryInterface(ent, IID_Sound); | |||||||||||
if (cmpSound) | if (cmpSound) | |||||||||||
cmpSound.PlaySoundGroup(name); | cmpSound.PlaySoundGroup(name); | |||||||||||
} | } | |||||||||||
/** | ||||||||||||
* Gets the matching impact sound group depending on the . | ||||||||||||
* @param {string} type - The type of damage. | ||||||||||||
* @param {number} target - The entity id of the target. | ||||||||||||
* @param {number} attacker - The entity id of the attacker. | ||||||||||||
* @param {boolean} missed - Whether the target was missed. | ||||||||||||
* @return {string} - The impact sound group. | ||||||||||||
*/ | ||||||||||||
function GetImpactSoundGroup(type, target, attacker, missed) | ||||||||||||
{ | ||||||||||||
let cmpSound = Engine.QueryInterface(attacker, IID_Sound); | ||||||||||||
if (!cmpSound) | ||||||||||||
return ""; | ||||||||||||
let attackImpactType = "attack_impact_" + type.toLowerCase(); | ||||||||||||
if (missed) | ||||||||||||
return cmpSound.GetSoundGroup(attackImpactType + "_missed"); | ||||||||||||
let cmpIdentity = Engine.QueryInterface(target, IID_Identity); | ||||||||||||
if (cmpIdentity) | ||||||||||||
{ | ||||||||||||
Silier: if we missed and group does not exist, you end up calling identity and returning material hit… | ||||||||||||
let classes = cmpIdentity.GetClassesList(); | ||||||||||||
for(let impactClass in g_ImpactSoundsClasses) | ||||||||||||
if(MatchesClassList(classes, g_ImpactSoundsClasses[impactType])) | ||||||||||||
Done Inline Actionsnegate + early return, less nesting is easier to read Silier: negate + early return, less nesting is easier to read | ||||||||||||
return cmpSound.GetSoundGroup(attackImpactType + "_" + impactClass); | ||||||||||||
} | ||||||||||||
return cmpSound.GetSoundGroup(attackImpactType); | ||||||||||||
} | ||||||||||||
Done Inline Actions
Silier: | ||||||||||||
Engine.RegisterGlobal("GetImpactSoundGroup", GetImpactSoundGroup); | ||||||||||||
Engine.RegisterGlobal("PlaySound", PlaySound); | Engine.RegisterGlobal("PlaySound", PlaySound); | |||||||||||
Done Inline Actionsthis looks wrong, also above. Silier: this looks wrong, also above.
first part of || will be always true |
Wildfire Games · Phabricator
if we missed and group does not exist, you end up calling identity and returning material hit anyway