kopia lustrzana https://github.com/backface/turtlestitch
fix reportURL
rodzic
6b85025c94
commit
13a4348840
|
@ -53,6 +53,41 @@ Process.prototype.reportPi = function (min, max) {
|
|||
return Math.PI;
|
||||
};
|
||||
|
||||
// Process URI retrieval (interpolated)
|
||||
|
||||
Process.prototype.reportURL = function (url) {
|
||||
var response;
|
||||
if (!this.httpRequest) {
|
||||
// use the location protocol unless the user specifies otherwise
|
||||
if (url.indexOf('//') < 0 || url.indexOf('//') > 8) {
|
||||
if (location.protocol === 'file:') {
|
||||
// allow requests from locally loaded sources
|
||||
url = 'https://' + url;
|
||||
} else {
|
||||
url = location.protocol + '//' + url;
|
||||
}
|
||||
}
|
||||
this.httpRequest = new XMLHttpRequest();
|
||||
this.httpRequest.open("GET", url, true);
|
||||
// cache-control, commented out for now
|
||||
// added for Snap4Arduino but has issues with local robot servers
|
||||
// this.httpRequest.setRequestHeader('Cache-Control', 'max-age=0');
|
||||
this.httpRequest.send(null);
|
||||
if (this.context.isCustomCommand) {
|
||||
// special case when ignoring the result, e.g. when
|
||||
// communicating with a robot to control its motors
|
||||
this.httpRequest = null;
|
||||
return null;
|
||||
}
|
||||
} else if (this.httpRequest.readyState === 4) {
|
||||
response = this.httpRequest.responseText;
|
||||
this.httpRequest = null;
|
||||
return response;
|
||||
}
|
||||
this.pushContext('doYield');
|
||||
this.pushContext();
|
||||
};
|
||||
|
||||
Process.prototype.reportProxiedURL = function (url) {
|
||||
return this.reportURL(this.proxy + '/' + url);
|
||||
};
|
||||
|
@ -61,7 +96,7 @@ Process.prototype.origReportDistanceTo = Process.prototype.reportDistanceTo;
|
|||
Process.prototype.reportDistanceTo = function (name) {
|
||||
var thisObj = this.blockReceiver();
|
||||
if (thisObj && this.inputOption(name) === 'mouse-pointer') {
|
||||
return new Point(thisObj.xPosition(), thisObj.yPosition()).distanceTo(new Point(this.reportMouseX(), this.reportMouseY()));
|
||||
return new Point(thisObj.xPosition(), thisObj.yPosition()).distanceTo(new Point(this.reportMouseX(), this.reportMouseY()));
|
||||
} else {
|
||||
return this.origReportDistanceTo(name);
|
||||
}
|
||||
|
@ -71,9 +106,9 @@ Process.prototype.origDoGotoObject = Process.prototype.doGotoObject;
|
|||
Process.prototype.doGotoObject = function (name) {
|
||||
var thisObj = this.blockReceiver(),
|
||||
stage;
|
||||
|
||||
|
||||
if (thisObj && this.inputOption(name) === 'random position') {
|
||||
stage = thisObj.parentThatIsA(StageMorph);
|
||||
stage = thisObj.parentThatIsA(StageMorph);
|
||||
if (stage) {
|
||||
thisObj.gotoXY(
|
||||
this.reportBasicRandom(stage.reportX(stage.left()), stage.reportX(stage.right())),
|
||||
|
@ -88,11 +123,11 @@ Process.prototype.doGotoObject = function (name) {
|
|||
Process.prototype.reportRandomPosition = function () {
|
||||
var thisObj = this.blockReceiver(),
|
||||
stage;
|
||||
|
||||
|
||||
if (thisObj) {
|
||||
stage = thisObj.parentThatIsA(StageMorph);
|
||||
return new List([this.reportBasicRandom(stage.reportX(stage.left()), stage.reportX(stage.right())),
|
||||
this.reportBasicRandom(stage.reportY(stage.top()), stage.reportY(stage.bottom()))]);
|
||||
this.reportBasicRandom(stage.reportY(stage.top()), stage.reportY(stage.bottom()))]);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue