Exemplo n.º 1
0
        public void AddAttribute()
        {
            bool collectionChanged = false;

            Game game = new Game("Test Game");
            game.Attributes.CollectionChanged += (o, e) => collectionChanged = true;

            Attribute attribute = new Attribute("test");
            game.AddAttribute(attribute);

            Assert.IsTrue(collectionChanged);
            Assert.AreEqual(game.Attributes.Count(x => x.Name == "test"), 1);
        }
Exemplo n.º 2
0
        public Game LoadGame()
        {
            Parser parser = new Parser(grammar);
            src = File.ReadAllText(FileName.FullName);
            ParseTree parseTree = parser.Parse(src, FileName.FullName);

            if (parseTree.HasErrors())
            {
                throw new StorageException(BuildErrorMessage(parseTree.ParserMessages, FileName.Name));
            }

            root = parseTree.Root;
            var nameProperty = GetProperties(root).First(x => x.Item1 == "Name");
            var name = getStrVal((ParseTreeNode)nameProperty.Item2);
            game = new Game(new Value(name).GetStringValue());
            AddDefaultUsings(game);
            IEnumerable<ParseTreeNode> usings = grammar.GetOfType(root, grammar.Uses);

            foreach(ParseTreeNode node in usings)
            {
                Using use = CreateUsing(node);
                game.AddUsing(use);
            }

            foreach (Tuple<string, object> attribute in GetProperties(root))
            {
                ParseTreeNode attributeNode = (ParseTreeNode)attribute.Item2;
                if (attribute.Item1 != "Name")
                {
                    game.AddAttribute(new Attribute(attribute.Item1) { Value = new Value(getStrVal(attributeNode)) });
                }
            }

            foreach (ParseTreeNode prototype in grammar.GetOfType(root, grammar.Prototype))
            {
                Entity entity = CreateEntity(prototype, null, true);
                game.AddPrototype(entity);
            }

            foreach (ParseTreeNode serviceNode in grammar.GetOfType(root, grammar.Service))
            {
                Service service = CreateService(serviceNode);
                game.AddService(service);
            }

            foreach (ParseTreeNode sceneNode in grammar.GetOfType(root, grammar.Scene))
            {
                Scene scene = CreateScene(sceneNode);
                game.AddScene(scene);
            }

            var firstScene = game.GetAttribute("FirstScene");
            game.FirstScene = game.GetScene(firstScene.Value.GetStringValue());
            game.RemoveAttribute(firstScene);

            return game;
        }
Exemplo n.º 3
0
        public void RemoveAttribute()
        {
            int eventsFired = 0;

            Game game = new Game("Test Game");
            game.Attributes.CollectionChanged += (o, e) => eventsFired++;

            Attribute attribute = new Attribute("test");
            game.AddAttribute(attribute);
            game.RemoveAttribute(attribute);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(game.Attributes.Count(x => x.Name == "test"), 0);
        }
Exemplo n.º 4
0
        public void Game_RemoveAttribute()
        {
            var game = new Game("Test Game");
            var attribute = new Attribute("test");
            game.AddAttribute(attribute);
            game.SelectedAttribute = attribute;

            CommandHelper.TestUndoableCommand(
                () => Assert.AreEqual(1, game.Attributes.Count),
                () => game.RemoveAttributeCommand.Execute(null),
                () => Assert.AreEqual(0, game.Attributes.Count)
            );
        }