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; }
public ModData(string mod, bool useLoadScreen = false) { Languages = new string[0]; Manifest = new Manifest(mod); ObjectCreator = new ObjectCreator(Manifest); Manifest.LoadCustomData(ObjectCreator); if (useLoadScreen) { LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); } WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); var spriteLoaders = new List <ISpriteLoader>(); foreach (var format in Manifest.SpriteFormats) { var loader = ObjectCreator.FindType(format + "Loader"); if (loader == null || !loader.GetInterfaces().Contains(typeof(ISpriteLoader))) { throw new InvalidOperationException("Unable to find a sprite loader for type '{0}'.".F(format)); } spriteLoaders.Add((ISpriteLoader)ObjectCreator.CreateBasic(loader)); } SpriteLoaders = spriteLoaders.ToArray(); 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); // HACK: Mount only local folders so we have a half-working environment for the asset installer GlobalFileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) { GlobalFileSystem.Mount(dir); } defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
public MapPreview(string uid, MapCache cache) { this.cache = cache; Uid = uid; Title = "Unknown Map"; Type = "Unknown"; Author = "Unknown Author"; PlayerCount = 0; Bounds = Rectangle.Empty; SpawnPoints = NoSpawns; Status = MapStatus.Unavailable; Class = MapClassification.Unknown; }
// For linting purposes only! public MapPreview(Map map, ModData modData) { this.modData = modData; cache = modData.MapCache; Uid = map.Uid; Package = map.Package; var mapPlayers = new MapPlayers(map.PlayerDefinitions); var spawns = new List <CPos>(); foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn")) { var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); spawns.Add(s.Get <LocationInit>().Value); } innerData = new InnerData { MapFormat = map.MapFormat, Title = map.Title, Categories = map.Categories, Author = map.Author, TileSet = map.Tileset, Players = mapPlayers, PlayerCount = mapPlayers.Players.Count(x => x.Value.Playable), SpawnPoints = spawns.ToArray(), GridType = map.Grid.Type, Bounds = map.Bounds, Preview = null, Status = MapStatus.Available, Class = MapClassification.Unknown, Visibility = map.Visibility, }; innerData.SetCustomRules(modData, this, new Dictionary <string, MiniYaml>() { { "Rules", map.RuleDefinitions }, { "Weapons", map.WeaponDefinitions }, { "Voices", map.VoiceDefinitions }, { "Music", map.MusicDefinitions }, { "Notifications", map.NotificationDefinitions }, { "Sequences", map.SequenceDefinitions }, { "ModelSequences", map.ModelSequenceDefinitions } }); }
public ModData(string mod, bool useLoadScreen = false) { Languages = new string[0]; Manifest = new Manifest(mod); // Allow mods to load types from the core Game assembly, and any additional assemblies they specify. var assemblies = new[] { typeof(Game).Assembly }.Concat( Manifest.Assemblies.Select(path => Assembly.LoadFrom(Platform.ResolvePath(path)))); ObjectCreator = new ObjectCreator(assemblies); Manifest.LoadCustomData(ObjectCreator); if (useLoadScreen) { LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); } WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); SoundLoaders = GetLoaders <ISoundLoader>(Manifest.SoundFormats, "sound"); SpriteLoaders = 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(() => RulesetCache.Load()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
public void UpdateMaps(MapCache mapcache) { lock (mapActionQueue) { if (!dirty) { return; } dirty = false; foreach (var mapAction in mapActionQueue) { var map = mapcache.FirstOrDefault(x => x.Package?.Name == mapAction.Key && x.Status == MapStatus.Available); if (map != null) { if (mapAction.Value == MapAction.Delete) { Console.WriteLine(mapAction.Key + " was deleted"); map.Invalidate(); } else { Console.WriteLine(mapAction.Key + " was updated"); map.Invalidate(); mapcache.LoadMap(mapAction.Key.Replace(package.Name + Path.DirectorySeparatorChar, ""), package, classification, mapGrid, map.Uid); } } else { if (mapAction.Value != MapAction.Delete) { Console.WriteLine(mapAction.Key + " was added"); mapcache.LoadMap(mapAction.Key.Replace(package?.Name + Path.DirectorySeparatorChar, ""), package, classification, mapGrid, null); } } } mapActionQueue.Clear(); } }
public ModData(string mod) { Languages = new string[0]; Manifest = new Manifest(mod); ObjectCreator = new ObjectCreator(Manifest); LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); var loaders = new List <ISpriteLoader>(); foreach (var format in Manifest.SpriteFormats) { var loader = ObjectCreator.FindType(format + "Loader"); if (loader == null || !loader.GetInterfaces().Contains(typeof(ISpriteLoader))) { throw new InvalidOperationException("Unable to find a sprite loader for type '{0}'.".F(format)); } loaders.Add((ISpriteLoader)ObjectCreator.CreateBasic(loader)); } SpriteLoaders = loaders.ToArray(); // HACK: Mount only local folders so we have a half-working environment for the asset installer GlobalFileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) { GlobalFileSystem.Mount(dir); } defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
public MapPreview(ModData modData, string uid, MapGridType gridType, MapCache cache) { this.cache = cache; this.modData = modData; Uid = uid; innerData = new InnerData { Title = "Unknown Map", Categories = new[] { "Unknown" }, Author = "Unknown Author", TileSet = "unknown", Players = null, PlayerCount = 0, SpawnPoints = NoSpawns, GridType = gridType, Bounds = Rectangle.Empty, Preview = null, Status = MapStatus.Unavailable, Class = MapClassification.Unknown, Visibility = MapVisibility.Lobby, }; }
public ModData(string mod) { Languages = new string[0]; Manifest = new Manifest(mod); ObjectCreator = new ObjectCreator(Manifest); LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); // HACK: Mount only local folders so we have a half-working environment for the asset installer GlobalFileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) { GlobalFileSystem.Mount(dir); } defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
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; }