Iso Game Level Editor

by Robodude

HTML

<script src="https://dl.dropboxusercontent.com/u/938212/kinetic-v4.5.2.min.js"></script>
<button id="stage">Stage</button>
        <button id="printLevel">Get Level Data</button>
        <button id="copyQtoA">Copy Q to A</button>

        <br />

        <div id="container"></div>

CSS

#container
    {
        width: 1000px;
        height: 500px;
        border: 1px solid black;        
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }

JavaScript

var _copyPts = function(e, i, a) {
        if(e instanceof Array) {
            return e.slice();
        }
        else if(e instanceof Object) {
            var r = {};
            for(var k in e) {
                if(e.hasOwnProperty(k)) r[k] = e[k];
            }
            return r;
        }
        
        return e;
    };

    var stage;
    var selectedShape = null;
    $("#stage").click(function () {
        console.log(stage);
    });

    $("#printLevel").click(function () {
        var lg = stage.get(".lineGroup")[0];
        var lines = lg.get(".line");
        var start = [];

        for (var i = 0; i < lines.length; i++) {
            start.push({
                color: "rgba(0,0,255,1)",
                points: lines[i].getPoints()
            });
        }

        var ag = stage.get(".answerGroup")[0];
        var lines = ag.get(".line2");
        var end = [];

        for (var i = 0; i < lines.length; i++) {
            end.push({
                color: "rgba(0,0,255,1)",
                points: lines[i].getPoints()
            });
        }

        var level = {
            start: start,
            end: end
        }

        console.log(level);
        console.log(JSON.stringify(level));
    });

    $("#copyQtoA").click(function () {
        var lg = stage.get(".lineGroup")[0];
        var lines = lg.get(".line");
        console.log(lines);
        var end = [];

        for (var i = 0; i < lines.length; i++) {
            end.push({
                color: "rgba(255,0,0,1)",
                points: lines[i].getPoints()
            });
        }
        
        var ag = stage.get(".answerGroup")[0];

        buildLines(ag, end, false);
        stage.draw();
    });

    $(document).ready(function () {

        stage = new Kinetic.Stage({
            container: "container",
            height: $("#container").height(),
            width: $("#container").width()
        });

        var layer = new Kinetic.Layer({
            name:...