示例#1
0
 /// <summary>
 /// Removes the system fulfilling the given interface
 /// </summary>
 /// <param name="uri">Uri path</param>
 public static void remove(GameUri uri)
 {
     if (uri.isValid())
     {
         _store.Remove(uri);
     }
     else
     {
         logger.error("invalid uri");
     }
 }
示例#2
0
        /// <summary>
        /// Registers an object. These objects will be removed when CoreRegistry.clear() is called (typically when game state changes)
        /// </summary>
        /// <typeparam name="U">The system itself</typeparam>
        /// <param name="uri">Uri path</param>
        /// <param name="obj">The system itself</param>
        /// <returns>The system itself</returns>
        public static U put <U>(GameUri uri, U obj)
        {
            if (uri.isValid())
            {
                _store.Add(uri, obj);
            }
            else
            {
                logger.error("invalid uri");
            }

            return(obj);
        }
示例#3
0
        /// <summary>
        /// Looks up a system and throws an exception if it doesn't exist
        /// </summary>
        /// <typeparam name="T">The type to cast to</typeparam>
        /// <param name="uri">Uri path</param>
        /// <returns>The system fulfilling the given interface</returns>
        public static T require <T>(GameUri uri)
            where T : class
        {
            if (uri.isValid())
            {
                object obj;
                if (_store.TryGetValue(uri, out obj))
                {
                    T t = obj as T;
                    if (t != null)
                    {
                        return(t);
                    }

                    logger.error("invalid cast {0} to {1}", obj.GetType().Name, typeof(T).Name);
                }
            }
            else
            {
                logger.error("invalid uri");
            }

            throw new Exception(string.Format("{0} is required", uri));
        }
示例#4
0
        /// <summary>
        /// Looks up the system fulfilling the given interface
        /// </summary>
        /// <typeparam name="T">The type to cast to</typeparam>
        /// <param name="uri">Uri path</param>
        /// <returns>The system fulfilling the given interface</returns>
        public static T get <T>(GameUri uri)
            where T : class
        {
            if (uri.isValid())
            {
                object obj;
                if (_store.TryGetValue(uri, out obj))
                {
                    T t = obj as T;
                    if (t != null)
                    {
                        return(t);
                    }

                    logger.error("invalid cast {0} to {1}", obj.GetType().Name, typeof(T).Name);
                }
            }
            else
            {
                logger.error("invalid uri");
            }

            return(null);
        }
示例#5
0
 public bool Equals(GameUri uri)
 {
     return(this.normalisedName == uri.normalisedName);
 }