Ejemplo n.º 1
0
        public async Task Load(Stream stream, IEnumerable <ILayerProvider> layerProviders)
        {
            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(UnderscoredNamingConvention.Instance) // see height_in_inches in sample yml
                               .Build();

            using (var reader = new StreamReader(stream))
            {
                target = deserializer.Deserialize <Target>(reader);
            }
            Dictionary <int, List <Mod> > orders = new Dictionary <int, List <Mod> >()
            {
                { int.MaxValue, new List <Mod>() }
            };

            foreach (var mod in target.Mods)
            {
                if (!Path.IsPathRooted(mod.ModPath))
                {
                    mod.ModPath = Path.GetFullPath(mod.ModPath, target.ModDirectory);
                }

                if (!Path.IsPathRooted(mod.RootPath))
                {
                    mod.RootPath = Path.GetFullPath(mod.RootPath, target.RootPath);
                }

                if (mod.Order > 0)
                {
                    if (!orders.ContainsKey(mod.Order))
                    {
                        orders.Add(mod.Order, new List <Mod>());
                    }
                    orders[mod.Order].Add(mod);
                }
                else
                {
                    orders[int.MaxValue].Add(mod);
                }
            }

            var mods = orders
                       .OrderBy(kvp => kvp.Key)
                       .SelectMany(kvp => kvp.Value)
            ;

            target.Mods = mods;


            var layers = new List <ILayer>();

            foreach (var mod in target.Mods)
            {
                foreach (var layerProvider in layerProviders)
                {
                    if (layerProvider.CanCreateLayer(mod))
                    {
                        layers.AddRange(layerProvider.CreateLayer(mod));
                        break;
                    }
                }
            }

            layerService = new LayerService(layers, target.RootPath);
            await layerService.PreLoad();

            Operation = new ModLinkerOperation(layerService);
        }
Ejemplo n.º 2
0
 public ModLinkerOperation(LayerService layerService)
 {
     this.layerService = layerService;
 }