Esempio n. 1
0
        public EditorDefinition(WorldModel worldModel, Element source)
        {
            m_tabs = new Dictionary<string, IEditorTab>();
            m_controls = new Dictionary<string, IEditorControl>();
            m_appliesTo = source.Fields.GetString("appliesto");
            m_pattern = source.Fields.GetString("pattern");
            m_originalPattern = source.Fields.GetString(FieldDefinitions.OriginalPattern.Property);
            m_description = source.Fields.GetString("description");
            m_create = source.Fields.GetString("create");
            m_expressionType = source.Fields.GetString("expressiontype");

            foreach (Element e in worldModel.Elements.GetElements(ElementType.EditorTab))
            {
                if (e.Parent == source)
                {
                    m_tabs.Add(e.Name, new EditorTab(this, worldModel, e));
                }
            }

            foreach (Element e in worldModel.Elements.GetElements(ElementType.EditorControl))
            {
                if (e.Parent == source)
                {
                    m_controls.Add(e.Name, new EditorControl(this, worldModel, e));
                }
            }
        }
Esempio n. 2
0
 public Walkthroughs(WorldModel worldModel)
 {
     foreach (Element walkthroughElement in worldModel.Elements.GetElements(ElementType.Walkthrough))
     {
         m_walkthroughs.Add(walkthroughElement.Name, new Walkthrough(walkthroughElement, this));
     }
 }
Esempio n. 3
0
 public GameLoader(WorldModel worldModel, LoadMode mode)
 {
     m_worldModel = worldModel;
     m_scriptFactory = new ScriptFactory(worldModel);
     m_scriptFactory.ErrorHandler += AddError;
     AddLoaders(mode);
     AddExtendedAttributeLoaders(mode);
     AddXMLLoaders(mode);
 }
Esempio n. 4
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            m_original = m_worldModel.GetElementFactory(ElementType.Object).Create("original");
            m_original.Fields.Set(attributeName, attributeValue);
            m_original.Fields.Set(listAttributeName, new QuestList<string>(listAttributeValue));
            m_original.Fields.Resolve(null);
            Assert.AreEqual(attributeValue, m_original.Fields.GetString(attributeName));
            Assert.AreEqual(3, m_original.Fields.GetAsType<QuestList<string>>(listAttributeName).Count);
        }
Esempio n. 5
0
        internal EditableScriptFactory(EditorController controller, ScriptFactory factory, WorldModel worldModel)
        {
            m_controller = controller;
            m_scriptFactory = factory;
            m_worldModel = worldModel;

            foreach (Element editor in worldModel.Elements.GetElements(ElementType.Editor).Where(e => IsScriptEditor(e)))
            {
                string appliesTo = editor.Fields.GetString("appliesto");
                m_scriptData.Add(appliesTo, new EditableScriptData(editor));
            }
        }
Esempio n. 6
0
 public TimerRunner(WorldModel worldModel, bool initialise)
 {
     m_worldModel = worldModel;
     if (initialise)
     {
         // When a game begins, set initial triggers. We don't need to do this when loading
         // a saved game.
         foreach (Element timer in EnabledTimers)
         {
             timer.Fields[FieldDefinitions.Trigger] = timer.Fields[FieldDefinitions.Interval];
         }
     }
 }
Esempio n. 7
0
        public ScriptFactory(WorldModel worldModel)
        {
            m_worldModel = worldModel;

            // Use Reflection to create instances of all IScriptConstructors
            foreach (Type t in AxeSoftware.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(),
                typeof(IScriptConstructor)))
            {
                AddConstructor((IScriptConstructor)Activator.CreateInstance(t));
            }

            m_setConstructor = (SetScriptConstructor)InitScriptConstructor(new SetScriptConstructor());
            m_procConstructor = (FunctionCallScriptConstructor)InitScriptConstructor(new FunctionCallScriptConstructor());
        }
Esempio n. 8
0
        public EditorTab(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_controls = new Dictionary<string, IEditorControl>();
            m_caption = source.Fields.GetString("caption");

            foreach (Element e in worldModel.Elements.GetElements(ElementType.EditorControl))
            {
                if (e.Parent == source)
                {
                    m_controls.Add(e.Name, new EditorControl(parent, worldModel, e));
                }
            }
            m_visibilityHelper = new EditorVisibilityHelper(parent, worldModel, source);
        }
Esempio n. 9
0
        public GameSaver(WorldModel worldModel)
        {
            m_worldModel = worldModel;

            // Use Reflection to create instances of all IElementSavers (save individual elements)
            foreach (Type t in AxeSoftware.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(),
                typeof(IElementSaver)))
            {
                AddElementSaver((IElementSaver)Activator.CreateInstance(t));
            }

            // Use Reflection to create instances of all IElementsSavers (save all elements of a type)
            foreach (Type t in AxeSoftware.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(),
                typeof(IElementsSaver)))
            {
                AddElementsSaver((IElementsSaver)Activator.CreateInstance(t));
            }
        }
Esempio n. 10
0
        public EditorControl(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_parent = parent;
            m_worldModel = worldModel;
            m_source = source;
            m_controlType = source.Fields.GetString("controltype");
            m_caption = source.Fields.GetString("caption");
            m_attribute = source.Fields.GetString("attribute");
            if (source.Fields.HasType<int>("height")) m_height = source.Fields.GetAsType<int>("height");
            if (source.Fields.HasType<int>("width")) m_width = source.Fields.GetAsType<int>("width");
            if (source.Fields.HasType<bool>("expand")) m_expand = source.Fields.GetAsType<bool>("expand");
            m_visibilityHelper = new EditorVisibilityHelper(parent, worldModel, source);

            if (source.Fields.HasString("filtergroup"))
            {
                parent.RegisterFilter(source.Fields.GetString("filtergroup"), source.Fields.GetString("filter"), m_attribute);
            }
        }
Esempio n. 11
0
        public EditorVisibilityHelper(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_parent = parent;
            m_worldModel = worldModel;
            m_relatedAttribute = source.Fields.GetString("relatedattribute");
            if (m_relatedAttribute != null) m_alwaysVisible = false;
            m_visibleIfRelatedAttributeIsType = source.Fields.GetString("relatedattributedisplaytype");
            m_visibleIfElementInheritsType = source.Fields.GetString("mustinherit");
            m_notVisibleIfElementInheritsType = source.Fields.GetAsType<QuestList<string>>("mustnotinherit");
            if (m_visibleIfElementInheritsType != null || m_notVisibleIfElementInheritsType != null) m_alwaysVisible = false;
            m_filterGroup = source.Fields.GetString("filtergroup");
            m_filter = source.Fields.GetString("filter");
            if (m_filter != null) m_alwaysVisible = false;

            string expression = source.Fields.GetString("onlydisplayif");
            if (expression != null)
            {
                m_visibilityExpression = new Expression<bool>(Utility.ConvertVariablesToFleeFormat(expression), worldModel);
                m_alwaysVisible = false;
            }
        }
Esempio n. 12
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            // a
            // - b
            //   - c
            //   - d
            // - e
            // f

            Element a = m_worldModel.GetElementFactory(ElementType.Object).Create("a");
            Element b = m_worldModel.GetElementFactory(ElementType.Object).Create("b");
            b.Parent = a;
            Element c = m_worldModel.GetElementFactory(ElementType.Object).Create("c");
            c.Parent = b;
            Element d = m_worldModel.GetElementFactory(ElementType.Object).Create("d");
            d.Parent = b;
            Element e = m_worldModel.GetElementFactory(ElementType.Object).Create("e");
            e.Parent = a;
            Element f = m_worldModel.GetElementFactory(ElementType.Object).Create("f");
        }
Esempio n. 13
0
        public void Setup()
        {
            const string inheritedTypeName = "inherited";
            const string subInheritedTypeName = "subtype";
            const string defaultObject = "defaultobject";

            m_worldModel = new WorldModel();

            m_defaultType = m_worldModel.GetElementFactory(ElementType.ObjectType).Create(defaultObject);
            m_defaultType.Fields.Set(attributeDefinedByDefaultName, attributeDefinedByDefaultValue);
            m_defaultType.Fields.Set(attributeDefinedByDefault2Name, attributeDefinedByDefault2Value);

            m_subType = m_worldModel.GetElementFactory(ElementType.ObjectType).Create(subInheritedTypeName);
            m_subType.Fields.Set(inheritedAttribute2Name, inheritedAttribute2Value);
            m_subType.Fields.Set(attributeDefinedByDefault2Name, attributeDefinedByDefault2OverriddenValue);

            m_objectType = m_worldModel.GetElementFactory(ElementType.ObjectType).Create(inheritedTypeName);
            m_objectType.Fields.Set(inheritedAttributeName, inheritedAttributeValue);
            m_objectType.Fields.AddType(m_subType);

            m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object");
            m_object.Fields.Resolve(null);
            m_object.Fields.AddType(m_objectType);
        }
Esempio n. 14
0
 private void SaveElementAndChildren(GameXmlWriter writer, WorldModel worldModel, Element walkThrough)
 {
     m_walkthroughSaver.StartSave(writer, walkThrough);
     foreach (Element child in worldModel.Elements.GetElements(ElementType.Walkthrough).Where(e => e.Parent == walkThrough))
     {
         SaveElementAndChildren(writer, worldModel, child);
     }
     m_walkthroughSaver.EndSave(writer, walkThrough);
 }
Esempio n. 15
0
 public void Save(GameXmlWriter writer, WorldModel worldModel)
 {
     foreach (Element walkThrough in worldModel.Elements.GetElements(ElementType.Walkthrough).Where(e => e.Parent == null))
     {
         SaveElementAndChildren(writer, worldModel, walkThrough);
     }
 }
Esempio n. 16
0
            public void Save(GameXmlWriter writer, WorldModel worldModel)
            {
                IEnumerable<Element> allEditors = worldModel.Elements.GetElements(ElementType.Editor);
                IEnumerable<Element> allTabs = worldModel.Elements.GetElements(ElementType.EditorTab);
                IEnumerable<Element> allControls = worldModel.Elements.GetElements(ElementType.EditorControl);

                foreach (Element editor in allEditors.Where(e => !e.MetaFields[MetaFieldDefinitions.Library]))
                {
                    m_editorSaver.StartSave(writer, editor);
                    foreach (Element tab in allTabs.Where(t => t.Parent == editor))
                    {
                        m_tabSaver.StartSave(writer, tab);
                        foreach (Element control in allControls.Where(c => c.Parent == tab))
                        {
                            m_controlSaver.Save(writer, control);
                        }
                        m_tabSaver.EndSave(writer, tab);
                    }
                    m_editorSaver.EndSave(writer, editor);
                }
            }
Esempio n. 17
0
 internal UndoLogger(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
Esempio n. 18
0
 public void DoUndo(WorldModel worldModel)
 {
     const string undoTurnTemplate = "UndoTurn";
     m_attributes.Reverse();
     if (!worldModel.EditMode)
     {
         if (worldModel.Template.DynamicTemplateExists(undoTurnTemplate))
         {
             worldModel.Print(worldModel.Template.GetDynamicText(undoTurnTemplate, m_command));
         }
     }
     foreach (IUndoAction l in m_attributes)
     {
         l.DoUndo(worldModel);
     }
 }
Esempio n. 19
0
 public void DoRedo(WorldModel worldModel)
 {
     m_attributes.Reverse();     // Undo reverses attributes, so put them back in the correct order
     foreach (IUndoAction l in m_attributes)
     {
         l.DoRedo(worldModel);
     }
 }
Esempio n. 20
0
 public void Setup()
 {
     m_worldModel = new WorldModel();
 }
Esempio n. 21
0
 internal Element(WorldModel worldModel)
     : this(worldModel, null)
 {
 }
Esempio n. 22
0
 public Template(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
Esempio n. 23
0
            public void Save(GameXmlWriter writer, WorldModel worldModel)
            {
                ObjectSaver elementSaver = new ObjectSaver();
                elementSaver.GameSaver = GameSaver;

                IEnumerable<Element> allObjects = worldModel.Elements.GetElements(ElementType.Object);

                foreach (Element e in allObjects.Where(e => e.Parent == null && GameSaver.CanSave(e)))
                {
                    SaveObjectAndChildren(writer, allObjects, e, elementSaver);
                }
            }
Esempio n. 24
0
        void m_worldModel_ElementFieldUpdated(object sender, WorldModel.ElementFieldUpdatedEventArgs e)
        {
            if (!m_initialised) return;

            if (ElementUpdated != null) ElementUpdated(this, new ElementUpdatedEventArgs(e.Element.Name, e.Attribute, WrapValue(e.NewValue, e.Element, e.Attribute), e.IsUndo));

            if (e.Attribute == "parent")
            {
                BeginTreeUpdate();
                RemoveElementAndSubElementsFromTree(e.Element);
                AddElementAndSubElementsToTree(e.Element);
                EndTreeUpdate();
                if (ElementsUpdated != null) ElementsUpdated();
            }

            if (e.Attribute == "anonymous" || e.Attribute == "alias"
                || e.Element.Type == ObjectType.Exit && (e.Attribute == "to" || e.Attribute == "name")
                || e.Element.Type == ObjectType.Command && (e.Attribute == "name" || e.Attribute == "pattern" || e.Attribute == "isverb")
                || e.Element.Type == ObjectType.TurnScript && (e.Attribute == "name")
                || e.Element.ElemType == ElementType.IncludedLibrary && (e.Attribute == "filename")
                || e.Element.ElemType == ElementType.Template && (e.Attribute == "templatename")
                || e.Element.ElemType == ElementType.Javascript && (e.Attribute == "src"))
            {
                if (e.Element.Name != null)
                {
                    // element name might be null if we're undoing an element add
                    RetitledNode(e.Element.Name, GetDisplayName(e.Element));
                    if (ElementsUpdated != null) ElementsUpdated();
                }
            }

            if (e.Element.Type == ObjectType.Command && e.Attribute == "isverb")
            {
                MoveNove(e.Element.Name, GetDisplayName(e.Element), GetElementTreeParent(e.Element));
            }
        }
Esempio n. 25
0
 void m_worldModel_ElementRefreshed(object sender, WorldModel.ElementRefreshEventArgs e)
 {
     if (m_initialised)
     {
         if (ElementRefreshed != null) ElementRefreshed(this, new ElementRefreshedEventArgs(e.Element.Name));
     }
 }
Esempio n. 26
0
        internal Element(WorldModel worldModel, Element element)
        {
            m_worldModel = worldModel;

            if (element == null)
            {
                // New element
                m_fields = new Fields(worldModel, this, false);
                m_metaFields = new Fields(worldModel, this, true);
            }
            else
            {
                // Clone element
                m_fields = element.Fields.Clone(this);
                m_metaFields = element.MetaFields.Clone(this);
            }

            Fields.AttributeChanged += Fields_AttributeChanged;
            Fields.AttributeChangedSilent += Fields_AttributeChangedSilent;
            m_metaFields.AttributeChanged += MetaFields_AttributeChanged;
            m_metaFields.AttributeChangedSilent += MetaFields_AttributeChangedSilent;
        }
Esempio n. 27
0
        public bool Initialise(string filename)
        {
            m_filename = filename;
            m_worldModel = new WorldModel(filename, null);
            m_scriptFactory = new ScriptFactory(m_worldModel);
            m_worldModel.ElementFieldUpdated += m_worldModel_ElementFieldUpdated;
            m_worldModel.ElementRefreshed += m_worldModel_ElementRefreshed;
            m_worldModel.ElementMetaFieldUpdated += m_worldModel_ElementMetaFieldUpdated;
            m_worldModel.UndoLogger.TransactionsUpdated += UndoLogger_TransactionsUpdated;
            m_worldModel.Elements.ElementRenamed += Elements_ElementRenamed;

            bool ok = m_worldModel.InitialiseEdit();

            // need to initialise the EditableScriptFactory after we've loaded the game XML above,
            // as the editor definitions contain the "friendly" templates for script commands.
            m_editableScriptFactory = new EditableScriptFactory(this, m_scriptFactory, m_worldModel);

            m_initialised = true;

            m_worldModel.ObjectsUpdated += m_worldModel_ObjectsUpdated;

            foreach (Element e in m_worldModel.Elements.GetElements(ElementType.Editor))
            {
                EditorDefinition def = new EditorDefinition(m_worldModel, e);
                if (def.AppliesTo != null)
                {
                    // Normal editor definition for editing an element or a script command
                    m_editorDefinitions.Add(def.AppliesTo, def);
                }
                else if (def.Pattern != null)
                {
                    // Editor definition for an expression template in the "if" editor
                    m_expressionDefinitions.Add(def.Pattern, def);
                }
            }

            if (ok)
            {
                UpdateTree();
            }
            else
            {
                string message = "Failed to load game due to the following errors:" + Environment.NewLine;
                foreach (string error in m_worldModel.Errors)
                {
                    message += "* " + error + Environment.NewLine;
                }
                ShowMessage(message);
            }

            return ok;
        }
Esempio n. 28
0
 public Packager(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
Esempio n. 29
0
        void m_worldModel_ElementMetaFieldUpdated(object sender, WorldModel.ElementFieldUpdatedEventArgs e)
        {
            if (!m_initialised) return;

            if (e.Attribute == "library")
            {
                // Refresh the element in the tree by deleting and readding it
                RemovedNode(e.Element.Name);
                AddElementAndSubElementsToTree(e.Element);
            }
        }