BitteWenden's Solar Crusaders Mod

Adds some functionality to the Solar Crusaders Alpha

目前为 2015-10-25 提交的版本。查看 最新版本

// ==UserScript==
// @name         BitteWenden's Solar Crusaders Mod
// @version      0.1
// @description  Adds some functionality to the Solar Crusaders Alpha
// @author       BitteWenden
// @match        http://solarcrusaders.com/
// @grant        GM_addStyle
// @namespace https://gf.qytechs.cn/users/18854
// ==/UserScript==

var startupTimerFreq = 5000; // expressed in miliseconds
var allShips;
var overlay;
var shipsToModify;
alert("You're using a modified version of the game. Any bugs you encounter could be caused by the modification so please send a message to BitteWenden in the Solar Crusader forums if you encounter a mod caused bug. Feel free to contact me if you have any suggestions! Select some ships and press 'F' to open the mod menu.");

function setPlayable(ships) {   
    for (var ship of ships) {
        ship.isPlayer = true;
    }
}

function createInputs() {
    window.addEventListener('keydown', KeyCheck, true);
    overlay = document.createElement ('div');
    overlay.innerHTML = '<div id="dialog"><h2 id="shipsToEditLabel">No Ships Selected!</h2><label for="shipColorChooser" >Set Ship Color: </label><input id="shipColorChooser" type="color"></input></br><label for="shipScaleChooser" >Set Scale: </label><input placeholder="1" id="shipScaleChooser" type="number"></input></br><h3>Press Enter to Proceed or ESC to exit.</h3></div>';
    overlay.setAttribute ('id', 'overlay');
    document.body.appendChild (overlay);
}

function init() {
    
    allShips = game.world.getChildAt(1).children;
    if(allShips[0].isPlayer !== undefined) {
        clearInterval(startupTestInterval)
        setPlayable(allShips);
        
        createInputs();
    }
    
}

function KeyCheck(e) {
    if(overlay.style.visibility == "visible") {
        if(e.keyCode == 13) {
        
             var colorChooser = document.getElementById("shipColorChooser");
             var rgbColorObj = hexToRgb(colorChooser.value);
            
            var r = rgbColorObj.r.toString();
            if(rgbColorObj.r < 100) {
                r = "0" + r;
                console.log(r);
                if(rgbColorObj.r < 10) {
                    r = "0" + r;
                }
            }
            var g = rgbColorObj.g.toString();
            if(rgbColorObj.g < 100) {
                g = "0" + g;
                 console.log(g);
                if(rgbColorObj.g < 10) {
                    g = "0" + g;
                }
            }
            var b = rgbColorObj.b.toString();
            if(rgbColorObj.b < 100) {
                b = "0" + b;
                if(rgbColorObj.b < 10) {
                    b = "0" + b;
                }
            }
            console.log(r);
            console.log(g);
            console.log(b);
           var rgbColor = r + g + b;
             var scaleChooser = document.getElementById("shipScaleChooser");
            var scale = scaleChooser.value;
            if(scale === 0) {
                scale = 0.1;
            }
            for(var ship of shipsToModify) {
                ship.tint = rgbColor;
                
                ship.scale.x = scale,
                    ship.scale.y = scale;
            }
            console.log(rgbColor);
            overlay.style.visibility = "hidden";
        }  
        
        if(e.keyCode == 27) {
        
            overlay.style.visibility = "hidden";
        }  
    }
       
    else if(e.keyCode == 70) {
        if(overlay !== undefined) {
            overlay.style.visibility = "visible";
            shipsToModify = [];
            for(var ship of allShips) {
                if(ship.selected === true)
                shipsToModify.push(ship);
            }
            if(shipsToModify.length !== 0) {
                var labelString = "Selected: ";
                var first = true;
                for(var ship of shipsToModify) {
                    if(first === true) {
                         first = false;
                    }
                    else {
                         labelString += ",";
                    }
                    if(ship.name)
                    labelString += ship.name;
                    
                    
                }
                var label = document.getElementById("shipsToEditLabel");
                label.innerHTML = labelString;
                console.log("Selected:" + labelString);
            }
        }
    }
}

var startupTestInterval = setInterval(function(){ init() }, startupTimerFreq );



GM_addStyle ( multilineStr ( function () {/*!
    #overlay {
     visibility: hidden;
     position: absolute;
     left: 0px;
     top: 0px;
     width:100%;
     height:100%;
     text-align:center;
     z-index: 1000;
     }
     
     #dialog {
     width: 30vw;
     height: 40vh;
     background-color: rgba(255, 165, 0, 0.8);
     margin-left: auto;
    margin-right: auto;
    margin-top:10vh;
     }
     #shipsToEditLabel {
     height: 2em;
     width: 100%;
     text-overflow: ellipsis;
     overflow: hidden;
     white-space: nowrap;
     color:black;
     }
     
     label{
     color:black;
     }
     h3{
     color:black;
     }
*/} ) );

function multilineStr (dummyFunc) {
    var str = dummyFunc.toString ();
    str     = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
            .replace (/\s*\*\/\s*\}\s*$/, '')   // Strip */ }
            .replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
            ;
    return str;
}

function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}    
  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址