Exemplo n.º 1
0
        public void AddComponentWithExistingDefine()
        {
            Game game = new Game("Test Game");

            Using use = new Using() { File = Path.GetFileName(typeof(TransformComponent).Assembly.Location) };
            game.AddUsing(use);

            Define define = new Define(TransformComponentShort, TransformComponentType);
            use.AddDefine(define);

            Entity entity = new Entity() { Name = "entity" };

            Component component = new Component(game.GetPlugin(TransformComponentShort));
            entity.AddComponent(component);
            game.AddPrototype(entity);

            Assert.AreEqual(1, game.Usings.Count);
            Assert.AreEqual(1, game.Usings.Single().Defines.Count(x => x.Name == TransformComponentShort && x.Class == TransformComponentType));
            Assert.AreEqual(TransformComponentShort, component.Type);
        }
Exemplo n.º 2
0
        public static void AddDefaultUsings(Game game)
        {
            //TODO add functions here as well later
            Using defaults = new Using();
            defaults.File = null;
            List<string> defaultEvts = new List<string>()
            {
                "AttributeChanges",
                "SceneStarts",
                "TriggerOccurs",
                "OnCreate"
            };
            addDefaults(defaults, defaultEvts, "Event");
            List<string> defaultComponents = new List<string>()
            {
                "Transform"
            };
            addDefaults(defaults, defaultComponents, "Component");
            List<string> defaultActions = new List<string>()
            {
                "PushScene",
                "PopScene",
                "ChangeScene",
                "PopScene",
                "FireTrigger",
                "CreateEntity",
                "Destroy",
                "CreateTimer",
                "PauseTimers",
                "ResumeTimers",
                "Quit",
                "PointTowards"
            };
            addDefaults(defaults, defaultActions, "Action");

            List<string> defaultManagers = new List<string>()
            {
                "Time"
            };

            addDefaults(defaults, defaultManagers, "Manager");
            game.AddUsing(defaults);
        }
Exemplo n.º 3
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.º 4
0
        public void RemoveUsing()
        {
            int eventsFired = 0;

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

            Using use = new Using() { File = "Test.dll" };
            game.AddUsing(use);
            game.RemoveUsing(use);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(game.Usings.Count(), 0);
        }
Exemplo n.º 5
0
        public void GetDefinedPlugin()
        {
            Game game = new Game("Test Game");

            Using use = new Using() { File = "Kinectitude.Core.dll" };
            use.AddDefine(new Define(TransformComponentShort, TransformComponentType));
            game.AddUsing(use);

            Plugin plugin = game.GetPlugin(TransformComponentShort);

            Assert.IsNotNull(plugin);
            Assert.AreEqual(TransformComponentType, plugin.ClassName);
        }
Exemplo n.º 6
0
        public void AddUsing()
        {
            bool collectionChanged = false;

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

            Using use = new Using() { File = "Test.dll" };
            game.AddUsing(use);

            Assert.IsTrue(collectionChanged);
            Assert.AreEqual(game.Usings.Count(), 1);
            Assert.AreEqual(game.Usings.First().File, "Test.dll");
        }