import { wall, wallMask, basket, basketMask } from "./collisionConfig";
import StartScene from "./StartScene";

const createBox = (_this: StartScene) => {
    // _this._egretRender.rectangle(750 / 2, 1624, 750, 100, null, { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } });
    _this._egretRender.rectangle(0, 1624 / 2, 10, 1624, null, { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } });
    _this._egretRender.rectangle(750, 1624 / 2, 10, 1624, null, { isStatic: true, collisionFilter: { group: wall, category: wall, mask: wallMask } });

    const seesaw = _this._egretRender.rectangle(375, 1043, 503, 70, _this['arrow'], {
        isStatic: true,
        restitution:0,
        collisionFilter: { group: basket, category: basket, mask: basketMask },
    });
    // _this.arrowContainer.addChild(seesaw['display']);

    // const brick = _this._egretRender.circle(200, 1173+100+50, 5, null, {
    //     isStatic: true,restitution:0,
    //     collisionFilter: { group: basket, category: basket, mask: basketMask },
    // });

    // const brick2 = _this._egretRender.circle(750-200, 1173+100+50, 5, null, {
    //     isStatic: true,restitution:0,
    //     collisionFilter: { group: basket, category: basket, mask: basketMask },
    // });

    const offsetx = 0-40;
    const offsety = 0-110;
    const offset2x = 0+8;
    const offset2y = 0-110;

    
    const basketLeft1 = Matter.Bodies.circle(60+offsetx, 1353+offsety, 5, { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } })
    Matter.World.add(_this._engine.world, basketLeft1);

    const basketRight1 = Matter.Bodies.circle(161+offsetx, 1353+offsety, 5, { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } })
    Matter.World.add(_this._engine.world, basketRight1);
    
    const basketPath = Matter.Vertices.fromPath('62 1363 72 1453 144 1450 157 1361 155 1361 133 1444 80 1445', null);
    const basketBody = Matter.Bodies.fromVertices(108+offsetx, 1428+offsety, [basketPath], { isStatic: true, collisionFilter: { group: basket, category: basket, mask: basketMask } }, true);
    Matter.World.add(_this._engine.world, basketBody);


    const basketRight = Matter.Bodies.circle(721+offset2x, 1353+offset2y, 6, { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } })
    Matter.World.add(_this._engine.world, basketRight);

    const basketLeft = Matter.Bodies.circle(553+offset2x, 1353+offset2y, 6, { isStatic: true, friction: 0, collisionFilter: { group: basket, category: basket, mask: basketMask } })
    Matter.World.add(_this._engine.world, basketLeft);

    const basketRightPath = Matter.Vertices.fromPath('556 1355 603 1430 632 1439 665 1435 705 1406 719 1366 643 1432 ', null);
    const rightBasketBody = Matter.Bodies.fromVertices(649+offset2x, 1408+offset2y, [basketRightPath], { isStatic: true, collisionFilter: { group: basket, category: basket, mask: basketMask } }, true);
    Matter.World.add(_this._engine.world, rightBasketBody);

    //钉子约束
    // const nailConstraint = Matter.Constraint.create({
    //     pointA: {
    //         x: 373,
    //         y: 1173
    //     },
    //     bodyB: seesaw,
    //     pointB: {
    //         x: 0,
    //         y: 0
    //     },
    //     stiffness: 1
    // })

    // Matter.World.add(_this._engine.world, nailConstraint);

    return { seesaw: seesaw }
}

export default createBox