<commit_before><commit_msg>Created a new effect that calls code delegates.<commit_after>﻿using SadConsole.Effects;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace SadConsole.Core.Effects
{
    // Not sure if I should make this serailizable... 
    class CodeEffect : CellEffectBase
    {
        public string Id;
        public object Tag;
        public bool UseDuration;
        public double Duration;

        private double timeElapsed;

        Action<CodeEffect, Cell> applyAction;
        Action<CodeEffect, Cell> clearAction;
        Action<CodeEffect, double, double> updateAction;
        Action<CodeEffect> restartAction;

        public CodeEffect(string id, Action<CodeEffect, Cell> apply, Action<CodeEffect, Cell> clear, Action<CodeEffect, double, double> update, Action<CodeEffect> restart)
        {
            Id = id;
        }

        public override void Apply(Cell cell)
        {
            applyAction(this, cell);
        }

        public override void Clear(Cell cell)
        {
            clearAction(this, cell);
        }

        public override ICellEffect Clone()
        {
            throw new NotSupportedException();
        }

        public override void Update(double timeElapsed)
        {
            this.timeElapsed += timeElapsed;

            if (this.timeElapsed >= Duration)
                IsFinished = true;

            updateAction(this, timeElapsed, this.timeElapsed);
        }

        public override void Restart()
        {
            base.Restart();
            restartAction(this);
        }

        public override string ToString()
        {
            return string.Format("CODE-{0}", Id);
        }
    }
}
{'fraction_non_alphanumeric': 0.08199541284403669, 'fraction_numerical': 0.0005733944954128441, 'mean_word_length': 2.050699300699301, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '350171', 'n_tokens_mistral': 449, 'n_tokens_neox': 433, 'n_words': 123}