import { SGraphView } from "@saga-web/graph/lib";
import { SMouseButton, SMouseEvent, SNetUtil } from "@saga-web/base/lib";
import { SPoint } from "@saga-web/draw/lib";
export class FloorView extends SGraphView {
    constructor() {
        super(...arguments);
        this._leftKeyPos = new SPoint();
        this.spaceKey = false;
    }
    saveFloorJson(name) {
        if (!this.scene || !this.scene.json)
            return;
        let url = URL.createObjectURL(new Blob([this.scene.json]));
        SNetUtil.downLoad(name, url);
    }
    onKeyDown(event) {
        let keyCode = event.keyCode;
        this.spaceKey = false;
        switch (keyCode) {
            case 32:
                this.spaceKey = true;
                break;
            case 87:
                this.origin.y -= 10;
                break;
            case 83:
                this.origin.y += 10;
                break;
            case 68:
                this.origin.x += 10;
                break;
            case 65:
                this.origin.x -= 10;
                break;
            default:
                super.onKeyDown(event);
                break;
        }
    }
    onKeyUp(event) {
        this.spaceKey = false;
        super.onKeyUp(event);
    }
    onMouseDown(event) {
        let se = new SMouseEvent(event);
        if (se.buttons & SMouseButton.LeftButton) {
            this._leftKeyPos.x = se.x;
            this._leftKeyPos.y = se.y;
        }
        super.onMouseDown(event);
    }
    onMouseMove(event) {
        let se = new SMouseEvent(event);
        if (se.buttons & SMouseButton.LeftButton) {
            this.origin.x += se.x - this._leftKeyPos.x;
            this.origin.y += se.y - this._leftKeyPos.y;
            this._leftKeyPos.x = se.x;
            this._leftKeyPos.y = se.y;
            this.update();
        }
        super.onMouseMove(event);
    }
}
