예제 #1
0
        public void TestWorldValidator_DialogueOptionWithMissingDestination()
        {
            var w = new WorldFactory {
                ResourcesDirectory = EmptyDir
            }.Create();
            var v = new WorldValidator();

            var d = new DialogueNode()
            {
                Identifier = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905"),
                Body       = new List <TextBlock>
                {
                    new TextBlock("I dare say")
                },
                Options =
                {
                    new DialogueOption()
                    {
                        Text = "Rather!",

                        //This is missing
                        Destination = new Guid("d7bcff5f-31a4-41ad-a71e-9b51a6565fc3")
                    }
                }
            };

            w.Dialogue.AllDialogues.Add(d);

            v.ValidateDialogue(w, w.Player, new DialogueInitiation()
            {
                Next = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905")
            }, w.Player.CurrentLocation);

            StringAssert.Contains("Could not find Dialogue 'd7bcff5f-31a4-41ad-a71e-9b51a6565fc3", v.Errors.ToString());
        }
예제 #2
0
        public void TestWorldValidator_DialogueOptionWithNoText()
        {
            var world =
                new WorldFactory {
                ResourcesDirectory = EmptyDir
            }
            .Create();

            var v = new WorldValidator();

            var d = new DialogueNode()
            {
                Identifier = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905"),
                Body       = new List <TextBlock>
                {
                    new TextBlock("I dare say")
                },
                Options = { new DialogueOption() }
            };

            world.Dialogue.AllDialogues.Add(d);

            v.ValidateDialogue(world, world.Player, new DialogueInitiation()
            {
                Next = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905")
            }, world.Player.CurrentLocation);

            StringAssert.Contains("A Dialogue Option of Dialogue '1cf15faf-837b-4629-84c5-bdfa7631a905' has no Text", v.Errors.ToString());
        }
예제 #3
0
        public void TestValidate_BadBehaviour()
        {
            WorldValidator v = new WorldValidator();

            var w    = new World();
            var blue = new ItemBlueprint
            {
                Name       = "Hammer",
                Behaviours =
                    new List <BehaviourBlueprint>()
                {
                    new BehaviourBlueprint()
                    {
                        OnPush = new BehaviourEventHandlerBlueprint()
                        {
                            Effect = new List <EffectBlueprint> {
                                new EffectBlueprint {
                                    Lua = "aa + bb + cc"
                                }
                            }
                        }
                    }
                }
            };

            v.ValidateItem(w, w.ItemFactory.Create(w, blue), new Room("Test Room", w, 't'));

            StringAssert.Contains(@"Error testing OnPush of Behaviour Unnamed Object of on 'Hammer' in room 'Test Room' with test actor 'test actor'", v.Warnings.ToString());
        }
예제 #4
0
        public void TestEmpty()
        {
            var dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "EmptyDir"));

            if (dir.Exists)
            {
                dir.Delete(true);
            }

            dir.Create();

            var f = new WorldFactory()
            {
                ResourcesDirectory = dir.FullName
            };

            f.Create();

            var v = new WorldValidator();

            v.Validate(f);
            Assert.IsEmpty(v.Errors.ToString());
            Assert.IsEmpty(v.Warnings.ToString());
            Assert.AreEqual(0, v.ErrorCount);
            Assert.AreEqual(0, v.WarningCount);
        }
예제 #5
0
        public void TestWorldValidator_BadYaml()
        {
            var dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "BadYamlDir"));

            if (dir.Exists)
            {
                dir.Delete(true);
            }

            dir.Create();

            var f = new WorldFactory()
            {
                ResourcesDirectory = dir.FullName
            };

            File.WriteAllText(Path.Combine(dir.FullName, "rooms.yaml"), "ffffff");

            var v = new WorldValidator();

            v.Validate(f);
            StringAssert.Contains("Error Creating World", v.Errors.ToString());
            StringAssert.Contains("Error loading RoomBlueprint in file", v.Errors.ToString());
            StringAssert.Contains("rooms.yaml", v.Errors.ToString());


            Assert.IsEmpty(v.Warnings.ToString());
            Assert.AreEqual(1, v.ErrorCount);
            Assert.AreEqual(0, v.WarningCount);
        }
예제 #6
0
        public void TestValidate_SlotNotFound()
        {
            WorldValidator v = new WorldValidator();

            var w    = new World();
            var blue = new ItemBlueprint
            {
                Name = "Hammer",
                Slot = new ItemSlot("Handers", 5)
            };

            v.ValidateItem(w, w.ItemFactory.Create(w, blue), Mock.Of <IRoom>());

            StringAssert.Contains(@"Item Hammer lists Slot named Handers but no Actors or Default slots are listed with that name (Slots seen were '')", v.Warnings.ToString());
        }
예제 #7
0
        public void TestValidate_BadPlanCondition()
        {
            WorldValidator v = new WorldValidator();

            var plan = new Plan()
            {
                Condition =
                {
                    new ConditionCode("this is bat country")
                }
            };

            v.Validate(Mock.Of <IWorld>(), plan, Mock.Of <IActor>());

            StringAssert.Contains("Error executing 'ConditionCode' script code 'return this is bat country'.", v.Warnings.ToString());
        }
예제 #8
0
        public void TestWorldValidator_Success()
        {
            var v = new WorldValidator();

            v.IncludeStackTraces = true;
            v.Validate(new WorldFactory()
            {
                ResourcesDirectory = NormalResourcesDirectory
            });

            Assert.IsEmpty(v.Errors.ToString());
            Assert.IsEmpty(v.Warnings.ToString());

            Assert.AreEqual(0, v.WarningCount);
            Assert.AreEqual(0, v.ErrorCount);
        }
예제 #9
0
        public void TestValidate_BadPlanMissingDoFrame()
        {
            WorldValidator v = new WorldValidator();

            var plan = new Plan()
            {
                Name      = "Do something nefarious",
                Condition =
                {
                    new ConditionCode("true")
                }
            };

            v.Validate(Mock.Of <IWorld>(), plan, Mock.Of <IActor>());

            StringAssert.Contains("Plan 'Do something nefarious' has no DoFrame", v.Errors.ToString());
        }
예제 #10
0
        public void TestValidate_BadPlanBadDoFrame()
        {
            WorldValidator v = new WorldValidator();

            var plan = new Plan()
            {
                Name      = "Do something nefarious",
                Condition =
                {
                    new ConditionCode("true")
                },
                Do = new FrameSourceCode("fffff")
            };

            v.Validate(Mock.Of <IWorld>(), plan, Mock.Of <IActor>());

            StringAssert.Contains(@"Failed to validate DoFrame of Plan 'Do something nefarious'", v.Warnings.ToString());
        }
예제 #11
0
        public async Task Validate_Type_Privacy(bool valid, AccountType type, WorldPrivacy privacy)
        {
            using (var provider = await CreateProvider())
            {
                var worlds = provider.GetRequiredService <IWorldRepository>();

                IValidator <World> validator = new WorldValidator(worlds);

                var world = new World {
                    Account = new Account {
                        Type = type,
                    },
                    Privacy = privacy
                };

                var target = new ValidationTarget <World>(world);
                validator.Validate(target);
                Assert.Equal(valid, !target.GetResult().HasErrors);
            }
        }
예제 #12
0
        public void TestWorldValidator_DialogueWithNoText()
        {
            var w = new WorldFactory {
                ResourcesDirectory = EmptyDir
            }.Create();
            var v = new WorldValidator();

            var d = new DialogueNode()
            {
                Identifier = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905")
            };

            w.Dialogue.AllDialogues.Add(d);

            v.ValidateDialogue(w, w.Player, new DialogueInitiation()
            {
                Next = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905")
            }, w.Player.CurrentLocation);

            StringAssert.Contains("Dialogue '1cf15faf-837b-4629-84c5-bdfa7631a905' has no Body Text", v.Errors.ToString());
        }
예제 #13
0
        protected IWorld Setup(params string[] pairs)
        {
            List <WorldFactoryResource> resources = new List <WorldFactoryResource>();

            for (int i = 0; i < pairs.Length; i += 2)
            {
                resources.Add(new WorldFactoryResource(pairs[i], pairs[i + 1]));
            }

            var wf = new CookBookWorldFactory(resources);

            //make sure that the directory setup passes validation
            var validator = new WorldValidator();

            validator.Validate(wf);

            Assert.AreEqual(0, validator.Warnings.Length, "Recipe resulted in warnings during world validation: " + validator.Warnings);
            Assert.AreEqual(0, validator.Errors.Length, "Recipe resulted in errors during world validation: " + validator.Errors);

            return(wf.Create());
        }
예제 #14
0
        [TestCase("sdf sdf sdf", "syntax error near 'sdf'")] // bad compile time value
        public void TestWorldValidator_DialogueOptionWithBadEffectCode(string badCode, string expectedError)
        {
            var w = new WorldFactory {
                ResourcesDirectory = EmptyDir
            }.Create();
            var v = new WorldValidator();

            var d = new DialogueNode()
            {
                Identifier = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905"),
                Body       = new List <TextBlock>
                {
                    new TextBlock("I dare say")
                },
                Options =
                {
                    new DialogueOption()
                    {
                        Text   = "Do stuff",
                        Effect =
                        {
                            new EffectCode(badCode)
                        }
                    }
                }
            };

            w.Dialogue.AllDialogues.Add(d);

            v.ValidateDialogue(w, w.Player, new DialogueInitiation()
            {
                Next = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905")
            }, w.Player.CurrentLocation);


            StringAssert.Contains("Error testing EffectCode of Option 'Do stuff' of Dialogue '1cf15faf-837b-4629-84c5-bdfa7631a905'", v.Warnings.ToString());
            StringAssert.Contains(expectedError, v.Warnings.ToString());
        }
예제 #15
0
        public void TestWorldValidator_BadConditionCode()
        {
            var w = new WorldFactory {
                ResourcesDirectory = EmptyDir
            }.Create();
            var v = new WorldValidator();

            var d = new DialogueNode()
            {
                Identifier = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905"),
                Condition  = { new ConditionCode("Tr oll oll = 1") }
            };

            w.Dialogue.AllDialogues.Add(d);

            v.ValidateDialogue(w, w.Player, new DialogueInitiation()
            {
                Next = new Guid("1cf15faf-837b-4629-84c5-bdfa7631a905")
            }, w.Player.CurrentLocation);

            StringAssert.Contains("Error testing dialogue condition on '1cf15faf-837b-4629-84c5-bdfa7631a905'", v.Warnings.ToString());
            StringAssert.Contains("<eof> expected near 'oll'", v.Warnings.ToString());
        }
예제 #16
0
        public void TestWorldValidator_MissingDialogue()
        {
            var v = new WorldValidator();
            var f = new WorldFactory
            {
                ResourcesDirectory = NormalResourcesDirectory
            };

            var w = f.Create();

            w.Dialogue.AllDialogues.Clear();
            w.RoomFactory.Blueprints.Add(new RoomBlueprint()
            {
                Dialogue = new DialogueInitiation()
                {
                    Next = Guid.NewGuid()
                }
            });
            v.Validate(w);

            Assert.AreEqual(v.ErrorCount, 1);

            StringAssert.Contains("Could not find Dialogue", v.Errors.ToString());
        }
        public static void Build()
        {
            if (Application.isBatchMode)
            {
                Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
            }

            ParseCommandLineArguments(out var args);
            BuildConfig config = new BuildConfig(args);

            if (Application.isEditor && !Application.isBatchMode)
            {
                bool confirmed = EditorUtility.DisplayDialog($"Create build {config.buildName}?", $"This will replace the contents of\n{Path.GetFullPath(config.buildRoot)}", "Continue");
                if (!confirmed)
                {
                    return;
                }
            }

            AssetBundle.UnloadAllAssetBundles(true);

            Debug.Log("Validating Project...");
            WorldDefinition worldDefinition = null;
            var             worldInfos      = WorldInfoEditor.GetAllWorldInfos().ToList();

            if (worldInfos.Count == 0)
            {
                Debug.Log("No WorldInfo assets found");
            }
            else if (worldInfos.Count > 1)
            {
                Error("More than one WorldInfo assets exists in project. This is a limitation of our current bundle distribution system.");
                return;
            }
            else
            {
                Debug.Log("WORLD INFOS: " + string.Join(" ", worldInfos));
                var worldInfo       = worldInfos.First();
                var worldInfoPath   = AssetDatabase.GetAssetPath(worldInfo);
                var worldInfoBundle = AssetDatabase.GetImplicitAssetBundleName(worldInfoPath);
                worldDefinition = new WorldDefinition
                {
                    name       = Application.productName,
                    version    = Application.version,
                    infoAsset  = worldInfoPath,
                    infoBundle = worldInfoBundle
                };
                Debug.Log($"SELECTED: {worldInfo} at {worldInfoPath} from {worldInfoBundle}");

                WorldInfoEditor.PrepareAllForBuildSynchronously();
                if (!WorldValidator.ValidateAll())
                {
                    Error("Failed to Validate WorldInfo");
                }
            }

            Debug.Log("Building Project...");
            if (Directory.Exists(config.buildRoot))
            {
                Directory.Delete(config.buildRoot, recursive: true);
            }
            Directory.CreateDirectory(config.buildRoot);
            foreach (var target in config.targets)
            {
                DoBuild(config, target);
            }

            Debug.Log("Building Manifest...");
            var manifestBundlePath = config.buildRoot + "/" + config.GetManifestPath(config.targets.First());
            var manifestBundle     = AssetBundle.LoadFromFile(manifestBundlePath);
            var manifest           = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            var manifestJson       = $"{config.BuildPath}/manifest.json";

            using (StreamWriter file = new StreamWriter(manifestJson))
            {
                var bundleSet = new BundleSetDefinition
                {
                    uriRoot     = config.uriRoot,
                    androidPath = config.GetManifestPath(BuildTarget.Android),
                    osxPath     = config.GetManifestPath(BuildTarget.StandaloneOSX),
                    windowsPath = config.GetManifestPath(BuildTarget.StandaloneWindows),
                    iosPath     = config.GetManifestPath(BuildTarget.iOS),
                    bundlePaths = manifest.GetAllAssetBundles()
                };
                BundleSetDefinition bundlesForManifest = null;
                if (worldDefinition == null)
                {
                    bundlesForManifest = bundleSet;
                }
                else
                {
                    worldDefinition.bundles = bundleSet;
                }
                file.Write(JsonUtility.ToJson(new ProjectManifest {
                    isAWorldProject = worldDefinition != null,
                    world           = worldDefinition,
                    bundles         = bundlesForManifest
                }));
            }

            Debug.Log($"Build Completed for {config.buildName} version {config.version} at {config.BuildPath}");
            if (Application.isBatchMode)
            {
                ExitWithResult(BuildResult.Succeeded);
            }
        }
예제 #18
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments<Options>(args)
                   .WithParsed<Options>(o =>
                   {

                       if(!string.IsNullOrWhiteSpace(o.CompileDialogue))
                       {
                           var b = new DialogueBuilder();
                           try
                           {
                                var result = b.BuildAndSerialize(new FileInfo(o.CompileDialogue));
                                
                                if(result == null)
                                    Console.WriteLine("No file created");
                                else
                                    Console.WriteLine("Created " + result.FullName);
                           }
                           catch(Exception ex)
                           {
                               Console.WriteLine(ex.Message);
                           }
                           return;
                       }

                       var f = new WorldFactory();
                       if(o.ResourcesDirectory != null)
                            f.ResourcesDirectory = o.ResourcesDirectory;

                       if (o.Validate)
                       {
                           var validator = new WorldValidator();
                            validator.IncludeStackTraces = o.StackTraces;
                            validator.Validate(f);
                            

                            if(validator.Warnings.Length > 0)
                            {
                                Console.WriteLine("WARNINGS:");
                                Console.WriteLine(validator.Warnings);
                            }

                            if(validator.Errors.Length > 0)
                            {
                                Console.WriteLine("ERRORS:");
                                Console.WriteLine(validator.Errors);
                            }


                            Console.WriteLine("Finished Validation:");
                            Console.WriteLine(validator.ErrorCount + " Errors");
                            Console.WriteLine(validator.WarningCount + " Warnings");
                       }
                       else
                       {
                            //Don't log to the console when Console Gui is running 
                            LogManager.Configuration.RemoveTarget("logconsole");

                            Application.Init();
                            var mainWindow = new MainWindow(f);
                            Application.Top.Add(mainWindow);
                            Application.Run();                
                       }
                   });
        }
예제 #19
0
        private static Dictionary <string, Breed> BuildBreedDefinitions()
        {
            string worldDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/StandingData");

            string pathToWorld = worldDirectory + "/Monsters.xml";

            if (!File.Exists(pathToWorld))
            {
                throw new ArgumentOutOfRangeException(pathToWorld);
            }

            var xmlDoc = new XmlDocument();

            xmlDoc.Load(pathToWorld);

            var validator = new WorldValidator();
            var pathToXsd = worldDirectory + "/MonstersSchema.xsd";

            validator.Validate(xmlDoc.OuterXml, pathToXsd);

            var xmlRoot = xmlDoc.DocumentElement;

            if (xmlRoot == null)
            {
                throw new InvalidOperationException("Empty xml document.");
            }
            var xnm = new XmlNamespaceManager(xmlDoc.NameTable);

            xnm.AddNamespace("ns", "http://JonSaffron/Labyrinth/Monsters");

            var result = new Dictionary <string, Breed>();

            foreach (XmlElement breedElement in xmlRoot.SelectNodesEx("ns:Breed", xnm))
            {
                var breed = new Breed
                {
                    Name    = breedElement.GetAttribute(nameof(Breed.Name)),
                    Texture = breedElement.GetAttribute(nameof(Breed.Texture)),
                    BaseMovesDuringAnimation = int.Parse(breedElement.GetAttribute(nameof(Breed.BaseMovesDuringAnimation)))
                };

                XmlElement inherentBehaviours = (XmlElement)breedElement.SelectSingleNode("ns:InherentBehaviours", xnm);
                if (inherentBehaviours != null)
                {
                    foreach (XmlElement behaviour in inherentBehaviours.ChildNodes)
                    {
                        breed.InherentBehaviours.Add(behaviour.LocalName);
                    }
                }

                XmlElement inherentProperties = (XmlElement)breedElement.SelectSingleNode("ns:InherentProperties", xnm);
                if (inherentProperties != null)
                {
                    foreach (XmlElement property in inherentProperties.ChildNodes)
                    {
                        var propertyValue = property.GetAttribute("value");
                        breed.InherentProperties.Add(property.Name, propertyValue);
                    }
                }

                XmlElement movement = (XmlElement)breedElement.SelectSingleNode("ns:Movement", xnm);
                if (movement != null)
                {
                    var defaultMobility = movement.GetAttribute("Default");
                    if (!string.IsNullOrWhiteSpace(defaultMobility))
                    {
                        breed.BreedMovement.DefaultMobility = (MonsterMobility)Enum.Parse(typeof(MonsterMobility), defaultMobility);
                    }
                    var changeRooms = movement.GetAttribute("ChangeRooms");
                    if (!string.IsNullOrWhiteSpace(changeRooms))
                    {
                        breed.BreedMovement.ChangeRooms = (ChangeRooms)Enum.Parse(typeof(ChangeRooms), changeRooms);
                    }
                    var speed = movement.GetAttribute("Speed");
                    if (!string.IsNullOrWhiteSpace(speed))
                    {
                        breed.BreedMovement.Speed = decimal.Parse(speed);
                    }

                    foreach (XmlElement moveElement in movement.SelectNodesEx("ns:Move", xnm))
                    {
                        var type           = (MonsterMobility)Enum.Parse(typeof(MonsterMobility), moveElement.GetAttribute("Type"));
                        var implementation = moveElement.GetAttribute("Implementation");
                        breed.BreedMovement.Moves.Add(type, implementation);
                    }
                }

                result.Add(breed.Name, breed);
            }

            return(result);
        }