public ModAssetRepository(AssetReaderCollection assetReaderCollection, IAssetLoader syncLoader, IAsyncAssetLoader asyncLoader, IEnumerable <IContentSource> sources = null) : base(syncLoader, asyncLoader)
        {
            AssetReaderCollection = assetReaderCollection;

            if (sources != null)
            {
                SetSources(sources, AssetRequestMode.DoNotLoad);
            }
        }
Ejemplo n.º 2
0
        internal void PrepareAssets()
        {
            //Open the file.

            if (File != null)
            {
                fileHandle = File.Open();
            }

            //Create the asset repository

            var sources = new List <IContentSource>();

            if (File != null)
            {
                sources.Add(new TModContentSource(File));
            }

            var assetReaderCollection = new AssetReaderCollection();

            if (!Main.dedServ)
            {
                //TODO: Now, how do we unhardcode this?

                //Ambiguous
                assetReaderCollection.RegisterReader(new XnbReader(Main.instance.Services), ".xnb");
                //Textures
                assetReaderCollection.RegisterReader(new PngReader(Main.instance.Services.Get <IGraphicsDeviceService>().GraphicsDevice), ".png");
                assetReaderCollection.RegisterReader(new RawImgReader(Main.instance.Services.Get <IGraphicsDeviceService>().GraphicsDevice), ".rawimg");
                //Audio
                assetReaderCollection.RegisterReader(new WavReader(), ".wav");
                assetReaderCollection.RegisterReader(new MP3Reader(), ".mp3");
                assetReaderCollection.RegisterReader(new OggReader(), ".ogg");
            }

            var delayedLoadTypes = new List <Type> {
                typeof(Texture2D),
                typeof(DynamicSpriteFont),
                typeof(SpriteFont),
                typeof(Effect)
            };

            SetupAssetRepository(sources, assetReaderCollection, delayedLoadTypes);

            var asyncAssetLoader = new AsyncAssetLoader(assetReaderCollection, 20);

            foreach (var type in delayedLoadTypes)
            {
                asyncAssetLoader.RequireTypeCreationOnTransfer(type);
            }

            var assetLoader = new AssetLoader(assetReaderCollection);

            Assets = new ModAssetRepository(assetReaderCollection, assetLoader, asyncAssetLoader, sources.ToArray());
        }
Ejemplo n.º 3
0
 public override void SetupAssetRepository(IList <IContentSource> sources, AssetReaderCollection assetReaderCollection, IList <Type> delayedLoadTypes)
 {
     sources.Clear();
     sources.Add(new AssemblyResourcesContentSource(Assembly.GetExecutingAssembly(), "Terraria.ModLoader.Default."));
 }
Ejemplo n.º 4
0
 /// <summary> Override this only if you know what you're doing. This hook can be used allow your mod to natively use assets from somewhere else but its .tmod file, or for registering asset readers. </summary>
 /// <param name="sources">The list with content sources. By default, this list has 1 entry with the default content source that loads assets from the mod's .tmod file.</param>
 /// <param name="assetReaderCollection">The AssetReaderCollection that will be used for this mod's Assets repository. Use its .RegisterReader() method to register new 'IAssetReader's.</param>
 /// <param name="delayedLoadTypes">This list contains types that the asynchronous asset loader should delay loading of. Types like that are usually graphics related.</param>
 public virtual void SetupAssetRepository(IList <IContentSource> sources, AssetReaderCollection assetReaderCollection, IList <Type> delayedLoadTypes)
 {
 }