Пример #1
0
        private void Add(EditableScriptBase script, int?index, bool fromUpdate)
        {
            script.Updated += script_Updated;
            if (index.HasValue)
            {
                m_scripts.Insert(index.Value, script);
            }
            else
            {
                m_scripts.Add(script);
            }

            if (m_underlyingScript == null)
            {
                InitialiseMultiScript(new MultiScript(m_controller.WorldModel));
            }

            if (!fromUpdate)
            {
                // Add underlying script to multiscript.
                // We don't always want to do this - we might be responding
                // to a multiscript update in the first place so no point adding the same
                // script again!

                m_adding = true;
                m_underlyingScript.Add(script.Script);
                m_adding = false;
            }

            System.Diagnostics.Debug.Assert(m_replacingScripts || m_underlyingScript.Scripts.Count() == m_scripts.Count);
        }
Пример #2
0
        private void multiScript_ScriptUpdated(object sender, ScriptUpdatedEventArgs e)
        {
            if (m_adding)
            {
                return;
            }

            // Has the update to the MultiScript removed one of the scripts? If so we need
            // to remove it from this wrapper too.
            if (e.RemovedScript != null)
            {
                foreach (IEditableScript es in m_scripts.ToArray())
                {
                    EditableScriptBase s = (EditableScriptBase)es;
                    if (s.Script == e.RemovedScript)
                    {
                        m_scripts.Remove(es);
                    }
                }
            }
            if (e.AddedScript != null)
            {
                Add(m_controller.ScriptFactory.CreateEditableScript(e.AddedScript), true);
            }
            if (e.InsertedScript != null)
            {
                Add(m_controller.ScriptFactory.CreateEditableScript(e.InsertedScript), e.Index, true);
            }
            if (e.ScriptsReplaced)
            {
                m_replacingScripts = true;
                m_scripts.Clear();
                foreach (var script in ((MultiScript)sender).Scripts)
                {
                    Add(m_controller.ScriptFactory.CreateEditableScript(script), true);
                }
                m_replacingScripts = false;
            }
            if (Updated != null)
            {
                Updated(this, new EditableScriptsUpdatedEventArgs());
            }
            if (UnderlyingValueUpdated != null)
            {
                UnderlyingValueUpdated(this, new DataWrapperUpdatedEventArgs());
            }

            System.Diagnostics.Debug.Assert(m_underlyingScript.Scripts.Count() == m_scripts.Count);
        }
Пример #3
0
 private void Add(EditableScriptBase script, bool fromUpdate)
 {
     Add(script, null, fromUpdate);
 }
Пример #4
0
        private void Add(EditableScriptBase script, int? index, bool fromUpdate)
        {
            script.Updated += script_Updated;
            if (index.HasValue)
            {
                m_scripts.Insert(index.Value, script);
            }
            else
            {
                m_scripts.Add(script);
            }

            if (m_underlyingScript == null)
            {
                InitialiseMultiScript(new MultiScript(m_controller.WorldModel));
            }

            if (!fromUpdate)
            {
                // Add underlying script to multiscript.
                // We don't always want to do this - we might be responding
                // to a multiscript update in the first place so no point adding the same
                // script again!

                m_adding = true;
                m_underlyingScript.Add(script.Script);
                m_adding = false;
            }

            System.Diagnostics.Debug.Assert(m_replacingScripts || m_underlyingScript.Scripts.Count() == m_scripts.Count);
        }
Пример #5
0
 private void Add(EditableScriptBase script, bool fromUpdate)
 {
     Add(script, null, fromUpdate);
 }