Exemplo n.º 1
0
        public override void Initialize(Harmony plibInstance)
        {
            Instance = this;

            shapes.Clear();
            foreach (var light in GetSharedData(EMPTY_SHAPES))
            {
                var ls = PRemoteLightWrapper.LightToInstance(light);
                shapes.Add(ls);
                if (ls == null)
                {
                    // Moe must clean it!
                    LogLightingWarning("Foreign contaminant in PLightManager!");
                }
            }

            LightingPatches.ApplyPatches(plibInstance);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers a light shape handler.
        /// </summary>
        /// <param name="identifier">A unique identifier for this shape. If another mod has
        /// already registered that identifier, the previous mod will take precedence.</param>
        /// <param name="handler">The handler for that shape.</param>
        /// <param name="rayMode">The type of visual rays that are displayed from the light.</param>
        /// <returns>The light shape which can be used.</returns>
        public ILightShape Register(string identifier, CastLightDelegate handler,
                                    LightShape rayMode = (LightShape)(-1))
        {
            if (string.IsNullOrEmpty(identifier))
            {
                throw new ArgumentNullException(nameof(identifier));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            ILightShape lightShape = null;

            RegisterForForwarding();
            // Try to find a match for this identifier
            var registered = GetSharedData(EMPTY_SHAPES);
            int n          = registered.Count;

            foreach (var obj in registered)
            {
                var light = PRemoteLightWrapper.LightToInstance(obj);
                // Might be from another assembly so the types may or may not be compatible
                if (light != null && light.Identifier == identifier)
                {
                    LogLightingDebug("Found existing light shape: " + identifier + " from " +
                                     (obj.GetType().Assembly.GetNameSafe() ?? "?"));
                    lightShape = light;
                    break;
                }
            }
            if (lightShape == null)
            {
                // Not currently existing
                lightShape = new PLightShape(n + 1, identifier, handler, rayMode);
                LogLightingDebug("Registered new light shape: " + identifier);
                registered.Add(lightShape);
            }
            return(lightShape);
        }