<commit_before>function ShipDesigner(descr) {
    this.setup(descr);
    this.init();
};

ShipDesigner.prototype = new State();

ShipDesigner.prototype.init = function() {
    this.back = new Menu({
	"state" : this,
	"items" : [
        {
	    "text" : "Back",
	    "action" : function (state) {
		stateManager.switchState("menu");
		}
	    },
        ],
	"width" : 100,
	"height" : 100,
	"location" : [ g_canvas.width - 100, 0]
	});

    this.menu2 = new Menu({
	"state" : this,
	"items" : [
        {
	    "text" : "Echo Ship JSON",
	    "action" : function (state)
             {
                var ship = state.currentShip.assemble(state.grid);
                util.echoJSON(state.currentShip);
                state.currentShip.disassemble(state.grid);
		    }
	    },
	    {
	        "text" : "Add Selected Part",
		"action" : function(state){
		    state.addPart($("#in7").val());
		}
	    }
        ],
	"width" : 200,
	"height" : 100,
	"location" : [ 260, 0]
	});

    this.menu = new Menu({
	    "state" : this,
	    "items" : [
		{
		"text": "New Ship",
		"action" : function (state){
		    state.newShip();
		    }
		},
		{
		"text": "Save Ship",
		"action" : function (state){
		    state.saveShip();
		    },
		},
		{
		"text": "Load Ship",
		"action" : function (state){
		    state.loadShip();
		    },
		},
		{
		"text": "Clear Storage",
		"action" : function (state){
		    util.storageSave("ships",undefined);
		    $("#in9").empty();
		    console.log("ship storage cleared");
		    },
		}
	    ],
	    "width" : 100,
	    "height" : g_canvas.height*2,
	    "itemHeight" : 25,
		"location": [55,-g_canvas.height+70]
    });

    
    this.grid = new Grid({
	    "dims" : [32,32],
        "width" : 525,
        "height" : 525,
        "location": [375,375]
	});

    this.newShip();
    }

ShipDesigner.prototype.newShip = function ()
{
    this.currentShip = new Ship(
            {
            });
    this.addedParts = this.currentShip.parts;
}


ShipDesigner.prototype.addPart = function (partInd){
    var parts = util.storageLoad("parts");
    var part = new Part(parts[partInd]);
    this.heldPart = part.toDesigner(this.grid);
    if(this.addedParts){
		this.indexOfHeldPart = this.addedParts.length;
        this.addedParts.push(this.heldPart);
    } else {
        this.addedParts = [this.heldPart];
		this.indexOfHeldPart = 0;
    }
    console.log(part);
}



ShipDesigner.prototype.saveShip = function ()
{
    this.currentShip = new Ship({"parts"
    : this.addedParts,
    "name": $('#in5').val()
    });

    if(this.currentShip)
    {
        this.currentShip.assemble(this.grid);
        var ships = util.storageLoad("ship");
        if (ships){
            ships.push(this.currentShip);
        } else {
            ships = [this.currentShip];
            }
        util.storageSave("ships",ships);
        this.currentShip.disassemble(this.grid);
        var ships = util.storageLoad("ships");
        $("#in9").empty();
        if(ships)
        {
            $.each(ships, function (key,value) {
                $("#in9").append('<option value="'+key+'">'+value.name+'</option>');});
        }
    }
}

ShipDesigner.prototype.loadShip = function ()
{
    var ships = util.storageLoad("ships");
    var ship = new Ship(ships[$('#in9').val()]);
    var ship = ship.disassemble(this.grid);
    var gri = this.grid;
    this.addedParts = ship.parts;
}

ShipDesigner.prototype.onActivation = function ()
{<commit_msg>added launch button to ship designer<commit_after>function ShipDesigner(descr) {
    this.setup(descr);
    this.init();
};

ShipDesigner.prototype = new State();

ShipDesigner.prototype.init = function() {
    this.back = new Menu({
	"state" : this,
	"items" : [
        {
	    "text" : "Back",
	    "action" : function (state) {
		stateManager.switchState("menu");
		}
	    },
		{
		"text" : "Launch",
		"action" : function(state) {
		state.currentShip.assemble(state.grid);
		console.log(state.currentShip);
		entityManager.clearShips();
		entityManager.generateShip(state.currentShip);
		stateManager.switchState("simulation");
		}
		},
        ],
	"width" : 100,
	"height" : 100,
	"location" : [ g_canvas.width - 100, 0]
	});

    this.menu2 = new Menu({
	"state" : this,
	"items" : [
        {
	    "text" : "Echo Ship JSON",
	    "action" : function (state)
             {
                var ship = state.currentShip.assemble(state.grid);
                util.echoJSON(state.currentShip);
                state.currentShip.disassemble(state.grid);
		    }
	    },
	    {
	        "text" : "Add Selected Part",
		"action" : function(state){
		    state.addPart($("#in7").val());
		}
	    }
        ],
	"width" : 200,
	"height" : 100,
	"location" : [ 260, 0]
	});

    this.menu = new Menu({
	    "state" : this,
	    "items" : [
		{
		"text": "New Ship",
		"action" : function (state){
		    state.newShip();
		    }
		},
		{
		"text": "Save Ship",
		"action" : function (state){
		    state.saveShip();
		    },
		},
		{
		"text": "Load Ship",
		"action" : function (state){
		    state.loadShip();
		    },
		},
		{
		"text": "Clear Storage",
		"action" : function (state){
		    util.storageSave("ships",undefined);
		    $("#in9").empty();
		    console.log("ship storage cleared");
		    },
		}
	    ],
	    "width" : 100,
	    "height" : g_canvas.height*2,
	    "itemHeight" : 25,
		"location": [55,-g_canvas.height+70]
    });

    
    this.grid = new Grid({
	    "dims" : [32,32],
        "width" : 525,
        "height" : 525,
        "location": [375,375]
	});

    this.loadShip();
    }

ShipDesigner.prototype.newShip = function ()
{
    this.currentShip = new Ship(
            {
            });
    this.addedParts = this.currentShip.parts;
}


ShipDesigner.prototype.addPart = function (partInd){
    var parts = util.storageLoad("parts");
    var part = new Part(parts[partInd]);
    this.heldPart = part.toDesigner(this.grid);
    if(this.addedParts){
		this.indexOfHeldPart = this.addedParts.length;
        this.addedParts.push(this.heldPart);
    } else {
        this.addedParts = [this.heldPart];
		this.indexOfHeldPart = 0;
    }
	this.currentShip.parts = this.addedParts
    console.log(part);
}



ShipDesigner.prototype.saveShip = function ()
{
    this.currentShip = new Ship({"parts"
    : this.addedParts,
    "name": $('#in5').val()
    });

    if(this.currentShip)
    {
        this.currentShip.assemble(this.grid);
        var ships = util.storageLoad("ship");
        if (ships){
            ships.push(this.currentShip);
        } else {
            ships = [this.currentShip];
            }
        util.storageSave("ships",ships);
        this.currentShip.disassemble(this.grid);
        var ships = util.storageLoad("ships");
        $("#in9").empty();
        if(ships)
        {
            $.each(ships, function (key,value) {
                $("#in9").append('<option value="'+key+'">'+value.name+'</option>');});
        }
    }
}

ShipDesigner.prototype.loadShip = function ()
{
    var ships = util.storageLoad("ships");
    var ship = new Ship(ships[$('#in9').val()]);
    var ship = ship.disassemble(this.grid);
	this.currentShip = ship;
    var gri = this.grid;
    this.addedParts = ship.parts;
	console.log(this.currentShip);
}

ShipDesigner.prototype.onActivation = function ()
{
{'fraction_non_alphanumeric': 0.17548670139840966, 'fraction_numerical': 0.014806690430490814, 'mean_word_length': 2.294941282746161, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1263854', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2486, 'n_words': 415}