Esempio n. 1
0
        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.
            SpriteEditorScene saveInstance = SpriteEditorScene.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);
        }
Esempio n. 2
0
        public static object GetValueForProperty(string fileName, string objectName, string propertyName)
        {
            string extension = FileManager.GetExtension(fileName);

            switch (extension)
            {
                #region case Scene (scnx)
            case "scnx":

                SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                string oldRelative = FileManager.RelativeDirectory;
                FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);

                object returnValue = GetValueForPropertyInScene(ses, objectName, propertyName);

                FileManager.RelativeDirectory = oldRelative;

                return(returnValue);

                //break;
                #endregion

                #region case ShapeCollection (shcx)

            case "shcx":
                ShapeCollectionSave scs = ShapeCollectionSave.FromFile(fileName);
                return(GetValueForPropertyInShapeCollection(scs, objectName, propertyName));

                //break;

                #endregion
            }
            return(null);
        }
Esempio n. 3
0
        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");
            SpriteEditorScene ses = SpriteEditorScene.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);
        }
Esempio n. 4
0
        public static void LoadScene(string fileName)
        {
            if (mScene != null)
            {
                mScene.RemoveFromManagers();
                mScene.Clear();
            }

            SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

            mScene = ses.ToScene(AppState.Self.PermanentContentManager);

            mScene.AddToManagers();

            FileMenuWindow.AttemptEmitterAttachment(fileName);
        }
        private AnimationChainListSave GetAnimationChainListFromScnxReference(NamedObjectSave referencedNos)
        {
            string sourceFileName = ContentDirectory + referencedNos.SourceFile;

            string sourceFileDirectory = FlatRedBall.IO.FileManager.GetDirectory(sourceFileName);

            AnimationChainListSave acls = null;

            SpriteEditorScene ses;

            if (System.IO.File.Exists(sourceFileName))
            {
                ses = SpriteEditorScene.FromFile(sourceFileName);
                string truncatedName = referencedNos.SourceName.Substring(0, referencedNos.SourceName.LastIndexOf('(') - 1);



                SpriteSave spriteSave = ses.FindSpriteByName(truncatedName);

                if (spriteSave != null && !string.IsNullOrEmpty(spriteSave.AnimationChainsFile))
                {
                    acls = AnimationChainListSave.FromFile(
                        sourceFileDirectory + spriteSave.AnimationChainsFile);
                }

                if (acls == null)
                {
                    SpriteFrameSave sfs = ses.FindSpriteFrameSaveByName(truncatedName);

                    if (sfs != null)
                    {
                        acls = AnimationChainListSave.FromFile(
                            sourceFileDirectory + sfs.ParentSprite.AnimationChainsFile);
                    }
                }
            }



            return(acls);
        }
Esempio n. 6
0
        public static void AutoSearchScn(Window callingWindow)
        {
            callingWindow.Parent.CloseWindow();
            List <string> allFiles = FileManager.GetAllFilesInDirectory(System.IO.Directory.GetCurrentDirectory());

            for (int i = allFiles.Count - 1; i > -1; i--)
            {
                if (FlatRedBall.IO.FileManager.GetExtension(allFiles[i]) != "scnx")
                {
                    allFiles.RemoveAt(i);
                }
            }


            //throw new NotImplementedException("Feature not implemented.  Complain on FlatRedBall forums");



            foreach (string scnFile in allFiles)
            {
                SpriteEditorScene ses = SpriteEditorScene.FromFile(scnFile);

                foreach (SpriteSave ss in ses.SpriteList)
                {
                    for (int i = EditorData.lastLoadedFile.emitters.Count - 1; i > -1; i--)
                    {
                        if (EditorData.lastLoadedFile.emitters[i].ParentSpriteName != null)
                        {
                            if (ss.Name == EditorData.lastLoadedFile.emitters[i].ParentSpriteName)
                            {
                                EditorData.LoadScene(scnFile);

                                return;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        private static void AddResetVariablesForSpriteOrSpriteFrame(NamedObjectSave nos, List <string> variables)
        {
            // todo - support resetting animation chains on Sprites that aren't using a .scnx
            if (nos.SourceType == SourceType.File && !string.IsNullOrEmpty(nos.SourceFile))
            {
                string            fullFile = ProjectManager.MakeAbsolute(nos.SourceFile);
                SpriteEditorScene ses      = SpriteEditorScene.FromFile(fullFile);

                int endingIndex = nos.SourceName.LastIndexOf('(');

                string     nameWithoutType = nos.SourceName.Substring(0, endingIndex - 1);
                SpriteSave ss = ses.FindSpriteByName(nameWithoutType);

                string animationChainFileName = "";
                if (ss != null)
                {
                    animationChainFileName = ss.AnimationChainsFile;
                }
                else
                {
                    SpriteFrameSave sfs = ses.FindSpriteFrameSaveByName(nameWithoutType);
                    if (sfs != null)
                    {
                        animationChainFileName = sfs.ParentSprite.AnimationChainsFile;
                    }
                }

                if (!string.IsNullOrEmpty(animationChainFileName))
                {
                    variables.Add("CurrentChainName");
                    variables.Add("CurrentFrameIndex");
                }
            }

            variables.Add("Alpha");
            variables.Add("AlphaRate");
        }
Esempio n. 8
0
        public static List <string> GetNamedObjectsIn(string fileName)
        {
            string        extension    = FileManager.GetExtension(fileName);
            List <string> listToReturn = new List <string>();

            switch (extension)
            {
                #region case Scene (scnx)
            case "scnx":

                SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                for (int i = 0; i < ses.PositionedModelSaveList.Count; i++)
                {
                    listToReturn.Add(ses.PositionedModelSaveList[i].Name + " (PositionedModel)");
                }

                for (int i = 0; i < ses.SpriteFrameSaveList.Count; i++)
                {
                    listToReturn.Add(ses.SpriteFrameSaveList[i].ParentSprite.Name + " (SpriteFrame)");
                }

                for (int i = 0; i < ses.SpriteGridList.Count; i++)
                {
                    listToReturn.Add(ses.SpriteGridList[i].Name + " (SpriteGrid)");
                }

                for (int i = 0; i < ses.SpriteList.Count; i++)
                {
                    listToReturn.Add(ses.SpriteList[i].Name + " (Sprite)");
                }

                for (int i = 0; i < ses.TextSaveList.Count; i++)
                {
                    listToReturn.Add(ses.TextSaveList[i].Name + " (Text)");
                }
                break;
                #endregion

                #region case ShapeCollection (shcx)

            case "shcx":
                ShapeCollectionSave scs = ShapeCollectionSave.FromFile(fileName);

                for (int i = 0; i < scs.AxisAlignedCubeSaves.Count; i++)
                {
                    listToReturn.Add(scs.AxisAlignedCubeSaves[i].Name + " (AxisAlignedCube)");
                }
                for (int i = 0; i < scs.AxisAlignedRectangleSaves.Count; i++)
                {
                    listToReturn.Add(scs.AxisAlignedRectangleSaves[i].Name + " (AxisAlignedRectangle)");
                }
                for (int i = 0; i < scs.CircleSaves.Count; i++)
                {
                    listToReturn.Add(scs.CircleSaves[i].Name + " (Circle)");
                }
                for (int i = 0; i < scs.PolygonSaves.Count; i++)
                {
                    listToReturn.Add(scs.PolygonSaves[i].Name + " (Polygon)");
                }
                for (int i = 0; i < scs.SphereSaves.Count; i++)
                {
                    listToReturn.Add(scs.SphereSaves[i].Name + " (Sphere)");
                }
                break;

                #endregion

                #region NodeNetwork (nntx)
            case "nntx":
                NodeNetworkSave nns = NodeNetworkSave.FromFile(fileName);

                for (int i = 0; i < nns.PositionedNodes.Count; i++)
                {
                    listToReturn.Add(nns.PositionedNodes[i].Name + " (PositionedNode)");
                }

                break;
                #endregion

                #region EmitterList (emix)
            case "emix":
                EmitterSaveList esl = EmitterSaveList.FromFile(fileName);

                for (int i = 0; i < esl.emitters.Count; i++)
                {
                    listToReturn.Add(esl.emitters[i].Name + " (Emitter)");
                }

                break;

                #endregion

                #region Case AnimationChainList (achx)

            case "achx":
                AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName);

                for (int i = 0; i < acls.AnimationChains.Count; i++)
                {
                    listToReturn.Add(acls.AnimationChains[i].Name + " (AnimationChain)");
                }
                break;
                #endregion

                #region Case SplineList (splx)
            case "splx":
                SplineSaveList ssl = SplineSaveList.FromFile(fileName);

                for (int i = 0; i < ssl.Splines.Count; i++)
                {
                    listToReturn.Add(ssl.Splines[i].Name + " (Spline)");
                }

                break;

                #endregion
            }

            return(listToReturn);
        }
Esempio n. 9
0
        public static List <string> GetFilesReferencedByAsset(string file, bool readRecursively)
        {
            string fileExtension = FileManager.GetExtension(file);

            List <string> referencedFiles = null;           // = new List<string>();

            switch (fileExtension)
            {
                #region Scene (.scnx)

            case "scnx":

                SpriteEditorScene ses = SpriteEditorScene.FromFile(file);
                referencedFiles = ses.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region Emitter List (.emix)

            case "emix":
                EmitterSaveList esl = EmitterSaveList.FromFile(file);
                referencedFiles = esl.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region SpriteRig (.srgx)

            case "srgx":
                SpriteRigSave srs = SpriteRigSave.FromFile(file);
                referencedFiles = srs.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region AnimationChain List

            case "achx":
                AnimationChainListSave acls = AnimationChainListSave.FromFile(file);
                referencedFiles = acls.GetReferencedFiles(RelativeType.Absolute);
                break;

                #endregion

                #region Bitmap Font Generator Config File (.bmfc)

            case "bmfc":

                referencedFiles = new List <string>();

                // These are only referenced IF they actually exist
                string referencedFileToAdd = FileManager.RemoveExtension(file) + ".png";
                if (FileManager.FileExists(referencedFileToAdd))
                {
                    referencedFiles.Add(referencedFileToAdd);
                }

                referencedFileToAdd = FileManager.RemoveExtension(file) + ".fnt";
                if (FileManager.FileExists(referencedFileToAdd))
                {
                    referencedFiles.Add(referencedFileToAdd);
                }
                break;

                #endregion

                #region X File (.x)

            case "x":
                referencedFiles = GetTextureReferencesInX(file);
                break;

                #endregion

                #region WME File (.wme)
            case "wme":
                referencedFiles = new List <string>();
                WMELoader.GetReferencedFiles(file, referencedFiles, RelativeType.Absolute);

                break;

                #endregion

                #region Spline List (.slpx) - falls to default

            case "splx":

                #endregion
            default:
                referencedFiles = new List <string>();
                break;
            }

            if (readRecursively)
            {
                for (int i = referencedFiles.Count - 1; i > -1; i--)
                {
                    referencedFiles.AddRange(GetFilesReferencedByAsset(referencedFiles[i], true));
                }
            }

            // Files may include "../", so let's get rid of that stuff
            for (int i = 0; i < referencedFiles.Count; i++)
            {
                referencedFiles[i] = FileManager.Standardize(referencedFiles[i], "", false);
            }


            return(referencedFiles);
        }
Esempio n. 10
0
        public static List <SourceReferencingFile> GetSourceReferencingFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, ErrorBehavior errorBehavior, ref string error, ref string verboseError)
        {
            string fileExtension = FileManager.GetExtension(fileName);

            List <SourceReferencingFile> referencedFiles = null;

            switch (fileExtension)
            {
            case "scnx":
                try
                {
                    SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                    referencedFiles = ses.GetSourceReferencingReferencedFiles(RelativeType.Absolute);
                }
                catch (Exception e)
                {
                    error           = "Error loading file " + fileName + ": " + e.Message;
                    referencedFiles = new List <SourceReferencingFile>();
                    verboseError    = e.ToString();
                }
                break;

            default:
                referencedFiles = new List <SourceReferencingFile>();
                break;
            }
/**/
            if (topLevelOrRecursive == TopLevelOrRecursive.Recursive)
            {
                //First we need to get a list of all referenced files
                List <string> filesToSearch = new List <string>();

                try
                {
                    // GetFilesReferencedByAsset can throw an error if the file doesn't
                    // exist.  But we don't really care if it's missing if it can't reference
                    // others.  I mean, sure we care, but it's not relevant here.  Other systems
                    // can check for that.
                    if (CanFileReferenceOtherFiles(fileName))
                    {
                        GetFilesReferencedByAsset(fileName, topLevelOrRecursive, filesToSearch);
                    }
                }
                catch (Exception e)
                {
                    if (errorBehavior == ErrorBehavior.ThrowException)
                    {
                        throw e;
                    }
                    else
                    {
                        error += e.Message + "\n";
                    }
                }



                if (filesToSearch != null)
                {
                    for (int i = filesToSearch.Count - 1; i > -1; i--)
                    {
                        string errorForThisFile        = "";
                        string verboseErrorForThisFile = "";
                        List <SourceReferencingFile> subReferencedFiles = GetSourceReferencingFilesReferencedByAsset(filesToSearch[i], topLevelOrRecursive,
                                                                                                                     errorBehavior, ref errorForThisFile, ref verboseErrorForThisFile);
                        // error may have already been set.  If it has already been set, we don't want to dump more errors (which may just be duplicates anyway)
                        if (string.IsNullOrEmpty(error))
                        {
                            error += errorForThisFile;
                        }

                        if (subReferencedFiles != null)
                        {
                            referencedFiles.AddRange(subReferencedFiles);
                        }
                    }
                }
            }
/**/
            return(referencedFiles);
        }
Esempio n. 11
0
        public void PerformLoadScn(string fileName, bool replace)
        {
            // This method is public because this method is called if the user drags a
            // .scnx onto the SpriteEditor

            #region Mark how many objects before loading in case there is an insertion.
            // If there is an insertion, only the newly-added objects should have post load
            // logic performed on them

            int numSpritesBefore         = GameData.Scene.Sprites.Count;
            int numOfSGsBefore           = GameData.Scene.SpriteGrids.Count;
            int numOfSpriteFramesBefore  = GameData.Scene.SpriteFrames.Count;
            int numberOfPositionedModels = GameData.Scene.PositionedModels.Count;

            #endregion

            SpriteEditorScene tempSES = SpriteEditorScene.FromFile(fileName);

            #region See if there are any Models that reference files that aren't on disk

            string sceneDirectory = FileManager.GetDirectory(fileName);
            for (int i = 0; i < tempSES.PositionedModelSaveList.Count; i++)
            {
                PositionedModelSave modelSave = tempSES.PositionedModelSaveList[i];

                if (!FileManager.FileExists(modelSave.ModelFileName))
                {
                    // See if there's a .x with that name

                    if (FileManager.FileExists(sceneDirectory + modelSave.ModelFileName + ".x"))
                    {
                        modelSave.ModelFileName = modelSave.ModelFileName + ".x";
                    }
                }
            }
            #endregion

            #region Now, see if there are any other files that haven't been found and create the error window

            List <string> texturesNotFound = tempSES.GetMissingFiles();
            if (texturesNotFound.Count != 0)
            {
                OkListWindow okListWindow = new OkListWindow(
                    "There are files that the .scnx references which cannot be located.",
                    "Error loading .scnx");

                foreach (string file in texturesNotFound)
                {
                    okListWindow.AddItem(file);
                }

                return;
            }
            #endregion

            #region if replacing, clear the old scene out
            if (replace)
            {
                SpriteManager.RemoveScene(GameData.Scene, true);
                FlatRedBallServices.Unload(GameData.SceneContentManager);

                tempSES.SetCamera(GameData.Camera);

#if FRB_MDX
                if (tempSES.CoordinateSystem == FlatRedBall.Math.CoordinateSystem.RightHanded)
                {
                    GameData.Camera.Z *= -1;
                }
#endif

                GameData.EditorProperties.PixelSize = tempSES.PixelSize;

                GuiData.EditorPropertiesGrid.Refresh();

                // 4/16/2011:  The following line of code
                // was causing errors when saving the .scnx
                // file through CTRL+S.  Taking it out because
                // I don't see why we need this anyway.
                // GameData.FileName = FileManager.RemoveExtension(fileName);
                GameData.FileName = fileName;
                FlatRedBallServices.Owner.Text = "SpriteEditor - Currently editing " + GameData.FileName;

                GuiData.MenuStrip.LastFileTypeLoaded = FileManager.GetExtension(fileName);
            }
            #endregion


            Scene newlyLoadedScene = tempSES.ToScene <EditorSprite>(GameData.SceneContentManager);

            GameData.Scene.AddToThis(newlyLoadedScene);
            // This caused
            // a double-add.
            // Not sure why we're
            // adding GameData.Scene.
            //GameData.Scene.AddToManagers();
            newlyLoadedScene.AddToManagers();

            GuiData.ListWindow.RefreshListsShown();

            #region Add the used Textures to the texture ListBox

            for (int i = numSpritesBefore; i < GameData.Scene.Sprites.Count; i++)
            {
                GuiData.ListWindow.Add(GameData.Scene.Sprites[i].Texture);
                GuiData.ListWindow.Add(GameData.Scene.Sprites[i].AnimationChains);
            }

            for (int i = numOfSpriteFramesBefore; i < GameData.Scene.SpriteFrames.Count; i++)
            {
                GuiData.ListWindow.Add(GameData.Scene.SpriteFrames[i].Texture);
                GuiData.ListWindow.Add(GameData.Scene.SpriteFrames[i].AnimationChains);
            }

            for (int i = numOfSGsBefore; i < GameData.Scene.SpriteGrids.Count; i++)
            {
                SpriteGrid sg = GameData.Scene.SpriteGrids[i];
                sg.PopulateGrid(GameData.Camera.X, GameData.Camera.Y, 0f);

                sg.RefreshPaint();
                List <Texture2D> texturesToAdd = sg.GetUsedTextures();
                foreach (Texture2D tex in texturesToAdd)
                {
                    GuiData.ListWindow.Add(tex);
                }
            }
            #endregion

            CheckForExtraFiles(FileManager.RemoveExtension(fileName));
            GameData.Scene.Sprites.SortZInsertionDescending();


            if (tempSES.AssetsRelativeToSceneFile)
            {
                FileManager.ResetRelativeToCurrentDirectory();
            }
        }
Esempio n. 12
0
 public void TestLoading()
 {
     SpriteEditorScene.ManualDeserialization = true;
     SpriteEditorScene.FromFile("Content/BorwnClayout.scnx");
 }