Exemplo n.º 1
0
        //-------------------------------------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="EventFactory" /> class.
        /// </summary>
        public EventFactory()
        {
            // Create a dictionary for storing event reference keys and types.
            EventReference = new Dictionary <EventKey, Type>();

            // Collect and loop through all of the event types.
            foreach (var eventObject in AttributeExtensions.GetTypesWith <DirectorEventAttribute>(true))
            {
                // Check if the class is abstract base class, we don't want to add that.
                if (eventObject.GetTypeInfo().IsAbstract)
                {
                    continue;
                }

                // Check the attribute itself from the event we are working on, which gives us the event type enumerable.
                var eventAttribute = eventObject.GetTypeInfo().GetAttributes <DirectorEventAttribute>(true).First();

                // Initialize the execution history dictionary with every event type.
                foreach (var modeType in Enum.GetValues(typeof(EventCategory)))
                {
                    // Create key for the event execution counter.
                    var eventKey = new EventKey((EventCategory)modeType, eventObject.Name, eventAttribute.EventExecutionType);
                    if (!EventReference.ContainsKey(eventKey))
                    {
                        EventReference.Add(eventKey, eventObject);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:WolfCurses.Window.Form.FormFactory" /> class.
        /// </summary>
        public FormFactory()
        {
            // Create dictionaries for reference tracking for what states belong to what game modes.
            LoadedForms = new Dictionary <Type, Type>();

            // Collect all of the states with the custom attribute decorated on them.
            var foundStates = AttributeExtensions.GetTypesWith <ParentWindowAttribute>(false);

            foreach (var stateType in foundStates)
            {
                // GetModule the attribute itself from the state we are working on, which gives us the game Windows enum.
                var stateAttribute  = stateType.GetTypeInfo().GetAttributes <ParentWindowAttribute>(false).First();
                var stateParentMode = stateAttribute.ParentWindow;

                // Add the state reference list for lookup and instancing later during runtime.
                LoadedForms.Add(stateType, stateParentMode);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:OregonTrailDotNet.Module.Director.EventFactory" /> class.
        /// </summary>
        public EventFactory()
        {
            // Create dictionaries for storing event reference types, history of execution, and execution count.
            EventReference = new Dictionary <EventKey, Type>();

            // Collect all of the event types with the attribute decorated on them.
            var randomEvents = AttributeExtensions.GetTypesWith <DirectorEventAttribute>(true);

            foreach (var eventObject in randomEvents)
            {
                // Check if the class is abstract base class, we don't want to add that.
                if (eventObject.GetTypeInfo().IsAbstract)
                {
                    continue;
                }

                // Check the attribute itself from the event we are working on, which gives us the event type enum.
                var eventAttribute = eventObject.GetTypeInfo().GetAttributes <DirectorEventAttribute>(true).First();
                var eventType      = eventAttribute.EventCategory;

                // Initialize the execution history dictionary with every event type.
                foreach (var modeType in Enum.GetValues(typeof(EventCategory)))
                {
                    // Only proceed if enum value matches attribute enum value for event type.
                    if (!modeType.Equals(eventType))
                    {
                        continue;
                    }

                    // Create key for the event execution counter.
                    var eventKey = new EventKey((EventCategory)modeType, eventObject.Name,
                                                eventAttribute.EventExecutionType);

                    // Reference type for creating instances.
                    if (!EventReference.ContainsKey(eventKey))
                    {
                        EventReference.Add(eventKey, eventObject);
                    }
                }
            }
        }