SharpLibEar/Event.cs
author StephaneLenclud
Sat, 23 Jul 2016 16:00:04 +0200
changeset 210 83dd86e73448
child 212 1a0791daa243
permissions -rw-r--r--
Most basic event action manager.
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@210
    11
    public abstract class MEvent
StephaneLenclud@210
    12
    {
StephaneLenclud@210
    13
        [DataMember]
StephaneLenclud@210
    14
        public string Name { get; protected set; }
StephaneLenclud@210
    15
StephaneLenclud@210
    16
        [DataMember]
StephaneLenclud@210
    17
        public string Description { get; protected set; }
StephaneLenclud@210
    18
StephaneLenclud@210
    19
        public abstract void Trigger();
StephaneLenclud@210
    20
    };
StephaneLenclud@210
    21
StephaneLenclud@210
    22
    [DataContract]
StephaneLenclud@210
    23
    public abstract class Event : MEvent
StephaneLenclud@210
    24
    {
StephaneLenclud@210
    25
        public List<Action> Actions;
StephaneLenclud@210
    26
StephaneLenclud@210
    27
        protected Event()
StephaneLenclud@210
    28
        {
StephaneLenclud@210
    29
           Actions = new List<Action>();
StephaneLenclud@210
    30
        }
StephaneLenclud@210
    31
StephaneLenclud@210
    32
        public override void Trigger()
StephaneLenclud@210
    33
        {
StephaneLenclud@210
    34
            Console.WriteLine("Event '" + Name + "' triggered.");
StephaneLenclud@210
    35
            foreach (Action action in Actions)
StephaneLenclud@210
    36
            {
StephaneLenclud@210
    37
                action.Execute();
StephaneLenclud@210
    38
            }
StephaneLenclud@210
    39
        }
StephaneLenclud@210
    40
    }
StephaneLenclud@210
    41
StephaneLenclud@210
    42
}