VPA-Keyboard

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

目前為 2016-05-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
        }
    }
}