Patcher.Rules.RuleRunner.DoInserts C# (CSharp) Method

DoInserts() private method

private DoInserts ( FormProxy sourceProxy ) : void
sourceProxy FormProxy
return void
        private void DoInserts(FormProxy sourceProxy)
        {
            if (rule.Inserts != null)
            {
                foreach (var insert in rule.Inserts)
                {
                    Form targetForm;
                    if (insert.Copy && sourceProxy != null && sourceProxy.Form.FormKind == insert.InsertedFormKind)
                    {
                        // Copy form data if  source is the same as target (and source is not null)
                        targetForm = sourceProxy.Form.CopyForm(true);
                    }
                    else
                    {
                        // Create new otherwise
                        targetForm = engine.Context.CreateForm(insert.InsertedFormKind);
                    }

                    var targetProxy = engine.ProxyProvider.CreateFormProxy(targetForm, ProxyMode.Target);
                    if (insert.Method(sourceProxy, targetProxy))
                    {
                        if (insert.InsertedFormId != 0)
                        {
                            // Set explicit Form ID
                            targetForm.FormId = insert.InsertedFormId;
                        }

                        engine.ActivePlugin.AddForm(targetForm);
                        Created++;

                        // Tag the new form now that it has a Form ID
                        // if it has been tagged during its creation
                        foreach (var text in targetProxy.DelayedTags)
                        {
                            engine.Tags.Tag(text, targetForm.FormId);
                        }
                    }
                }
            }
        }