private void UpdateFromMetaAction(AIDAdventure adventure)
        {
            var actions = adventure.MetaActions;

            actions.Sort();

            lock (adventure.Actions)
            {
                var removedHeads = new List <AIDAction>(adventure.Actions);
                int count        = actions.Count;
                for (int i = 0; i < count; i++)
                {
                    var head = adventure.Actions.FirstOrDefault(x => x.Action.id == actions[i].id);
                    if (head == null)
                    {
                        head = new AIDAction(this, actions[i]);
                        adventure.Actions.Add(head);
                        adventure.Actions.Sort();

                        head.UpdatedCallback();
                    }
                    else
                    {
                        head.Action = actions[i];
                        head.UpdatedCallback();
                        removedHeads.Remove(head);
                    }

                    //merge action if they are one-line texts
                    var innerActions = new List <AIDungeonWrapper.Action>();
                    for (; i + 1 < count; i++)
                    {
                        if (!EndsWithNewLine(actions[i].text) && !StartsWithNewLine(actions[i + 1].text))
                        {
                            innerActions.Add(actions[i + 1]);
                        }
                        else
                        {
                            break;
                        }
                    }

                    var added              = innerActions.Except(head.InnerActions);
                    var removed            = head.InnerActions.Except(innerActions);
                    var innerActionChanged = (removed.Count() + added.Count()) > 0;
                    if (innerActionChanged)
                    {
                        head.InnerActions.Clear();
                        head.InnerActions.AddRange(innerActions);
                        head.InnerActions.Sort();
                        head.UpdatedCallback();
                    }
                }
                foreach (var removedHead in removedHeads)
                {
                    adventure.Actions.Remove(removedHead);
                }
            }
            OnActionsChanged?.Invoke(adventure.PublicId, adventure.Actions);
        }
        public void Clear()
        {
            foreach (var adventure in this.Adventures.Values)
            {
                lock (adventure.Actions)
                {
                    foreach (var action in adventure.Actions)
                    {
                        action.Dispose();
                    }
                    adventure.Actions.Clear();
                }

                OnActionsChanged?.Invoke(adventure.PublicId, adventure.Actions);
            }
            this.Adventures.Clear();
        }