Beispiel #1
0
function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb)
{
    $assert->ok(MyGame\Example\Monster::MonsterBufferHasIdentifier($bb));
    $monster = \MyGame\Example\Monster::GetRootAsMonster($bb);
    $assert->strictEqual($monster->GetHp(), 80);
    $assert->strictEqual($monster->GetMana(), 150);
    // default
    $assert->strictEqual($monster->GetName(), 'MyMonster');
    $pos = $monster->GetPos();
    $assert->strictEqual($pos->GetX(), 1.0);
    $assert->strictEqual($pos->GetY(), 2.0);
    $assert->strictEqual($pos->GetZ(), 3.0);
    $assert->Equal($pos->GetTest1(), 3.0);
    $assert->strictEqual($pos->GetTest2(), \MyGame\Example\Color::Green);
    $t = $pos->GetTest3();
    $assert->strictEqual($t->GetA(), 5);
    $assert->strictEqual($t->GetB(), 6);
    $assert->strictEqual($monster->GetTestType(), \MyGame\Example\Any::Monster);
    $monster2 = new \MyGame\Example\Monster();
    $assert->strictEqual($monster->GetTest($monster2) != null, true);
    $assert->strictEqual($monster2->GetName(), 'Fred');
    $assert->strictEqual($monster->GetInventoryLength(), 5);
    $invsum = 0;
    for ($i = 0; $i < $monster->GetInventoryLength(); $i++) {
        $invsum += $monster->GetInventory($i);
    }
    $assert->strictEqual($invsum, 10);
    $assert->strictEqual(bin2hex($monster->GetInventoryBytes()), "0001020304");
    $test_0 = $monster->GetTest4(0);
    $test_1 = $monster->GetTest4(1);
    $assert->strictEqual($monster->GetTest4Length(), 2);
    $assert->strictEqual($test_0->GetA() + $test_0->GetB() + $test_1->GetA() + $test_1->GetB(), 100);
    $assert->strictEqual($monster->GetTestarrayofstringLength(), 2);
    $assert->strictEqual($monster->GetTestarrayofstring(0), 'test1');
    $assert->strictEqual($monster->GetTestarrayofstring(1), 'test2');
    $fred = $monster->getEnemy();
    $assert->Equal('Fred', $fred->getName());
    $assert->strictEqual($monster->GetTestbool(), false);
}
Beispiel #2
0
 public function getEnemy()
 {
     $obj = new Monster();
     $o = $this->__offset(28);
     return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0;
 }