package ru.m.puzzlez.render.mask;

import flash.display.GraphicsPathCommand;
import flash.geom.Rectangle;
import openfl.Vector;
import ru.m.puzzlez.core.Part;
import ru.m.puzzlez.render.mask.IPartMaskBuilder;

class BaseMaskBuilder implements IPartMaskBuilder {

    public function new() {
    }

    private function createBound(path:DrawPath, fromX:Float, fromY:Float, toX:Float, toY:Float, type:BoundType):Void {
        path.commands.push(GraphicsPathCommand.LINE_TO);
        path.data.push(toX);
        path.data.push(toY);
    }

    public function build(rect:Rectangle, bounds:Bounds):DrawPath {
        var path:DrawPath = {
            commands: new Vector<GraphicsPathCommand>(),
            data: new Vector<Float>(),
        }
        path.commands.push(GraphicsPathCommand.MOVE_TO);
        path.data.push(rect.left);
        path.data.push(rect.top);
        createBound(path, rect.left, rect.top, rect.right, rect.top, bounds.top);
        createBound(path, rect.right, rect.top, rect.right, rect.bottom, bounds.right);
        createBound(path, rect.right, rect.bottom, rect.left, rect.bottom, bounds.bottom);
        createBound(path, rect.left, rect.bottom, rect.left, rect.top, bounds.left);
        return path;
    }
}
