protected override async Task LoadContent() { await base.LoadContent(); var cube = new Entity { new ModelComponent { Model = Asset.Load <Model>("cube Model") } }; cube.Transform.Scale = new Vector3(10000); cube.Transform.Position = new Vector3(0, 0, 10); Scene.AddChild(cube); var imageElement = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")) }; var imageEntity = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(150) } }; imageEntity.Transform.Position = new Vector3(-500, 0, 0); Scene.AddChild(imageEntity); var imageEntity2 = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(200) } }; imageEntity2.Transform.Position = new Vector3(0, 250, 0); Scene.AddChild(imageEntity2); var imageEntity3 = new Entity { new UIComponent { RootElement = imageElement, IsFullScreen = false, VirtualResolution = new Vector3(250) } }; imageEntity3.Transform.Position = new Vector3(0, 0, -500); Scene.AddChild(imageEntity3); // setup the camera var camera = new TestCamera { Yaw = MathUtil.Pi / 4, Pitch = MathUtil.Pi / 4, Position = new Vector3(500, 500, 500), MoveSpeed = 100 }; camera.SetTarget(cube, true); CameraComponent = camera.Camera; Script.Add(camera); }
/// <summary> /// Shortcut for calling <see cref="Send(string, string, int)"/> followed by <see cref="AssertReply(string, string, uint, string[], string, int)"/>. /// </summary> /// <param name="userSays">The text of the message to send.</param> /// <param name="expected">The expected text of a message from the bot.</param> /// <param name="description">A message to send if the actual response is not as expected.</param> /// <param name="timeout">The amount of time in milliseconds within which a response is expected.</param> /// <param name="path">path.</param> /// <param name="line">line number.</param> /// <returns>A new <see cref="TestScript"/> object that appends this exchange to the modeled exchange.</returns> /// <remarks>This method does not modify the original <see cref="TestScript"/> object.</remarks> /// <exception cref="Exception">The bot did not respond as expected.</exception> public TestScript Test(string userSays, string expected, string description = null, uint timeout = 3000, [CallerFilePath] string path = "", [CallerLineNumber] int line = 0) { Script.Add(new UserSays(path: path, line: line) { Text = userSays }); Script.Add(new AssertReply(path: path, line: line) { Text = expected, Description = description, Timeout = timeout, Exact = true }); return(this); }
private static Script genVersion(ScriptContext context) { Script script = createEmptyScript(context, "xsharper //version");; script.Id = "version"; script.Add(new Set("process", "${=System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName}")); script.Add(new Set("net", "${=string.Join(', ',(string[])XS.Utils.GetInstalledNETVersions())}")); script.Add(new Print { OutTo = "^bold", Value = HelpHelper.GetLogo(context) }); script.Add(new Print()); script.Add(new Print { Transform = TransformRules.Trim | TransformRules.Expand, NewLine = false, Value = @" Environment: ==================== Operating system : ${=Environment.OSVersion.VersionString} Available .NET Frameworks : ${net} .NET Framework : ${=Environment.Version} Current directory : ${=.CurrentDirectory} Privileges : ${=.IsAdministrator?'Administrator':'Not administrator (use //requireAdmin)'} XSharper executable : ${process} Configuration file : ${=AppDomain.CurrentDomain.SetupInformation.ConfigurationFile} ${=File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)?'':'(does not exist)'} Environment variables: ======================= XSH_PATH : ${%XSH_PATH%|''} XSH_REF : ${%XSH_REF%|''} XSH_COLORS : ${%XSH_COLORS%|''}" }); script.Add(new Print()); return(script); }
/// <summary> /// Adds an assertion that the bot's response is contained within a set of acceptable responses. /// </summary> /// <param name="candidates">The set of acceptable messages.</param> /// <param name="description">A message to send if the actual response is not as expected.</param> /// <param name="timeout">The amount of time in milliseconds within which a response is expected.</param> /// <param name="path">path.</param> /// <param name="line">line number.</param> /// <returns>A new <see cref="TestScript"/> object that appends this assertion to the modeled exchange.</returns> /// <remarks>This method does not modify the original <see cref="TestScript"/> object.</remarks> /// <exception cref="Exception">The bot did not respond as expected.</exception> public TestScript AssertReplyOneOf(string[] candidates, string description = null, uint timeout = 3000, [CallerFilePath] string path = "", [CallerLineNumber] int line = 0) { var assertReplyOneOf = new AssertReplyOneOf(path: path, line: line) { Description = description, Timeout = timeout, Exact = true }; assertReplyOneOf.Text.AddRange(candidates.ToList()); Script.Add(assertReplyOneOf); return(this); }
protected override async Task LoadContent() { await base.LoadContent(); Window.Position = Int2.Zero; // avoid possible side effects due to position of the window in the screen. #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP // Register 3D card name ImageTester.ImageTestResultConnection.DeviceName += "_" + GraphicsDevice.Adapter.Description; #endif Script.Add(RegisterTestsInternal); }
protected override async Task LoadContent() { await base.LoadContent(); CreatePipeline(); // Add custom game init at load time here // ... // Add a custom script Script.Add(GameScript1); await Asset.LoadAsync <SpriteGroup>("nol"); }
public Script Parse(string scriptString) { Script script = new Script(); CommandFactory factory = new CommandFactory(); scriptString = scriptString.Replace("\r\n", "\n"); string[] lines = scriptString.Trim().Split('\n'); script.Add(factory.CreateCommand(lines[0])); //first line is a special command to show form. for(int i = 1; i < lines.Length; i++) { if(lines[i].Trim() == string.Empty) { script.Add(factory.CreateCommand()); } else if(lines[i].Trim().StartsWith("'")) { script.Add(factory.CreateCommand()); } else { //this requires exactly one space between tokens.. *sigh* //don't want to split args or force quotes around strings with spaces.. string thisLine = lines[i]; int firstBreak = thisLine.IndexOf(" "); int secondBreak = thisLine.IndexOf(" ", firstBreak + 1); string control = thisLine.Substring(0, firstBreak); string action = thisLine.Substring(firstBreak + 1, secondBreak - firstBreak - 1); string args = thisLine.Substring(secondBreak + 1); script.Add(factory.CreateCommand(control, action, args)); } } return script; }
/// <summary> /// Adds an assertion that the turn processing logic responds as expected. /// </summary> /// <param name="assertions">assertions.</param> /// <param name="description">A message to send if the actual response is not as expected.</param> /// <param name="timeout">The amount of time in milliseconds within which a response is expected.</param> /// <param name="path">path.</param> /// <param name="line">line number.</param> /// <returns>A new <see cref="TestScript"/> object that appends this assertion to the modeled exchange.</returns> /// <remarks>This method does not modify the original <see cref="TestScript"/> object.</remarks> /// <exception cref="Exception">The bot did not respond as expected.</exception> public TestScript AssertReplyActivity(string[] assertions, string description = null, uint timeout = 3000, [CallerFilePath] string path = "", [CallerLineNumber] int line = 0) { var action = new AssertReplyActivity(path: path, line: line) { Description = description, Timeout = timeout }; if (assertions != null) { action.Assertions.AddRange(assertions); } Script.Add(action); return(this); }
public Script Parse(string scriptString) { Script script = new Script(); CommandFactory factory = new CommandFactory(); scriptString = scriptString.Replace("\r\n", "\n"); string[] lines = scriptString.Trim().Split('\n'); script.Add(factory.CreateCommand(lines[0])); //first line is a special command to show form. for (int i = 1; i < lines.Length; i++) { if (lines[i].Trim() == string.Empty) { script.Add(factory.CreateCommand()); } else if (lines[i].Trim().StartsWith("'")) { script.Add(factory.CreateCommand()); } else { //this requires exactly one space between tokens.. *sigh* //don't want to split args or force quotes around strings with spaces.. string thisLine = lines[i]; int firstBreak = thisLine.IndexOf(" "); int secondBreak = thisLine.IndexOf(" ", firstBreak + 1); string control = thisLine.Substring(0, firstBreak); string action = thisLine.Substring(firstBreak + 1, secondBreak - firstBreak - 1); string args = thisLine.Substring(secondBreak + 1); script.Add(factory.CreateCommand(control, action, args)); } } return(script); }
private static Script execGenerator(ScriptContext context, string c, string prefix, string suffix) { Script script = createEmptyScript(context, "generated"); if (context.Compiler.DefaultNETVersion >= new Version(3, 5)) { // Yeah, I know it's deprecated, and it's best to use full assembly names, but // but I don't really want to scan GAC myself #pragma warning disable 618 context.AddAssembly(Assembly.LoadWithPartialName("System.Xml.Linq"), false); context.AddAssembly(Assembly.LoadWithPartialName("System.Core"), false); #pragma warning restore 618 } script.Add(new Rem { Text = "----- Generated from command line -------" + Environment.NewLine + "\t" + c + Environment.NewLine + "\t ------------" }); script.Parameters.Add(new CommandLineParameter("arg", CommandLineValueCount.Multiple) { Last = true, Default = "", Required = false }); script.UnknownSwitches = true; c = c.Trim(); if (c.StartsWith("\"", StringComparison.Ordinal) && c.EndsWith("\"", StringComparison.Ordinal)) { c = c.Substring(1, c.Length - 2); } if (c == "-") { c = Console.In.ReadToEnd(); } if (c.StartsWith("=")) { prefix = "=" + prefix; c = "${=" + c.Substring(1) + "}"; } if (prefix != null || suffix != null) { c = prefix + Environment.NewLine + c + Environment.NewLine + suffix; } c = c.Replace("`", "\""); AppDomainLoader.progress("Read script begin"); using (new ScriptContextScope(context)) script.Load(c); AppDomainLoader.progress("Read script end"); return(script); }
public override void Bind(Entity entity, Main main, bool creating = false) { entity.CannotSuspend = true; Script script = entity.GetOrCreate <Script>("Script"); script.Add(new CommandBinding(script.Delete, entity.Delete)); this.SetMain(entity, main); entity.Add("Execute", script.Execute, Command.Perms.LinkableAndExecutable); entity.Add("ExecuteOnLoad", script.ExecuteOnLoad); entity.Add("DeleteOnExecute", script.DeleteOnExecute); entity.Add("Script", script.Name, new PropertyEntry.EditorData { Options = FileFilter.Get(main, main.MapDirectory, null, ".cs", delegate() { List <string> scripts = new List <string>(); Assembly assembly = Assembly.GetExecutingAssembly(); foreach (Type type in assembly.GetTypes()) { if (type.Namespace == Script.ScriptNamespace && type.IsClass && type.BaseType == typeof(GameScripts.ScriptBase)) { bool available = false; if (main.Settings.GodModeProperty) { available = true; } else { FieldInfo prop = type.GetField("AvailableInReleaseEditor", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); if ((bool)prop.GetValue(type) == true) { available = true; } } if (available) { scripts.Add(type.Name); } } } return(scripts); }), RefreshOnChange = true, }); entity.Add("Errors", script.Errors, null, true); }
public ScriptNode Deserialize(Instruction instruction) { if (instruction == null) { return(null); } ScriptNode node; if (_nodeByInstruction.TryGetValue(instruction, out node)) { return(node); } node = new ScriptNode(); _nodeByInstruction.Add(instruction, node); _script.Add(node); InstructionSerializer.DeserializeInstruction(instruction, node, this); return(node); }
public void Create(BehaviorCreationTypes type) { CreateNewBehaviorscript(); switch (type) { case BehaviorCreationTypes.SolidObject: Script.Add(new BehaviorscriptCommand("00 09 00 00")); Script.Add(new BehaviorscriptCommand("11 01 00 01")); Script.Add(new BehaviorscriptCommand("2a 00 00 00 00 00 00 00")); Script.Add(new BehaviorscriptCommand("08 00 00 00")); Script.Add(new BehaviorscriptCommand("0c 00 00 00 80 38 39 cc")); Script.Add(new BehaviorscriptCommand("09 00 00 00")); break; } ParseScript(); }
//---------------------------------- public static void Init(string folder = "") { container = new Element(); container.Unclickable = true; container.InnerAlign = GUIAlign.None; InputManager.MouseDown += MouseDown; InputManager.MouseUp += MouseUp; if (folder != "") { string[] files = Directory.GetFiles(folder); scripts = new Script(); string prefix = @" using System; using System.Collections.Generic; using System.Text; using RageEngine.Utils; using System.IO; using SharpDX; using RageEngine.ContentPipeline; using RageEngine.Input; namespace Elements { public class "; string prefix2 = ": Element { public "; string prefix3 = "():base(){}"; string prefixend = "}}"; foreach (String file in files) { if (file == "") { continue; } string name = Path.GetFileNameWithoutExtension(file); StreamReader reader = Resources.GetStreamReader(file); string fileScript = reader.ReadToEnd(); scripts.Add(file, prefix + name + prefix2 + name + prefix3 + fileScript + prefixend); reader.Close(); } scripts.Compile(); } }
protected override Task LoadContent() { EntityAddQueue = new ConcurrentQueue <Entity>(); EntityRemoveQueue = new ConcurrentQueue <Entity>(); // Make camera CamController = new FreeCamera(); Script.Add(CamController); if (ReqFname != null) { // Load the model... var modelFname = ReqFname; LoadModel(modelFname); } Script.AddTask(UpdateFrame); return(base.LoadContent()); }
private void AddSceneToParent([NotNull] Scene scene, [NotNull] Scene parent) { // Add to parent parent.Children.Add(scene); // Add virtual anchor var anchorEntity = new Entity { Id = scene.Id, Name = $"Virtual anchor of scene {scene.Id}" }; // Disable component gizmo anchorEntity.Tags.Add(GizmoBase.NoGizmoKey, true); parent.Entities.Add(anchorEntity); // Create script for virtual anchor var anchorScript = new VirtualAnchorScript(); anchorEntity.Components.Add(anchorScript); // Note: because the script processor is disabled in editor game, we have to add the script manually Script.Add(anchorScript); }
protected override Task LoadContent() { // long press gestures Input.ActivatedGestures.Add(new GestureConfigLongPress()); Input.ActivatedGestures.Add(new GestureConfigLongPress { RequiredNumberOfFingers = 2 }); Input.ActivatedGestures.Add(new GestureConfigLongPress { RequiredNumberOfFingers = 3 }); // drag gestures //Input.ActivatedGestures.Add(new GestureConfigDrag(GestureShape.Horizontal)); //Input.ActivatedGestures.Add(new GestureConfigDrag(GestureShape.Vertical)); //Input.ActivatedGestures.Add(new GestureConfigDrag(GestureShape.Free)); //Input.ActivatedGestures.Add(new GestureConfigDrag(GestureShape.Horizontal) { RequiredNumberOfFingers = 2 }); //Input.ActivatedGestures.Add(new GestureConfigDrag(GestureShape.Vertical) { RequiredNumberOfFingers = 2 }); //Input.ActivatedGestures.Add(new GestureConfigDrag(GestureShape.Free) { RequiredNumberOfFingers = 2 }); // flick gestures //Input.ActivatedGestures.Add(new GestureConfigFlick(GestureShape.Horizontal)); //Input.ActivatedGestures.Add(new GestureConfigFlick(GestureShape.Vertical)); //Input.ActivatedGestures.Add(new GestureConfigFlick(GestureShape.Free)); //Input.ActivatedGestures.Add(new GestureConfigFlick(GestureShape.Horizontal) { RequiredNumberOfFingers = 2 }); //Input.ActivatedGestures.Add(new GestureConfigFlick(GestureShape.Vertical) { RequiredNumberOfFingers = 2 }); //Input.ActivatedGestures.Add(new GestureConfigFlick(GestureShape.Free) { RequiredNumberOfFingers = 2 }); // rotation gestures Input.ActivatedGestures.Add(new GestureConfigComposite()); // taps gestures Input.ActivatedGestures.Add(new GestureConfigTap(1, 1)); Input.ActivatedGestures.Add(new GestureConfigTap(2, 1)); Input.ActivatedGestures.Add(new GestureConfigTap(1, 2)); Input.ActivatedGestures.Add(new GestureConfigTap(2, 2)); Script.Add(LogGestures); return(Task.FromResult(0)); }
protected override async Task LoadContent() { await base.LoadContent(); var knightModel = Asset.Load <Model>("knight Model"); knight = new Entity { new ModelComponent { Model = knightModel } }; knight.Transform.Position = new Vector3(0, 0f, 0f); var animationComponent = knight.GetOrCreate <AnimationComponent>(); animationComponent.Animations.Add("Run", Asset.Load <AnimationClip>("knight Run")); animationComponent.Animations.Add("Idle", Asset.Load <AnimationClip>("knight Idle")); // We will test both non-optimized and optimized clips megalodonClip = CreateModelChangeAnimation(new ProceduralModelDescriptor(new CubeProceduralModel { Size = Vector3.One, MaterialInstance = { Material = knightModel.Materials[0].Material } }).GenerateModel(Services)); knightOptimizedClip = CreateModelChangeAnimation(Asset.Load <Model>("knight Model")); knightOptimizedClip.Optimize(); animationComponent.Animations.Add("ChangeModel1", megalodonClip); animationComponent.Animations.Add("ChangeModel2", knightOptimizedClip); Scene.Entities.Add(knight); camera = new TestCamera(); CameraComponent = camera.Camera; Script.Add(camera); LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true); GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White); camera.Position = new Vector3(6.0f, 2.5f, 1.5f); camera.SetTarget(knight, true); }
public void ScriptProducesStatements() { var a = JS.Id("a"); Script script1 = new Script { JS.Var(a), { JS.For(a.AssignWith(3), a.IsGreaterThan(0), a.PreDecrement()) .Do(JS.Alert(a)), JS.Return(a) } }; Assert.AreEqual(3, script1.Statements.Count); Assert.AreEqual("var a;for(a=3;a>0;--a)alert(a);return a;", script1.ToString()); Script script2 = new Script(); script2.Add(script1); Assert.AreEqual("var a;for(a=3;a>0;--a)alert(a);return a;", script2.ToString()); }
// decode an individual script from a binary stream private static Script ReadScript(BinaryReader reader, uint length) { var result = new Script(); byte code; var initialOffset = reader.BaseStream.Position; while (reader.BaseStream.Position < initialOffset + length) { code = reader.ReadByte(); // something is wrong, abort if (!BattleScriptInstruction.OpCodes.ContainsKey(code)) { break; } var op = BattleScriptInstruction.OpCodes[code]; var args = new List <short>(); // argument values are different lengths, depending on the op foreach (var a in op.Args) { switch (a.Type) { case ArgType.Short: args.Add(reader.ReadInt16()); break; default: args.Add(reader.ReadByte()); break; } } result.Add(new BattleScriptInstruction(op, args.ToArray())); } return(result); }
protected override async Task LoadContent() { await base.LoadContent(); var knightModel = Content.Load <Model>("knight Model"); knight = new Entity { new ModelComponent { Model = knightModel } }; knight.Transform.Position = new Vector3(0, 0f, 0f); var animationComponent = knight.GetOrCreate <AnimationComponent>(); animationComponent.Animations.Add("Run", Content.Load <AnimationClip>("knight Run")); animationComponent.Animations.Add("Idle", Content.Load <AnimationClip>("knight Idle")); // We will test both non-optimized and optimized clips megalodonClip = CreateModelChangeAnimation(new ProceduralModelDescriptor(new CubeProceduralModel { Size = Vector3.One, MaterialInstance = { Material = knightModel.Materials[0].Material } }).GenerateModel(Services)); knightOptimizedClip = CreateModelChangeAnimation(Content.Load <Model>("knight Model")); knightOptimizedClip.Optimize(); animationComponent.Animations.Add("ChangeModel1", megalodonClip); animationComponent.Animations.Add("ChangeModel2", knightOptimizedClip); Scene.Entities.Add(knight); camera = new TestCamera(Services.GetSafeServiceAs <SceneSystem>().GraphicsCompositor); CameraComponent = camera.Camera; Script.Add(camera); camera.Position = new Vector3(6.0f, 2.5f, 1.5f); camera.SetTarget(knight, true); }
protected override async Task LoadContent() { await base.LoadContent(); var cube = new Entity { new ModelComponent { Model = Content.Load <Model>("cube Model") } }; cube.Transform.Scale = new Vector3(10000); cube.Transform.Position = new Vector3(0, 0, 10); Scene.Entities.Add(cube); var imageElement = new ImageElement { Source = (SpriteFromTexture) new Sprite(Content.Load <Texture>("uv")) }; var imageEntity = new Entity { new UIComponent { Page = new UIPage { RootElement = imageElement }, IsFullScreen = false, Resolution = new Vector3(150) } }; imageEntity.Transform.Scale = new Vector3(150); imageEntity.Transform.Position = new Vector3(-500, 0, 0); Scene.Entities.Add(imageEntity); var imageEntity2 = new Entity { new UIComponent { Page = new UIPage { RootElement = imageElement }, IsFullScreen = false, Resolution = new Vector3(200) } }; imageEntity2.Transform.Position = new Vector3(0, 250, 0); imageEntity2.Transform.Scale = new Vector3(200); Scene.Entities.Add(imageEntity2); var imageEntity3 = new Entity { new UIComponent { Page = new UIPage { RootElement = imageElement }, IsFullScreen = false, Resolution = new Vector3(250) } }; imageEntity3.Transform.Position = new Vector3(0, 0, -500); imageEntity3.Transform.Scale = new Vector3(250); Scene.Entities.Add(imageEntity3); // setup the camera var camera = new TestUICamera(Services.GetServiceAs <SceneSystem>().GraphicsCompositor) { Yaw = MathUtil.Pi / 4, Pitch = MathUtil.Pi / 4, Position = new Vector3(500, 500, 500), MoveSpeed = 100 }; camera.SetTarget(cube, true); CameraComponent = camera.Camera; Script.Add(camera); }
protected override async Task LoadContent() { await base.LoadContent(); // setup the camera var camera = new TestCamera { Yaw = 0, Pitch = 0, Position = new Vector3(0, 0, 1000), MoveSpeed = 100 }; CameraComponent = camera.Camera; Script.Add(camera); UIRoot.Transform.Rotation = Quaternion.RotationX(MathUtil.Pi / 3f); UIComponent.RootElement = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")) }; UIComponent.IsFullScreen = false; UIComponent.IsBillboard = false; UIComponent.VirtualResolution = new Vector3(200, 200, 100); var cube = new Entity { new ModelComponent { Model = Asset.Load <Model>("cube Model") } }; cube.Transform.Scale = new Vector3(10000); cube.Transform.Position = new Vector3(0, 0, 10); Scene.AddChild(cube); var font = Asset.Load <SpriteFont>("CourierNew12"); var textBlockZ0 = new TextBlock { Font = font, TextColor = Color.Black, TextSize = 20, Text = "At depth 0", VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true, BackgroundColor = Color.Red }; var entity1 = new Entity { new UIComponent { RootElement = textBlockZ0, IsFullScreen = false, IsBillboard = false, VirtualResolution = new Vector3(150) } }; entity1.Transform.Position = new Vector3(-500, 0, 0); Scene.AddChild(entity1); var textBlockZ500 = new TextBlock { Font = font, TextColor = Color.Black, TextSize = 20, Text = "At depth 300", VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true, BackgroundColor = Color.Red }; var entity2 = new Entity { new UIComponent { RootElement = textBlockZ500, IsFullScreen = false, IsBillboard = false, VirtualResolution = new Vector3(150) } }; entity2.Transform.Position = new Vector3(300, 0, 300); Scene.AddChild(entity2); var textBlockZM500 = new TextBlock { Font = font, TextColor = Color.Black, TextSize = 20, Text = "At depth -300", VerticalAlignment = VerticalAlignment.Center, SynchronousCharacterGeneration = true, BackgroundColor = Color.Red }; var entity3 = new Entity { new UIComponent { RootElement = textBlockZM500, IsFullScreen = false, IsBillboard = false, VirtualResolution = new Vector3(150) } }; entity3.Transform.Position = new Vector3(0, 300, -300); Scene.AddChild(entity3); elements.Add(entity1); elements.Add(entity2); elements.Add(entity3); }
protected override async Task LoadContent() { await base.LoadContent(); CreatePipeline(true); IsMouseVisible = true; //Input.ActivatedGestures.Add(new GestureConfigDrag()); // Creates all primitives // type pos axis var primitives = new List <Tuple <GeometricPrimitive, Vector3, Vector3> > { Tuple.Create(GeometricPrimitive.Cube.New(GraphicsDevice), 2 * Vector3.UnitX, new Vector3(1, 1, 1)), Tuple.Create(GeometricPrimitive.Teapot.New(GraphicsDevice), -2 * Vector3.UnitX, new Vector3(-1, 1, 1)), Tuple.Create(GeometricPrimitive.GeoSphere.New(GraphicsDevice), 2 * Vector3.UnitY, new Vector3(1, 0, 1)), Tuple.Create(GeometricPrimitive.Cylinder.New(GraphicsDevice), -2 * Vector3.UnitY, new Vector3(-1, -1, 1)), Tuple.Create(GeometricPrimitive.Torus.New(GraphicsDevice), 2 * Vector3.UnitZ, new Vector3(1, -1, 1)), Tuple.Create(GeometricPrimitive.Sphere.New(GraphicsDevice), -2 * Vector3.UnitZ, new Vector3(0, 1, 1)), }; primitiveEntities = new Entity[primitives.Count]; rotationAxis = new Vector3[primitives.Count]; var material = Asset.Load <Material>("BasicMaterial"); for (var i = 0; i < primitives.Count; ++i) { var mesh = new Mesh { Draw = primitives[i].Item1.ToMeshDraw(), MaterialIndex = 0, }; mesh.Parameters.Set(RenderingParameters.RenderGroup, RenderGroups.Group1); var entity = new Entity { new ModelComponent { Model = new Model { mesh, material } }, new TransformationComponent { Translation = primitives[i].Item2 } }; Entities.Add(entity); primitiveEntities[i] = entity; rotationAxis[i] = primitives[i].Item3; } var reflectivePrimitive = GeometricPrimitive.Sphere.New(GraphicsDevice); var reflectiveMesh = new Mesh { Draw = reflectivePrimitive.ToMeshDraw(), }; reflectiveMesh.Parameters.Set(RenderingParameters.RenderGroup, RenderGroups.Group2); var reflectEntity = new Entity { new ModelComponent { Model = new Model { reflectiveMesh } }, new TransformationComponent(), new CubemapSourceComponent { IsDynamic = true, Size = 128 } }; Entities.Add(reflectEntity); reflectEntity.Get <ModelComponent>().Parameters.Set(TexturingKeys.TextureCube0, reflectEntity.Get <CubemapSourceComponent>().Texture); var mainCameraTargetEntity = new Entity(Vector3.Zero); Entities.Add(mainCameraTargetEntity); mainCamera = new Entity { new CameraComponent { AspectRatio = 8 / 4.8f, FarPlane = 1000, NearPlane = 1, VerticalFieldOfView = 0.6f, Target = mainCameraTargetEntity, TargetUp = cameraUp, }, new TransformationComponent { Translation = cameraInitPos } }; Entities.Add(mainCamera); RenderSystem.Pipeline.SetCamera(mainCamera.Get <CameraComponent>()); // Add a custom script Script.Add(GameScript1); }
protected override async Task LoadContent() { await base.LoadContent(); var debugSheet = Content.Load <SpriteSheet>("DebugSpriteSheet"); // normal reference one var normal = CreateSpriteEntity(debugSheet, "Normal"); normal.Transform.Position = new Vector3(75, 75, 0); normal.Transform.RotationEulerXYZ = new Vector3(0.8f, 1.2f, 0.3f); normal.Get <SpriteComponent>().CurrentSprite.Center = new Vector2(75); // billboard var billboard = CreateSpriteEntity(debugSheet, "Billboard"); billboard.Transform.Position = new Vector3(150, 150, 0); billboard.Transform.RotationEulerXYZ = new Vector3(0.5f, 1f, 1.5f); billboard.Get <SpriteComponent>().SpriteType = SpriteType.Billboard; // ratio var child = CreateSpriteEntity(debugSheet, "Child", false); child.Transform.Position = new Vector3(100, 0, 0); ratio = CreateSpriteEntity(debugSheet, "OtherRatio"); ratio.Transform.Position = new Vector3(350, 150, 0); ratio.AddChild(child); // depth test var onBack = CreateSpriteEntity(debugSheet, "OnBack"); onBack.Transform.Position = new Vector3(75, 250, 0); onBack.Transform.RotationEulerXYZ = new Vector3(0, 1f, 0); onBack.Get <SpriteComponent>().CurrentSprite.Center = new Vector2(75); var onFront = CreateSpriteEntity(debugSheet, "OnFront"); onFront.Transform.Position = new Vector3(75, 350, 0.1f); onFront.Transform.RotationEulerXYZ = new Vector3(0, 1f, 0); onFront.Get <SpriteComponent>().CurrentSprite.Center = new Vector2(75); var noDepth = CreateSpriteEntity(debugSheet, "NoDepth"); noDepth.Transform.Position = new Vector3(75, 450, 0.2f); noDepth.Get <SpriteComponent>().CurrentSprite.Center = new Vector2(75); noDepth.Get <SpriteComponent>().IgnoreDepth = true; // create the rotating sprites rotatingSprites.Add(CreateSpriteEntity(debugSheet, "Center")); rotatingSprites.Add(CreateSpriteEntity(debugSheet, "TopLeft")); rotatingSprites.Add(CreateSpriteEntity(debugSheet, "OutOfImage")); for (int i = 0; i < rotatingSprites.Count; i++) { // Add some z-offset, so non-deterministic sorting due to threading does not cause issues with blending and depth testing enabled rotatingSprites[i].Transform.Position = new Vector3(ScreenWidth, ScreenHeight, 0) / 2; } // add all the entities to the scene foreach (var entity in entities) { SceneSystem.SceneInstance.RootScene.Entities.Add(entity); } cameraScript = new TestCamera(Services.GetSafeServiceAs <SceneSystem>().GraphicsCompositor); CameraComponent = cameraScript.Camera; Script.Add(cameraScript); cameraScript.Yaw = 0; cameraScript.Pitch = 0; cameraScript.Position = new Vector3(400, 300, 800); }
public FillScript(PageDetails pageDetails, string fillUsername, string fillPassword) { if (pageDetails == null) { return; } DocumentUUID = pageDetails.DocumentUUID; List <PageDetails.Field> usernames = new List <PageDetails.Field>(); List <PageDetails.Field> passwords = new List <PageDetails.Field>(); var passwordFields = pageDetails.Fields.Where(f => f.Type == "password" && f.Viewable).ToArray(); if (!passwordFields.Any()) { // not able to find any viewable password fields. maybe there are some "hidden" ones? passwordFields = pageDetails.Fields.Where(f => f.Type == "password").ToArray(); } foreach (var form in pageDetails.Forms) { var passwordFieldsForForm = passwordFields.Where(f => f.Form == form.Key).ToArray(); passwords.AddRange(passwordFieldsForForm); if (string.IsNullOrWhiteSpace(fillUsername)) { continue; } foreach (var pf in passwordFieldsForForm) { var username = FindUsernameField(pageDetails, pf, false, true); if (username == null) { // not able to find any viewable username fields. maybe there are some "hidden" ones? username = FindUsernameField(pageDetails, pf, true, true); } if (username != null) { usernames.Add(username); } } } if (passwordFields.Any() && !passwords.Any()) { // The page does not have any forms with password fields. Use the first password field on the page and the // input field just before it as the username. var pf = passwordFields.First(); passwords.Add(pf); if (!string.IsNullOrWhiteSpace(fillUsername) && pf.ElementNumber > 0) { var username = FindUsernameField(pageDetails, pf, false, false); if (username == null) { // not able to find any viewable username fields. maybe there are some "hidden" ones? username = FindUsernameField(pageDetails, pf, true, false); } if (username != null) { usernames.Add(username); } } } foreach (var username in usernames) { Script.Add(new List <string> { "click_on_opid", username.OpId }); Script.Add(new List <string> { "fill_by_opid", username.OpId, fillUsername }); } foreach (var password in passwords) { Script.Add(new List <string> { "click_on_opid", password.OpId }); Script.Add(new List <string> { "fill_by_opid", password.OpId, fillPassword }); } if (passwords.Any()) { AutoSubmit = new Submit { FocusOpId = passwords.First().OpId }; } }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("Font"); wireframeState = new RasterizerStateDescription(CullMode.Back) { FillMode = FillMode.Wireframe }; materials.Add(Content.Load <Material>("NoTessellation")); materials.Add(Content.Load <Material>("FlatTessellation")); materials.Add(Content.Load <Material>("PNTessellation")); materials.Add(Content.Load <Material>("PNTessellationAE")); materials.Add(Content.Load <Material>("FlatTessellationDispl")); materials.Add(Content.Load <Material>("FlatTessellationDisplAE")); materials.Add(Content.Load <Material>("PNTessellationDisplAE")); RenderContext.GetShared(Services).RendererInitialized += RendererInitialized; var cube = new Entity("Cube") { new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel { Size = new Vector3(80), MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) }; var sphere = new Entity("Sphere") { new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel { Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) }; var megalodon = new Entity { new ModelComponent { Model = Content.Load <Model>("megalodon Model") } }; megalodon.Transform.Position = new Vector3(0, -30f, -10f); var knight = new Entity { new ModelComponent { Model = Content.Load <Model>("knight Model") } }; knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0); knight.Transform.Position = new Vector3(0, -50f, 20f); knight.Transform.Scale = new Vector3(0.6f); entities.Add(sphere); entities.Add(cube); entities.Add(megalodon); entities.Add(knight); camera = new TestCamera(Services.GetSafeServiceAs <SceneSystem>().GraphicsCompositor); CameraComponent = camera.Camera; Script.Add(camera); // TODO GRAPHICS REFACTOR ChangeModel(0); camera.Position = new Vector3(25, 45, 80); camera.SetTarget(currentEntity, true); }
/// <summary> /// Sends conversation update. /// </summary> /// <param name="path">Optional path to caller file. </param> /// <param name="line">Optional number for the caller's line.</param> /// <returns>Modified TestScript.</returns> public TestScript SendConversationUpdate([CallerFilePath] string path = "", [CallerLineNumber] int line = 0) { Script.Add(new UserConversationUpdate(path: path, line: line)); return(this); }
protected override async Task LoadContent() { await base.LoadContent(); // create pipeline CreatePipeline(); // setup the scene var material = Asset.Load <Material>("BasicMaterial"); teapotEntity = new Entity() { new ModelComponent() { Model = new Model() { material, new Mesh() { Draw = GeometricPrimitive.Teapot.New(GraphicsDevice).ToMeshDraw(), MaterialIndex = 0, } } } }; Entities.Add(teapotEntity); var textureCube = Asset.Load <Texture>("uv_cube"); var staticCubemapEntity = new Entity() { new CubemapSourceComponent(textureCube) { InfluenceRadius = 2f, IsDynamic = false }, new TransformationComponent() { Translation = Vector3.UnitZ } }; Entities.Add(staticCubemapEntity); dynamicCubemapEntity = new Entity() { new CubemapSourceComponent(textureCube) { InfluenceRadius = 0.5f, IsDynamic = false }, new TransformationComponent() { Translation = Vector3.Zero } }; Entities.Add(dynamicCubemapEntity); var mainCamera = new Entity() { new CameraComponent { AspectRatio = 8 / 4.8f, FarPlane = 20, NearPlane = 1, VerticalFieldOfView = 0.6f, Target = teapotEntity, TargetUp = Vector3.UnitY, }, new TransformationComponent { Translation = new Vector3(4, 3, 0) } }; Entities.Add(mainCamera); RenderSystem.Pipeline.SetCamera(mainCamera.Get <CameraComponent>()); Script.Add(GameScript1); }
private static Script getSampleScript(ScriptContext context) { Script script = new Script(); script.Id = "WAIT"; script.VersionInfo.Title = "WAIT"; script.VersionInfo.Value = "(Generated sample script)"; script.EngineVersion = context.CoreVersion.ToString(); script.Parameters.Add( new CommandLineParameter { Default = "2000", Value = "Number of seconds to wait", Description = "seconds", Switch = "seconds", Count = CommandLineValueCount.Single } ); script.Parameters.Add( new CommandLineParameter { Default = "0", Value = "Display this message", Switch = "help", Synonyms = "?;helpme", Unspecified = "true" } ); script.Add(new Code { Value = "Context.WriteLine(\"Hello, world!\");" }); script.Add(new Code { Value = "Context.WriteLine(\"This script will be waiting for {0} seconds.\",c[\"seconds\"]);" }); Timer timer = new Timer { OutTo = "execTime", Format = TimerFormat.TimeSpan }; timer.Add(new Sleep { Timeout = "${seconds}" }); script.AddTry(timer); script.AddTry(new Print { Value="Execution took ${execTime}"}); script.AddTry(new Throw { Value = "Test error" }); script.AddTry(new Print { Value = "This will not be printed" }); script.AddCatch(new Print { Value = "Catched exception: ${=c.CurrentException.Message}" }); script.AddFinally(new Print { Value = "Clean up part" }); return script; }
public Script Sum(Script A, Script B) { Script script = new Script(); script._arr.AddRange(A._arr); script._arr.AddRange(B._arr); script.Add(new SwfDotnet.Format.ActionScript.Action(10)); return script; }
protected override async Task LoadContent() { await base.LoadContent(); spriteBatch = new SpriteBatch(GraphicsDevice); font = Asset.Load <SpriteFont>("Font"); wireframeState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back) { FillMode = FillMode.Wireframe }); materials.Add(Asset.Load <Material>("NoTessellation")); materials.Add(Asset.Load <Material>("FlatTessellation")); materials.Add(Asset.Load <Material>("PNTessellation")); materials.Add(Asset.Load <Material>("PNTessellationAE")); materials.Add(Asset.Load <Material>("FlatTessellationDispl")); materials.Add(Asset.Load <Material>("FlatTessellationDisplAE")); materials.Add(Asset.Load <Material>("PNTessellationDisplAE")); var cube = new Entity("Cube") { new ModelComponent(new ProceduralModelDescriptor(new CubeProceduralModel { Size = new Vector3(80), MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) }; var sphere = new Entity("Sphere") { new ModelComponent(new ProceduralModelDescriptor(new SphereProceduralModel { Radius = 50, Tessellation = 5, MaterialInstance = { Material = materials[0] } }).GenerateModel(Services)) }; var megalodon = new Entity { new ModelComponent { Model = Asset.Load <Model>("megalodon Model") } }; megalodon.Transform.Position = new Vector3(0, -30f, -10f); var knight = new Entity { new ModelComponent { Model = Asset.Load <Model>("knight Model") } }; knight.Transform.RotationEulerXYZ = new Vector3(-MathUtil.Pi / 2, MathUtil.Pi / 4, 0); knight.Transform.Position = new Vector3(0, -50f, 20f); knight.Transform.Scale = new Vector3(0.6f); entities.Add(sphere); entities.Add(cube); entities.Add(megalodon); entities.Add(knight); camera = new TestCamera(); CameraComponent = camera.Camera; Script.Add(camera); LightingKeys.EnableFixedAmbientLight(GraphicsDevice.Parameters, true); GraphicsDevice.Parameters.Set(EnvironmentLightKeys.GetParameterKey(LightSimpleAmbientKeys.AmbientLight, 0), (Color3)Color.White); ChangeModel(0); SetWireframe(true); camera.Position = new Vector3(25, 45, 80); camera.SetTarget(currentEntity, true); }
private void SetupScene() { // Load default graphics compositor SceneSystem.GraphicsCompositor = Content.Load <GraphicsCompositor>("GraphicsCompositor"); Scene = new Scene(); Scene.Entities.Add(Camera); //var ambientLight = new Entity { new LightComponent { Type = new LightAmbient { Color = new ColorRgbProvider(Color.White) }, Intensity = 1 } }; ////var ambientLight = new Entity { new LightComponent { Type = new LightDirectional { Color = new ColorRgbProvider(Color.White) }, Intensity = 1 } }; ////ambientLight.Transform.RotationEulerXYZ = new Vector3(0.0f, (float) Math.PI, 0.0f); //Scene.Entities.Add(ambientLight); var directionalLight = new Entity { new LightComponent { Type = new LightDirectional { Color = new ColorRgbProvider(Color.White), Shadow = { Enabled = true } }, Intensity = 1 }, }; directionalLight.Transform.Rotation = Quaternion.RotationY(MathUtil.PiOverTwo * 0.2f); Scene.Entities.Add(directionalLight); //var pointLight1 = new Entity { new LightComponent() { Type = new LightPoint { Color = new ColorRgbProvider(Color.Red), Radius = 100.0f, Shadow = { Enabled = false } }, Intensity = 1.0f } }; //pointLight1.Transform.Position.X = 5.0f; //Scene.Entities.Add(pointLight1); //var directionalLight2 = new Entity { new LightComponent { Type = new LightSpot { Range = 25, Color = new ColorRgbProvider(Color.White), Shadow = { Enabled = false } }, Intensity = 20 }, }; //directionalLight2.Transform.Position = Vector3.UnitX * 40; //directionalLight2.Transform.Rotation = Quaternion.RotationY(MathUtil.PiOverTwo); //Scene.Entities.Add(directionalLight2); var rand = new Random(); for (int i = 0; i < 512; ++i) { var pointLight1 = new Entity { new LightComponent() { Type = i % 2 == 0 ? (ILight) new LightPoint { Color = new ColorRgbProvider(new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1.0f)), Radius = 2.0f, Shadow = { Enabled = false }, } : new LightSpot { Color = new ColorRgbProvider(new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1.0f)), Range = 4.0f, Shadow = { Enabled = false }, }, Intensity = 10.0f } }; pointLight1.Transform.Position = new Vector3( (float)rand.NextDouble() * 20.0f - 10.0f, (float)rand.NextDouble() * 20.0f - 10.0f, (float)rand.NextDouble() * 20.0f - 10.0f ); Scene.Entities.Add(pointLight1); } SceneSystem.SceneInstance = new SceneInstance(Services, Scene); // Load default graphics compositor SceneSystem.GraphicsCompositor = Content.Load <GraphicsCompositor>("GraphicsCompositor"); camera = new TestCamera(Services.GetSafeServiceAs <SceneSystem>().GraphicsCompositor); CameraComponent = camera.Camera; Script.Add(camera); }