Example #1
0
        public void Save(IDataDescriptor descriptor, IDataManagerArguments arguments)
        {
            PlayerDescriptor playerDescriptor = ((PlayerDescriptor)descriptor);

            string filePath = EngineConstants.FILEPATH_DATA + playerDescriptor.Name + EngineConstants.ACC_FILE_EXT;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (var binaryWriter = new BinaryWriter(fileStream))
                {
                    binaryWriter.Write(playerDescriptor.Name);
                    binaryWriter.Write(playerDescriptor.Password);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.Sprite.TextureName);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.HorizontalFrames);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.VerticalFrames);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.FrameWidth);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.FrameHeight);
                    binaryWriter.Write(playerDescriptor.Speed);
                    binaryWriter.Write(playerDescriptor.Stats.MaximumHealth);
                    binaryWriter.Write(playerDescriptor.Stats.Health);
                    binaryWriter.Write(playerDescriptor.Stats.Strength);
                    binaryWriter.Write(playerDescriptor.Stats.Intelligence);
                    binaryWriter.Write(playerDescriptor.Stats.Dexterity);
                    binaryWriter.Write(playerDescriptor.Stats.Defense);
                    binaryWriter.Write(playerDescriptor.Level);
                    binaryWriter.Write(playerDescriptor.Position.X);
                    binaryWriter.Write(playerDescriptor.Position.Y);
                    binaryWriter.Write(playerDescriptor.MapID);
                    binaryWriter.Write(playerDescriptor.Role.Name);
                    binaryWriter.Write(playerDescriptor.Role.Level);
                }
            }
        }
        public override ItemModel Load(IDataManagerArguments arguments)
        {
            var itemArguments = (arguments as ContentFileDataLoaderArguments);

            var desc = new ItemModel();

            using (var fileStream = new FileStream(this.RootPath + itemArguments.FileName + EngineConstants.ITEM_FILE_EXT, FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    desc.Name         = binaryReader.ReadString();
                    desc.SpriteInfo   = new SpriteInfo(binaryReader.ReadString());
                    desc.Stackable    = binaryReader.ReadBoolean();
                    desc.ItemType     = (ItemTypes)Enum.Parse(typeof(ItemTypes), binaryReader.ReadString());
                    desc.SlotType     = (EquipmentSlots)Enum.Parse(typeof(EquipmentSlots), binaryReader.ReadString());
                    desc.Strength     = binaryReader.ReadInt32();
                    desc.Intelligence = binaryReader.ReadInt32();
                    desc.Dexterity    = binaryReader.ReadInt32();
                    desc.Defence      = binaryReader.ReadInt32();
                    desc.Health       = binaryReader.ReadInt32();

                    int scriptCount = binaryReader.ReadInt32();
                    for (int i = 0; i < scriptCount; i++)
                    {
                        desc.Scripts.Add(binaryReader.ReadString(), binaryReader.ReadString());
                    }
                }
            }

            return(desc);
        }
Example #3
0
        public override BaseAnimation <IAnimationLayer <SpriteInfo> > Load(IDataManagerArguments arguments)
        {
            var animationDescription = new BaseAnimation <IAnimationLayer <SpriteInfo> >();

            using (FileStream fileStream = File.Open(this.RootPath + (arguments as ContentFileDataLoaderArguments).FileName, FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    animationDescription.Name = binaryReader.ReadString();
                    animationDescription.SubSurfaceAnimation.FrameWidth  = binaryReader.ReadInt32();
                    animationDescription.SubSurfaceAnimation.FrameHeight = binaryReader.ReadInt32();
                    animationDescription.SubSurfaceAnimation.FrameTime   = binaryReader.ReadInt32();
                    animationDescription.SubSurfaceAnimation.LoopCount   = binaryReader.ReadInt32();
                    animationDescription.SubSurfaceAnimation.TexturePath = binaryReader.ReadString();

                    animationDescription.SurfaceAnimation.FrameWidth  = binaryReader.ReadInt32();
                    animationDescription.SurfaceAnimation.FrameHeight = binaryReader.ReadInt32();
                    animationDescription.SurfaceAnimation.FrameTime   = binaryReader.ReadInt32();
                    animationDescription.SurfaceAnimation.LoopCount   = binaryReader.ReadInt32();
                    animationDescription.SurfaceAnimation.TexturePath = binaryReader.ReadString();
                }
            }

            return(animationDescription);
        }
        public override void Save(IContentModel descriptor, IDataManagerArguments arguments)
        {
            var itemDesc = (ItemModel)descriptor;

            string filePath = this.RootPath + (arguments as ContentFileDataLoaderArguments).FileName + EngineConstants.ITEM_FILE_EXT;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (var binaryWriter = new BinaryWriter(fileStream))
                {
                    binaryWriter.Write(itemDesc.Name);
                    binaryWriter.Write(itemDesc.SpriteInfo.TextureName);
                    binaryWriter.Write(itemDesc.Stackable);
                    binaryWriter.Write(itemDesc.ItemType.ToString());
                    binaryWriter.Write(itemDesc.SlotType.ToString());
                    binaryWriter.Write(itemDesc.Strength);
                    binaryWriter.Write(itemDesc.Intelligence);
                    binaryWriter.Write(itemDesc.Dexterity);
                    binaryWriter.Write(itemDesc.Defence);
                    binaryWriter.Write(itemDesc.Health);
                    binaryWriter.Write(itemDesc.Scripts.Count);
                    foreach (var script in itemDesc.Scripts)
                    {
                        binaryWriter.Write(script.Key);
                        binaryWriter.Write(script.Value);
                    }
                }
            }
        }
        public override void Save(IContentDescriptor descriptor, IDataManagerArguments arguments)
        {
            PlayerDescriptor playerDescriptor = ((PlayerDescriptor)descriptor);

            using (var fileStream = new FileStream(this.RootPath + playerDescriptor.Name + EngineConstants.ACC_FILE_EXT, FileMode.OpenOrCreate))
            {
                using (var binaryWriter = new BinaryWriter(fileStream))
                {
                    binaryWriter.Write(playerDescriptor.Name);
                    binaryWriter.Write(playerDescriptor.Password);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.Sprite.TextureName);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.FrameWidth);
                    binaryWriter.Write(playerDescriptor.SpriteSheet.FrameHeight);
                    binaryWriter.Write(playerDescriptor.Speed);
                    binaryWriter.Write(playerDescriptor.Stats.Health);
                    binaryWriter.Write(playerDescriptor.Stats.CurrentHealth);
                    binaryWriter.Write(playerDescriptor.Stats.Strength);
                    binaryWriter.Write(playerDescriptor.Stats.Intelligence);
                    binaryWriter.Write(playerDescriptor.Stats.Dexterity);
                    binaryWriter.Write(playerDescriptor.Stats.Defense);
                    binaryWriter.Write(playerDescriptor.Level);
                    binaryWriter.Write(playerDescriptor.Position.X);
                    binaryWriter.Write(playerDescriptor.Position.Y);
                    binaryWriter.Write(playerDescriptor.MapID);
                    binaryWriter.Write(playerDescriptor.Role.Name);
                    binaryWriter.Write(playerDescriptor.Role.Level);
                    binaryWriter.Write(playerDescriptor.Reach.X);
                    binaryWriter.Write(playerDescriptor.Reach.Y);
                }
            }
        }
        public override void Save(IContentModel contentModel, IDataManagerArguments arguments)
        {
            var model = (SpellModel)contentModel;

            string filePath = this.RootPath + (arguments as ContentFileDataLoaderArguments).FileName + EngineConstants.SPELL_FILE_EXT;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (var binaryWriter = new BinaryWriter(fileStream))
                {
                    binaryWriter.Write(model.Name);

                    if (model.DisplaySprite != null)
                    {
                        binaryWriter.Write(model.DisplaySprite.TextureName);
                    }
                    else
                    {
                        binaryWriter.Write("");
                    }

                    binaryWriter.Write(model.CastTime);
                    binaryWriter.Write(model.ActiveTime);
                    binaryWriter.Write(model.CooldownTime);

                    binaryWriter.Write(model.HealthCost);
                    binaryWriter.Write(model.ManaCost);

                    binaryWriter.Write(model.CasterAnimationPath);
                    binaryWriter.Write(model.TargetAnimationPath);

                    binaryWriter.Write(model.StatModifiers.Strength);
                    binaryWriter.Write(model.StatModifiers.Intelligence);
                    binaryWriter.Write(model.StatModifiers.Dexterity);
                    binaryWriter.Write(model.StatModifiers.Defense);
                    binaryWriter.Write(model.StatModifiers.Vitality);

                    binaryWriter.Write(model.StatRequirements.Strength);
                    binaryWriter.Write(model.StatRequirements.Intelligence);
                    binaryWriter.Write(model.StatRequirements.Dexterity);
                    binaryWriter.Write(model.StatRequirements.Defense);
                    binaryWriter.Write(model.StatRequirements.Vitality);

                    binaryWriter.Write(model.Scripts.Count);
                    foreach (var script in model.Scripts)
                    {
                        binaryWriter.Write(script.Key);
                        binaryWriter.Write(script.Value);
                    }
                }
            }
        }
        public override SpellModel Load(IDataManagerArguments arguments)
        {
            var spellArguments = (arguments as ContentFileDataLoaderArguments);

            var model = new SpellModel();

            using (var fileStream = new FileStream(this.RootPath + spellArguments.FileName + EngineConstants.SPELL_FILE_EXT, FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    model.Name          = binaryReader.ReadString();
                    model.DisplaySprite = new SpriteInfo(binaryReader.ReadString());
                    model.CastTime      = binaryReader.ReadInt32();
                    model.ActiveTime    = binaryReader.ReadInt32();
                    model.CooldownTime  = binaryReader.ReadInt32();

                    model.HealthCost = binaryReader.ReadInt32();
                    model.ManaCost   = binaryReader.ReadInt32();

                    model.CasterAnimationPath = binaryReader.ReadString();
                    model.TargetAnimationPath = binaryReader.ReadString();

                    model.StatModifiers.Strength     = binaryReader.ReadInt32();
                    model.StatModifiers.Intelligence = binaryReader.ReadInt32();
                    model.StatModifiers.Dexterity    = binaryReader.ReadInt32();
                    model.StatModifiers.Defense      = binaryReader.ReadInt32();
                    model.StatModifiers.Vitality     = binaryReader.ReadInt32();

                    model.StatRequirements.Strength     = binaryReader.ReadInt32();
                    model.StatRequirements.Intelligence = binaryReader.ReadInt32();
                    model.StatRequirements.Dexterity    = binaryReader.ReadInt32();
                    model.StatRequirements.Defense      = binaryReader.ReadInt32();
                    model.StatRequirements.Vitality     = binaryReader.ReadInt32();

                    int scriptCount = binaryReader.ReadInt32();
                    for (int i = 0; i < scriptCount; i++)
                    {
                        model.Scripts.Add(binaryReader.ReadString(), binaryReader.ReadString());
                    }
                }
            }

            return(model);
        }
Example #8
0
        public override void Save(IContentDescriptor descriptor, IDataManagerArguments arguments)
        {
            var npcDesc = (NPCDescriptor)descriptor;

            string filePath = this.RootPath + (arguments as ContentFileDataLoaderArguments).FileName + EngineConstants.NPC_FILE_EXT;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (var binaryWriter = new BinaryWriter(fileStream))
                {
                    binaryWriter.Write(npcDesc.Name);
                    binaryWriter.Write(npcDesc.Level);
                    binaryWriter.Write(npcDesc.Speed);
                    binaryWriter.Write(npcDesc.Stats.Strength);
                    binaryWriter.Write(npcDesc.Stats.Defense);
                    binaryWriter.Write(npcDesc.Stats.Dexterity);
                    binaryWriter.Write(npcDesc.Stats.CurrentHealth);
                    binaryWriter.Write(npcDesc.Stats.Intelligence);
                    binaryWriter.Write(npcDesc.Stats.Health);
                    binaryWriter.Write(npcDesc.CollisionBounds.X);
                    binaryWriter.Write(npcDesc.CollisionBounds.Y);
                    binaryWriter.Write(npcDesc.CollisionBounds.Width);
                    binaryWriter.Write(npcDesc.CollisionBounds.Height);
                    binaryWriter.Write(npcDesc.AggresiveRange);
                    binaryWriter.Write(npcDesc.TexturePath);
                    binaryWriter.Write(npcDesc.MaxRoam.X);
                    binaryWriter.Write(npcDesc.MaxRoam.Y);
                    binaryWriter.Write(npcDesc.FrameSize.X);
                    binaryWriter.Write(npcDesc.FrameSize.Y);
                    binaryWriter.Write(npcDesc.Reach.X);
                    binaryWriter.Write(npcDesc.Reach.Y);

                    binaryWriter.Write(npcDesc.Scripts.Count);
                    foreach (var script in npcDesc.Scripts)
                    {
                        binaryWriter.Write(script);
                    }

                    binaryWriter.Write(npcDesc.Dialogue);
                    binaryWriter.Write(npcDesc.DialogueBranch);
                }
            }
        }
        public MapDescriptor Load(IDataManagerArguments arguments)
        {
            MapDescriptor map = null;

            string path = Core.EngineConstants.FILEPATH_MAPS + (arguments as MapDataLoaderArguments)?.Name + EngineConstants.MAP_FILE_EXT;

            using (var fileStream = new FileStream(path, FileMode.Open))
            {
                using (var bR = new BinaryReader(fileStream))
                {
                    // Load the tileset information
                    int tilesetCount = bR.ReadInt32();
                    for (int i = 0; i < tilesetCount; i++)
                    {
                        // We can throw this information away as it is used only in the editor suite.
                        string tilesetPath = bR.ReadString();
                    }

                    string name       = bR.ReadString();
                    var    dimensions = new Vector(bR.ReadInt32(), bR.ReadInt32());

                    map = new MapDescriptor(dimensions, name)
                    {
                        Dark = bR.ReadBoolean()
                    };


                    map.Bounds = new Rect(0, 0, (int)map.Dimensions.X, (int)map.Dimensions.Y);

                    int layerCount = bR.ReadInt32();
                    for (int i = 0; i < layerCount; i++)
                    {
                        string layerName = bR.ReadString();
                        int    lIndex    = bR.ReadInt32();

                        var layer = new LayerDescriptor(map.Dimensions, layerName, lIndex);

                        for (int x = 0; x < layer.Tiles.GetLength(0); x++)
                        {
                            for (int y = 0; y < layer.Tiles.GetLength(1); y++)
                            {
                                if (bR.ReadBoolean())
                                {
                                    layer.Tiles[x, y] = new TileDescriptor(new Vector(x * EngineConstants.TILE_WIDTH,
                                                                                      y * EngineConstants.TILE_HEIGHT))
                                    {
                                        Attribute = (TileAttributes)bR.ReadByte()
                                    };

                                    int    attributeDataLength = bR.ReadInt32();
                                    byte[] attributeData       = bR.ReadBytes(attributeDataLength);
                                    layer.Tiles[x, y].AttributeData = AttributeData.Deserialize(attributeData);

                                    if (bR.ReadBoolean())
                                    {
                                        layer.Tiles[x, y].Animated    = bR.ReadBoolean();
                                        layer.Tiles[x, y].LightSource = bR.ReadBoolean();

                                        string spriteName = bR.ReadString();
                                        float  zIndex     = bR.ReadSingle(); // We can throw this away

                                        layer.Tiles[x, y].SpriteInfo = new SpriteInfo(spriteName)
                                        {
                                            Transform =
                                            {
                                                Position = new Vector(x * EngineConstants.TILE_WIDTH, y * EngineConstants.TILE_HEIGHT),
                                                Color    = new Color(bR.ReadByte(),                   bR.ReadByte(),                   bR.ReadByte(),   bR.ReadByte()),
                                                Rect     = new Rect(bR.ReadInt32(),                   bR.ReadInt32(),                  bR.ReadInt32(),  bR.ReadInt32())
                                            }
                                        };

                                        layer.Tiles[x, y].FrameCount = bR.ReadInt32();
                                    }
                                }
                            }
                        }

                        int mapObjectCount = bR.ReadInt32();
                        for (int mI = 0; mI < mapObjectCount; mI++)
                        {
                            var mapObject = new MapObjectDescriptor()
                            {
                                Position = new Vector(bR.ReadSingle(), bR.ReadSingle())
                            };

                            if (bR.ReadBoolean())
                            {
                                string texturePath = bR.ReadString();
                                mapObject.Sprite = new SpriteInfo(texturePath)
                                {
                                    Transform =
                                    {
                                        Rect = new Rect(bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32())
                                    }
                                };
                            }

                            mapObject.Animated = bR.ReadBoolean();

                            mapObject.FrameTime = bR.ReadInt32();

                            string scriptPath = bR.ReadString();

                            var lightSource = bR.ReadBoolean();
                            var lightRadius = bR.ReadSingle();
                            var lightColor  = new Color(bR.ReadByte(), bR.ReadByte(), bR.ReadByte(), bR.ReadByte());

                            if (lightSource)
                            {
                                mapObject.LightInformation = new LightInformation()
                                {
                                    Radius = lightRadius,
                                    Color  = lightColor
                                };
                            }
                        }

                        map.Layers.Add(layerName, layer);
                    }
                }
            }

            return(map);
        }
 public override bool Exists(IDataManagerArguments arguments)
 {
     return(File.Exists(this.RootPath + (arguments as ContentFileDataLoaderArguments).FileName + EngineConstants.SPELL_FILE_EXT));
 }
Example #11
0
        public PlayerDescriptor Load(IDataManagerArguments arguments)
        {
            var playerDataLoaderArgs = arguments as PlayerDataLoaderArguments;

            string filePath = EngineConstants.FILEPATH_ACCOUNTS + playerDataLoaderArgs.Username + EngineConstants.ACC_FILE_EXT;

            string      name     = "";
            string      password = "";
            SpriteSheet sprite;
            float       speed;
            int         level;
            int         health;
            int         maximumHealth;
            int         strength;
            int         intelligence;
            int         dexterity;
            int         defense;
            Vector      position;
            string      mapID;
            Role        role;

            try
            {
                using (var fileStream = new FileStream(filePath, FileMode.Open))
                {
                    using (var binaryReader = new BinaryReader(fileStream))
                    {
                        name     = binaryReader.ReadString();
                        password = binaryReader.ReadString();
                        sprite   = new SpriteSheet(new SpriteInfo(binaryReader.ReadString()), binaryReader.ReadInt32(),
                                                   binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32());
                        speed         = binaryReader.ReadSingle();
                        maximumHealth = binaryReader.ReadInt32();
                        health        = binaryReader.ReadInt32();
                        strength      = binaryReader.ReadInt32();
                        intelligence  = binaryReader.ReadInt32();
                        dexterity     = binaryReader.ReadInt32();
                        defense       = binaryReader.ReadInt32();
                        level         = binaryReader.ReadInt32();
                        position      = new Vector(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        mapID         = binaryReader.ReadString();
                        role          = new Role(binaryReader.ReadString(), binaryReader.ReadInt32());
                    }
                }

                var playerDescriptor = new PlayerDescriptor(name, password)
                {
                    SpriteSheet = sprite,
                    Speed       = speed,
                    Level       = level,
                    Position    = position,
                    MapID       = mapID,
                    Stats       = new Stats()
                    {
                        Health        = health,
                        MaximumHealth = maximumHealth,
                        Strength      = strength,
                        Intelligence  = intelligence,
                        Dexterity     = dexterity,
                        Defense       = defense,
                    },
                    Role = role
                };

                return(playerDescriptor);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #12
0
 public bool Exists(IDataManagerArguments arguments)
 {
     return(File.Exists(EngineConstants.FILEPATH_DATA + (arguments as PlayerDataLoaderArguments)?.Username + EngineConstants.ACC_FILE_EXT));
 }
Example #13
0
        public override MapDescriptor <LayerDescriptor <TileDescriptor <SpriteInfo> > > Load(IDataManagerArguments arguments)
        {
            MapDescriptor <LayerDescriptor <TileDescriptor <SpriteInfo> > > map = null;

            var mapArguments = (arguments as ContentFileDataLoaderArguments);

            using (var fileStream = new FileStream(this.RootPath + mapArguments.FileName + EngineConstants.MAP_FILE_EXT, FileMode.Open))
            {
                using (var bR = new BinaryReader(fileStream))
                {
                    // Load the tileset information
                    int           tilesetCount = bR.ReadInt32();
                    List <string> tilesetPaths = new List <string>();
                    for (int i = 0; i < tilesetCount; i++)
                    {
                        // We can throw this information away as it is used only in the editor suite.
                        string tilesetPath = bR.ReadString();
                        tilesetPaths.Add(tilesetPath);
                    }

                    string name       = bR.ReadString();
                    var    dimensions = new Vector(bR.ReadInt32(), bR.ReadInt32());

                    map = new MapDescriptor <LayerDescriptor <TileDescriptor <SpriteInfo> > >(dimensions, name)
                    {
                        Dark = bR.ReadBoolean()
                    };
                    map.TilesetPaths.AddRange(tilesetPaths);

                    map.Bounds = new Rect(0, 0, (int)map.Dimensions.X, (int)map.Dimensions.Y);

                    int layerCount = bR.ReadInt32();
                    for (int i = 0; i < layerCount; i++)
                    {
                        string layerName = bR.ReadString();
                        int    lIndex    = bR.ReadInt32();

                        var layer = new LayerDescriptor <TileDescriptor <SpriteInfo> >(map.Dimensions, layerName, lIndex);

                        for (int x = 0; x < layer.Tiles.GetLength(0); x++)
                        {
                            for (int y = 0; y < layer.Tiles.GetLength(1); y++)
                            {
                                if (bR.ReadBoolean())
                                {
                                    layer.Tiles[x, y] = new TileDescriptor <SpriteInfo>(new Vector(x * EngineConstants.TILE_SIZE, y * EngineConstants.TILE_SIZE));

                                    if (bR.ReadBoolean()) // Is there a valid attribute saved for this tile?
                                    {
                                        int    attributeDataLength = bR.ReadInt32();
                                        byte[] attributeData       = bR.ReadBytes(attributeDataLength);
                                        layer.Tiles[x, y].Attribute = TileAttribute.Deserialize(attributeData);
                                    }

                                    if (bR.ReadBoolean())
                                    {
                                        layer.Tiles[x, y].Animated    = bR.ReadBoolean();
                                        layer.Tiles[x, y].LightSource = bR.ReadBoolean();

                                        string spriteName = bR.ReadString();
                                        float  zIndex     = bR.ReadSingle(); // We can throw this away

                                        layer.Tiles[x, y].Sprite = new SpriteInfo(spriteName)
                                        {
                                            Transform =
                                            {
                                                Position   = new Vector(x * EngineConstants.TILE_SIZE, y * EngineConstants.TILE_SIZE),
                                                Color      = new Color(bR.ReadByte(),                  bR.ReadByte(),                 bR.ReadByte(),   bR.ReadByte()),
                                                Rect       = new Rect(bR.ReadInt32(),                  bR.ReadInt32(),                bR.ReadInt32(),  bR.ReadInt32()),
                                                LayerDepth = zIndex
                                            }
                                        };

                                        layer.Tiles[x, y].FrameCount = bR.ReadInt32();
                                    }
                                }
                            }
                        }

                        //int mapObjectCount = bR.ReadInt32();
                        //for (int mI = 0; mI < mapObjectCount; mI++)
                        //{
                        //    var mapObject = new MapObjectDescriptor()
                        //    {
                        //        Position = new Vector(bR.ReadSingle(), bR.ReadSingle())
                        //    };

                        //    if (bR.ReadBoolean())
                        //    {
                        //        string texturePath = bR.ReadString();
                        //        mapObject.Sprite = new SpriteInfo(texturePath)
                        //        {
                        //            Transform =
                        //            {
                        //                Rect = new Rect(bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32())
                        //            }
                        //        };
                        //    }

                        //    mapObject.Animated = bR.ReadBoolean();

                        //    mapObject.FrameTime = bR.ReadInt32();

                        //    string scriptPath = bR.ReadString();

                        //    var lightSource = bR.ReadBoolean();
                        //    var lightRadius = bR.ReadSingle();
                        //    var lightColor = new Color(bR.ReadByte(), bR.ReadByte(), bR.ReadByte(), bR.ReadByte());

                        //    if (lightSource)
                        //    {
                        //        mapObject.LightInformation = new LightInformation()
                        //        {
                        //            Radius = lightRadius,
                        //            Color = lightColor
                        //        };
                        //    }

                        //}

                        map.AddLayer(layerName, layer);
                    }
                }
            }

            return(map);
        }
 public bool Exists(IDataManagerArguments arguments)
 {
     throw new System.NotImplementedException();
 }
 public override bool Exists(IDataManagerArguments arguments)
 {
     return(File.Exists(this.RootPath + (arguments as PlayerDataArguments).Username + EngineConstants.ACC_FILE_EXT));
 }
Example #16
0
 public abstract void Save(IContentDescriptor descriptor, IDataManagerArguments arguments);
Example #17
0
 public abstract T Load(IDataManagerArguments arguments);
Example #18
0
 public abstract bool Exists(IDataManagerArguments arguments);
Example #19
0
        public void Save(IDataDescriptor descriptor, IDataManagerArguments arguments)
        {
            MapDescriptor mapDesc = (MapDescriptor)descriptor;

            string filePath = (arguments as MapDataLoaderArguments).Name;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (var bW = new BinaryWriter(fileStream))
                {
                    bW.Write(mapDesc.TilesetPaths.Count);

                    foreach (var tilesetPath in mapDesc.TilesetPaths)
                    {
                        bW.Write(tilesetPath);
                    }

                    bW.Write(mapDesc.Name);

                    bW.Write((int)mapDesc.Dimensions.X);
                    bW.Write((int)mapDesc.Dimensions.Y);

                    bW.Write(mapDesc.Dark);

                    bW.Write(mapDesc.Layers.Count);

                    foreach (var layer in mapDesc.Layers.Values)
                    {
                        bW.Write(layer.Name);
                        bW.Write(layer.LayerIndex);

                        for (int x = 0; x < layer.Tiles.GetLength(0); x++)
                        {
                            for (int y = 0; y < layer.Tiles.GetLength(1); y++)
                            {
                                if (layer.Tiles[x, y] != null)
                                {
                                    bW.Write(true);

                                    bW.Write((byte)layer.Tiles[x, y].Attribute);

                                    var attributeData = layer.Tiles[x, y].AttributeData.Serialize();

                                    bW.Write(attributeData.Length);
                                    bW.Write(attributeData);

                                    if (layer.Tiles[x, y].SpriteInfo != null)
                                    {
                                        bW.Write(true);

                                        bW.Write(layer.Tiles[x, y].Animated);
                                        bW.Write(layer.Tiles[x, y].LightSource);

                                        bW.Write(layer.Tiles[x, y].SpriteInfo.TextureName);

                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.LayerDepth);


                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Color.R);
                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Color.G);
                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Color.B);
                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Color.A);

                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Rect.Left);
                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Rect.Top);
                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Rect.Width);
                                        bW.Write(layer.Tiles[x, y].SpriteInfo.Transform.Rect.Height);

                                        bW.Write(layer.Tiles[x, y].FrameCount);
                                    }
                                    else
                                    {
                                        bW.Write(false);
                                    }
                                }
                                else
                                {
                                    bW.Write(false);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #20
0
 public override bool Exists(IDataManagerArguments arguments)
 {
     throw new NotImplementedException();
 }
Example #21
0
        public override NPCDescriptor Load(IDataManagerArguments arguments)
        {
            try
            {
                var npcArguments = (arguments as ContentFileDataLoaderArguments);

                string        name            = "";
                int           level           = 0;
                float         speed           = 0f;
                Rect          collisionBounds = new Rect();
                int           aggresiveRange  = 0;
                string        texturePath     = "";
                Vector        maxRoam         = new Vector();
                Vector        frameSize       = new Vector();
                Vector        reach           = new Vector();
                Stats         stats;
                List <string> scripts        = new List <string>();
                long          uniqueID       = 0;
                string        dialogue       = "";
                string        dialogueBranch = "";

                using (var fileStream = new FileStream(this.RootPath + npcArguments.FileName + EngineConstants.NPC_FILE_EXT, FileMode.OpenOrCreate))
                {
                    using (var binaryReader = new BinaryReader(fileStream))
                    {
                        name  = binaryReader.ReadString();
                        level = binaryReader.ReadInt32();
                        speed = binaryReader.ReadSingle();

                        stats = new Stats()
                        {
                            Strength      = binaryReader.ReadInt32(),
                            Defense       = binaryReader.ReadInt32(),
                            Dexterity     = binaryReader.ReadInt32(),
                            CurrentHealth = binaryReader.ReadInt32(),
                            Intelligence  = binaryReader.ReadInt32(),
                            Health        = binaryReader.ReadInt32()
                        };

                        collisionBounds = new Rect(binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32(), binaryReader.ReadInt32());
                        aggresiveRange  = binaryReader.ReadInt32();
                        texturePath     = binaryReader.ReadString();
                        maxRoam         = new Vector(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        frameSize       = new Vector(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        reach           = new Vector(binaryReader.ReadSingle(), binaryReader.ReadSingle());

                        int scriptCount = binaryReader.ReadInt32();
                        for (int i = 0; i < scriptCount; i++)
                        {
                            scripts.Add(binaryReader.ReadString());
                        }

                        dialogue       = binaryReader.ReadString();
                        dialogueBranch = binaryReader.ReadString();
                    }
                }

                var desc = NPCDescriptor.Create(npcArguments.FileName);
                desc.Name            = name;
                desc.Level           = level;
                desc.Speed           = speed;
                desc.Stats           = stats;
                desc.CollisionBounds = collisionBounds;
                desc.AggresiveRange  = aggresiveRange;
                desc.TexturePath     = texturePath;
                desc.MaxRoam         = maxRoam;
                desc.FrameSize       = frameSize;
                desc.Reach           = reach;
                desc.Dialogue        = dialogue;
                desc.DialogueBranch  = dialogueBranch;
                desc.Scripts.AddRange(scripts);

                return(desc);
            }
            catch (IOException exception)
            {
                Engine.Services.Get <Logger>().LogEvent("Unable to load NPC. " + exception.Message, LogTypes.ERROR, exception);
                return(null);
            }
        }
Example #22
0
 public override void Save(IContentModel descriptor, IDataManagerArguments arguments)
 {
     throw new NotImplementedException();
 }
Example #23
0
        public override void Save(IContentDescriptor descriptor, IDataManagerArguments arguments)
        {
            var mapDesc = (IMapDescriptor <ILayerDescriptor <ITileDescriptor <SpriteInfo> > >)descriptor;

            string filePath = this.RootPath + (arguments as ContentFileDataLoaderArguments).FileName + EngineConstants.MAP_FILE_EXT;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (var bW = new BinaryWriter(fileStream))
                {
                    bW.Write(mapDesc.TilesetPaths.Count);

                    foreach (var tilesetPath in mapDesc.TilesetPaths)
                    {
                        bW.Write(tilesetPath);
                    }

                    bW.Write(mapDesc.Name);

                    bW.Write((int)mapDesc.Dimensions.X);
                    bW.Write((int)mapDesc.Dimensions.Y);

                    bW.Write(mapDesc.Dark);

                    bW.Write(mapDesc.Layers.Count);

                    foreach (var layer in mapDesc.Layers)
                    {
                        bW.Write(layer.Name);
                        bW.Write(layer.LayerIndex);

                        for (int x = 0; x < layer.Tiles.GetLength(0); x++)
                        {
                            for (int y = 0; y < layer.Tiles.GetLength(1); y++)
                            {
                                if (layer.Tiles[x, y] != null)
                                {
                                    bW.Write(true);

                                    if (layer.Tiles[x, y].Attribute == null)
                                    {
                                        bW.Write(false);
                                    }
                                    else
                                    {
                                        bW.Write(true);

                                        var attributeData = layer.Tiles[x, y].Attribute.Serialize();

                                        bW.Write(attributeData.Length);
                                        bW.Write(attributeData);
                                    }

                                    if (layer.Tiles[x, y].Sprite != null)
                                    {
                                        bW.Write(true);

                                        bW.Write(layer.Tiles[x, y].Animated);
                                        bW.Write(layer.Tiles[x, y].LightSource);

                                        bW.Write(layer.Tiles[x, y].Sprite.TextureName);

                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.LayerDepth);

                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Color.R);
                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Color.G);
                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Color.B);
                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Color.A);

                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Rect.X);
                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Rect.Y);
                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Rect.Width);
                                        bW.Write(layer.Tiles[x, y].Sprite.Transform.Rect.Height);

                                        bW.Write(layer.Tiles[x, y].FrameCount);
                                    }
                                    else
                                    {
                                        bW.Write(false);
                                    }
                                }
                                else
                                {
                                    bW.Write(false);
                                }
                            }
                        }
                    }
                }
            }
        }