diff options
Diffstat (limited to 'objects.js')
| -rw-r--r-- | objects.js | 136 |
1 files changed, 63 insertions, 73 deletions
@@ -155,7 +155,7 @@ SpriteMorph.uber = PenMorph.prototype; SpriteMorph.prototype.categories = [ - 'motion', + 'map', 'control', 'looks', 'sensing', @@ -168,7 +168,7 @@ SpriteMorph.prototype.categories = ]; SpriteMorph.prototype.blockColor = { - motion : new Color(74, 108, 212), + map : new Color(74, 108, 212), looks : new Color(143, 86, 227), sound : new Color(207, 74, 217), pen : new Color(0, 161, 120), @@ -202,6 +202,25 @@ SpriteMorph.prototype.bubbleMaxTextWidth = 130; SpriteMorph.prototype.initBlocks = function () { SpriteMorph.prototype.blocks = { + // Map (Snap! in Your Own World) + reportLocation: { + type: 'reporter', + category: 'map', + spec: 'current location' + }, + focusMap: { + type: 'command', + category: 'map', + spec: 'set focus to %l with zoom %n', + defaults: [null, 12] + }, + addMarker: { + dev: true, + type: 'command', + category: 'map', + spec: 'add a marker to %l' + }, + // Motion forward: { only: SpriteMorph, @@ -1340,6 +1359,16 @@ SpriteMorph.prototype.init = function (globals) { this.isDraggable = true; this.isDown = false; + // Snap! - YOW code + this.icon = L.icon({ + iconUrl: 'images/marker-icon.png', + iconRetinaUrl: 'images/marker-icon-2x.png', + shadowUrl: 'images/marker-shadow.png' + }); + this.geoposition = window.map.getCenter(); + this.marker = L.marker(this.geoposition, {icon: this.icon, title: this.name}); + this.marker.addTo(window.map); + this.heading = 90; this.changed(); this.drawNew(); @@ -1626,7 +1655,7 @@ SpriteMorph.prototype.variableBlock = function (varName) { SpriteMorph.prototype.blockTemplates = function (category) { var blocks = [], myself = this, varNames, button, - cat = category || 'motion', txt; + cat = category || 'map', txt; function block(selector) { if (StageMorph.prototype.hiddenPrimitives[selector]) { @@ -1702,7 +1731,16 @@ SpriteMorph.prototype.blockTemplates = function (category) { } } - if (cat === 'motion') { + if (cat === 'map') { + + blocks.push(block('reportLocation')); + blocks.push(block('focusMap')); + + //if (this.world().isDevMode) { + blocks.push(block('addMarker')); + //} + + } /* else if (cat === 'motion') { blocks.push(block('forward')); blocks.push(block('turn')); @@ -1729,7 +1767,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(watcherToggle('direction')); blocks.push(block('direction')); - } else if (cat === 'looks') { + } */ else if (cat === 'looks') { blocks.push(block('doSwitchToCostume')); blocks.push(block('doWearNextCostume')); @@ -1912,6 +1950,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('reportDate')); + blocks.push(block('reportLocation')); // for debugging: /////////////// @@ -4411,73 +4450,15 @@ StageMorph.prototype.drawNew = function () { }; StageMorph.prototype.drawOn = function (aCanvas, aRect) { - // make sure to draw the pen trails canvas as well - var rectangle, area, delta, src, context, w, h, sl, st, ws, hs; - if (!this.isVisible) { - return null; - } + var map = document.getElementById('map'); + var rectangle, area; rectangle = aRect || this.bounds; area = rectangle.intersect(this.bounds).round(); - if (area.extent().gt(new Point(0, 0))) { - delta = this.position().neg(); - src = area.copy().translateBy(delta).round(); - context = aCanvas.getContext('2d'); - context.globalAlpha = this.alpha; - - sl = src.left(); - st = src.top(); - w = Math.min(src.width(), this.image.width - sl); - h = Math.min(src.height(), this.image.height - st); - - if (w < 1 || h < 1) { - return null; - } - context.drawImage( - this.image, - src.left(), - src.top(), - w, - h, - area.left(), - area.top(), - w, - h - ); - - // pen trails - ws = w / this.scale; - hs = h / this.scale; - context.save(); - context.scale(this.scale, this.scale); - try { - context.drawImage( - this.penTrails(), - src.left() / this.scale, - src.top() / this.scale, - ws, - hs, - area.left() / this.scale, - area.top() / this.scale, - ws, - hs - ); - } catch (err) { // sometimes triggered only by Firefox - // console.log(err); - context.restore(); - context.drawImage( - this.penTrails(), - 0, - 0, - this.dimensions.x, - this.dimensions.y, - this.left(), - this.top(), - this.dimensions.x * this.scale, - this.dimensions.y * this.scale - ); - } - context.restore(); - } + map.style.width = this.dimensions.x * this.scale + 'px'; + map.style.height = this.dimensions.y * this.scale + 'px'; + map.style.left = area.left() + 'px'; + map.style.top = area.top() + 'px'; + window.map.invalidateSize(); }; StageMorph.prototype.clearPenTrails = function () { @@ -4869,7 +4850,7 @@ StageMorph.prototype.removeAllClones = function () { StageMorph.prototype.blockTemplates = function (category) { var blocks = [], myself = this, varNames, button, - cat = category || 'motion', txt; + cat = category || 'map', txt; function block(selector) { if (myself.hiddenPrimitives[selector]) { @@ -4939,7 +4920,15 @@ StageMorph.prototype.blockTemplates = function (category) { } } - if (cat === 'motion') { + if (cat === 'map') { + + blocks.push(block('reportLocation')); + blocks.push(block('focusMap')); + if (this.world().isDevMode) { + blocks.push(block('addMarker')); + } + + } /* else if (cat === 'motion') { txt = new TextMorph(localize( 'Stage selected:\nno motion primitives' @@ -4948,7 +4937,7 @@ StageMorph.prototype.blockTemplates = function (category) { txt.setColor(this.paletteTextColor); blocks.push(txt); - } else if (cat === 'looks') { + } */ else if (cat === 'looks') { blocks.push(block('doSwitchToCostume')); blocks.push(block('doWearNextCostume')); @@ -5095,6 +5084,7 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('reportDate')); + blocks.push(block('reportLocation')); // for debugging: /////////////// |
