LoadFromManifest() публичный Метод

public LoadFromManifest ( Manifest manifest ) : void
manifest Manifest
Результат void
Пример #1
0
        public ModData(Manifest mod, InstalledMods mods, bool useLoadScreen = false)
        {
            Languages = new string[0];

            // Take a local copy of the manifest
            Manifest       = new Manifest(mod.Id, mod.Package);
            ObjectCreator  = new ObjectCreator(Manifest, mods);
            PackageLoaders = ObjectCreator.GetLoaders <IPackageLoader>(Manifest.PackageFormats, "package");

            ModFiles = new FS(mods, PackageLoaders);
            ModFiles.LoadFromManifest(Manifest);
            Manifest.LoadCustomData(ObjectCreator);

            if (useLoadScreen)
            {
                LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value);
                LoadScreen.Init(this, Manifest.LoadScreen.ToDictionary(my => my.Value));
                LoadScreen.Display();
            }

            WidgetLoader = new WidgetLoader(this);
            MapCache     = new MapCache(this);

            SoundLoaders  = ObjectCreator.GetLoaders <ISoundLoader>(Manifest.SoundFormats, "sound");
            SpriteLoaders = ObjectCreator.GetLoaders <ISpriteLoader>(Manifest.SpriteFormats, "sprite");

            var sequenceFormat = Manifest.Get <SpriteSequenceFormat>();
            var sequenceLoader = ObjectCreator.FindType(sequenceFormat.Type + "Loader");
            var ctor           = sequenceLoader != null?sequenceLoader.GetConstructor(new[] { typeof(ModData) }) : null;

            if (sequenceLoader == null || !sequenceLoader.GetInterfaces().Contains(typeof(ISpriteSequenceLoader)) || ctor == null)
            {
                throw new InvalidOperationException("Unable to find a sequence loader for type '{0}'.".F(sequenceFormat.Type));
            }

            SpriteSequenceLoader = (ISpriteSequenceLoader)ctor.Invoke(new[] { this });
            SpriteSequenceLoader.OnMissingSpriteError = s => Log.Write("debug", s);

            defaultRules    = Exts.Lazy(() => Ruleset.LoadDefaults(this));
            defaultTileSets = Exts.Lazy(() =>
            {
                var items = new Dictionary <string, TileSet>();

                foreach (var file in Manifest.TileSets)
                {
                    var t = new TileSet(DefaultFileSystem, file);
                    items.Add(t.Id, t);
                }

                return((IReadOnlyDictionary <string, TileSet>)(new ReadOnlyDictionary <string, TileSet>(items)));
            });

            defaultSequences = Exts.Lazy(() =>
            {
                var items = DefaultTileSets.ToDictionary(t => t.Key, t => new SequenceProvider(DefaultFileSystem, this, t.Value, null));
                return((IReadOnlyDictionary <string, SequenceProvider>)(new ReadOnlyDictionary <string, SequenceProvider>(items)));
            });

            initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
        }
Пример #2
0
        public void Run(ModData modData, string[] args)
        {
            var filename = Path.GetFileName(args[1]);
            var path     = Path.GetDirectoryName(args[1]);

            var fs = new OpenRA.FileSystem.FileSystem();

            // Needed to access the global mix database
            fs.LoadFromManifest(modData.Manifest);

            fs.Mount(path, "parent");
            var package = new MixFile(fs, "parent|" + filename);

            foreach (var kv in package.Index.OrderBy(kv => kv.Value.Offset))
            {
                Console.WriteLine("{0}:", kv.Key);
                Console.WriteLine("\tOffset: {0}", kv.Value.Offset);
                Console.WriteLine("\tLength: {0}", kv.Value.Length);
            }
        }
Пример #3
0
        public ModContentLogic(Widget widget, ModData modData, Manifest mod, ModContent content, Action onCancel)
        {
            this.content = content;

            var panel = widget.Get("CONTENT_PANEL");

            var modObjectCreator  = new ObjectCreator(mod, Game.Mods);
            var modPackageLoaders = modObjectCreator.GetLoaders <IPackageLoader>(mod.PackageFormats, "package");
            var modFileSystem     = new FS(Game.Mods, modPackageLoaders);

            modFileSystem.LoadFromManifest(mod);

            var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null);

            foreach (var s in sourceYaml)
            {
                sources.Add(s.Key, new ModContent.ModSource(s.Value));
            }

            var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);

            foreach (var d in downloadYaml)
            {
                downloads.Add(d.Key, new ModContent.ModDownload(d.Value));
            }

            modFileSystem.UnmountAll();

            scrollPanel = panel.Get <ScrollPanelWidget>("PACKAGES");
            template    = scrollPanel.Get <ContainerWidget>("PACKAGE_TEMPLATE");

            var headerTemplate = panel.Get <LabelWidget>("HEADER_TEMPLATE");
            var headerLines    = !string.IsNullOrEmpty(content.HeaderMessage) ? content.HeaderMessage.Replace("\\n", "\n").Split('\n') : new string[0];
            var headerHeight   = 0;

            foreach (var l in headerLines)
            {
                var line = (LabelWidget)headerTemplate.Clone();
                line.GetText   = () => l;
                line.Bounds.Y += headerHeight;
                panel.AddChild(line);

                headerHeight += headerTemplate.Bounds.Height;
            }

            panel.Bounds.Height  += headerHeight;
            panel.Bounds.Y       -= headerHeight / 2;
            scrollPanel.Bounds.Y += headerHeight;

            var discButton = panel.Get <ButtonWidget>("CHECK_DISC_BUTTON");

            discButton.Bounds.Y += headerHeight;
            discButton.IsVisible = () => discAvailable;

            discButton.OnClick = () => Ui.OpenWindow("DISC_INSTALL_PANEL", new WidgetArgs
            {
                { "afterInstall", () => { } },
                { "sources", sources },
                { "content", content }
            });

            var backButton = panel.Get <ButtonWidget>("BACK_BUTTON");

            backButton.Bounds.Y += headerHeight;
            backButton.OnClick   = () => { Ui.CloseWindow(); onCancel(); };

            PopulateContentList();
            Game.RunAfterTick(Ui.ResetTooltips);
        }
Пример #4
0
        public ModContentPromptLogic(Widget widget, ModData modData, Manifest mod, ModContent content, Action continueLoading)
        {
            this.content = content;
            CheckRequiredContentInstalled();

            var panel          = widget.Get("CONTENT_PROMPT_PANEL");
            var headerTemplate = panel.Get <LabelWidget>("HEADER_TEMPLATE");
            var headerLines    = !string.IsNullOrEmpty(content.InstallPromptMessage) ? content.InstallPromptMessage.Replace("\\n", "\n").Split('\n') : new string[0];
            var headerHeight   = 0;

            foreach (var l in headerLines)
            {
                var line = (LabelWidget)headerTemplate.Clone();
                line.GetText   = () => l;
                line.Bounds.Y += headerHeight;
                panel.AddChild(line);

                headerHeight += headerTemplate.Bounds.Height;
            }

            panel.Bounds.Height += headerHeight;
            panel.Bounds.Y      -= headerHeight / 2;

            var advancedButton = panel.Get <ButtonWidget>("ADVANCED_BUTTON");

            advancedButton.Bounds.Y += headerHeight;
            advancedButton.OnClick   = () =>
            {
                Ui.OpenWindow("CONTENT_PANEL", new WidgetArgs
                {
                    { "mod", mod },
                    { "content", content },
                    { "onCancel", CheckRequiredContentInstalled }
                });
            };

            var quickButton = panel.Get <ButtonWidget>("QUICK_BUTTON");

            quickButton.IsVisible = () => !string.IsNullOrEmpty(content.QuickDownload);
            quickButton.Bounds.Y += headerHeight;
            quickButton.OnClick   = () =>
            {
                var modObjectCreator  = new ObjectCreator(mod, Game.Mods);
                var modPackageLoaders = modObjectCreator.GetLoaders <IPackageLoader>(mod.PackageFormats, "package");
                var modFileSystem     = new FS(mod.Id, Game.Mods, modPackageLoaders);
                modFileSystem.LoadFromManifest(mod);

                var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
                modFileSystem.UnmountAll();

                var download = downloadYaml.FirstOrDefault(n => n.Key == content.QuickDownload);
                if (download == null)
                {
                    throw new InvalidOperationException("Mod QuickDownload `{0}` definition not found.".F(content.QuickDownload));
                }

                Ui.OpenWindow("PACKAGE_DOWNLOAD_PANEL", new WidgetArgs
                {
                    { "download", new ModContent.ModDownload(download.Value) },
                    { "onSuccess", continueLoading }
                });
            };

            var quitButton = panel.Get <ButtonWidget>("QUIT_BUTTON");

            quitButton.GetText   = () => requiredContentInstalled ? "Continue" : "Quit";
            quitButton.Bounds.Y += headerHeight;
            quitButton.OnClick   = () =>
            {
                if (requiredContentInstalled)
                {
                    continueLoading();
                }
                else
                {
                    Game.Exit();
                }
            };

            Game.RunAfterTick(Ui.ResetTooltips);
        }
Пример #5
0
        public ModData(Manifest mod, InstalledMods mods, bool useLoadScreen = false)
        {
            Languages = Array.Empty <string>();

            // Take a local copy of the manifest
            Manifest       = new Manifest(mod.Id, mod.Package);
            ObjectCreator  = new ObjectCreator(Manifest, mods);
            PackageLoaders = ObjectCreator.GetLoaders <IPackageLoader>(Manifest.PackageFormats, "package");

            ModFiles = new FS(mod.Id, mods, PackageLoaders);
            ModFiles.LoadFromManifest(Manifest);
            Manifest.LoadCustomData(ObjectCreator);

            if (useLoadScreen)
            {
                LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value);
                LoadScreen.Init(this, Manifest.LoadScreen.ToDictionary(my => my.Value));
                LoadScreen.Display();
            }

            WidgetLoader = new WidgetLoader(this);
            MapCache     = new MapCache(this);

            SoundLoaders  = ObjectCreator.GetLoaders <ISoundLoader>(Manifest.SoundFormats, "sound");
            SpriteLoaders = ObjectCreator.GetLoaders <ISpriteLoader>(Manifest.SpriteFormats, "sprite");
            VideoLoaders  = ObjectCreator.GetLoaders <IVideoLoader>(Manifest.VideoFormats, "video");

            var terrainFormat = Manifest.Get <TerrainFormat>();
            var terrainLoader = ObjectCreator.FindType(terrainFormat.Type + "Loader");
            var terrainCtor   = terrainLoader?.GetConstructor(new[] { typeof(ModData) });

            if (terrainLoader == null || !terrainLoader.GetInterfaces().Contains(typeof(ITerrainLoader)) || terrainCtor == null)
            {
                throw new InvalidOperationException($"Unable to find a terrain loader for type '{terrainFormat.Type}'.");
            }

            TerrainLoader = (ITerrainLoader)terrainCtor.Invoke(new[] { this });

            var sequenceFormat = Manifest.Get <SpriteSequenceFormat>();
            var sequenceLoader = ObjectCreator.FindType(sequenceFormat.Type + "Loader");
            var sequenceCtor   = sequenceLoader?.GetConstructor(new[] { typeof(ModData) });

            if (sequenceLoader == null || !sequenceLoader.GetInterfaces().Contains(typeof(ISpriteSequenceLoader)) || sequenceCtor == null)
            {
                throw new InvalidOperationException($"Unable to find a sequence loader for type '{sequenceFormat.Type}'.");
            }

            SpriteSequenceLoader = (ISpriteSequenceLoader)sequenceCtor.Invoke(new[] { this });

            var modelFormat = Manifest.Get <ModelSequenceFormat>();
            var modelLoader = ObjectCreator.FindType(modelFormat.Type + "Loader");
            var modelCtor   = modelLoader?.GetConstructor(new[] { typeof(ModData) });

            if (modelLoader == null || !modelLoader.GetInterfaces().Contains(typeof(IModelSequenceLoader)) || modelCtor == null)
            {
                throw new InvalidOperationException($"Unable to find a model loader for type '{modelFormat.Type}'.");
            }

            ModelSequenceLoader = (IModelSequenceLoader)modelCtor.Invoke(new[] { this });
            ModelSequenceLoader.OnMissingModelError = s => Log.Write("debug", s);

            Hotkeys = new HotkeyManager(ModFiles, Game.Settings.Keys, Manifest);

            Translation = new Translation(Game.Settings.Player.Language, Manifest.Translations, DefaultFileSystem);

            defaultRules       = Exts.Lazy(() => Ruleset.LoadDefaults(this));
            defaultTerrainInfo = Exts.Lazy(() =>
            {
                var items = new Dictionary <string, ITerrainInfo>();

                foreach (var file in Manifest.TileSets)
                {
                    var t = TerrainLoader.ParseTerrain(DefaultFileSystem, file);
                    items.Add(t.Id, t);
                }

                return((IReadOnlyDictionary <string, ITerrainInfo>)(new ReadOnlyDictionary <string, ITerrainInfo>(items)));
            });

            defaultSequences = Exts.Lazy(() =>
            {
                var items = DefaultTerrainInfo.ToDictionary(t => t.Key, t => new SequenceProvider(DefaultFileSystem, this, t.Key, null));
                return((IReadOnlyDictionary <string, SequenceProvider>)(new ReadOnlyDictionary <string, SequenceProvider>(items)));
            });

            initialThreadId = Environment.CurrentManagedThreadId;
        }