Example #1
0
        public void RunWalkthrough()
        {
            string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\");
            string templateFolder = System.IO.Path.Combine(folder, @"..\..\..\WorldModel\WorldModel\Core");
            WorldModel worldModel = new WorldModel(
                System.IO.Path.Combine(folder, @"..\..\walkthrough.aslx"),
                templateFolder,
                null);

            Mock<IPlayer> player = new Mock<IPlayer>();
            worldModel.Initialise(player.Object);
            worldModel.Begin();

            foreach (string cmd in worldModel.Walkthroughs.Walkthroughs["debug"].Steps)
            {
                if (cmd.StartsWith("assert:"))
                {
                    string expr = cmd.Substring(7);
                    Assert.AreEqual(true, worldModel.Assert(expr), expr);
                }
                else
                {
                    worldModel.SendCommand(cmd);
                }
            }
        }
Example #2
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));
                }
            }
        }
Example #3
0
 public Walkthroughs(WorldModel worldModel)
 {
     foreach (Element walkthroughElement in worldModel.Elements.GetElements(ElementType.Walkthrough))
     {
         m_walkthroughs.Add(walkthroughElement.Name, new Walkthrough(walkthroughElement, this));
     }
 }
Example #4
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);
     }
 }
Example #5
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            a = m_worldModel.GetElementFactory(ElementType.Object).Create("a");
            b = m_worldModel.GetElementFactory(ElementType.Object).Create("b");
            c = m_worldModel.GetElementFactory(ElementType.Object).Create("c");
        }
Example #6
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);
 }
Example #7
0
 public GameLoader(WorldModel worldModel, LoadMode mode, bool? isCompiled = null)
 {
     IsCompiledFile = isCompiled ?? false;
     m_worldModel = worldModel;
     m_scriptFactory = new ScriptFactory(worldModel);
     m_scriptFactory.ErrorHandler += AddError;
     AddLoaders(mode);
     AddExtendedAttributeLoaders(mode);
     AddXMLLoaders(mode);
 }
Example #8
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object");
            var list = new QuestList<object> {"string1"};
            var dictionary = new QuestDictionary<object> {{"key1", "nested string"}};
            list.Add(dictionary);
            m_object.Fields.Set("list", list);
            m_object.Fields.Resolve(null);
        }
        public void Setup()
        {
            m_worldModel = new WorldModel();
            m_scriptFactory = new ScriptFactory(m_worldModel);

            m_constructor = new SwitchScriptConstructor();
            m_constructor.WorldModel = m_worldModel;            
            m_constructor.ScriptFactory = m_scriptFactory;

            scriptContext = new ScriptContext(m_worldModel);
        }
Example #10
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);
        }
Example #11
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(IsScriptEditor))
            {
                string appliesTo = editor.Fields.GetString("appliesto");
                m_scriptData.Add(appliesTo, new EditableScriptData(editor, worldModel));
            }
        }
Example #12
0
            public void Save(GameXmlWriter writer, WorldModel worldModel)
            {
                ObjectSaver elementSaver = new ObjectSaver();
                elementSaver.GameSaver = GameSaver;

                IEnumerable<Element> allObjects = worldModel.Elements.GetElements(ElementType.Object).OrderBy(o => o.MetaFields[MetaFieldDefinitions.SortIndex]);

                foreach (Element e in allObjects.Where(e => e.Parent == null && GameSaver.CanSave(e)))
                {
                    SaveObjectAndChildren(writer, allObjects, e, elementSaver);
                }
            }
Example #13
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];
         }
     }
 }
Example #14
0
        public ScriptFactory(WorldModel worldModel)
        {
            m_worldModel = worldModel;

            // Use Reflection to create instances of all IScriptConstructors
            foreach (Type t in TextAdventures.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());
        }
Example #15
0
 public EditableScriptData(Element editor, WorldModel worldModel)
 {
     DisplayString = editor.Fields.GetString("display");
     Category = editor.Fields.GetString("category");
     CreateString = editor.Fields.GetString("create");
     AdderDisplayString = editor.Fields.GetString("add");
     IsVisibleInSimpleMode = !editor.Fields.GetAsType<bool>("advanced");
     IsDesktopOnly = editor.Fields.GetAsType<bool>("desktop");
     CommonButton = editor.Fields.GetString("common");
     var expression = editor.Fields.GetString("onlydisplayif");
     if (expression != null)
     {
         m_visibilityExpression = new Expression<bool>(Utility.ConvertVariablesToFleeFormat(expression), new ScriptContext(worldModel, true));
     }
 }
Example #16
0
        public EditorTab(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_controls = new Dictionary<string, IEditorControl>();
            m_caption = source.Fields.GetString("caption");
            IsTabVisibleInSimpleMode = !source.Fields.GetAsType<bool>("advanced");

            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);
            m_source = source;
        }
Example #17
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);
     }
 }
Example #18
0
        public GameSaver(WorldModel worldModel)
        {
            m_worldModel = worldModel;

            // Use Reflection to create instances of all IElementSavers (save individual elements)
            foreach (Type t in TextAdventures.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 TextAdventures.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(),
                typeof(IElementsSaver)))
            {
                AddElementsSaver((IElementsSaver)Activator.CreateInstance(t));
            }
        }
Example #19
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);
            IsControlVisibleInSimpleMode = !source.Fields.GetAsType<bool>("advanced");
            m_id = source.Name;

            if (source.Fields.HasString("filtergroup"))
            {
                parent.RegisterFilter(source.Fields.GetString("filtergroup"), source.Fields.GetString("filter"), m_attribute);
            }
        }
Example #20
0
        public void TestListExtension_InheritingDirectly()
        {
            WorldModel worldModel = new WorldModel();

            Element type1 = worldModel.GetElementFactory(ElementType.ObjectType).Create("type1");
            type1.Fields.AddFieldExtension("listfield", new QuestList<string>(new[] { "a" }, true));

            Element type2 = worldModel.GetElementFactory(ElementType.ObjectType).Create("type2");
            type2.Fields.AddType(type1);
            type2.Fields.AddFieldExtension("listfield", new QuestList<string>(new[] { "b" }, true));

            Element obj = worldModel.GetElementFactory(ElementType.Object).Create("object");
            obj.Fields.AddType(type2);

            var result = obj.Fields.GetAsType<QuestList<string>>("listfield");

            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(result.Contains("a"));
            Assert.IsTrue(result.Contains("b"));
        }
Example #21
0
        public void RunWalkthrough()
        {
            string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\");
            string templateFolder = System.IO.Path.Combine(folder, @"..\..\..\WorldModel\WorldModel\Core");
            WorldModel worldModel = new WorldModel(
                System.IO.Path.Combine(folder, @"..\..\savetest.aslx"),
                templateFolder,
                null);

            Mock<IPlayer> player = new Mock<IPlayer>();
            bool success = worldModel.Initialise(player.Object);
            Assert.IsTrue(success, "Initialisation failed");

            worldModel.Begin();

            worldModel.SendCommand("update");

            string tempFilename = System.IO.Path.GetTempFileName();
            worldModel.Save(tempFilename, null);

            WorldModel savedGameWorldModel = new WorldModel(tempFilename, null, null);
            success = savedGameWorldModel.Initialise(player.Object);
            Assert.IsTrue(success, "Initialisation failed");

            savedGameWorldModel.Begin();

            foreach (string cmd in worldModel.Walkthroughs.Walkthroughs["verify"].Steps)
            {
                if (cmd.StartsWith("assert:"))
                {
                    string expr = cmd.Substring(7);
                    Assert.AreEqual(true, worldModel.Assert(expr), expr);
                }
                else
                {
                    worldModel.SendCommand(cmd);
                }
            }

            System.IO.File.Delete(tempFilename);
        }
Example #22
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.GetAsType<QuestList<string>>("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), new TextAdventures.Quest.Scripts.ScriptContext(worldModel, true));
                m_alwaysVisible = false;
            }
        }
Example #23
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");
        }
Example #24
0
        public bool Initialise()
        {
            m_game = GameLauncher.GetGame(m_filename, null);
            m_v4Game = m_game as LegacyASL.LegacyGame;
            m_v5Game = m_game as WorldModel;
            m_helper = new PlayerHelper(m_game, m_dummyUI);

            try
            {
                if (!m_helper.Initialise(m_dummyUI, out m_errors))
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                m_errors.Add(ex.Message);
                return false;
            }

            return true;
        }
Example #25
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);
        }
Example #26
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(this, new EventArgs());
                RemoveElementAndSubElementsFromTree(e.Element);
                AddElementAndSubElementsToTree(e.Element);
                EndTreeUpdate(this, new EventArgs());
                if (ElementsUpdated != null) ElementsUpdated(this, new EventArgs());
            }

            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(this, new RetitledNodeEventArgs { Key = e.Element.Name, NewTitle = GetDisplayName(e.Element) });
                    if (ElementsUpdated != null) ElementsUpdated(this, new EventArgs());
                }
            }

            if (e.Element.Type == ObjectType.Command && e.Attribute == "isverb")
            {
                MoveNove(e.Element.Name, GetDisplayName(e.Element), GetElementTreeParent(e.Element));
            }

            if (e.Element.ElemType == ElementType.IncludedLibrary && e.Attribute == "filename")
            {
                if (LibrariesUpdated != null) LibrariesUpdated(this, new LibrariesUpdatedEventArgs());
            }
        }
Example #27
0
 public Packager(WorldModel worldModel)
 {
     m_worldModel = worldModel;
 }
Example #28
0
 void m_worldModel_LoadStatus(object sender, WorldModel.LoadStatusEventArgs e)
 {
     if (LoadStatus != null)
     {
         LoadStatus(this, new LoadStatusEventArgs(e.Status));
     }
 }
Example #29
0
 void m_worldModel_ElementRefreshed(object sender, WorldModel.ElementRefreshEventArgs e)
 {
     if (m_initialised)
     {
         if (ElementRefreshed != null) ElementRefreshed(this, new ElementRefreshedEventArgs(e.Element.Name));
     }
 }
Example #30
0
        void m_worldModel_ElementMetaFieldUpdated(object sender, WorldModel.ElementFieldUpdatedEventArgs e)
        {
            if (!m_initialised) return;

            //System.Diagnostics.Debug.Print("Updated: {0}.{1} = {2}", e.Element, e.Attribute, e.NewValue);

            if (e.Attribute == "sortindex")
            {
                RemovedNode(this, new RemovedNodeEventArgs { Key = e.Element.Name });
                AddElementAndSubElementsToTree(e.Element, GetElementPosition(e.Element));
                if (ElementMoved != null) ElementMoved(this, new ElementMovedEventArgs { Key = e.Element.Name });
            }

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