/// <summary> /// Parses an SgbFile for model entries or further gimmicks, and adds groups /// to the given MapGroup. /// </summary> /// <param name="file"></param> /// <param name="parent"></param> /// <param name="models"></param> private static void AddSgbModelsToMap(ref Map map, ref MapGroup mg, SgbFile file) { foreach (var sgbGroup in file.Data.OfType <SgbGroup>()) { foreach (var mdl in sgbGroup.Entries.OfType <SgbModelEntry>()) { int modelId = map.TryAddUniqueModel(mdl.Model.Model.ToMapModel()); mg.AddEntry(mdl.Model.ToMapModelEntry(modelId)); } } }
/// <summary> /// Returns a Map containing all groups in the Territory instantiated via /// the given TerritoryType. /// </summary> /// <param name="teriType"></param> /// <returns></returns> private static Map ReadTerritory(TerritoryType teriType, SaintCoinach.Graphics.Territory teri = null) { Map map = new Map(); teri = teri ?? new SaintCoinach.Graphics.Territory(teriType); if (teri.Terrain != null) { MapGroup terrainMapGroup = new MapGroup(MapGroup.GroupType.TERRAIN, "teri"); terrainMapGroup.groupTransform = Transform.Empty; foreach (TransformedModel mdl in teri.Terrain.Parts) { int modelId = map.TryAddUniqueModel(mdl.Model.ToMapModel()); terrainMapGroup.AddEntry(mdl.ToMapModelEntry(modelId)); } map.AddMapGroup(terrainMapGroup); } foreach (LgbFile lgbFile in teri.LgbFiles) { var validGroups = lgbFile.Groups.Where(_ => !EventCheck(_.Name)).Select(_ => _); foreach (LgbGroup lgbGroup in validGroups) { MapGroup lgbMapGroup = new MapGroup(MapGroup.GroupType.LGB, lgbGroup.Name); lgbMapGroup.groupTransform = Transform.Empty; foreach (var mdl in lgbGroup.Entries.OfType <LgbModelEntry>()) { int modelId = map.TryAddUniqueModel(mdl.Model.Model.ToMapModel()); lgbMapGroup.AddEntry(mdl.Model.ToMapModelEntry(modelId)); } foreach (var gim in lgbGroup.Entries.OfType <LgbGimmickEntry>()) { MapGroup gimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(gim.Name, gim.Gimmick.File.Path)); gimMapGroup.groupTransform = TransformFromGimmickHeader(gim.Header); AddSgbModelsToMap(ref map, ref gimMapGroup, gim.Gimmick); foreach (var rootGimGroup in gim.Gimmick.Data.OfType <SgbGroup>()) { foreach (var rootGimEntry in rootGimGroup.Entries.OfType <SgbGimmickEntry>()) { if (rootGimEntry.Gimmick != null) { MapGroup rootGimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(rootGimEntry.Name, rootGimEntry.Gimmick.File.Path)); rootGimMapGroup.groupTransform = TransformFromGimmickHeader(rootGimEntry.Header); AddSgbModelsToMap(ref map, ref rootGimMapGroup, rootGimEntry.Gimmick); foreach (var subGimGroup in rootGimEntry.Gimmick.Data.OfType <SgbGroup>()) { foreach (var subGimEntry in subGimGroup.Entries.OfType <SgbGimmickEntry>()) { MapGroup subGimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(subGimEntry.Name, subGimEntry.Gimmick.File.Path)); subGimMapGroup.groupTransform = TransformFromGimmickHeader(subGimEntry.Header); AddSgbModelsToMap(ref map, ref subGimMapGroup, subGimEntry.Gimmick); rootGimMapGroup.AddGroup(subGimMapGroup); } } gimMapGroup.AddGroup(rootGimMapGroup); } } } lgbMapGroup.AddGroup(gimMapGroup); } foreach (var eobj in lgbGroup.Entries.OfType <LgbEventObjectEntry>()) { if (eobj.Gimmick == null) { continue; } MapGroup gimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(eobj.Name, eobj.Gimmick.File.Path)); gimMapGroup.groupTransform = TransformFromGimmickHeader(eobj.Header); AddSgbModelsToMap(ref map, ref gimMapGroup, eobj.Gimmick); foreach (var rootGimGroup in eobj.Gimmick.Data.OfType <SgbGroup>()) { foreach (var rootGimEntry in rootGimGroup.Entries.OfType <SgbGimmickEntry>()) { if (rootGimEntry.Gimmick != null) { MapGroup rootGimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(rootGimEntry.Name, rootGimEntry.Gimmick.File.Path)); rootGimMapGroup.groupTransform = TransformFromGimmickHeader(rootGimEntry.Header); AddSgbModelsToMap(ref map, ref rootGimMapGroup, rootGimEntry.Gimmick); foreach (var subGimGroup in rootGimEntry.Gimmick.Data.OfType <SgbGroup>()) { foreach (var subGimEntry in subGimGroup.Entries.OfType <SgbGimmickEntry>()) { MapGroup subGimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(subGimEntry.Name, subGimEntry.Gimmick.File.Path)); subGimMapGroup.groupTransform = TransformFromGimmickHeader(subGimEntry.Header); AddSgbModelsToMap(ref map, ref subGimMapGroup, subGimEntry.Gimmick); rootGimMapGroup.AddGroup(subGimMapGroup); } } gimMapGroup.AddGroup(rootGimMapGroup); } } foreach (var sgb1cEntry in rootGimGroup.Entries.OfType <SgbGroup1CEntry>()) { if (sgb1cEntry.Gimmick != null) { MapGroup rootGimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(sgb1cEntry.Name, sgb1cEntry.Gimmick.File.Path)); rootGimMapGroup.groupTransform = Transform.Empty; AddSgbModelsToMap(ref map, ref rootGimMapGroup, sgb1cEntry.Gimmick); foreach (var subGimGroup in sgb1cEntry.Gimmick.Data.OfType <SgbGroup>()) { foreach (var subGimEntry in subGimGroup.Entries.OfType <SgbGimmickEntry>()) { MapGroup subGimMapGroup = new MapGroup(MapGroup.GroupType.SGB, GetGimmickName(subGimEntry.Name, subGimEntry.Gimmick.File.Path)); subGimMapGroup.groupTransform = TransformFromGimmickHeader(subGimEntry.Header); AddSgbModelsToMap(ref map, ref subGimMapGroup, subGimEntry.Gimmick); rootGimMapGroup.AddGroup(subGimMapGroup); } } gimMapGroup.AddGroup(rootGimMapGroup); } } } lgbMapGroup.AddGroup(gimMapGroup); } map.AddMapGroup(lgbMapGroup); } } return(map); }