Ejemplo n.º 1
0
 /// <summary>
 /// De-serialize the effect
 /// </summary>
 /// <param name="reader">Reader instance</param>
 public override void Read(BinaryReader reader)
 {
     base.Read(reader);
     mSourcePos           = reader.ReadVector2i();
     mTargetPos           = reader.ReadVector2i();
     mTargetEntity        = reader.ReadEntityID();
     mAlphaFade           = reader.ReadInt32();
     mProjecticleColor    = reader.ReadColor32();
     mProjecticleSprite   = reader.ReadPackedSpriteID();
     mProjecticleSprite45 = reader.ReadPackedSpriteID();
     mRotate      = reader.ReadBoolean();
     mLaunchSound = SoundSerializer.Deserialize(reader.ReadInt32());
     mLandSound   = SoundSerializer.Deserialize(reader.ReadInt32());
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Load game
        /// </summary>
        /// <param name="filename">File name</param>
        /// <param name="player">Player ref</param>
        /// <param name="gameMap">GameMap ref</param>
        /// <param name="gameState">Current game state ref</param>
        /// <param name="console">Console ref</param>
        /// <returns>True if successful</returns>
        public static bool LoadGame(string filename, ref EntityID player, ref GameMap gameMap, ref GameState gameState, Console console)
        {
            string fullFilename = Application.persistentDataPath + "/" + C.SAVE_FOLDER + "/" + filename;

            if (!File.Exists(fullFilename))
            {
                console.Log(C.FSTR.Set("File ").Append(fullFilename).Append(" doesn't exist, can't load game!"));
                return(false);
            }

            EntityStore.Clear();

            player    = EntityID.empty;
            gameMap   = null;
            gameState = GameState.INVALID_STATE;

            FileStream file = null;

            try
            {
                file = File.Open(fullFilename, FileMode.Open);
            }
            catch
            {
                // Do nothing
            }

            if (file == null)
            {
                console.Log(C.FSTR.Set("Failed to load game from ").Append(fullFilename).Append(", can't open file."));
                return(false);
            }

            try
            {
#if !DEBUG_SAVES
                var reader = new BinaryReader(file);
#else
                var reader = new GameReader(file);
#endif

                EntityStore.Read(reader);

                // Read player entityID
                player = reader.ReadEntityID();

                // Read GameMap
                var gameMapSize = reader.ReadVector2i();
                gameMap = new GameMap(gameMapSize);

                // Read terrain tiles
                for (int x = 0; x < gameMap.size.width; x++)
                {
                    for (int y = 0; y < gameMap.size.height; y++)
                    {
                        gameMap.terrain[x, y] = reader.ReadTile();
                    }
                }

                // Read FOV tiles
                for (int x = 0; x < gameMap.size.width; x++)
                {
                    for (int y = 0; y < gameMap.size.height; y++)
                    {
                        gameMap.fov[x, y] = reader.ReadFOVTile();
                    }
                }

                // Read background color
                gameMap.backgroundColor = reader.ReadColor32();

                // Read music
                gameMap.music = SoundSerializer.Deserialize(reader.ReadInt32());

                // Read dungeon level
                gameMap.dungeonLevel = reader.ReadInt32();

                gameMap.RefreshTilemap();

                // Read Console contents
                int consoleSize = reader.ReadInt32();
                console.Clear();
                for (int i = 0; i < consoleSize; i++)
                {
                    console.Log(reader.ReadFastString());
                }

                // Read the effects manager
                EffectManager.Instance.Read(reader);

                gameState = (GameState)reader.ReadInt32();

                reader.Close();
            }
            catch (System.Exception e)
            {
                throw new System.Exception("Failed loading: " + e.ToString());
            }

            gameMap.UpdateAllEntityMapPositions();

            return(true);
        }