コード例 #1
0
 /**
  * @param gries\MControl\Server\Commander $commander
  * @param gries\MControl\Builder\Structure $structure
  * @param gries\MControl\Builder\Block     $block1
  * @param gries\MControl\Builder\Block     $block2
  */
 function it_builds_the_structure_at_the_correct_starting_point(Commander $commander, Structure $structure, Block $block1, Block $block2)
 {
     $this->beConstructedWith($commander);
     // fixtures
     $block1->getCoordinates()->willReturn(array('x' => 1, 'y' => 1, 'z' => 1));
     $block1->getType()->willReturn('iron_block');
     $block1->getMeta()->willReturn(1);
     $block2->getCoordinates()->willReturn(array('x' => 1, 'y' => 2, 'z' => 1));
     $block2->getType()->willReturn('diamond_block');
     $block2->getMeta()->willReturn(0);
     $structure->getBlocks()->willReturn(array($block1, $block2));
     // mocks
     $commander->setBlock('iron_block', array('x' => 143, 'y' => 55, 'z' => -70), 1)->shouldBeCalled();
     $commander->setBlock('diamond_block', array('x' => 143, 'y' => 56, 'z' => -70), 0)->shouldBeCalled();
     $this->build($structure, array('x' => 142, 'y' => 54, 'z' => -71));
 }
コード例 #2
0
 /**
  * @param gries\MControl\Builder\BlockTypeColorMapping $blockTypeColorMapping
  */
 function it_creates_multiple_levels_of_the_image_depending_on_the_given_heigh(BlockTypeColorMapping $blockTypeColorMapping)
 {
     $blackBlockType = new BlockType(array('name' => 'coal_block'));
     $blockTypeColorMapping->getBlockTypeForRgbColor(255, 255, 255)->willReturn($blackBlockType);
     $whiteBlockType = new BlockType(array('name' => 'iron_block', 'meta' => 2));
     $blockTypeColorMapping->getBlockTypeForRgbColor(0, 0, 0)->willReturn($whiteBlockType);
     $this->beConstructedWith($blockTypeColorMapping);
     $expectedStructure = new Structure();
     $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 1, 'z' => 1));
     $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 1, 'z' => 2));
     $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 1, 'z' => 1), 2);
     $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 1, 'z' => 2), 2);
     $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 2, 'z' => 1));
     $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 2, 'z' => 2));
     $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 2, 'z' => 1), 2);
     $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 2, 'z' => 2), 2);
     // returns a 2x2 image with 2 black and 2 white pixels
     $image = $this->getImage();
     $this->convert($image, 2)->shouldBeLike($expectedStructure);
 }
コード例 #3
0
ファイル: StructureScanner.php プロジェクト: gries/mcontrol
 public function scan(array $coordinates, $width, $length, $height)
 {
     $structure = new Structure();
     // go through the height
     for ($y = 1; $y <= $height; $y++) {
         // go through the length
         for ($z = 1; $z <= $length; $z++) {
             // go through the width
             for ($x = 1; $x <= $width; $x++) {
                 $currentX = $coordinates['x'] + $x;
                 $currentY = $coordinates['y'] + $y;
                 $currentZ = $coordinates['z'] + $z;
                 $currentCoordinates = array('x' => $currentX, 'y' => $currentY, 'z' => $currentZ);
                 $type = $this->scanner->detectBlockType($currentCoordinates);
                 // default to air
                 if (!$type) {
                     $type = new BlockType(array('name' => 'air', 'meta' => 0));
                 }
                 $structure->createBlock($type->getName(), array('x' => $x, 'y' => $y, 'z' => $z), $type->getMeta());
             }
         }
     }
     return $structure;
 }
コード例 #4
0
 /**
  * @param gries\MControl\Server\BlockTypeScanner $scanner
  */
 function it_should_scan_a_structure_block_by_block_for_given_coordinates(BlockTypeScanner $scanner)
 {
     $scanner->detectBlockType(array('x' => 6, 'y' => 6, 'z' => 6))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0)));
     $scanner->detectBlockType(array('x' => 7, 'y' => 6, 'z' => 6))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0)));
     $scanner->detectBlockType(array('x' => 8, 'y' => 6, 'z' => 6))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0)));
     $scanner->detectBlockType(array('x' => 6, 'y' => 6, 'z' => 7))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'air', 'meta' => 1)));
     $scanner->detectBlockType(array('x' => 7, 'y' => 6, 'z' => 7))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0)));
     $scanner->detectBlockType(array('x' => 8, 'y' => 6, 'z' => 7))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0)));
     $expectedStructure = new Structure();
     $expectedStructure->createBlock('iron', array('x' => 1, 'y' => 1, 'z' => 1), 0);
     $expectedStructure->createBlock('iron', array('x' => 2, 'y' => 1, 'z' => 1), 0);
     $expectedStructure->createBlock('iron', array('x' => 3, 'y' => 1, 'z' => 1), 0);
     $expectedStructure->createBlock('air', array('x' => 1, 'y' => 1, 'z' => 2), 1);
     $expectedStructure->createBlock('iron', array('x' => 2, 'y' => 1, 'z' => 2), 0);
     $expectedStructure->createBlock('iron', array('x' => 3, 'y' => 1, 'z' => 2), 0);
     $coordinates = array('x' => 5, 'y' => 5, 'z' => 5);
     $width = 3;
     $height = 1;
     $length = 2;
     $this->scan($coordinates, $width, $length, $height)->shouldBeLike($expectedStructure);
 }
コード例 #5
0
ファイル: StructureBuilder.php プロジェクト: gries/mcontrol
 public function build(Structure $structure, array $startingCoordinates)
 {
     foreach ($structure->getBlocks() as $block) {
         $this->buildBlock($block, $startingCoordinates);
     }
 }
コード例 #6
0
 public function getByStructure(Structure $structure)
 {
     return $this->em->getRepository('gries\\MControl\\Builder\\Block')->findOneBy(array('structure_id' => $structure->getId()));
 }