예제 #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));
                }
            }
        }
예제 #2
0
파일: Walkthrough.cs 프로젝트: Pertex/Quest
 public Walkthroughs(WorldModel worldModel)
 {
     foreach (Element walkthroughElement in worldModel.Elements.GetElements(ElementType.Walkthrough))
     {
         m_walkthroughs.Add(walkthroughElement.Name, new Walkthrough(walkthroughElement, this));
     }
 }
예제 #3
0
파일: GameLoader.cs 프로젝트: Pertex/Quest
 public GameLoader(WorldModel worldModel, LoadMode mode)
 {
     m_worldModel = worldModel;
     m_scriptFactory = new ScriptFactory(worldModel);
     m_scriptFactory.ErrorHandler += AddError;
     AddLoaders(mode);
     AddExtendedAttributeLoaders(mode);
     AddXMLLoaders(mode);
 }
예제 #4
0
파일: CloneTests.cs 프로젝트: Pertex/Quest
        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);
        }
예제 #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));
            }
        }
예제 #6
0
파일: TimerRunner.cs 프로젝트: Pertex/Quest
 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];
         }
     }
 }
예제 #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());
        }
예제 #8
0
파일: EditorTab.cs 프로젝트: Pertex/Quest
        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);
        }
예제 #9
0
파일: GameSaver.cs 프로젝트: Pertex/Quest
        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));
            }
        }
예제 #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);
            }
        }
예제 #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;
            }
        }
예제 #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");
        }
예제 #13
0
파일: FieldsTests.cs 프로젝트: Pertex/Quest
        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);
        }
예제 #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);
 }
예제 #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);
     }
 }
예제 #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);
                }
            }
예제 #17
0
파일: UndoLogger.cs 프로젝트: Pertex/Quest
 internal UndoLogger(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
예제 #18
0
파일: UndoLogger.cs 프로젝트: Pertex/Quest
 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);
     }
 }
예제 #19
0
파일: UndoLogger.cs 프로젝트: Pertex/Quest
 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);
     }
 }
예제 #20
0
 public void Setup()
 {
     m_worldModel = new WorldModel();
 }
예제 #21
0
파일: Element.cs 프로젝트: Pertex/Quest
 internal Element(WorldModel worldModel)
     : this(worldModel, null)
 {
 }
예제 #22
0
파일: Templates.cs 프로젝트: Pertex/Quest
 public Template(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
예제 #23
0
파일: ObjectSaver.cs 프로젝트: Pertex/Quest
            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);
                }
            }
예제 #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));
            }
        }
예제 #25
0
 void m_worldModel_ElementRefreshed(object sender, WorldModel.ElementRefreshEventArgs e)
 {
     if (m_initialised)
     {
         if (ElementRefreshed != null) ElementRefreshed(this, new ElementRefreshedEventArgs(e.Element.Name));
     }
 }
예제 #26
0
파일: Element.cs 프로젝트: Pertex/Quest
        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;
        }
예제 #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;
        }
예제 #28
0
파일: Packager.cs 프로젝트: Pertex/Quest
 public Packager(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
예제 #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);
            }
        }