turtlestitch/stitchcode/stitchcodeChangeSet.js

169 wiersze
4.0 KiB
JavaScript
Czysty Zwykły widok Historia

// Stitchode's main changes and addtions to snap! go in here
// sorry it lacks proper documentation
2015-01-15 11:19:37 +00:00
var tStitch = {};
2015-01-15 11:19:37 +00:00
tStitch.debug_msg = function (st,clear) {
2014-12-14 14:37:25 +00:00
o = new String();
if (!clear) {
o = document.getElementById("bug").innerHTML;
} else {
o = "";
}
o += st;
document.getElementById("bug").innerHTML = o;
}
tStitch.getBaseURL = function () {
var url = location.href; // entire url including querystring - also: window.location.href;
var baseURL = url.substring(0, url.lastIndexOf('/'));
return baseURL + "/";
}
tStitch.debug = true;
tStitch.stitches = {};
tStitch.stitches.x = new Array();
tStitch.stitches.y = new Array();
tStitch.stitches.jump = new Array();
2014-12-14 14:37:25 +00:00
tStitch.clearPoints = function() {
tStitch.stitches.x = new Array();
tStitch.stitches.y = new Array();
tStitch.stitches.jump = new Array();
}
tStitch.addPoint = function (x,y,jump) {
if (tStitch.debug) {
2014-12-14 14:37:25 +00:00
s = new String();
s = s + "(" + x + "," + y;
if (jump) s = s + ",jump";
s+= ")";
tStitch.debug_msg(s);
}
tStitch.stitches.x.push(x);
tStitch.stitches.y.push(y);
tStitch.stitches.jump.push(jump);
}
2014-12-14 14:37:25 +00:00
tStitch.upload = function() {
2015-02-16 19:44:04 +00:00
tStitch.debug_msg("uploading points... sending SAVE with num points= " + tStitch.stitches.x.length, true);
params = { "x[]": tStitch.stitches.x, "y[]":tStitch.stitches.y, "j[]":tStitch.stitches.jump };
2015-02-16 19:44:04 +00:00
$.fileDownload(tStitch.getBaseURL() +"stitchcode/backend/save.py", {
successCallback: function (html, url) {
alert("DSD");
},
failCallback: function (html, url) {
alert(
'Your file download just failed for this URL:' + url +
'\r\n' + 'Here was the resulting error HTML: \r\n'
+ html
);
},
httpMethod: "POST",
data: params
});
2014-12-14 14:37:25 +00:00
}
/* Sprite */
2014-12-14 14:37:25 +00:00
// modified SpriteMorph turtle functions
SpriteMorph.prototype.forward = function (steps) {
var dest,
dist = steps * this.parent.scale || 0;
if (dist >= 0) {
dest = this.position().distanceAngle(dist, this.heading);
} else {
dest = this.position().distanceAngle(
Math.abs(dist),
(this.heading - 180)
);
}
this.setPosition(dest);
this.positionTalkBubble();
tx = dest.x - this.parent.topLeft().x
ty = dest.y - this.parent.topLeft().y
tjump = !this.isDown;
tStitch.addPoint(tx,ty,tjump);
//alert("move to: " + tx + "x" + ty + " - isJump = " + tjump);
};
SpriteMorph.prototype.gotoXY = function (x, y, justMe) {
var stage = this.parentThatIsA(StageMorph),
newX,
newY,
dest;
newX = stage.center().x + (+x || 0) * stage.scale;
newY = stage.center().y - (+y || 0) * stage.scale;
if (this.costume) {
dest = new Point(newX, newY).subtract(this.rotationOffset);
} else {
dest = new Point(newX, newY).subtract(this.extent().divideBy(2));
}
this.setPosition(dest, justMe);
this.positionTalkBubble();
tx = dest.x - this.parent.topLeft().x
2014-12-14 14:37:25 +00:00
ty = dest.y - this.parent.topLeft().y
tjump = !this.isDown;
//alert("jump to: " + tx + "x" + ty);
tStitch.addPoint(tx,ty,tjump);
};
2014-12-14 14:37:25 +00:00
SpriteMorph.prototype.clear = function () {
this.parent.clearPenTrails();
tStitch.clearPoints();
2014-12-14 14:37:25 +00:00
if (tStitch.debug) {
2015-03-12 20:26:26 +00:00
tStitch.debug_msg("",true);
2014-12-14 14:37:25 +00:00
}
};
/*
// Definition of new block categories
SpriteMorph.prototype.categories =
[
'motion',
'control',
'shapes',
'colors',
'sensing',
'operators',
'variables',
'lists',
'my blocks'
];
SpriteMorph.prototype.blockColor = {
motion : new Color(74, 108, 212),
shapes : new Color(143, 86, 227),
colors : new Color(207, 74, 217),
sound : new Color(207, 74, 217), // we need to keep this color for the zoom blocks dialog
control : new Color(230, 168, 34),
sensing : new Color(4, 148, 220),
operators : new Color(98, 194, 19),
variables : new Color(243, 118, 29),
lists : new Color(217, 77, 17),
other : new Color(150, 150, 150),
'my blocks': new Color(150, 150, 60),
2014-12-14 14:37:25 +00:00
};
// now move also "make a block to 'my blocks'
2014-12-14 14:37:25 +00:00
*/