VPA-Keyboard

For planets.nu -- Add VPA-key strokes, and commands

Устаревшая версия за 31.05.2016. Перейдите к последней версии.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Для установки этого скрипта вам необходимо установить расширение, такое как Tampermonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name        VPA-Keyboard
// @author      Quapla
// @copyright   Basecode: Kero van Gelder, 2016 - latest: Quapla
// @license     Lesser Gnu Public License, version 3
// @description For planets.nu -- Add VPA-key strokes, and commands
// @namespace   quapla/VPA-Keyboard
// @include     http://planets.nu/*
// @include     http://play.planets.nu/*
// @include     http://test.planets.nu/*
// @version     1.0.1
// @grant       none
// ==/UserScript==

// Reference:   Kero van Gelder's Keayboard: http://chmeee.org/ext/planets.nu/Keyboard.user.js


sharedContent.prototype.planetSurvey_McNimblesToolkit = sharedContent.prototype.planetSurvey;
sharedContent.prototype.planetSurvey = function(planetId) {
    vgap.currentPlanetSurvey = planetId;
    this.planetSurvey_McNimblesToolkit(planetId);
}

sharedContent.prototype.editNote_McNimblesToolkit = sharedContent.prototype.editNote;
sharedContent.prototype.editNote = function(noteId, noteType) {
    vgap.currentNoteId = noteId;
    vgap.currentNoteType = noteType;
    this.editNote_McNimblesToolkit(noteId, noteType);
    $("#EditNote").focus();
}

vgapShipScreen.prototype.shipMission_McNimblesToolkit = vgapShipScreen.prototype.shipMission;
vgapShipScreen.prototype.shipMission = function() {
    this.shipMissionOpen = true;
    this.shipMission_McNimblesToolkit();
}

vgapShipScreen.prototype.selectMission_McNimblesToolkit = vgapShipScreen.prototype.selectMission;
vgapShipScreen.prototype.selectMission = function(missionId) {
    this.selectMission_McNimblesToolkit(missionId);
    this.shipMissionOpen = false;
}

vgapShipScreen.prototype.primaryEnemy_McNimblesToolkit = vgapShipScreen.prototype.primaryEnemy;
vgapShipScreen.prototype.primaryEnemy = function() {
    this.primaryEnemyOpen = true;
    this.primaryEnemy_McNimblesToolkit();
}
vgapShipScreen.prototype.selectEnemy_McNimblesToolkit = vgapShipScreen.prototype.selectEnemy;
vgapShipScreen.prototype.selectEnemy = function(enemyId) {
    this.selectEnemy_McNimblesToolkit(enemyId);
    this.primaryEnemyOpen = false;
}
vgaPlanets.prototype.closeMore_McNimblesToolkit = vgaPlanets.prototype.closeMore;
vgaPlanets.prototype.closeMore = function(callback) {
    vgap.closeMore_McNimblesToolkit(callback);
    this.primaryEnemyOpen = false;
    vgap.currentPlanetSurvey = null;
    vgap.shipScreen.shipMissionOpen = false;
}

vgaPlanets.prototype.hotkey_McNimblesToolkit = vgaPlanets.prototype.hotkey;
vgaPlanets.prototype.hotkey = function(event) {
    if (vgap.shipScreen.primaryEnemyOpen) {
        var enemy = 0;
        if (event.keyCode >= 48 && event.keyCode <= 57) enemy = event.keyCode - 48;
        if (event.keyCode >= 65 && event.keyCode <= 90) enemy = event.keyCode - 65 + 10;
        if (enemy <= vgap.players.length) {
            vgap.shipScreen.selectEnemy(enemy);
            return;
        }
    }

    if (vgap.shipScreen.shipMissionOpen) {
        var missionId = -1;
        if (event.keyCode == 67) missionId = 9;       // 'c', Cloak
        else if (event.keyCode == 69) missionId = 0;  // 'e', Explore
        else if (event.keyCode == 73) missionId = 7;  // 'i', Intercept
        else if (event.keyCode == 75) missionId = 3;  // 'k', Kill
        else if (event.keyCode == 76) missionId = 2;  // 'l', Lay Mines
        else if (event.keyCode == 77) missionId = 1;  // 'm', Mine Sweep
        else if (event.keyCode == 83 && event.shiftKey) missionId = 8;  // 'S', Special / Super Spy
        else if (event.keyCode == 83) missionId = 4;  // 's', Sensor Sweep
        else if (event.keyCode == 84) missionId = 6;  // 't', Tow
        if (missionId >= 0) {
            vgap.shipScreen.selectMission(missionId);
            return;
        }
    }

    if (vgap.editNoteOpen) {
        if (event.keyCode == 13 && event.ctrlKey) {
            this.saveNote(vgap.currentNoteId, vgap.currentNoteType);
            return;
        }
    }

    if (event.keyCode == 27) {
        if (this.findObjectFeatureActivated) vgap.map.hideFindObjectFeature();
        else if (vgap.moreOpen) this.closeMore();
        else if (this.lcOpen) this.deselectAll();
        else this.hotkey_McNimblesToolkit(event);
        return;
    }

    if (vgap.hotkeysOn) {
        switch (event.keyCode) {
        case 8:
            if ((this.starbaseScreenOpen || this.planetScreenOpen || this.shipScreenOpen) && !this.moreOpen) {
                vgap.rPrev();
                return;
            }
        case 78: // 'n'
            if (event.shiftKey) {
                if (this.planetScreenOpen) {
                    shtml.editNote(vgap.planetScreen.planet.id, 1);
                    return;
                } else if (vgap.currentPlanetSurvey > 0) { // ship screen is open, but unowned planet is selected
                    shtml.editNote(vgap.currentPlanetSurvey, 1);
                    return
                } else if (this.shipScreenOpen) {
                    shtml.editNote(vgap.shipScreen.ship.id, 2);
                    return;
                } else if (this.starbaseScreenOpen) {
                    shtml.editNote(vgap.starbaseScreen.starbase.id, 3);
                    return;
                }
            }
            break;
        case 88: // 'x'
            this.map.clearTools();
            return;
        case 90: // 'z'
            this.map.zoomFarInOrOut_OnWaypointOrPlanet();
            return;
        case 188: // '<'
            if (event.shiftKey) {
                vgap.unrotateActiveObject();
                return;
            }
        case 190: // '>'
            if (event.shiftKey) {
                vgap.rotateActiveObject();
                return;
            }
        }
    }

    this.hotkey_McNimblesToolkit(event);
}

vgapMap.prototype.zoomFarInOrOut_OnWaypointOrPlanet = function() {
    var zoomedOut = (this.zoom < 29);
    if (zoomedOut) {
        this.zoomFactorBeforeZoomingInDeeply = this.zoom;
        this.setZoom(42);
    } else {
        this.setZoom(this.zoomFactorBeforeZoomingInDeeply);
    }
    var x, y;
    if (this.activeShip) {
        x = this.activeShip.targetx;
        y = this.activeShip.targety;
    } else if (this.activePlanet) {
        x = this.activePlanet.x;
        y = this.activePlanet.y;
    } else {
        x = this.centerX;
        y = this.centerY;
    }

    this.centerX = x;
    this.centerY = y;
    this.canvas.x = x - $(window).width() / 2 / this.zoom;
    this.canvas.y = y - $(window).height() / 2 / this.zoom;
    this.draw();
}

vgaPlanets.prototype.rotateActiveObject = function() {
    if (vgap.planetScreenOpen) {
        var planet = vgap.map.activePlanet;
        if (planet.isbase) {
            vgap.map.selectStarbase(planet.id);
        } else {
            var ships = vgap.shipsAt(planet.x, planet.y);
            if (ships.length > 0) vgap.map.selectShip(ships[0].id);
            // else only a planet
        }
    } else if (vgap.starbaseScreenOpen) {
        var planet = vgap.map.activePlanet;
        var ships = vgap.shipsAt(planet.x, planet.y);
        if (ships.length > 0) {
            vgap.map.selectShip(ships[0].id);
        } else {
            vgap.map.selectPlanet(planet.id);
        }
    } else if (vgap.shipScreenOpen) {
        var ship = vgap.map.activeShip;
        var ships = vgap.shipsAt(ship.x, ship.y)
        var index = ships.indexOf(ship);
        if (index == ships.length - 1) {
            var planet = vgap.planetAt(ship.x, ship.y)
            if (planet) {
                vgap.map.selectPlanet(planet.id);
            } else if (ships.length > 1) {
                vgap.map.selectShip(ships[0].id);
            } // else Cannot rotate 1 ship
        } else {
            vgap.map.selectShip(ships[index+1].id);
        }
    }
}

vgaPlanets.prototype.unrotateActiveObject = function() {
    if (vgap.planetScreenOpen) {
        var planet = vgap.map.activePlanet;
        var ships = vgap.shipsAt(planet.x, planet.y);
        if (ships.length > 0) {
            vgap.map.selectShip(ships[ships.length-1].id);
        } else if (planet.isbase) {
            vgap.map.selectStarbase(planet.id);
        } // else only a planet
    } else if (vgap.starbaseScreenOpen) {
        var planet = vgap.map.activePlanet;
        vgap.map.selectPlanet(planet.id);
    } else if (vgap.shipScreenOpen) {
        var ship = vgap.map.activeShip;
        var ships = vgap.shipsAt(ship.x, ship.y)
        var index = ships.indexOf(ship);
        if (index == 0) {
            var planet = vgap.planetAt(ship.x, ship.y)
            if (planet) {
                if (planet.isbase) {
                    vgap.map.selectStarbase(planet.id);
                } else {
                    vgap.map.selectPlanet(planet.id);
                }
            } else {
                if (ships.length > 1) vgap.map.selectShip(ships[ships.length-1].id);
            }
        } else {
            vgap.map.selectShip(ships[index-1].id);
        }
    }
}