/// <summary> MusicalLoop Constructor </summary> /// <exception cref="ArgumentNullException"> Thrown if input material, particle system, or LoopFGHashMap are null </exception> /// <exception cref="MultipleActiveLoopsInFGException"> Thrown if fg has multiple active loops </exception> public MusicalLoop(LoopFunctionalGroup fg1, string soundFile1, Material mat1, uint currMeasure, ParticleSystem particleSystem1, LoopFGHashMap lFGHashMap1) { // Pre-conditions if (mat1 == null) { throw new ArgumentNullException(String.Format("{0} is null", mat1), "mat1"); } if (particleSystem1 == null) { throw new ArgumentNullException(String.Format("{0} is null", particleSystem1), "particleSystem1"); } if (lFGHashMap1 == null) { throw new ArgumentNullException(String.Format("{0} is null", lFGHashMap1), "lFGHashMap1"); } if (!lFGHashMap1.CheckMaxOneActiveFGLoop(fg1)) { throw new MultipleActiveLoopsInFGException(fg1.ToString()); } // Initialize variables this.funcGroup = fg1; this.soundFile = soundFile1; this.mat = mat1; this.particleSystem = particleSystem1; this.lFGHashMap = lFGHashMap1; SetLoopState(LoopState.Inactive, currMeasure); }
/// <summary> LoopState Setter /// (calling it rather than _state will ensure variables that need to be changed and /// methods() that need to be called with the LoopState are /// Will discuss my struggle with information hiding vs. principle of least suprise in interview /// </summary> /// <exception cref="ArgumentNullException"> Thrown if NewLoopState is null </exception> /// <exception cref="MultipleActiveLoopsInFGException"> /// Thrown if after method, multiple loops associated with one fg are now active </exception> private void SetLoopState(LoopState value, uint currMeasure) { //Preconditions if (value == null) { throw new ArgumentNullException(String.Format("{0} is null", value), "value"); } //Change State this._state = value; //Every time Loop State is changed, must also: mat.BeginAnimation(); this.measureOfLastStateChange = currMeasure; Console.WriteLine("Set MusicalLoop's new state to: " + _state.Name); if (!lFGHashMap.CheckMaxOneActiveFGLoop(funcGroup)) { throw new MultipleActiveLoopsInFGException(funcGroup.ToString()); } }