public static void WriteAddToManagersBottomUpForNamedObjectList(List<NamedObjectSave> namedObjectList, ICodeBlock codeBlock, IElement element, List<string[]> reusableEntireFileRfses) { foreach(var nos in namedObjectList.Where(nos=>nos.SourceType != SourceType.FlatRedBallType || nos.SourceClassType != "Layer")) { ReferencedFileSave filePullingFrom = null; string[] foundPair = null; if (nos.SourceType == SourceType.File && nos.SourceName != null) { if (nos.IsEntireFile) { filePullingFrom = element.GetReferencedFileSave(nos.SourceFile); } else { foreach (string[] stringPair in reusableEntireFileRfses) { if (stringPair[0] == nos.SourceFile) { foundPair = stringPair; break; } } } } NamedObjectSave entireFileNos = null; if (foundPair != null) { entireFileNos = element.GetNamedObjectRecursively(foundPair[1]); } //mReusableEntireFileRfses // We need to add this object if it is not part // of an EntireFile object, or if it has a custom // Layer. // Update September 30, 2012 // This could also be an object // from a file that is part of a // Screen, therefore it is already // added to managers. If so, we don't // want to add it again. // Update March 31, 2013 // If the object is part of a file, but // its layer differs from the object that // it is a part of, then we need to add it. // But we want to remove it from the engine before // re-adding so that it isn't part of 2 different if // the container is itself on a Layer. bool isAlreadyAdded = entireFileNos != null || (filePullingFrom != null && ReferencedFileSaveCodeGenerator.GetIfShouldAddToManagers(element, filePullingFrom)); if (!isAlreadyAdded || (entireFileNos != null && entireFileNos.LayerOn != nos.LayerOn) || (filePullingFrom != null && !string.IsNullOrEmpty(nos.LayerOn)) ) { if (isAlreadyAdded) { var ati = nos.GetAssetTypeInfo(); if (ati != null && !string.IsNullOrEmpty(ati.RecycledDestroyMethod)) { string recycleMethod = ati.RecycledDestroyMethod.Replace("this", nos.InstanceName) + ";"; codeBlock.Line(recycleMethod); } } NamedObjectSaveCodeGenerator.WriteAddToManagersForNamedObject(element, nos, codeBlock); } #region Loop through all contained NamedObjects in Lists - and call WriteAddToManagersForNamedObject recursively // Loop through all contained NamedObjects foreach (NamedObjectSave containedNos in nos.ContainedObjects) { WriteAddToManagersForNamedObject(element, containedNos, codeBlock); // 12/14/2010 // We used to add // objects which are // part of a list to their // list here, but if that happened, // then variables like Visible wouldn't // work properly. So this code was moved // into initialize // stringBuilder.AppendLine("\t\t\t" + namedObject.InstanceName + ".Add(" + containedNos.InstanceName + ");"); } #endregion } }