LCOV - code coverage report
Current view: top level - simulation/components - Sound.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 17 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 4 0.0 %

          Line data    Source code
       1             : function Sound() {}
       2             : 
       3           0 : Sound.prototype.Schema =
       4             :         "<a:help>Lists the sound groups associated with this unit.</a:help>" +
       5             :         "<a:example>" +
       6             :                 "<SoundGroups>" +
       7             :                         "<walk>actor/human/movement/walk.xml</walk>" +
       8             :                         "<run>actor/human/movement/walk.xml</run>" +
       9             :                         "<attack_melee>attack/weapon/sword.xml</attack_melee>" +
      10             :                         "<death>actor/human/death/death.xml</death>" +
      11             :                 "</SoundGroups>" +
      12             :         "</a:example>" +
      13             :         "<element name='SoundGroups'>" +
      14             :                 "<zeroOrMore>" + /* TODO: make this more specific, like a list of specific elements */
      15             :                         "<element>" +
      16             :                                 "<anyName/>" +
      17             :                                 "<text/>" +
      18             :                         "</element>" +
      19             :                 "</zeroOrMore>" +
      20             :         "</element>";
      21             : 
      22           0 : Sound.prototype.Init = function()
      23             : {
      24             : };
      25             : 
      26           0 : Sound.prototype.Serialize = null; // we have no dynamic state to save
      27             : 
      28           0 : Sound.prototype.GetSoundGroup = function(name)
      29             : {
      30           0 :         return this.template.SoundGroups[name] || "";
      31             : };
      32             : 
      33           0 : Sound.prototype.PlaySoundGroup = function(name)
      34             : {
      35           0 :         if (name in this.template.SoundGroups)
      36             :         {
      37             :                 // Replace the "{lang}" codes with this entity's civ ID
      38           0 :                 let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
      39           0 :                 if (!cmpIdentity)
      40           0 :                         return;
      41           0 :                 let lang = cmpIdentity.GetLang();
      42             :                 // Replace the "{phenotype}" codes with this entity's phenotype ID
      43           0 :                 let phenotype = cmpIdentity.GetPhenotype();
      44             : 
      45           0 :                 let soundName = this.template.SoundGroups[name].replace(/\{lang\}/g, lang)
      46             :                         .replace(/\{phenotype\}/g, phenotype);
      47           0 :                 let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager);
      48           0 :                 if (cmpSoundManager)
      49           0 :                         cmpSoundManager.PlaySoundGroup(soundName, this.entity);
      50             :         }
      51             : };
      52             : 
      53           0 : Engine.RegisterComponentType(IID_Sound, "Sound", Sound);

Generated by: LCOV version 1.14