public static MapDrawableBatch FromScnx(string sceneFileName, string contentManagerName, bool verifySameTexturePerLayer) { // TODO: This line crashes when the path is already absolute! string absoluteFileName = FileManager.MakeAbsolute(sceneFileName); // TODO: The exception doesn't make sense when the file type is wrong. SceneSave saveInstance = SceneSave.FromFile(absoluteFileName); int startingIndex = 0; string oldRelativeDirectory = FileManager.RelativeDirectory; FileManager.RelativeDirectory = FileManager.GetDirectory(absoluteFileName); // get the list of sprites from our map file List <SpriteSave> spriteSaveList = saveInstance.SpriteList; // we use the sprites as defined in the scnx file to create and draw the map. MapDrawableBatch mMapBatch = FromSpriteSaves(spriteSaveList, startingIndex, spriteSaveList.Count, contentManagerName, verifySameTexturePerLayer); FileManager.RelativeDirectory = oldRelativeDirectory; // temp //mMapBatch = new MapDrawableBatch(32, 32, 32f, 64, @"content/tiles"); return(mMapBatch); }
public static LayeredTileMap FromScene(string fileName, string contentManagerName, bool verifySameTexturePerLayer) { Section.GetAndStartContextAndTime("Initial FromScene"); LayeredTileMap toReturn = new LayeredTileMap(); string absoluteFileName = FileManager.MakeAbsolute(fileName); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("FromFile"); SceneSave ses = SceneSave.FromFile(absoluteFileName); Section.EndContextAndTime(); Section.GetAndStartContextAndTime("BreaksNStuff"); string oldRelativeDirectory = FileManager.RelativeDirectory; FileManager.RelativeDirectory = FileManager.GetDirectory(absoluteFileName); var breaks = GetZBreaks(ses.SpriteList); int valueBefore = 0; MapDrawableBatch mdb; int valueAfter; float zValue = 0; Section.EndContextAndTime(); Section.GetAndStartContextAndTime("Create MDBs"); for (int i = 0; i < breaks.Count; i++) { valueAfter = breaks[i]; int count = valueAfter - valueBefore; mdb = MapDrawableBatch.FromSpriteSaves(ses.SpriteList, valueBefore, count, contentManagerName, verifySameTexturePerLayer); mdb.AttachTo(toReturn, false); mdb.RelativeZ = zValue; toReturn.mMapLists.Add(mdb); zValue += toReturn.mZSplit; valueBefore = valueAfter; } valueAfter = ses.SpriteList.Count; if (valueBefore != valueAfter) { int count = valueAfter - valueBefore; mdb = MapDrawableBatch.FromSpriteSaves(ses.SpriteList, valueBefore, count, contentManagerName, verifySameTexturePerLayer); mdb.AttachTo(toReturn, false); mdb.RelativeZ = zValue; toReturn.mMapLists.Add(mdb); } Section.EndContextAndTime(); FileManager.RelativeDirectory = oldRelativeDirectory; return(toReturn); }
void CustomInitialize() { SpriteManager.Camera.UsePixelCoordinates(); SpriteManager.Camera.X = 129; SpriteManager.Camera.Y = -216; FlatRedBallServices.GraphicsOptions.TextureFilter = Microsoft.Xna.Framework.Graphics.TextureFilter.Point; SpriteEditorScene ses = SceneSave.FromFile("Content/Screens/TmxScreen/FinalFantasyScene.scnx".ToLowerInvariant()); scene = new Scene(); ses.SetScene <Sprite>(ContentManagerName, scene, SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids); scene.Shift(new Vector3(0, 0, 0)); scene.AddToManagers(); TestLevel2.X -= 530; if (string.IsNullOrEmpty(TilbTest.MapLayers[0].Name)) { throw new Exception("Map layers names are not coming through"); } // Layer 0 should be called "LayerWithStuff" if (TmxWithEmptyLayers.MapLayers[0].Name != "LayerWithStuff") { throw new Exception("Having empty layers can screw up Layer names. " + "This layer should be named \"LayerWithStuff\" but it is instead named " + TmxWithEmptyLayers.MapLayers[0].Name); } TestRotatedTiles(); TestTileSizeOnMapWithObjects(); TestEntitiesInFolders(); TestCollisionLayerByType(); // Make the shapes visible, to make sure that they get removed when the screen is destroyed: foreach (var shapeCollection in TmxWithShapes.ShapeCollections) { shapeCollection.Visible = true; shapeCollection.AddToManagers(); } }
public static void GetFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> referencedFiles) { List <string> newReferencedFiles = new List <string>(); if (!CanFileReferenceOtherFiles(fileName)) { return; } else if (!FileManager.FileExists(fileName)) { throw new FileNotFoundException("Could not find file " + fileName, fileName); } else { string fileExtension = FileManager.GetExtension(fileName); switch (fileExtension) { #region Scene (.scnx) case "scnx": SceneSave ses = SceneSave.FromFile(fileName); try { newReferencedFiles = ses.GetReferencedFiles(RelativeType.Absolute); } catch (InvalidOperationException e) { MessageBox.Show("There is an invalid file reference in the file\n\n" + fileName + "\n\nGlue will skip this file. You should investigate this file in a text editor " + "to identify the issue.\n\nAdditional error information:\n\n" + e.ToString()); } break; #endregion #region Emitter List (.emix) case "emix": EmitterSaveList esl = EmitterSaveList.FromFile(fileName); newReferencedFiles = esl.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region AnimationChain List case "achx": AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName); newReferencedFiles = acls.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region X File (.x) case "x": newReferencedFiles = GetTextureReferencesInX(fileName); break; #endregion #region Spline List (.slpx) - falls to default case "splx": #endregion #region Font File (.fnt) case "fnt": newReferencedFiles = GetTextureReferencesInFnt(fileName); break; #endregion default: break; } // We still want to construct as good of a reference structure as possible // even if there are missing files. Therefore, we'll just keep track of errors and report them // at the end of the method bool didErrorOccur = false; string errorMessage = ""; if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { for (int i = newReferencedFiles.Count - 1; i > -1; i--) { // If this file can't reference other files, no need to even do a file check or throw errors. if (CanFileReferenceOtherFiles(newReferencedFiles[i]) == true) { if (File.Exists(newReferencedFiles[i])) { try { GetFilesReferencedByAsset(newReferencedFiles[i], topLevelOrRecursive, newReferencedFiles); } catch (Exception e) { didErrorOccur = true; errorMessage += e.Message; } } else { didErrorOccur = true; errorMessage += "Could not find the file " + newReferencedFiles[i] + " which is referenced in the file " + fileName + "\n"; } } } } // Files may include "../", so let's get rid of that stuff for (int i = 0; i < newReferencedFiles.Count; i++) { newReferencedFiles[i] = FileManager.Standardize(newReferencedFiles[i], "", false); } referencedFiles.AddRange(newReferencedFiles); if (didErrorOccur) { throw new Exception(errorMessage); } } }