Exemplo n.º 1
0
        public SplitEventEditor(IEventWork <T> block, IEnumerable <string> work, IEnumerable <string> flag)
        {
            Block = block;
            // load lines
            var worklines = work.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5);

            Work = EventWorkUtil.GetVars(worklines, (index, t, data) => new EventWork <T>(index, t, data));
            var flaglines = flag.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5);

            Flag = EventWorkUtil.GetVars(flaglines, (index, t, data) => new EventFlag(index, t, data));

            // initialize lines
            foreach (var g in Work)
            {
                foreach (var item in g.Vars)
                {
                    item.RawIndex = block.GetWorkRawIndex(item.Type, item.RelativeIndex);
                    ((EventWork <T>)item).Value = block.GetWork(item.RawIndex);
                }
            }
            foreach (var g in Flag)
            {
                foreach (var item in g.Vars)
                {
                    item.RawIndex          = block.GetFlagRawIndex(item.Type, item.RelativeIndex);
                    ((EventFlag)item).Flag = block.GetFlag(item.RawIndex);
                }
            }
        }
Exemplo n.º 2
0
 private void OnError(Exception e, IEventWork work)
 {
     try
     {
         Error?.Invoke(e, work);
     }
     catch
     {
     }
 }
Exemplo n.º 3
0
        public SAV_EventWork(SaveFile sav)
        {
            InitializeComponent();

            WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);

            if (sav is SAV7b s7b)
            {
                SAV = s7b.EventWork;
            }
            else if (sav is SAV8SWSH s8ss)
            {
                SAV = s8ss.EventWork;
            }
            SAV    = ((SAV7b)sav).EventWork;
            Origin = sav;

            DragEnter += Main_DragEnter;
            DragDrop  += Main_DragDrop;

            CB_Stats.Items.Clear();
            for (int i = 0; i < SAV.MaxWork; i++)
            {
                CB_Stats.Items.Add(i.ToString());
            }

            var work = GetStringList(sav.Version, "const");
            var flag = GetStringList(sav.Version, "flags");

            Editor = new SplitEventEditor <int>(SAV, work, flag);

            SuspendLayout();
            editing = true;
            LoadFlags(Editor.Flag);
            LoadWork(Editor.Work);
            editing = false;
            ResumeLayout();

            if (CB_Stats.Items.Count > 0)
            {
                CB_Stats.SelectedIndex = 0;
            }
            else
            {
                L_Stats.Visible = CB_Stats.Visible = NUD_Stat.Visible = false;
                TC_Features.TabPages.Remove(GB_Constants);
            }
            NUD_Flag.Maximum     = SAV.MaxFlag - 1;
            NUD_Flag.Text        = "0";
            c_CustomFlag.Checked = SAV.GetFlag(0);

            Text = $"{Text} ({sav.Version})";
        }
Exemplo n.º 4
0
 public void Enqueue(IEventWork item, int waitLength = 5)
 {
     for (int i = 0; i < mQueues.Count; i++)
     {
         if (mQueues[i].Count < waitLength)
         {
             mQueues[i].Enqueue(item);
             return;
         }
     }
     Next().Enqueue(item);
 }
Exemplo n.º 5
0
 public void Enqueue(IEventWork item)
 {
     mQueue.Enqueue(item);
     System.Threading.Interlocked.Increment(ref mCount);
     lock (_workSync)
     {
         if (!_doingWork)
         {
             System.Threading.ThreadPool.QueueUserWorkItem(OnStart);
             _doingWork = true;
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Compares a <see cref="before"/> and <see cref="after"/> <see cref="IEventWork{T}"/> object of the same type to find <see cref="EventFlag"/> changes.
        /// </summary>
        /// <typeparam name="T">Type of value used by <see cref="EventWork{T}"/></typeparam>
        /// <param name="before">Data before the event was triggered</param>
        /// <param name="after">Data after the event was triggered</param>
        /// <param name="on">List of flags that were turned on</param>
        /// <param name="off">List of flags that were turned off</param>
        public static void DiffSavesFlag <T>(IEventWork <T> before, IEventWork <T> after, List <int> on, List <int> off)
        {
            int max = before.MaxFlag;

            for (int i = 0; i < max; i++)
            {
                var b = before.GetFlag(i);
                var a = after.GetFlag(i);
                if (b == a)
                {
                    continue;
                }

                var arr = a ? on : off;
                arr.Add(i);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Compares a <see cref="before"/> and <see cref="after"/> <see cref="IEventWork{T}"/> object of the same type to find <see cref="EventWork{T}"/> changes.
        /// </summary>
        /// <typeparam name="T">Type of value used by <see cref="EventWork{T}"/></typeparam>
        /// <param name="before">Data before the event was triggered</param>
        /// <param name="after">Data after the event was triggered</param>
        /// <param name="changed"><see cref="EventVar.RawIndex"/> values that changed</param>
        /// <param name="changes">Summary of the <see cref="EventWork{T}"/> value change</param>
        public static void DiffSavesWork <T>(IEventWork <T> before, IEventWork <T> after, List <int> changed, List <string> changes)
        {
            int max = before.MaxWork;

            for (int i = 0; i < max; i++)
            {
                var b = before.GetWork(i);
                var a = after.GetWork(i);
                if (b is null || b.Equals(a))
                {
                    continue;
                }

                changed.Add(i);
                changes.Add($"{b} => {a}");
            }
        }