public void sort_a_block_with_properties_and_nested_blocks()
        {
            var block = new ObjectBlock("Test");

            block.AddBlock(new PropertyBlock("Prop2"));
            block.AddBlock(new PropertyBlock("Prop1"));

            var nested2 = new ObjectBlock("Nested2");

            nested2.AddBlock(new PropertyBlock("Prop5"));
            nested2.AddBlock(new PropertyBlock("Prop3"));

            block.AddBlock(new ObjectBlock("Nested1"));
            block.AddBlock(nested2);

            block.Sort(new BlockSorter());

            var blocks = block.Blocks.ToArray();

            blocks[0].As <PropertyBlock>().Name.ShouldEqual("Prop1");
            blocks[1].As <PropertyBlock>().Name.ShouldEqual("Prop2");

            blocks[2].As <ObjectBlock>().Name.ShouldEqual("Nested1");

            var nestedProperties = blocks[3].As <ObjectBlock>().Blocks.OfType <PropertyBlock>().ToArray();

            nestedProperties[0].Name.ShouldEqual("Prop3");
            nestedProperties[1].Name.ShouldEqual("Prop5");
        }
Пример #2
0
        private void ForceItem(Camera eye, ObjectBlock @object, ScenarioInstanceBlock instance)
        {
            DrawManager.ClearVisible( );
            using (_bucketManager.Begin( ))
            {
                CacheKey key;
                if ([email protected](out key))
                {
                    return;
                }

                var modelBlock  = @object?.Model.Get <ModelBlock>(key);
                var renderModel = modelBlock?.RenderModel.Get <RenderModelBlock>(key);

                if (renderModel == null)
                {
                    return;
                }

                if (eye.CanSee(instance, @object))
                {
                    Dispatch(eye, @object, instance);
                }
            }
        }
Пример #3
0
        public void testParseAndVerifySimpleValues()
        {
            string        adl     = System.IO.File.ReadAllText(@"..\..\..\..\java-libs\dadl-parser\src\test\resources\simple_values.dadl");
            DADLParser    parser  = new DADLParser(adl);
            ContentObject content = parser.parse();

            Assert.IsNotNull(content);
            Assert.IsNull(content.getComplexObjectBlock());
            Assert.IsNotNull(content.getAttributeValues());
            Assert.AreEqual(1, content.getAttributeValues().size());
            AttributeValue av = (AttributeValue)content.getAttributeValues().get(0);

            Assert.AreEqual("simple_values", av.getId());
            ObjectBlock ob = av.getValue();

            Assert.IsInstanceOfType(ob, typeof(SingleAttributeObjectBlock));
            SingleAttributeObjectBlock single = (SingleAttributeObjectBlock)ob;

            java.util.List values = single.getAttributeValues();
            Assert.AreEqual(10, values.size());
            assertDateTimeValue((AttributeValue)values.get(0), "2007-10-30T09:22:00");
            assertDateValue((AttributeValue)values.get(1), "2008-04-02");
            assertTimeValue((AttributeValue)values.get(2), "11:09:40");
            assertDurationValue((AttributeValue)values.get(3), "PT10M");
            assertStringValue((AttributeValue)values.get(4), "a string value");
            assertCharacterValue((AttributeValue)values.get(5), 'a');
            assertIntegerValue((AttributeValue)values.get(6), 100);
            assertRealValue((AttributeValue)values.get(7), 9.5);
            assertBooleanValue((AttributeValue)values.get(8), true);
        }
        public void get_mapped_children_for_existing_values()
        {
            var block1 = new ObjectBlock();

            block1.AddBlock(new PropertyBlock("Url")
            {
                Value = "url1"
            });

            var block2 = new ObjectBlock();

            block2.AddBlock(new PropertyBlock("Url")
            {
                Value = "url2"
            });

            var collection = new CollectionBlock("feed");

            collection.AddBlock(block1);
            collection.AddBlock(block2);
            theBlock.AddBlock(collection);

            var mappedValueSource = new ObjectBlockValues(theBlock, new FeedObjectSettings(), typeof(Solution));

            var values = mappedValueSource.GetChildren("Feeds").ToArray();

            values[0].Get("Url").ShouldEqual("url1");
            values[1].Get("Url").ShouldEqual("url2");
        }
Пример #5
0
        /// <summary>
        /// Creates an ObjectBlock representing the module.
        /// </summary>
        /// <returns>An ObjectBlock representing the module.</returns>
        public ObjectBlock CreateModuleBlock()
        {
            ObjectBlock block = new ObjectBlock(null, new ModuleBehaviour());

            block.AssignImage(images);
            return(block);
        }
Пример #6
0
        private void assertKeyedObject(KeyedObject ko, int key,
                                       String attribute, String value)
        {
            SimpleValue keyValue = ko.getKey();

            Assert.IsInstanceOfType(keyValue, typeof(IntegerValue));
            IntegerValue iv = (IntegerValue)keyValue;
            //Assert.AreEqual(iv.getValue(), key);

            ObjectBlock ob = ko.getObject();

            Assert.IsInstanceOfType(ob, typeof(SingleAttributeObjectBlock));
            SingleAttributeObjectBlock saob = (SingleAttributeObjectBlock)ob;

            java.util.List attributes = saob.getAttributeValues();
            Assert.AreEqual(attributes.size(), 1);
            AttributeValue av = (AttributeValue)attributes.get(0);

            Assert.AreEqual(av.getId(), attribute);

            ob = av.getValue();
            Assert.IsInstanceOfType(ob, typeof(PrimitiveObjectBlock));
            SimpleValue sv = ((PrimitiveObjectBlock)ob).getSimpleValue();

            Assert.IsInstanceOfType(sv, typeof(StringValue));
            StringValue str = (StringValue)sv;

            Assert.AreEqual(str.getValue(), value);
        }
Пример #7
0
        protected void CreateBlueprints()
        {
            if (!Utils.Nwn2ToolsetFunctions.ToolsetIsOpen())
            {
                return;
            }

            foreach (NWN2ObjectType type in Enum.GetValues(typeof(NWN2ObjectType)))
            {
                try {
                    string bag = String.Format(BlueprintBagNamingFormat, type.ToString());
                    if (!manager.HasBag(bag))
                    {
                        continue;
                    }

                    foreach (INWN2Blueprint blueprint in NWN2GlobalBlueprintManager.GetBlueprintsOfType(type, true, true, true))
                    {
                        ObjectBlock block = blocks.CreateBlueprintBlock(blueprint);
                        manager.AddMoveable(bag, block);
                    }
                }
                catch (Exception e) {
                    MessageBox.Show("Failed to populate bag of " + type + " blueprints.\n\n" + e);
                }
            }
        }
Пример #8
0
        public void CreateInstanceBlocksFromBlueprints(NWN2BlueprintCollection blueprints)
        {
            if (blueprints == null || blueprints.Count == 0)
            {
                return;
            }

            LaunchFlip();

            try {
                foreach (INWN2Blueprint blueprint in blueprints)
                {
                    ObjectBlock block = blocks.CreateInstanceBlockFromBlueprint(blueprint);
                    string      bag   = String.Format(Nwn2MoveableProvider.InstanceBagNamingFormat, blueprint.ObjectType);
                    if (window.BlockBox.HasBag(bag))
                    {
                        window.BlockBox.AddMoveable(bag, block, true);
                        //ActivityLog.Write(new Activity("CreatedBlockFromBlueprint","Block",block.GetLogText()));
                        Log.WriteMessage("created blueprint block (" + block.GetLogText() + ")");
                    }
                }
            }
            catch (Exception x) {
                MessageBox.Show("Something went wrong when creating a block from a blueprint.\n\n" + x);
            }
        }
        public void get_children_for_existing_values()
        {
            var block1 = new ObjectBlock();

            block1.AddBlock(new PropertyBlock("Url")
            {
                Value = "url1"
            });

            var block2 = new ObjectBlock();

            block2.AddBlock(new PropertyBlock("Url")
            {
                Value = "url2"
            });

            var collection = new CollectionBlock("feeds");

            collection.AddBlock(block1);
            collection.AddBlock(block2);
            theBlock.AddBlock(collection);

            var values = theValues.GetChildren("Feeds").ToArray();

            values[0].Get("Url").ShouldEqual("url1");
            values[1].Get("Url").ShouldEqual("url2");
        }
Пример #10
0
        public void CreateNarrativeThreadsBlock(INWN2Blueprint blueprint)
        {
            if (blueprint == null)
            {
                throw new ArgumentNullException("blueprint");
            }

            // Wait for up to 3 seconds for the image to appear:
            WaitForNarrativeThreadsImage(blueprint.Resource.ResRef.Value, 3000);

            Action action = new Action
                            (
                delegate()
            {
                string bag = String.Format(InstanceBagNamingFormat, blueprint.ObjectType.ToString());

                if (manager.HasBag(bag))
                {
                    ObjectBlock block = blocks.CreateInstanceBlockFromBlueprint(blueprint);
                    manager.AddMoveable(bag, block);
                }
            }
                            );

            uiThreadAccess.Dispatcher.Invoke(DispatcherPriority.Normal, action);
        }
Пример #11
0
        /// <summary>
        /// Gets whether a given Moveable represents a blueprint of one of a number of
        /// given types.
        /// </summary>
        /// <param name="moveable">The Moveable to check.</param>
        /// <param name="types">The types of blueprint we're looking for.</param>
        /// <returns>True if the Moveable represents a blueprint of one of the given types;
        /// false otherwise.</returns>
        public static bool IsBlueprint(Moveable moveable, List <NWN2ObjectType> types)
        {
            if (moveable == null)
            {
                throw new ArgumentNullException("moveable");
            }

            ObjectBlock block = moveable as ObjectBlock;

            if (block == null)
            {
                return(false);
            }

            foreach (NWN2ObjectType type in types)
            {
                string desc = String.Format(SubtypeFormat, BlueprintDescription, type.ToString());
                if (block.GetDescriptionOfObjectType() == desc)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #12
0
        /// <summary>
        /// Creates an ObjectBlock representing the player.
        /// </summary>
        /// <returns>An ObjectBlock representing the player.</returns>
        public ObjectBlock CreatePlayerBlock()
        {
            ObjectBlock block = new ObjectBlock(null, new PlayerBehaviour());

            block.AssignImage(images);
            return(block);
        }
Пример #13
0
        private void DispatchDeletion(ObjectBlock objectBlock, dynamic instance)
        {
            if (objectBlock == null)
            {
                return;
            }
            CacheKey cacheKey;

            if (!objectBlock.TryGetCacheKey(out cacheKey))
            {
                return;
            }

            var modelBlock  = objectBlock?.Model.Get <ModelBlock>(cacheKey);
            var renderBlock = modelBlock?.RenderModel.Get <RenderModelBlock>(cacheKey);

            if (renderBlock == null)
            {
                return;
            }

            var sections = renderBlock.Sections;

            foreach (var renderModelSection in sections)
            {
                foreach (var part in renderModelSection.SectionData.SelectMany(u => u.Section.Parts))
                {
                    //_drawManager.RemoveShader( part );
                    _drawManager.RemoveInstance(part, instance);
                }
            }
        }
Пример #14
0
        // Track blocks via the Pixy pan/tilt mechanism
        private ObjectBlock trackBlock(ObjectBlock[] blocks)
        {
            ObjectBlock trackedBlock = null;
            long        maxSize      = 0;

            foreach (ObjectBlock block in blocks)
            {
                if (oldBlock == null || (block.Signature == oldBlock.Signature))
                {
                    long newSize = block.Height * block.Width;
                    if (newSize > maxSize)
                    {
                        trackedBlock = block;
                        maxSize      = newSize;
                    }
                }
            }

            if (trackedBlock != null)
            {
                long panError  = X_CENTER - trackedBlock.X;
                long tiltError = trackedBlock.Y - Y_CENTER;
                panLoop.Update(panError);
                tiltLoop.Update(tiltError);
                pixyCam.SetServos(panLoop.Position, tiltLoop.Position);

                oldBlock = trackedBlock;
            }

            return(trackedBlock);
        }
Пример #15
0
        public void writes_the_values()
        {
            var block = new ObjectBlock();
            block.AddBlock(new PropertyBlock("prop1") { Value = "val1"} );
            block.AddBlock(new PropertyBlock("prop2") { Value = "val2" } );

            block.ToString().ShouldEqual("prop1: 'val1'{0}prop2: 'val2'{0}".ToFormat(Environment.NewLine));
        }
Пример #16
0
        protected void AssignImage(Image image, ObjectBlock block)
        {
            if (block == null)
            {
                throw new ArgumentNullException("block");
            }

            block.DisplayImage = image;
        }
        public void get_child_for_existing_values()
        {
            var child = new ObjectBlock("test");

            child.AddBlock(new PropertyBlock("sub-property"));
            theBlock.AddBlock(child);

            theValues.GetChild("test").Has("sub-property").ShouldBeTrue();
        }
        public void has_child()
        {
            var child = new ObjectBlock("test");

            child.AddBlock(new PropertyBlock("sub-property"));
            theBlock.AddBlock(child);

            theValues.HasChild("test").ShouldBeTrue();
        }
Пример #19
0
        /// <summary>
        /// Gets whether a given Moveable represents a blueprint.
        /// </summary>
        /// <param name="moveable">The Moveable to check.</param>
        /// <returns>True if the Moveable represents a blueprint;
        /// false otherwise.</returns>
        public static bool IsBlueprint(Moveable moveable)
        {
            if (moveable == null)
            {
                throw new ArgumentNullException("moveable");
            }

            ObjectBlock block = moveable as ObjectBlock;

            return(block != null && block.GetDescriptionOfObjectType().StartsWith(BlueprintDescription));
        }
Пример #20
0
        /// <summary>
        /// Gets whether a given Moveable represents an area.
        /// </summary>
        /// <param name="moveable">The Moveable to check.</param>
        /// <returns>True if the Moveable represents an area;
        /// false otherwise.</returns>
        public static bool IsArea(Moveable moveable)
        {
            if (moveable == null)
            {
                throw new ArgumentNullException("moveable");
            }

            ObjectBlock block = moveable as ObjectBlock;

            return(block != null && block.GetDescriptionOfObjectType() == AreaDescription);
        }
Пример #21
0
        // Follow blocks via the Zumo robot drive
        // This code makes the robot base turn and move to follow the pan/tilt tracking of the head
        private void followBlock(ObjectBlock trackedBlock)
        {
            long followError = RCS_CENTER_POS - panLoop.Position;

            // Size is the area of the object
            // We keep a running average of the last 8
            size += trackedBlock.Width * trackedBlock.Height;
            size -= size >> 3;

            // Forward speed decreases as we approach the object (size is larger)
            int forwardSpeed = Constrain(400 - ((int)size / 256), -100, 400);

            // Steering differential is proportional to the error times the forward speed
            long differential = (followError + (followError * forwardSpeed)) >> 8;

            // Adjust the left and right speeds by the steering differential
            int leftSpeed  = Constrain((int)(forwardSpeed + differential), -400, 400);
            int rightSpeed = Constrain((int)(forwardSpeed - differential), -400, 400);

            float leftPower, rightPower;
            ZumoMotorDirection leftDir, rightDir;

            if (leftSpeed >= 0)
            {
                leftDir = ZumoMotorDirection.Forward;
            }
            else
            {
                leftDir = ZumoMotorDirection.Backward;
            }

            if (rightSpeed >= 0)
            {
                rightDir = ZumoMotorDirection.Forward;
            }
            else
            {
                rightDir = ZumoMotorDirection.Backward;
            }

            leftPower  = Math.Abs(leftSpeed) / 500.0f;
            rightPower = Math.Abs(rightSpeed) / 500.0f;

            Debug.WriteLine(
                string.Format("followError={0}, size={1}, differential={2}, leftPower={3}, rightPower={4}",
                              followError,
                              size,
                              differential,
                              leftPower,
                              rightPower));

            motorDriver.SetLeftMotorPower(leftDir, leftPower);
            motorDriver.SetRightMotorPower(rightDir, rightPower);
        }
Пример #22
0
        // LogicBlock일때
        private void ConnectBlock(ObjectBlock block, MouseEventArgs e)
        {
            if (SelectedBlock is SettableObjectBlock && MargnetTarget is SettableObjectHole)
            {
                var settableObjectBlock = block as SettableObjectBlock;
                var settableObjectHole  = MargnetTarget as SettableObjectHole;

                // 연결 대상에 이미 블럭이 존재하는 경우
                if (settableObjectHole.SettableObjectBlock != null)
                {
                    // 기존 블럭을 캔버스로 이동
                    var detachedBlock = settableObjectHole.DetachBlock();

                    if (detachedBlock != null)
                    {
                        AttachToCanvas(detachedBlock);

                        detachedBlock.Position = block.Position;
                    }
                }

                // 블럭을 캔버스에서 연결 대상으로 이동
                DetachFromCanvas(block);
                settableObjectHole.SettableObjectBlock = settableObjectBlock;

                // 블럭 위치 재조정
                block.Position = new Point(0, 0);
            }
            else if (MargnetTarget is BaseObjectHole)
            {
                var objectHole = MargnetTarget as BaseObjectHole;

                // 연결 대상에 이미 블럭이 존재하는 경우
                if (objectHole.BaseObjectBlock != null)
                {
                    // 기존 블럭을 캔버스로 이동
                    var detachedBlock = objectHole.DetachBlock();

                    if (detachedBlock != null)
                    {
                        AttachToCanvas(detachedBlock);

                        detachedBlock.Position = block.Position;
                    }
                }

                // 블럭을 캔버스에서 연결 대상으로 이동
                DetachFromCanvas(block);
                objectHole.BaseObjectBlock = block;

                // 블럭 위치 재조정
                block.Position = new Point(0, 0);
            }
        }
Пример #23
0
        /// <summary>
        /// Gets whether a given Moveable represents a blueprint of a particular type.
        /// </summary>
        /// <param name="moveable">The Moveable to check.</param>
        /// <param name="type">The type of blueprint we're looking for.</param>
        /// <returns>True if the Moveable represents a blueprint of the given type;
        /// false otherwise.</returns>
        public static bool IsBlueprint(Moveable moveable, NWN2ObjectType type)
        {
            if (moveable == null)
            {
                throw new ArgumentNullException("moveable");
            }

            ObjectBlock block = moveable as ObjectBlock;
            string      desc  = String.Format(SubtypeFormat, BlueprintDescription, type.ToString());

            return(block != null && block.GetDescriptionOfObjectType() == desc);
        }
Пример #24
0
        private Point getPuckPosition(ObjectBlock block)
        {
            if (block != null)
            {
                if (block.Signature == 1 && block.Width >= 5 && block.Height >= 5)
                {
                    return(CoordinateHelper.TranslatePoint(block.X, block.Y));
                }
            }

            return(CoordinateHelper.INVALID_POINT);
        }
Пример #25
0
        /// <summary>
        /// Creates an ObjectBlock representing a given area.
        /// </summary>
        /// <param name="area">An object representing the behaviour of
        /// and information about the ObjectBlock which is to be created.</param>
        /// <returns>An ObjectBlock representing the given area.</returns>
        public ObjectBlock CreateAreaBlock(AreaBehaviour area)
        {
            if (area == null)
            {
                throw new ArgumentNullException("area");
            }

            ObjectBlock block = new ObjectBlock(null, area);

            block.AssignImage(images);
            return(block);
        }
Пример #26
0
        public ObjectBlock CreateBlueprintBlock(BlueprintBehaviour behaviour)
        {
            if (behaviour == null)
            {
                throw new ArgumentNullException("behaviour");
            }

            ObjectBlock block = new ObjectBlock(null, behaviour);

            block.AssignImage(images);
            return(block);
        }
Пример #27
0
        /// <summary>
        /// Creates an ObjectBlock representing a wildcard.
        /// </summary>
        /// <returns>An ObjectBlock representing a wildcard.</returns>
        public ObjectBlock CreateWildcardBlock(WildcardBehaviour wildcard)
        {
            if (wildcard == null)
            {
                throw new ArgumentNullException("wildcard");
            }

            ObjectBlock block = new ObjectBlock(null, wildcard);

            block.AssignImage(images);
            return(block);
        }
Пример #28
0
        /// <summary>
        /// Creates an ObjectBlock representing a given area.
        /// </summary>
        /// <param name="area">The area to represent.</param>
        /// <returns>An ObjectBlock representing the given area.</returns>
        public ObjectBlock CreateAreaBlock(NWN2GameArea area)
        {
            if (area == null)
            {
                throw new ArgumentNullException("area");
            }

            AreaBehaviour behaviour = CreateAreaBehaviour(area);

            ObjectBlock block = CreateAreaBlock(behaviour);

            return(block);
        }
Пример #29
0
        public ObjectBlock CreateInstanceBlock(INWN2Instance instance, NWN2GameArea area)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            InstanceBehaviour behaviour = CreateInstanceBehaviour(instance, area);

            ObjectBlock block = CreateInstanceBlock(behaviour);

            return(block);
        }
Пример #30
0
        public ObjectBlock CreateInstanceBlockFromBlueprint(INWN2Blueprint blueprint)
        {
            if (blueprint == null)
            {
                throw new ArgumentNullException("blueprint");
            }

            InstanceBehaviour behaviour = CreateInstanceBehaviourFromBlueprint(blueprint);

            ObjectBlock block = CreateInstanceBlock(behaviour);

            return(block);
        }
        public void If_PreviousBlock_ThenLastBlockHasCorrectObjectValue()
        {
            // ARRANGE
            // Create previous blocks
            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = executionContext.TryStart();
                if (startedOk)
                {
                    var blocks = executionContext.GetObjectBlocks<string>(x => x.WithObject("Testing123"));

                    foreach (var block in blocks)
                    {
                        block.Start();
                        block.Complete();
                    }
                }
            }

            var expectedLastBlock = new ObjectBlock<string>()
            {
                Object = "Testing123"
            };

            // ACT
            IObjectBlock<string> lastBlock = null;
            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = executionContext.TryStart();
                if (startedOk)
                {
                    lastBlock = executionContext.GetLastObjectBlock<string>();
                }
            }

            // ASSERT
            Assert.AreEqual(expectedLastBlock.Object, lastBlock.Object);
        }