示例#1
0
        internal static SpriteFrameSave FromXElement(System.Xml.Linq.XElement element)
        {
            SpriteFrameSave sfs = new SpriteFrameSave();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "BorderSides":
                    sfs.BorderSides = SceneSave.AsInt(subElement);
                    break;

                case "ParentSprite":
                    sfs.ParentSprite = SpriteSave.FromXElement(subElement);
                    break;

                case "SpriteBorderWidth":
                    sfs.SpriteBorderWidth = SceneSave.AsFloat(subElement);
                    break;

                case "TextureBorderWidth":
                    sfs.TextureBorderWidth = SceneSave.AsFloat(subElement);
                    break;

                default:
                    throw new NotImplementedException();

                    //break;
                }
            }

            return(sfs);
        }
示例#2
0
    // Required method by the ISaveable interface. This will get called from the SaveLoadManager, for each scene to save the dictionaries (GameObjectSave has a dict keyed by scene name)
    // This method will store the sceneData for the current scene (). It will then return a GameObjectSave, which just has a Dict of SceneSave data for each scene, keyed by scene name
    public GameObjectSave ISaveableSave()
    {
        // Delete the sceneData (dict of data to save in that scene, keyed by scene name) for the GameObject if it already exists in the persistent scene
        // which is where this data is going to be saved, so we can create a new one with updated dictionaries
        GameObjectSave.sceneData.Remove(Settings.PersistentScene);

        // Create the SaveScene for this gameObject (keyed by the scene name, storing multiple dicts for bools, the scene the player ended in, the players location, the gridPropertyDetails,
        // the SceneItems, and the inventory items and quantities, and the gameYear, day, hour, minute, second, season, day of week)
        SceneSave sceneSave = new SceneSave();

        // Create a new int dictionary to store the times
        sceneSave.intDictionary = new Dictionary <string, int>();

        // Create a new string dictionary, to store the day of the week and the season
        sceneSave.stringDictionary = new Dictionary <string, string>();

        // Add values to the int dictionary for the different time increments, keyed so we can easily retrieve them in load
        sceneSave.intDictionary.Add("gameYear", gameYear);
        sceneSave.intDictionary.Add("gameDay", gameDay);
        sceneSave.intDictionary.Add("gameHour", gameHour);
        sceneSave.intDictionary.Add("gameMinute", gameMinute);
        sceneSave.intDictionary.Add("gameSecond", gameSecond);

        // Add values to the string dictionary for the day of week and season, keyed so we can easily retrieve them in load
        sceneSave.stringDictionary.Add("gameDayOfWeek", gameDayOfWeek);
        sceneSave.stringDictionary.Add("gameSeason", gameSeason.ToString());

        // Add the SceneSave data for the TimeManager game object to the GameObjectSave, which is a dict storing all the dicts in a scene to be loaded/saved, keyed by the scene name
        // The time manager will get stored in the Persistent Scene
        GameObjectSave.sceneData.Add(Settings.PersistentScene, sceneSave);

        // Return the GameObjectSave, which has a dict of the Saved stuff for the TimeManager GameObject
        return(GameObjectSave);
    }
    public void ISaveableStoreScene(string sceneName)
    {
        // Remove old scene save for gameObject if exists
        GameObjectSave.sceneData.Remove(sceneName);

        // Get all items in the scene
        List <SceneItem> sceneItemList = new List <SceneItem>();

        Item[] itemsInScene = FindObjectsOfType <Item>();

        // Loop through all scene items
        foreach (Item item in itemsInScene)
        {
            SceneItem sceneItem = new SceneItem();
            sceneItem.itemCode = item.ItemCode;
            sceneItem.position = new Vector3Serializable(item.transform.position.x, item.transform.position.y, item.transform.position.z);
            sceneItem.itemName = item.name;

            // Add scene item to list
            sceneItemList.Add(sceneItem);
        }

        // Create list scene items in scene save and set to scene item list
        SceneSave sceneSave = new SceneSave();

        sceneSave.listSceneItem = sceneItemList;

        // Add scene save to gameobject
        GameObjectSave.sceneData.Add(sceneName, sceneSave);
    }
示例#4
0
    public GameObjectSave ISaveableSave()
    {
        //Remove current scene save
        GameObjectSave.sceneData.Remove(Settings.PersistentScene);

        //Create scene save
        SceneSave sceneSave = new SceneSave();

        //Create vector 3 serialisable dictionary
        sceneSave.vector3Dictionary = new Dictionary <string, Vector3Serializable>();

        //Create string dictionary
        sceneSave.stringDictionary = new Dictionary <string, string>();

        //Store target grid position, target world position, and target scene
        sceneSave.vector3Dictionary.Add("npcTargetGridPosition", new Vector3Serializable(npcMovement.npcTargetGridPosition.x, npcMovement.npcTargetGridPosition.y,
                                                                                         npcMovement.npcTargetGridPosition.z));
        sceneSave.vector3Dictionary.Add("npcTargetWorldPosition", new Vector3Serializable(npcMovement.npcTargetWorldPosition.x, npcMovement.npcTargetWorldPosition.y,
                                                                                          npcMovement.npcTargetWorldPosition.z));
        sceneSave.stringDictionary.Add("npcTargetScene", npcMovement.npcTargetScene.ToString());

        //Add scene save to game object
        GameObjectSave.sceneData.Add(Settings.PersistentScene, sceneSave);

        return(GameObjectSave);
    }
示例#5
0
        static FloatRectangle ToFloatRectangle(System.Xml.Linq.XElement element)
        {
            FloatRectangle toReturn = new FloatRectangle();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "Bottom":
                    toReturn.Bottom = SceneSave.AsFloat(subElement);
                    break;

                case "Left":
                    toReturn.Left = SceneSave.AsFloat(subElement);
                    break;

                case "Right":
                    toReturn.Right = SceneSave.AsFloat(subElement);
                    break;

                case "Top":
                    toReturn.Top = SceneSave.AsFloat(subElement);
                    break;

                default:
                    throw new NotImplementedException(subElement.Name.LocalName);
                    //break;
                }
            }


            return(toReturn);
        }
示例#6
0
    public GameObjectSave ISaveableSave()
    {
        // Delete existing scene save if exists
        GameObjectSave.sceneData.Remove(Settings.PersistentScene);

        // Create new scene save
        SceneSave sceneSave = new SceneSave();

        // Create new int dictionary
        sceneSave.intDictionary = new Dictionary <string, int>();

        // Create new string dictionary
        sceneSave.stringDictionary = new Dictionary <string, string>();

        // Add values to the int dictionary
        sceneSave.intDictionary.Add("gameYear", gameYear);
        sceneSave.intDictionary.Add("gameDay", gameDay);
        sceneSave.intDictionary.Add("gameHour", gameHour);
        sceneSave.intDictionary.Add("gameMinute", gameMinute);
        sceneSave.intDictionary.Add("gameSecond", gameSecond);

        // Add values to the string dictionary
        sceneSave.stringDictionary.Add("gameDayOfWeek", gameDayOfWeek);
        sceneSave.stringDictionary.Add("gameSeason", gameSeason.ToString());

        // Add scene save to game object for persistent scene
        GameObjectSave.sceneData.Add(Settings.PersistentScene, sceneSave);

        return(GameObjectSave);
    }
示例#7
0
    // Required method by the ISaveable interface. This will get called from the SaveLoadManager, for each scene to save the dictionaries (GameObjectSave has a dict keyed by scene name)
    // This method will store the sceneData for the persistent scene which the NPC lives on. It will then return a GameObjectSave, which just has a Dict of SceneSave data for each scene, keyed by scene name
    public GameObjectSave ISaveableSave()
    {
        // Delete the sceneData (dict of data to save in that scene, keyed by scene name) for the GameObject if it already exists in the persistent scene
        // which is where this data is going to be saved, so we can create a new one with updated dictionaries
        GameObjectSave.sceneData.Remove(Settings.PersistentScene);

        // Create the SaveScene for this gameObject (keyed by the scene name, storing multiple dicts for bools, the scene the player ended in, the players location, the gridPropertyDetails,
        // the SceneItems, and the inventory items and quantities, and the gameYear, day, hour, minute, second, season, day of week)
        SceneSave sceneSave = new SceneSave();

        // Create a new serializable Vector3 dictionary to store the NPCs target position
        sceneSave.vector3Dictionary = new Dictionary <string, Vector3Serializable>();

        // Create a new string dictionary to store the NPCs target scene
        sceneSave.stringDictionary = new Dictionary <string, string>();

        // Add values to the vector3 dictionary for the NPCs target grid and world positions, keyed so we can easily retrieve them on load
        sceneSave.vector3Dictionary.Add("npcTargetGridPosition", new Vector3Serializable(npcMovement.npcTargetGridPosition.x, npcMovement.npcTargetGridPosition.y, npcMovement.npcTargetGridPosition.z));
        sceneSave.vector3Dictionary.Add("npcTargetWorldPosition", new Vector3Serializable(npcMovement.npcTargetWorldPosition.x, npcMovement.npcTargetWorldPosition.y, npcMovement.npcTargetWorldPosition.z));

        // Add values to the string dictionary for the NPCs target scene, keyed so we can easily retrieve it on load
        sceneSave.stringDictionary.Add("npcTargetScene", npcMovement.npcTargetScene.ToString());
        sceneSave.stringDictionary.Add("npcTargetAnimation", npcMovement.npcTargetAnimationClip.ToString()); // I added this so we can save a string describing the target animatino clip, so we can play it when the npc is transported to his target

        // Add the SceneSave data for the NPC game object to the GameObjectSave, which is a dict storing all the dicts in a scene to be loaded/saved, keyed by the scene name
        // The NPC will get stored in the Persistent Scene
        GameObjectSave.sceneData.Add(Settings.PersistentScene, sceneSave);

        // Return the GameObjectSave, which has a dict of the Saved stuff for the CharacterCustomization GameObject
        return(GameObjectSave);
    }
示例#8
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.
            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);
        }
示例#9
0
        private static SceneSave DeserializeManually(string fileName)
        {
            SceneSave toReturn = new SceneSave();

            System.Xml.Linq.XDocument xDocument = null;

            using (var stream = FileManager.GetStreamForFile(fileName))
            {
                xDocument = System.Xml.Linq.XDocument.Load(stream);
            }

            System.Xml.Linq.XElement foundElement = null;

            foreach (var element in xDocument.Elements())
            {
                if (element.Name.LocalName == "SpriteEditorScene")
                {
                    foundElement = element;
                    break;
                }
            }

            LoadFromElement(toReturn, foundElement);

            return(toReturn);
        }
示例#10
0
        internal static DisplayRegionGridSave FromXElement(System.Xml.Linq.XElement element)
        {
            DisplayRegionGridSave drgs = new DisplayRegionGridSave();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "ReferenceGrid":
                    drgs.ReferenceGrid = ToFloatRectangleArrayArray(subElement);

                    break;

                case "FirstPaintedX":
                    drgs.FirstPaintedX = SceneSave.AsFloatList(subElement);
                    break;

                case "FirstPaintedY":
                    drgs.FirstPaintedY = SceneSave.AsFloat(subElement);
                    break;

                default:
                    throw new NotImplementedException(subElement.Name.LocalName);
                    //break;
                }
            }

            return(drgs);
        }
示例#11
0
        public static SceneSave FromFile(string fileName)
        {
            SceneSave tempScene = null;

#if !FRB_MDX
            if (ManualDeserialization)
            {
                tempScene = DeserializeManually(fileName);
            }
            else
#endif
            {
                tempScene = FileManager.XmlDeserialize <SceneSave>(fileName);
            }

            tempScene.mFileName = fileName;
            if (FileManager.IsRelative(fileName))
            {
                tempScene.mSceneDirectory = FileManager.GetDirectory(FileManager.RelativeDirectory + fileName);
            }
            else
            {
                tempScene.mSceneDirectory = FileManager.GetDirectory(fileName);
            }


            return(tempScene);
        }
示例#12
0
    /// <summary>
    /// Store items in the scene
    /// </summary>
    /// <param name="name"></param>
    public void ISaveableStoreScene(string name)
    {
        // If we already have an entry for this scene's name in the SceneData dictionary, remove it as we're going to be replacing it.
        GameObjectSave.SceneData.Remove(name);

        // Create a list of all items in the scene
        List <SceneItem> sceneItems = new List <SceneItem>();

        Item[] itemsInScene = FindObjectsOfType <Item>();

        // Populate the list
        foreach (Item item in itemsInScene)
        {
            SceneItem sceneItem = new SceneItem();
            sceneItem.itemCode = item.ItemCode;
            sceneItem.location = new Vector3Serializable(item.transform.position.x, item.transform.position.y, item.transform.position.z);
            sceneItem.itemName = item.name;

            sceneItems.Add(sceneItem);
        }

        // Save our scene item list to our sceneItemDict dictionary
        SceneSave sceneSave = new SceneSave();

        sceneSave.ListSceneItem = sceneItems;

        // Add our data to the SceneData dictionary
        GameObjectSave.SceneData.Add(name, sceneSave);
    }
    // One of the core methods, which will store all of the scene data, executed for every item in the SaveableObject list
    public void ISaveableStoreScene(string sceneName)
    {
        // Remove old scene save (dictionary keyed by scene name) for the gameObject if it exists
        GameObjectSave.sceneData.Remove(sceneName);

        // Get all of the items currently in the scene
        List <SceneItem> sceneItemList = new List <SceneItem>();

        Item[] itemsInScene = FindObjectsOfType <Item>();

        // Loop through all of the scene items, populate them, and add them to the sceneItemList
        foreach (Item item in itemsInScene)
        {
            // Populate each sceneItem with their proper variables: item code, position, name
            SceneItem sceneItem = new SceneItem();
            sceneItem.itemCode = item.ItemCode;
            sceneItem.position = new Vector3Serializable(item.transform.position.x, item.transform.position.y, item.transform.position.z);
            sceneItem.itemName = item.name;

            // Add the new scene item to the sceneItemList
            sceneItemList.Add(sceneItem);
        }

        // Create the list of scene items in the scene save and add to it to the sceneItemsList
        SceneSave sceneSave = new SceneSave();

        // Add this sceneItemList with all saveable items in the scene to the Item list
        sceneSave.listSceneItem = sceneItemList;

        // Add scene save to gameObjectSave a dictionary of sceneName: dict"sceneItemList" : list of saveable items)
        GameObjectSave.sceneData.Add(sceneName, sceneSave);
    }
示例#14
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");
            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);
        }
示例#15
0
    /// <summary>
    /// Set up the grid properties with their values from the map
    /// </summary>
    private void InitializeGridProperties()
    {
        // Loop through all the scriptable object assets which store the grid property values
        foreach (SO_GridProperties so_GridProperties in so_gridPropertiesArray)
        {
            // Create a dictionary to store the grid properties
            Dictionary <string, GridPropertyDetails> gridPropertyDictionary = new Dictionary <string, GridPropertyDetails>();

            // Loop through the GridPropertyList & pull out the grid property from the scriptable object
            foreach (GridProperty gridProperty in so_GridProperties.GridPropertyList)
            {
                GridPropertyDetails gridPropertyDetails;

                // Populate the gridPropertyDetails from the grid property from the scriptable object asset
                gridPropertyDetails = GetGridPropertyDetails(gridProperty.GridCoordinate.X, gridProperty.GridCoordinate.Y, gridPropertyDictionary);

                // If gridPropertyDetails is null, it didn't already exist in our dictionary, so create a new one
                if (gridPropertyDetails == null)
                {
                    gridPropertyDetails = new GridPropertyDetails();
                }

                switch (gridProperty.GridBoolProperty)
                {
                case GridBoolProperty.diggable:
                    gridPropertyDetails.IsDiggable = gridProperty.GridBoolValue;
                    break;

                case GridBoolProperty.canDropItem:
                    gridPropertyDetails.CanDropItem = gridProperty.GridBoolValue;
                    break;

                case GridBoolProperty.canPlaceFurniture:
                    gridPropertyDetails.CanPlaceFurniture = gridProperty.GridBoolValue;
                    break;

                default:
                    break;
                }

                SetGridPropertyDetails(gridProperty.GridCoordinate.X, gridProperty.GridCoordinate.Y, gridPropertyDetails, gridPropertyDictionary);
            }

            SceneSave sceneSave = new SceneSave();

            // Store the gridPropertyDictionary in the SceneSave's GridPropertyDetailsDictionary
            sceneSave.GridPropertyDetailsDictionary = gridPropertyDictionary;

            // If the current scene is the starting scene, set the gridPropertyDictionary member variable to the currently populated gridPropertyDictionary
            if (so_GridProperties.SceneName.ToString() == SceneControllerManager.Instance.startingSceneName.ToString())
            {
                this.gridPropertyDictionary = gridPropertyDictionary;
            }

            // Add the SceneSave with the populated GridPropertyDetailsDictionary to the GameObjectSave SceneData
            GameObjectSave.SceneData.Add(so_GridProperties.SceneName.ToString(), sceneSave);
        }
    }
示例#16
0
        private static void AddCameraFromXElement(SpriteEditorScene toReturn, System.Xml.Linq.XElement element)
        {
            CameraSave cameraSave = new CameraSave();

            toReturn.Camera = cameraSave;

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "FarClipPlane":
                    cameraSave.FarClipPlane = SceneSave.AsFloat(subElement);
                    break;

                case "Name":
                    //cameraSave. = subElement.Value;
                    break;

                case "NearClipPlane":
                    cameraSave.NearClipPlane = SceneSave.AsFloat(subElement);
                    break;

                case "Orthogonal":
                    cameraSave.Orthogonal = AsBool(subElement);
                    break;

                case "OrthogonalHeight":
                    cameraSave.OrthogonalHeight = SceneSave.AsFloat(subElement);
                    break;

                case "OrthogonalWidth":
                    cameraSave.OrthogonalWidth = SceneSave.AsFloat(subElement);
                    break;

                case "X":
                    cameraSave.X = SceneSave.AsFloat(subElement);
                    break;

                case "Y":
                    cameraSave.Y = SceneSave.AsFloat(subElement);
                    break;

                case "Z":
                    cameraSave.Z = SceneSave.AsFloat(subElement);
                    break;

                case "AspectRatio":
                    cameraSave.AspectRatio = SceneSave.AsFloat(subElement);
                    break;

                default:

                    throw new NotImplementedException("Error trying to apply property " +
                                                      subElement.Name.LocalName + " on Camera");
                    //break;
                }
            }
        }
示例#17
0
        private static void LoadFromElement(SpriteEditorScene toReturn, System.Xml.Linq.XElement element)
        {
            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "Sprite":
                    AddSpriteFromXElement(toReturn, subElement);

                    break;

                case "SpriteFrame":
                    SpriteFrameSave sfs = SpriteFrameSave.FromXElement(subElement);
                    toReturn.SpriteFrameSaveList.Add(sfs);
                    break;

                case "Camera":
                    AddCameraFromXElement(toReturn, subElement);

                    break;

                case "Text":
                    AddTextFromXElement(toReturn, subElement);
                    break;

                case "PixelSize":
                    toReturn.PixelSize = SceneSave.AsFloat(subElement);
                    break;

                case "AssetsRelativeToSceneFile":
                    toReturn.AssetsRelativeToSceneFile = AsBool(subElement);
                    break;

                case "CoordinateSystem":
                    toReturn.CoordinateSystem = (CoordinateSystem)Enum.Parse(typeof(CoordinateSystem), subElement.Value, true);
                    break;

                case "Snapping":
                    toReturn.Snapping = AsBool(subElement);
                    break;

                case "SpriteGrid":
                    SpriteGridSave spriteGridSave = SpriteGridSave.FromXElement(subElement);
                    toReturn.SpriteGridList.Add(spriteGridSave);
                    break;

                case "FileName":

                    // do nothing with this, shouldn't be here anyway:
                    break;

                default:
                    throw new NotImplementedException("Unexpected node in XML: " +
                                                      subElement.Name.LocalName);
                    //break;
                }
            }
        }
        private static void SetQuadWidthAndHeight(ReducedTileMapInfo toReturn, SceneSave ses)
        {
            if (ses.SpriteList.Count != 0)
            {
                SpriteSave spriteSave = ses.SpriteList[0];

                toReturn.QuadWidth  = spriteSave.ScaleX * 2;
                toReturn.QuadHeight = spriteSave.ScaleY * 2;
            }
        }
示例#19
0
        internal static List <float> AsFloatList(System.Xml.Linq.XElement element)
        {
            List <float> toReturn = new List <float>();

            foreach (var subElement in element.Elements())
            {
                toReturn.Add(SceneSave.AsFloat(subElement));
            }

            return(toReturn);
        }
示例#20
0
 void Awake()
 {
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
        //public AnimationFrame ToAnimationFrame(TextureAtlas textureAtlas)
        //{
        //    AnimationFrame toReturn = ToAnimationFrame(null, false);
        //    var entry = textureAtlas.GetEntryFor(this.TextureName);

        //    if (entry != null)
        //    {

        //        float left;
        //        float right;
        //        float top;
        //        float bottom;


        //        entry.FullToReduced(toReturn.LeftCoordinate, toReturn.RightCoordinate,
        //            toReturn.TopCoordinate, toReturn.BottomCoordinate,
        //            out left, out right, out top, out bottom);

        //        toReturn.LeftCoordinate = left;
        //        toReturn.RightCoordinate = right;
        //        toReturn.TopCoordinate = top;
        //        toReturn.BottomCoordinate = bottom;

        //    }

        //    return toReturn;
        //}


        internal static AnimationFrameSave FromXElement(System.Xml.Linq.XElement element)
        {
            AnimationFrameSave toReturn = new AnimationFrameSave();


            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "FlipHorizontal":
                    toReturn.FlipHorizontal = SceneSave.AsBool(subElement);
                    break;

                case "FlipVertical":
                    toReturn.FlipVertical = SceneSave.AsBool(subElement);
                    break;

                case "TextureName":
                    toReturn.TextureName = subElement.Value;
                    break;

                case "FrameLength":
                    toReturn.FrameLength = SceneSave.AsFloat(subElement);
                    break;

                case "LeftCoordinate":
                    toReturn.LeftCoordinate = SceneSave.AsFloat(subElement);
                    break;

                case "RightCoordinate":
                    toReturn.RightCoordinate = SceneSave.AsFloat(subElement);
                    break;

                case "TopCoordinate":
                    toReturn.TopCoordinate = SceneSave.AsFloat(subElement);
                    break;

                case "BottomCoordinate":
                    toReturn.BottomCoordinate = SceneSave.AsFloat(subElement);
                    break;

                case "RelativeX":
                    toReturn.RelativeX = SceneSave.AsFloat(subElement);
                    break;

                case "RelativeY":
                    toReturn.RelativeY = SceneSave.AsFloat(subElement);
                    break;
                }
            }

            return(toReturn);
        }
示例#22
0
    /// <summary>
    /// Saves the scene out for later loading with the model manager class. for information about the structure of thesave
    /// look as the SceneSave class
    /// </summary>
    public void SaveScene()
    {
        List <Transform> parents = new List <Transform>();
        SceneSave        save    = new SceneSave();

        count = Directory.GetFiles(Application.persistentDataPath + "/Saves/").Length;

        ObjectID[] objectList = GetComponentsInChildren <ObjectID>();
        save.OBJStrings = new string[objectList.Length];
        save.Positions  = new V3[objectList.Length];
        save.Rotations  = new V3[objectList.Length];
        save.Scales     = new V3[objectList.Length];
        save.Colors     = new float[objectList.Length, 3];
        save.Groups     = new int[objectList.Length];
        for (int i = 0; i < objectList.Length; i++)
        {
            save.OBJStrings[i] = ObjExporter.MeshToString(objectList[i].gameObject.GetComponent <MeshFilter>());
            save.Positions[i]  = new V3(objectList[i].transform.position);
            save.Rotations[i]  = new V3(objectList[i].transform.rotation.eulerAngles);
            save.Scales[i]     = new V3(objectList[i].transform.lossyScale);
            Color c = objectList[i].GetComponent <MeshRenderer>().material.color;
            save.Colors[i, 0] = c.r;
            save.Colors[i, 1] = c.g;
            save.Colors[i, 2] = c.b;
            if (objectList[i].gameObject.GetComponent <ObjectID>().HasParent)
            {
                if (parents.Contains(objectList[i].transform.parent))
                {
                    save.Groups[i] = parents.IndexOf(objectList[i].transform.parent);
                }
                else
                {
                    save.Groups[i] = parents.Count;
                    parents.Add(objectList[i].transform.parent);
                }
            }
            else
            {
                save.Groups[i] = -1;
            }
        }
        directory = string.Format(Application.persistentDataPath + "/Saves/");;
        Directory.CreateDirectory(directory);
        date = DateTime.Today;
        string     fileName = string.Format(@"{0}/Scene {1}.obj", directory, count);
        FileStream fs       = new FileStream(fileName, FileMode.Create);

        new BinaryFormatter().Serialize(fs, save);
        fs.Close();

        GameObject.Find("Tracker").GetComponent <TrackerScript>().saveSizes.Add(new System.IO.FileInfo(fileName).Length);
        ModelManager.instance.LoadScenes();
    }
示例#23
0
    /// <summary>
    /// Saves the GridPropertyDetailsDictionary for the current scene
    /// </summary>
    /// <param name="sceneName"></param>
    public void ISaveableStoreScene(string sceneName)
    {
        // Remove any old SceneData stored for the scene
        GameObjectSave.SceneData.Remove(sceneName);

        SceneSave sceneSave = new SceneSave();

        // Store the gridPropertyDictionary in the SceneSave
        sceneSave.GridPropertyDetailsDictionary = gridPropertyDictionary;

        // Add the SceneData to the GameObjectSave
        GameObjectSave.SceneData.Add(sceneName, sceneSave);
    }
    // save
    public void ISaveableStoreScene(string sceneName)
    {
        // Remove sceneSave for scene
        GameObjectSave.sceneData.Remove(sceneName);

        // Create sceneSave for scene
        SceneSave sceneSave = new SceneSave();

        // create & add dict grid property details dictionary
        sceneSave.gridPropertyDetailsDictionary = gridPropertyDictionary;

        // Add scene save to gameObject scene data
        GameObjectSave.sceneData.Add(sceneName, sceneSave);
    }
示例#25
0
        private SceneSave ReadSpriteEditorScene(ContentReader input)
        {
            SceneSave newObject = new SceneSave();

            int SpriteListCount = input.ReadInt32();

            for (int i = 0; i < SpriteListCount; i++)
            {
                newObject.SpriteList.Add(ObjectReader.ReadObject <FlatRedBall.Content.Scene.SpriteSave>(input));
            }
            int DynamicSpriteListCount = input.ReadInt32();

            for (int i = 0; i < DynamicSpriteListCount; i++)
            {
                newObject.DynamicSpriteList.Add(ObjectReader.ReadObject <FlatRedBall.Content.Scene.SpriteSave>(input));
            }
            newObject.Snapping  = input.ReadBoolean();
            newObject.PixelSize = input.ReadSingle();
            int SpriteGridListCount = input.ReadInt32();

            for (int i = 0; i < SpriteGridListCount; i++)
            {
                newObject.SpriteGridList.Add(ObjectReader.ReadObject <FlatRedBall.Content.SpriteGrid.SpriteGridSave>(input));
            }

            int LightSaveListCount = input.ReadInt32();

            for (int i = 0; i < LightSaveListCount; i++)
            {
#if SUPPORTS_LIGHTS
                newObject.LightSaveList.Add(ObjectReader.ReadObject <FlatRedBall.Content.Lighting.LightSave>(input));
#endif
            }

            int SpriteFrameSaveListCount = input.ReadInt32();
            for (int i = 0; i < SpriteFrameSaveListCount; i++)
            {
                newObject.SpriteFrameSaveList.Add(ObjectReader.ReadObject <FlatRedBall.Content.SpriteFrame.SpriteFrameSave>(input));
            }
            int TextSaveListCount = input.ReadInt32();
            for (int i = 0; i < TextSaveListCount; i++)
            {
                newObject.TextSaveList.Add(ObjectReader.ReadObject <FlatRedBall.Content.Saves.TextSave>(input));
            }
            newObject.SpriteEditorSceneProperties = input.ReadString();
            newObject.AssetsRelativeToSceneFile   = input.ReadBoolean();
            newObject.CoordinateSystem            = (FlatRedBall.Math.CoordinateSystem)Enum.ToObject(typeof(FlatRedBall.Math.CoordinateSystem), (int)input.ReadInt32());
            return(newObject);
        }
示例#26
0
    public GameObjectSave ISaveableSave()
    {
        // Remove existing save data for this scene if it exists
        GameObjectSave.SceneData.Remove(Settings.MainScene);

        SceneSave sceneSave = new SceneSave();

        // Instantiate the dictionary to store the money data
        sceneSave.moneyData = playerMoney;

        // Add the money data to the GameObjectSave
        GameObjectSave.SceneData.Add(Settings.MainScene, sceneSave);

        return(GameObjectSave);
    }
示例#27
0
        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();
            }
        }
    // Required method for the ISaveable interface. This will get called as we're moving inbetween scenes. This will save all of the gridPropertyDetailsDictionary
    // To be used again when we enter the scene again
    public void ISaveableStoreScene(string sceneName)
    {
        // Remove sceneSave for the scene
        GameObjectSave.sceneData.Remove(sceneName);

        // Create sceneSave for scene
        SceneSave sceneSave = new SceneSave();

        // Create and add dict grid property details dictionary
        sceneSave.gridPropertyDetailsDictionary = gridPropertyDictionary;

        // Create and add the boolDictionary for the first time scene loaded, to be stored and loaded again
        sceneSave.boolDictionary = new Dictionary <string, bool>();
        sceneSave.boolDictionary.Add("isFirstTimeSceneLoaded", isFirstTimeSceneLoaded);

        // Add scene save to the game object save scene data
        GameObjectSave.sceneData.Add(sceneName, sceneSave);
    }
示例#29
0
    public GameObjectSave ISaveableSave()
    {
        // Remove existing save data for this scene if it exists
        GameObjectSave.SceneData.Remove(Settings.MainScene);

        // Store inventoryLists in the SceneSave object
        SceneSave sceneSave = new SceneSave();

        sceneSave.ListInvItemArray = inventoryLists;

        // Save the maximum capacities of the invventory
        sceneSave.intArrayDictionary = new Dictionary <string, int[]>();
        sceneSave.intArrayDictionary.Add("inventoryListCapacityArray", inventoryListCapacityIntArray);

        // Add the scene data to the GameObjectSave
        GameObjectSave.SceneData.Add(Settings.MainScene, sceneSave);

        return(GameObjectSave);
    }
    public GameObjectSave ISaveableSave()
    {
        // Create new scene save
        SceneSave sceneSave = new SceneSave();

        // Remove any existing scene save for persistent scene for this gameobject
        GameObjectSave.sceneData.Remove(Settings.PersistentScene);

        // Add inventory lists array to persistent scene save
        sceneSave.listInvItemArray = inventoryLists;

        // Add  inventory list capacity array to persistent scene save
        sceneSave.intArrayDictionary = new Dictionary <string, int[]>();
        sceneSave.intArrayDictionary.Add("inventoryListCapacityArray", inventoryListCapacityIntArray);

        // Add scene save for gameobject
        GameObjectSave.sceneData.Add(Settings.PersistentScene, sceneSave);

        return(GameObjectSave);
    }