SharpLibEar/Event.cs
author StephaneLenclud
Sun, 21 Aug 2016 18:35:58 +0200
changeset 250 b2121d03f6f0
parent 238 c92587ddabcd
child 253 2dae7a163fff
permissions -rw-r--r--
Adding Harmony command selection dialog.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System;
StephaneLenclud@210
     5
using System.Collections.Generic;
StephaneLenclud@210
     6
using System.Runtime.Serialization;
StephaneLenclud@210
     7
StephaneLenclud@210
     8
namespace SharpLib.Ear
StephaneLenclud@210
     9
{
StephaneLenclud@210
    10
    [DataContract]
StephaneLenclud@238
    11
    public abstract class Event : Object
StephaneLenclud@210
    12
    {
StephaneLenclud@231
    13
        [DataMember]
StephaneLenclud@231
    14
        [AttributeObjectProperty
StephaneLenclud@231
    15
            (
StephaneLenclud@231
    16
                Id = "Event.Enabled",
StephaneLenclud@231
    17
                Name = "Enabled",
StephaneLenclud@231
    18
                Description = "When enabled an event instance can be triggered."
StephaneLenclud@231
    19
            )
StephaneLenclud@231
    20
        ]
Stephane@243
    21
        public bool Enabled { get; set; } = true;
StephaneLenclud@210
    22
Stephane@212
    23
        [DataMember]
Stephane@212
    24
        public List<Action> Actions = new List<Action>();
StephaneLenclud@210
    25
StephaneLenclud@231
    26
Stephane@243
    27
        protected override void DoConstruct()
Stephane@243
    28
        {
Stephane@243
    29
            base.DoConstruct();
StephaneLenclud@231
    30
Stephane@243
    31
            // TODO: Construct properties too
Stephane@243
    32
            foreach (Action a in Actions)
Stephane@243
    33
            {
Stephane@243
    34
                a.Construct();
Stephane@243
    35
            }
Stephane@243
    36
StephaneLenclud@210
    37
        }
StephaneLenclud@210
    38
StephaneLenclud@231
    39
StephaneLenclud@231
    40
        /// <summary>
StephaneLenclud@231
    41
        /// Allows testing from generic edit dialog.
StephaneLenclud@231
    42
        /// </summary>
StephaneLenclud@231
    43
        public void Test()
StephaneLenclud@231
    44
        {
StephaneLenclud@231
    45
            Console.WriteLine("Event test");
StephaneLenclud@231
    46
            Trigger();
StephaneLenclud@231
    47
        }
StephaneLenclud@231
    48
StephaneLenclud@231
    49
StephaneLenclud@231
    50
        public void Trigger()
StephaneLenclud@210
    51
        {
StephaneLenclud@229
    52
            Console.WriteLine("Event triggered: " + Name);
StephaneLenclud@210
    53
            foreach (Action action in Actions)
StephaneLenclud@210
    54
            {
StephaneLenclud@210
    55
                action.Execute();
StephaneLenclud@210
    56
            }
StephaneLenclud@210
    57
        }
StephaneLenclud@231
    58
StephaneLenclud@237
    59
        //
StephaneLenclud@237
    60
        public override bool Equals(object obj)
StephaneLenclud@237
    61
        {
StephaneLenclud@237
    62
            //Default implementation assumes event are the same if types are the same
StephaneLenclud@237
    63
            bool res=  obj.GetType() == GetType();
StephaneLenclud@237
    64
            return res;
StephaneLenclud@237
    65
        }
StephaneLenclud@231
    66
    };
StephaneLenclud@210
    67
StephaneLenclud@210
    68
}