Exemple #1
0
 void IContentRegistry.RegisterHandler <T>(string key, FileLoadMethod <T> method)
 {
     try
     {
         Interceptor.RegisterHandler(key, method);
     }
     catch (Exception err)
     {
         EntoFramework.Logger.ExitGameImmediately("Was unable to register custom handler in loader" + err);
     }
 }
        public static void RegisterFileLoader <T>(string assetName, FileLoadMethod <T> handler)
        {
            if (_HandledAssets.Exists(x => x.Key == assetName && x.Value == typeof(T)))
            {
                Log.Warning($"Load handler conflict on asset {assetName}. Using first");
                return;
            }
            KeyValuePair <string, Type> key = new KeyValuePair <string, Type>(assetName, typeof(T));

            _HandledAssets.Add(key);
            _LoaderRegistry.Add(key, handler);
        }
Exemple #3
0
        /// <summary>Register a delegate which loads an asset.</summary>
        /// <typeparam name="T">The expected asset type.</typeparam>
        /// <param name="assetName">The asset name to intercept.</param>
        /// <param name="handler">The handler which loads the asset.</param>
        internal void RegisterHandler <T>(string assetName, FileLoadMethod <T> handler)
        {
            // validate key
            assetName = this.NormaliseAssetName(assetName);
            if (!this.MarkHandledOrWarn(assetName))
            {
                return;
            }

            // add
            this.LoaderDelegate.Add(assetName, new KeyValuePair <Type, Delegate>(typeof(T), handler));
            this.ContentHelper.InvalidateCache(assetName);
        }
Exemple #4
0
        /// <summary>Load a matched asset.</summary>
        /// <param name="asset">Basic metadata about the asset being loaded.</param>
        public T Load <T>(IAssetInfo asset)
        {
            // texture redirect
            string redirectPath = this.GetRedirect <T>(asset);

            if (redirectPath != null)
            {
                string relativePath = ContentHandler.GetRelativePath(redirectPath, this.ModPath); // underlying content manager doesn't allow absolute paths
                return(this.ContentHelper.Load <T>(relativePath));
            }

            // loader delegate
            FileLoadMethod <T> loader = this.GetLoaderDelegate <T>(asset);

            if (loader != null)
            {
                return(loader.Invoke(asset.AssetName));
            }

            // none found?
            throw new InvalidOperationException("ContentManager: no asset loaders found. This shouldn't happen.");
        }
Exemple #5
0
 public void RegisterHandler <T>(string assetName, FileLoadMethod <T> handler)
 {
     Registry.RegisterHandler(assetName, handler);
 }