From 519ceac166494e6240380a3bcd0d27ff5083fb5a Mon Sep 17 00:00:00 2001 From: Beate Jost Date: Mon, 16 Dec 2024 19:46:18 +0100 Subject: [PATCH] Issue #1712: improve movable obstacle behaviour, regenerate victims when scoring run starts --- .../simulationLogic/simulation.objects.js | 2 +- .../simulationLogic/simulation.roberta.js | 2 +- .../simulationLogic/simulation.scene.js | 2 +- .../simulationLogic/simulation.objects.ts | 11 ++-- .../simulationLogic/simulation.roberta.ts | 50 +++++++++++++++---- .../simulationLogic/simulation.scene.ts | 29 +++++++++-- 6 files changed, 75 insertions(+), 21 deletions(-) diff --git a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.objects.js b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.objects.js index 98bc6691fb..d7be2f04f4 100644 --- a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.objects.js +++ b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.objects.js @@ -1,3 +1,3 @@ -var __extends=this&&this.__extends||function(){var t=function(e,s){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])},t(e,s)};return function(e,s){if("function"!=typeof s&&null!==s)throw new TypeError("Class extends value "+String(s)+" is not a constructor or null");function i(){this.constructor=e}t(e,s),e.prototype=null===s?Object.create(s):(i.prototype=s.prototype,new i)}}(),__spreadArray=this&&this.__spreadArray||function(t,e,s){if(s||2===arguments.length)for(var i,r=0,o=e.length;r=0)switch(t.stopImmediatePropagation(),o){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}}},e.prototype.handleMouseMove=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t,o=e.startX-this.mouseOldX,h=e.startY-this.mouseOldY;this.mouseOldX=e.startX,this.mouseOldY=e.startY;var n=this.corners.map((function(t){return t.isDown})).indexOf(!0);this.isMouseOn(e)&&(s("#robotLayer").css("cursor","pointer"),s("#robotLayer").data("hovered",!0),this.selected&&t.stopImmediatePropagation());for(var a=-1,c=0;c-1&&this.selected)switch(t.stopImmediatePropagation(),a){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}if(n>=0&&this.selected){if(this.w>=this.MIN_SIZE_OBJECT&&this.h>=this.MIN_SIZE_OBJECT)switch(n){case 0:this.x+=o,this.y+=h,this.w-=o,this.h-=h;break;case 1:this.y+=h,this.w+=o,this.h-=h;break;case 2:this.w+=o,this.h+=h;break;case 3:this.x+=o,this.w-=o,this.h+=h}else this.wthis.x&&t.startXthis.y&&t.startY=1&&(l.r=a[0]),a.length>=2&&(l.movable=a[1]>0),l.updateCorners(),l}return __extends(e,t),e.prototype.draw=function(t,e){if(t.save(),e.save(),this.type!==n.Obstacle&&this.type!==n.ColorArea||(this.type===n.Obstacle&&(t.shadowColor="#3e3e3e",t.shadowOffsetY=5,t.shadowOffsetX=5,t.shadowBlur=5,t.globalCompositeOperation="lighten"),t.fillStyle=this.color,t.beginPath(),t.arc(this.x,this.y,this.r,0,2*Math.PI),t.fill()),this.type===n.ColorArea&&(e.fillStyle=this.color,e.beginPath(),e.arc(this.x,this.y,this.r,0,2*Math.PI),e.fill()),this.selected){var s=Math.round(this.x),i=Math.round(this.y),r=Math.round(this.r);t.restore(),t.save(),t.lineWidth=2,t.strokeStyle="gray",t.fillStyle="black",t.beginPath(),t.arc(Math.round(s-r),Math.round(i-r),5,0,2*Math.PI),t.stroke(),t.fill(),t.beginPath(),t.arc(Math.round(s+r),Math.round(i-r),5,0,2*Math.PI),t.stroke(),t.fill(),t.beginPath(),t.arc(Math.round(s-r),Math.round(i+r),5,0,2*Math.PI),t.stroke(),t.fill(),t.beginPath(),t.arc(Math.round(s+r),Math.round(i+r),5,0,2*Math.PI),t.stroke(),t.fill()}t.restore(),e.restore()},e.prototype.handleKeyEvent=function(t){if(this.selected){switch(t.stopImmediatePropagation(),t.key){case"ArrowUp":this.y-=this.SHIFT;break;case"ArrowLeft":this.x-=this.SHIFT;break;case"ArrowDown":this.y+=this.SHIFT;break;case"ArrowRight":this.x+=this.SHIFT}if("c"===t.key&&(t.ctrlKey||t.metaKey)){this.myScene.uniqueObjectId,a.Circle;this.myScene.objectToCopy=c.copy(this),t.preventDefault()}this.updateCorners(),s("#robotLayer").attr("tabindex",0),s("#robotLayer").trigger("focus")}},e.prototype.handleMouseDown=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t;if(this.isDown=i.checkInCircle(e.startX,e.startY,this.x,this.y,this.r),this.isDown&&(t.stopImmediatePropagation(),this.mouseOldX=e.startX,this.mouseOldY=e.startY),this.isDown&&!this.selected)s("#robotLayer").css("cursor","pointer"),this.selected=!0;else if(this.selected&&!this.movable){this.corners.forEach((function(t){t.isDown=i.checkInCircle(e.startX,e.startY,t.x,t.y,15)}));var o=this.corners.map((function(t){return t.isDown})).indexOf(!0);if(o>=0)switch(t.stopImmediatePropagation(),o){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}}},e.prototype.handleMouseMove=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t,o=e.startX-this.mouseOldX,h=e.startY-this.mouseOldY;this.mouseOldX=e.startX,this.mouseOldY=e.startY;var n=this.corners.map((function(t){return t.isDown})).indexOf(!0);i.checkInCircle(e.startX,e.startY,this.x,this.y,this.r)&&(s("#robotLayer").css("cursor","pointer"),s("#robotLayer").data("hovered",!0),this.selected&&t.stopImmediatePropagation());var a=-1;if(!this.movable)for(var c=0;c-1&&this.selected)switch(t.stopImmediatePropagation(),a){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}n>=0&&this.selected?(Math.abs(o)>=Math.abs(h)?e.startX0){var e=o.getDotProduct(t,this.lastMove);this.lastMoveBumped?e&&(e<-.9||e&&e>.9)&&this.moveTo({x:this.x+t.x,y:this.y+t.y}):(this.lastMoveBumped=!1,this.moveTo({x:this.x+t.x,y:this.y+t.y}))}this.lastMove=t,this.collisions=[]},e.prototype.addObserver=function(t){this.observers.push(t)},e.prototype.notifyObservers=function(){for(var t=0,e=this.observers;t=0&&(t.stopImmediatePropagation(),s("#robotLayer").css("cursor","move"))}},e.prototype.handleMouseMove=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t,o=e.startX-this.mouseOldX,h=e.startY-this.mouseOldY;this.mouseOldX=e.startX,this.mouseOldY=e.startY;var n=this.corners.map((function(t){return t.isDown})).indexOf(!0);this.isMouseOn(e)&&(s("#robotLayer").css("cursor","pointer"),s("#robotLayer").data("hovered",!0),this.selected&&t.stopImmediatePropagation());for(var a=-1,c=0;c-1&&this.selected&&(s("#robotLayer").css("cursor","move"),t.stopImmediatePropagation()),n>=0&&this.selected){switch(n){case 0:this.ax+=o,this.ay+=h;break;case 1:this.bx+=o,this.by+=h;break;case 2:this.cx+=o,this.cy+=h}this.updateCorners()}else this.isDown&&(this.ax+=o,this.ay+=h,this.bx+=o,this.by+=h,this.cx+=o,this.cy+=h,this.updateCorners())},e.prototype.getLines=function(){return[{x1:this.ax,x2:this.bx,y1:this.ay,y2:this.by},{x1:this.bx,x2:this.cx,y1:this.by,y2:this.cy},{x1:this.ax,x2:this.cx,y1:this.ay,y2:this.cy}]},e.prototype.moveTo=function(t){var e=this.ax-t.x,s=this.ay-t.y;this.ax=t.x,this.ay=t.y,this.bx-=e,this.by-=s,this.cx-=e,this.cy-=s,this.updateCorners()},e.prototype.isMouseOn=function(t){var e=Math.floor(Math.abs((this.bx-this.ax)*(this.cy-this.ay)-(this.cx-this.ax)*(this.by-this.ay)));return Math.floor(Math.abs((this.ax-t.startX)*(this.by-t.startY)-(this.bx-t.startX)*(this.ay-t.startY)))+Math.floor(Math.abs((this.bx-t.startX)*(this.cy-t.startY)-(this.cx-t.startX)*(this.by-t.startY)))+Math.floor(Math.abs((this.cx-t.startX)*(this.ay-t.startY)-(this.ax-t.startX)*(this.cy-t.startY)))<=e},e.prototype.updateCorners=function(){0==this.corners.length?(this.corners[0]={x:this.ax,y:this.ay,isDown:!1},this.corners[1]={x:this.bx,y:this.by,isDown:!1},this.corners[2]={x:this.cx,y:this.cy,isDown:!1}):(this.corners[0]={x:this.ax,y:this.ay,isDown:this.corners[0].isDown},this.corners[1]={x:this.bx,y:this.by,isDown:this.corners[1].isDown},this.corners[2]={x:this.cx,y:this.cy,isDown:this.corners[2].isDown}),this.redraw()},e}(h);e.TriangleSimulationObject=d;var p=function(){function t(t,e,s,i){this.x=t,this.y=e,this.w=s,this.h=i}return t.prototype.getLines=function(){return i.getLinesFromRectangle(this)},t.prototype.getTolerance=function(){return 0},t}();e.Ground=p;var f=function(t){function e(e,s,i,r,o,h,n,a){var c=t.call(this,e,s,i,r,{x:90*o+10,y:90*h+10})||this;switch(c.w=90,c.h=90,c.type=r,c.rcjType=n,c.index=String(a),c.rcjType){case"checkPoint":c.color="#FFA500";break;case"start":c.color="#81E881"}return c}return __extends(e,t),e.prototype.draw=function(t,e){t.save(),this.rcjType&&(t.lineWidth=2,t.strokeStyle=this.color,t.strokeRect(this.x,this.y,this.w,this.h)),t.fillText(this.index,this.x+60,this.y+15),t.restore()},e.prototype.handleMouseDown=function(t){},e.prototype.handleMouseMove=function(t){},e}(l);e.RcjSimulationLabel=f})); +var __extends=this&&this.__extends||function(){var t=function(e,s){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])},t(e,s)};return function(e,s){if("function"!=typeof s&&null!==s)throw new TypeError("Class extends value "+String(s)+" is not a constructor or null");function i(){this.constructor=e}t(e,s),e.prototype=null===s?Object.create(s):(i.prototype=s.prototype,new i)}}(),__spreadArray=this&&this.__spreadArray||function(t,e,s){if(s||2===arguments.length)for(var i,r=0,o=e.length;r=0)switch(t.stopImmediatePropagation(),o){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}}},e.prototype.handleMouseMove=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t,o=e.startX-this.mouseOldX,h=e.startY-this.mouseOldY;this.mouseOldX=e.startX,this.mouseOldY=e.startY;var n=this.corners.map((function(t){return t.isDown})).indexOf(!0);this.isMouseOn(e)&&(s("#robotLayer").css("cursor","pointer"),s("#robotLayer").data("hovered",!0),this.selected&&t.stopImmediatePropagation());for(var a=-1,c=0;c-1&&this.selected)switch(t.stopImmediatePropagation(),a){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}if(n>=0&&this.selected){if(this.w>=this.MIN_SIZE_OBJECT&&this.h>=this.MIN_SIZE_OBJECT)switch(n){case 0:this.x+=o,this.y+=h,this.w-=o,this.h-=h;break;case 1:this.y+=h,this.w+=o,this.h-=h;break;case 2:this.w+=o,this.h+=h;break;case 3:this.x+=o,this.w-=o,this.h+=h}else this.wthis.x&&t.startXthis.y&&t.startY=1&&(l.r=a[0]),a.length>=2&&(l.movable=a[1]>0),l.updateCorners(),l}return __extends(e,t),e.prototype.draw=function(t,e){if(t.save(),e.save(),this.type!==n.Obstacle&&this.type!==n.ColorArea||(this.type===n.Obstacle&&(t.shadowColor="#3e3e3e",t.shadowOffsetY=5,t.shadowOffsetX=5,t.shadowBlur=5,t.globalCompositeOperation="lighten"),t.fillStyle=this.color,t.beginPath(),t.arc(this.x,this.y,this.r,0,2*Math.PI),t.fill()),this.type===n.ColorArea&&(e.fillStyle=this.color,e.beginPath(),e.arc(this.x,this.y,this.r,0,2*Math.PI),e.fill()),this.selected){var s=Math.round(this.x),i=Math.round(this.y),r=Math.round(this.r);t.restore(),t.save(),t.lineWidth=2,t.strokeStyle="gray",t.fillStyle="black",t.beginPath(),t.arc(Math.round(s-r),Math.round(i-r),5,0,2*Math.PI),t.stroke(),t.fill(),t.beginPath(),t.arc(Math.round(s+r),Math.round(i-r),5,0,2*Math.PI),t.stroke(),t.fill(),t.beginPath(),t.arc(Math.round(s-r),Math.round(i+r),5,0,2*Math.PI),t.stroke(),t.fill(),t.beginPath(),t.arc(Math.round(s+r),Math.round(i+r),5,0,2*Math.PI),t.stroke(),t.fill()}t.restore(),e.restore()},e.prototype.handleKeyEvent=function(t){if(this.selected){switch(t.stopImmediatePropagation(),t.key){case"ArrowUp":this.y-=this.SHIFT;break;case"ArrowLeft":this.x-=this.SHIFT;break;case"ArrowDown":this.y+=this.SHIFT;break;case"ArrowRight":this.x+=this.SHIFT}if("c"===t.key&&(t.ctrlKey||t.metaKey)){this.myScene.uniqueObjectId,a.Circle;this.myScene.objectToCopy=c.copy(this),t.preventDefault()}this.updateCorners(),s("#robotLayer").attr("tabindex",0),s("#robotLayer").trigger("focus")}},e.prototype.handleMouseDown=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t;if(this.isDown=i.checkInCircle(e.startX,e.startY,this.x,this.y,this.r),this.isDown&&(t.stopImmediatePropagation(),this.mouseOldX=e.startX,this.mouseOldY=e.startY),this.isDown&&!this.selected)s("#robotLayer").css("cursor","pointer"),this.selected=!0;else if(this.selected&&!this.movable){this.corners.forEach((function(t){t.isDown=i.checkInCircle(e.startX,e.startY,t.x,t.y,15)}));var o=this.corners.map((function(t){return t.isDown})).indexOf(!0);if(o>=0)switch(t.stopImmediatePropagation(),o){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}}},e.prototype.handleMouseMove=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t,o=e.startX-this.mouseOldX,h=e.startY-this.mouseOldY;this.mouseOldX=e.startX,this.mouseOldY=e.startY;var n=this.corners.map((function(t){return t.isDown})).indexOf(!0);i.checkInCircle(e.startX,e.startY,this.x,this.y,this.r)&&(s("#robotLayer").css("cursor","pointer"),s("#robotLayer").data("hovered",!0),this.selected&&t.stopImmediatePropagation());var a=-1;if(!this.movable)for(var c=0;c-1&&this.selected)switch(t.stopImmediatePropagation(),a){case 0:case 2:s("#robotLayer").css("cursor","nwse-resize");break;case 1:case 3:s("#robotLayer").css("cursor","nesw-resize")}n>=0&&this.selected?(Math.abs(o)>=Math.abs(h)?e.startX0){var e=o.getDotProduct(t,this.lastMove);this.lastMoveBumped?e&&(e<-.9||e&&e>.9)&&this.moveTo({x:this.x+t.x,y:this.y+t.y}):this.moveTo({x:this.x+t.x,y:this.y+t.y})}this.lastMove=t,this.collisions=[]},e.prototype.addObserver=function(t){this.observers.push(t)},e.prototype.notifyObservers=function(){for(var t=0,e=this.observers;t=0&&(t.stopImmediatePropagation(),s("#robotLayer").css("cursor","move"))}},e.prototype.handleMouseMove=function(t){t&&!t.startX&&i.extendMouseEvent(t,r.SimulationRoberta.Instance.scale,s("#robotLayer"));var e=t,o=e.startX-this.mouseOldX,h=e.startY-this.mouseOldY;this.mouseOldX=e.startX,this.mouseOldY=e.startY;var n=this.corners.map((function(t){return t.isDown})).indexOf(!0);this.isMouseOn(e)&&(s("#robotLayer").css("cursor","pointer"),s("#robotLayer").data("hovered",!0),this.selected&&t.stopImmediatePropagation());for(var a=-1,c=0;c-1&&this.selected&&(s("#robotLayer").css("cursor","move"),t.stopImmediatePropagation()),n>=0&&this.selected){switch(n){case 0:this.ax+=o,this.ay+=h;break;case 1:this.bx+=o,this.by+=h;break;case 2:this.cx+=o,this.cy+=h}this.updateCorners()}else this.isDown&&(this.ax+=o,this.ay+=h,this.bx+=o,this.by+=h,this.cx+=o,this.cy+=h,this.updateCorners())},e.prototype.getLines=function(){return[{x1:this.ax,x2:this.bx,y1:this.ay,y2:this.by},{x1:this.bx,x2:this.cx,y1:this.by,y2:this.cy},{x1:this.ax,x2:this.cx,y1:this.ay,y2:this.cy}]},e.prototype.moveTo=function(t){var e=this.ax-t.x,s=this.ay-t.y;this.ax=t.x,this.ay=t.y,this.bx-=e,this.by-=s,this.cx-=e,this.cy-=s,this.updateCorners()},e.prototype.isMouseOn=function(t){var e=Math.floor(Math.abs((this.bx-this.ax)*(this.cy-this.ay)-(this.cx-this.ax)*(this.by-this.ay)));return Math.floor(Math.abs((this.ax-t.startX)*(this.by-t.startY)-(this.bx-t.startX)*(this.ay-t.startY)))+Math.floor(Math.abs((this.bx-t.startX)*(this.cy-t.startY)-(this.cx-t.startX)*(this.by-t.startY)))+Math.floor(Math.abs((this.cx-t.startX)*(this.ay-t.startY)-(this.ax-t.startX)*(this.cy-t.startY)))<=e},e.prototype.updateCorners=function(){0==this.corners.length?(this.corners[0]={x:this.ax,y:this.ay,isDown:!1},this.corners[1]={x:this.bx,y:this.by,isDown:!1},this.corners[2]={x:this.cx,y:this.cy,isDown:!1}):(this.corners[0]={x:this.ax,y:this.ay,isDown:this.corners[0].isDown},this.corners[1]={x:this.bx,y:this.by,isDown:this.corners[1].isDown},this.corners[2]={x:this.cx,y:this.cy,isDown:this.corners[2].isDown}),this.redraw()},e}(h);e.TriangleSimulationObject=d;var p=function(){function t(t,e,s,i){this.x=t,this.y=e,this.w=s,this.h=i}return t.prototype.getLines=function(){return i.getLinesFromRectangle(this)},t.prototype.getTolerance=function(){return 0},t}();e.Ground=p;var f=function(t){function e(e,s,i,r,o,h,n,a){var c=t.call(this,e,s,i,r,{x:90*o+10,y:90*h+10})||this;switch(c.w=90,c.h=90,c.type=r,c.rcjType=n,c.index=String(a),c.rcjType){case"checkPoint":c.color="#FFA500";break;case"start":c.color="#81E881"}return c}return __extends(e,t),e.prototype.draw=function(t,e){t.save(),this.rcjType&&(t.lineWidth=2,t.strokeStyle=this.color,t.strokeRect(this.x,this.y,this.w,this.h)),t.fillText(this.index,this.x+60,this.y+15),t.restore()},e.prototype.handleMouseDown=function(t){},e.prototype.handleMouseMove=function(t){},e}(l);e.RcjSimulationLabel=f})); //# sourceMappingURL=simulation.objects.js.map //# sourceMappingURL=simulation.objects.js.map diff --git a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.roberta.js b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.roberta.js index b9baf7d353..f3060f5c71 100644 --- a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.roberta.js +++ b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/simulation.roberta.js @@ -1,3 +1,3 @@ -var __awaiter=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(this.scale*=1.025,this.scale>15&&(this.scale=15),s=!0):n<0&&(this.scale*=.925,this.scale<.25&&(this.scale=.25),s=!0),s){var c=this.scale-t,l=a("#canvasDiv").position(),u=this.scene.uCanvas.width*c,h=this.scene.uCanvas.height*c;l.top=l.top-h/2,l.left=l.left-u/2,a("#canvasDiv").css({top:l.top}),a("#canvasDiv").css({left:l.left}),this.scene.resetAllCanvas(!1)}return!1},e.prototype.importConfigData=function(){a("#backgroundFileSelector").val(null),a("#backgroundFileSelector").attr("accept",".json"),a("#backgroundFileSelector").off();var e=this;a("#backgroundFileSelector").onWrap("change",(function(t){var n=t.target.files[0],r=new FileReader;return r.onload=function(t){try{var n=JSON.parse(t.target.result);e.setNewConfig(n)}catch(e){console.error(e)}},r.readAsText(n),!1})),a("#backgroundFileSelector").clickWrap()},e.prototype.importImage=function(){var e=a("#backgroundFileSelector");e.val(null),e.attr("accept",".png, .jpg, .jpeg, .svg"),e.clickWrap();var t=this;e.on("change",(function(e){var n=e.target.files[0],i=new FileReader;return i.onload=function(){var e=new Image;e.onload=function(){var n=document.createElement("canvas");n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0);var i=n.toDataURL("image/png"),o=new Image(n.width,n.height);o.src=i,o.onload=function(){t.scene.customBackgroundLoaded?t.scene.imgBackgroundList[t.scene.imgBackgroundList.length-1]=o:t.scene.imgBackgroundList.push(o),t.setBackground(t.scene.imgBackgroundList.length-1)},r.isLocalStorageAvailable()&&(a("#show-message-confirm").oneWrap("shown.bs.modal",(function(){a("#confirm").off(),a("#confirm").on("click",(function(e){e.preventDefault(),localStorage.setItem("customBackground",JSON.stringify({image:i.replace(/^data:image\/(png|jpg);base64,/,""),timestamp:(new Date).getTime()}))})),a("#confirmCancel").off(),a("#confirmCancel").on("click",(function(e){e.preventDefault()}))})),s.displayPopupMessage("Blockly.Msg.POPUP_BACKGROUND_STORAGE",l.Msg.POPUP_BACKGROUND_STORAGE,l.Msg.YES,l.Msg.NO))},"string"==typeof i.result&&(e.src=i.result)},i.readAsDataURL(n),!1}))},e.prototype.init=function(e,t,n,r){var s=this;this.robotType=r||this.robotType,this.storedPrograms=e,this.resetRenderUntil(e.length);var a=[];this.interpreters=e.map((function(e){var t=JSON.parse(e.javaScriptProgram);return a.push(e.configuration),new i.Interpreter(t,new o.RobotSimBehaviour,s.callbackOnTermination.bind(s),s.breakpoints,e.programName,e.updateNNView)})),this.updateDebugMode(this.debugMode);var c=e.map((function(e){return e.programName}));this.scene.init(this.robotType,t,this.interpreters,a,c,this.importPoses,n)},e.prototype.initColorPicker=function(e){var t=this;e&&e.length>0?this.colorpicker=new c("#colorpicker",{shades:1,hues:8,customColors:e,setText:!1}):this.colorpicker=new c("#colorpicker",{shades:1,hues:8,setText:!1}),this.colorpicker.on("change",(function(e){t.scene.changeColorWithColorPicker(e)}));var n=c.prototype.close;c.prototype.close=function(){a(".huebee__container").off("mouseup touchend",(function(e){e.stopPropagation(),t.resetColorpickerCursor()})),n.call(this)};var r=c.prototype.open;c.prototype.open=function(){r.call(this),a(".huebee__container").on("mouseup touchend",(function(e){t.resetColorpickerCursor()})),a(".huebee").draggable({})}},e.prototype.initEvents=function(){var e=this,t=this;a(window).on("focus",(function(){return t.start(),!1})),a(window).on("blur",(function(){return t.stop(),!1})),a("#simDiv").on("wheel mousewheel touchmove",(function(t){e.handleMouseWheel(t)})),a("#canvasDiv").on("mousedown touchstart mousemove touchmove mouseup touchend mouseout touchcancel",(function(t){e.handleMouse(t)})),a("#robotLayer").on("click touchstart",(function(e){a("#robotLayer").attr("tabindex",0),a("#robotLayer").trigger("focus"),e.preventDefault()})),a("#blocklyDiv").on("click touchstart",(function(e){a("#blocklyDiv").trigger("focus"),e.preventDefault()}))},e.prototype.interpreterAddEvent=function(e){this.updateBreakpointEvent(),this.interpreters&&this.interpreters.forEach((function(t){return t.addEvent(e)}))},e.prototype.removeBreakPoint=function(e){for(var t=0;t0&&null!==this.interpreters)for(t=0;t0&&y.push(n),n.items&&n.items.obstacles&&n.items.obstacles>0){var k={};k.id=t.scene.uniqueObjectId,k.shape=f.SimObjectShape.Rectangle,k.color="#ff0000",k.newObjecttype=f.SimObjectType.Obstacle,k.p={x:n.x*t.TILE_SIZE+t.TILE_SIZE/4+10,y:n.y*t.TILE_SIZE+t.TILE_SIZE/4+10},k.params=[.5*t.TILE_SIZE,.5*t.TILE_SIZE],I.push(k)}})),d.length>=2&&b.length>=2&&v.length>=2&&E.length>=2){d.sort((function(e,t){return e.x-t.x})),b.sort((function(e,t){return e.y-t.y})),v.sort((function(e,t){return e.x-t.x})),E.sort((function(e,t){return e.y-t.y}));var k={id:t.scene.uniqueObjectId,p:{x:d[0].x*t.TILE_SIZE+10,y:d[0].y*t.TILE_SIZE+t.EV_WALL_SIZE},params:[t.TILE_SIZE*(d[d.length-1].x-d[0].x+1),t.EV_WALL_SIZE],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle},S={id:t.scene.uniqueObjectId,p:{x:b[0].x*t.TILE_SIZE+t.TILE_SIZE,y:b[0].y*t.TILE_SIZE+t.EV_WALL_SIZE},params:[t.EV_WALL_SIZE,t.TILE_SIZE*(b[b.length-1].y-b[0].y+1)],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle},T={id:t.scene.uniqueObjectId,p:{x:v[0].x*t.TILE_SIZE+10,y:v[0].y*t.TILE_SIZE+t.TILE_SIZE},params:[t.TILE_SIZE*(v[v.length-1].x-v[0].x+1),t.EV_WALL_SIZE],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle},w={id:t.scene.uniqueObjectId,p:{x:E[0].x*t.TILE_SIZE+10,y:E[0].y*t.TILE_SIZE+t.EV_WALL_SIZE},params:[t.EV_WALL_SIZE,t.TILE_SIZE*(E[E.length-1].y-E[0].y+1)],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle};I.push(k,S,T,w);var L=h.filter((function(e){return e.tileType.image.startsWith("ev3")}));!function(e,n){n.save(),n.translate(e.x*t.TILE_SIZE+t.TILE_SIZE/2,e.y*t.TILE_SIZE+t.TILE_SIZE/2);var r=0;switch(e.rot){case 0:break;case 90:r=Math.PI/2;break;case 180:r=Math.PI;break;case 270:r=270*Math.PI/180}n.rotate(r),n.beginPath(),n.moveTo(-t.TILE_SIZE/2,-t.TILE_SIZE/2),n.lineTo(t.TILE_SIZE/2,-t.TILE_SIZE/2),n.lineTo(t.TILE_SIZE/2,t.TILE_SIZE/2),n.closePath(),n.fillStyle="#000000",n.fill(),n.restore()}(L[Math.floor(Math.random()*L.length)],u)}if(g?m=t.getTilePose(g,e.tiles[g.next],{}):(i.rc="error",i.message="Unknown start tile"),p||(i.rc="error",i.message="Unknown evacuation zone entrance tile"),"ok"===i.rc){t.deleteAllColorArea(),t.deleteAllObstacle(),function(e,n){n.save(),n.translate(e.x*t.TILE_SIZE+t.TILE_SIZE/2,e.y*t.TILE_SIZE+t.TILE_SIZE/2);var r=0;switch(e.dir){case"top":break;case"right":r=Math.PI/2;break;case"bottom":r=Math.PI;break;case"left":r=270*Math.PI/180}n.rotate(r),n.fillStyle="#33B8CA",n.fillRect(-t.TILE_SIZE/2,-t.TILE_SIZE/2,t.TILE_SIZE,t.EV_WALL_SIZE),n.restore()}(p,u),function(e){e.strokeStyle="#dddddd",e.lineWidth=1;for(var n=1;n0)for(var u=0;u0)for(u=0;u0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0?(this.scale*=1.025,this.scale>15&&(this.scale=15),s=!0):n<0&&(this.scale*=.925,this.scale<.25&&(this.scale=.25),s=!0),s){var c=this.scale-t,l=a("#canvasDiv").position(),u=this.scene.uCanvas.width*c,h=this.scene.uCanvas.height*c;l.top=l.top-h/2,l.left=l.left-u/2,a("#canvasDiv").css({top:l.top}),a("#canvasDiv").css({left:l.left}),this.scene.resetAllCanvas(!1)}return!1},e.prototype.importConfigData=function(){a("#backgroundFileSelector").val(null),a("#backgroundFileSelector").attr("accept",".json"),a("#backgroundFileSelector").off();var e=this;a("#backgroundFileSelector").onWrap("change",(function(t){var n=t.target.files[0],r=new FileReader;return r.onload=function(t){try{var n=JSON.parse(t.target.result);e.setNewConfig(n)}catch(e){console.error(e)}},r.readAsText(n),!1})),a("#backgroundFileSelector").clickWrap()},e.prototype.importImage=function(){var e=a("#backgroundFileSelector");e.val(null),e.attr("accept",".png, .jpg, .jpeg, .svg"),e.clickWrap();var t=this;e.on("change",(function(e){var n=e.target.files[0],o=new FileReader;return o.onload=function(){var e=new Image;e.onload=function(){var n=document.createElement("canvas");n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0);var o=n.toDataURL("image/png"),i=new Image(n.width,n.height);i.src=o,i.onload=function(){t.scene.customBackgroundLoaded?t.scene.imgBackgroundList[t.scene.imgBackgroundList.length-1]=i:t.scene.imgBackgroundList.push(i),t.setBackground(t.scene.imgBackgroundList.length-1)},r.isLocalStorageAvailable()&&(a("#show-message-confirm").oneWrap("shown.bs.modal",(function(){a("#confirm").off(),a("#confirm").on("click",(function(e){e.preventDefault(),localStorage.setItem("customBackground",JSON.stringify({image:o.replace(/^data:image\/(png|jpg);base64,/,""),timestamp:(new Date).getTime()}))})),a("#confirmCancel").off(),a("#confirmCancel").on("click",(function(e){e.preventDefault()}))})),s.displayPopupMessage("Blockly.Msg.POPUP_BACKGROUND_STORAGE",l.Msg.POPUP_BACKGROUND_STORAGE,l.Msg.YES,l.Msg.NO))},"string"==typeof o.result&&(e.src=o.result)},o.readAsDataURL(n),!1}))},e.prototype.init=function(e,t,n,r){var s=this;this.robotType=r||this.robotType,this.storedPrograms=e,this.resetRenderUntil(e.length);var a=[];this.interpreters=e.map((function(e){var t=JSON.parse(e.javaScriptProgram);return a.push(e.configuration),new o.Interpreter(t,new i.RobotSimBehaviour,s.callbackOnTermination.bind(s),s.breakpoints,e.programName,e.updateNNView)})),this.updateDebugMode(this.debugMode);var c=e.map((function(e){return e.programName}));this.scene.init(this.robotType,t,this.interpreters,a,c,this.importPoses,n)},e.prototype.initColorPicker=function(e){var t=this;e&&e.length>0?this.colorpicker=new c("#colorpicker",{shades:1,hues:8,customColors:e,setText:!1}):this.colorpicker=new c("#colorpicker",{shades:1,hues:8,setText:!1}),this.colorpicker.on("change",(function(e){t.scene.changeColorWithColorPicker(e)}));var n=c.prototype.close;c.prototype.close=function(){a(".huebee__container").off("mouseup touchend",(function(e){e.stopPropagation(),t.resetColorpickerCursor()})),n.call(this)};var r=c.prototype.open;c.prototype.open=function(){r.call(this),a(".huebee__container").on("mouseup touchend",(function(e){t.resetColorpickerCursor()})),a(".huebee").draggable({})}},e.prototype.initEvents=function(){var e=this,t=this;a(window).on("focus",(function(){return t.start(),!1})),a(window).on("blur",(function(){return t.stop(),!1})),a("#simDiv").on("wheel mousewheel touchmove",(function(t){e.handleMouseWheel(t)})),a("#canvasDiv").on("mousedown touchstart mousemove touchmove mouseup touchend mouseout touchcancel",(function(t){e.handleMouse(t)})),a("#robotLayer").on("click touchstart",(function(e){a("#robotLayer").attr("tabindex",0),a("#robotLayer").trigger("focus"),e.preventDefault()})),a("#blocklyDiv").on("click touchstart",(function(e){a("#blocklyDiv").trigger("focus"),e.preventDefault()}))},e.prototype.interpreterAddEvent=function(e){this.updateBreakpointEvent(),this.interpreters&&this.interpreters.forEach((function(t){return t.addEvent(e)}))},e.prototype.removeBreakPoint=function(e){for(var t=0;t0&&null!==this.interpreters)for(t=0;t0)for(var u=0;u0)for(u=0;u0&&y.push(n),n.items&&n.items.obstacles&&n.items.obstacles>0){var v={};v.id=t.scene.uniqueObjectId,v.shape=f.SimObjectShape.Rectangle,v.color="#ff0000",v.newObjecttype=f.SimObjectType.Obstacle,v.p={x:n.x*t.TILE_SIZE+t.TILE_SIZE/4+10,y:n.y*t.TILE_SIZE+t.TILE_SIZE/4+10},v.params=[.5*t.TILE_SIZE,.5*t.TILE_SIZE],k.push(v)}})),d.length>=2&&g.length>=2&&_.length>=2&&S.length>=2){d.sort((function(e,t){return e.x-t.x})),g.sort((function(e,t){return e.y-t.y})),_.sort((function(e,t){return e.x-t.x})),S.sort((function(e,t){return e.y-t.y}));var T={id:t.scene.uniqueObjectId,p:{x:d[0].x*t.TILE_SIZE+10,y:d[0].y*t.TILE_SIZE+t.EV_WALL_SIZE},params:[t.TILE_SIZE*(d[d.length-1].x-d[0].x+1),t.EV_WALL_SIZE],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle},w={id:t.scene.uniqueObjectId,p:{x:g[0].x*t.TILE_SIZE+t.TILE_SIZE,y:g[0].y*t.TILE_SIZE+t.EV_WALL_SIZE},params:[t.EV_WALL_SIZE,t.TILE_SIZE*(g[g.length-1].y-g[0].y+1)],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle},L={id:t.scene.uniqueObjectId,p:{x:_[0].x*t.TILE_SIZE+10,y:_[0].y*t.TILE_SIZE+t.TILE_SIZE},params:[t.TILE_SIZE*(_[_.length-1].x-_[0].x+1),t.EV_WALL_SIZE],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle},x={id:t.scene.uniqueObjectId,p:{x:S[0].x*t.TILE_SIZE+10,y:S[0].y*t.TILE_SIZE+t.EV_WALL_SIZE},params:[t.EV_WALL_SIZE,t.TILE_SIZE*(S[S.length-1].y-S[0].y+1)],theta:0,color:"#ffffff",shape:f.SimObjectShape.Rectangle,type:f.SimObjectType.Obstacle};k.push(T,w,L,x);var P=h.filter((function(e){return e.tileType.image.startsWith("ev3")}));!function(e,n){n.save(),n.translate(e.x*t.TILE_SIZE+t.TILE_SIZE/2,e.y*t.TILE_SIZE+t.TILE_SIZE/2);var r=0;switch(e.rot){case 0:break;case 90:r=Math.PI/2;break;case 180:r=Math.PI;break;case 270:r=270*Math.PI/180}n.rotate(r),n.beginPath(),n.moveTo(-t.TILE_SIZE/2,-t.TILE_SIZE/2),n.lineTo(t.TILE_SIZE/2,-t.TILE_SIZE/2),n.lineTo(t.TILE_SIZE/2,t.TILE_SIZE/2),n.closePath(),n.fillStyle="#000000",n.fill(),n.restore()}(P[Math.floor(Math.random()*P.length)],u)}if(m?b=t.getTilePose(m,e.tiles[m.next],{}):(o.rc="error",o.message="Unknown start tile"),p||(o.rc="error",o.message="Unknown evacuation zone entrance tile"),"ok"===o.rc){t.deleteAllColorArea(),t.deleteAllObstacle(),function(e,n){n.save(),n.translate(e.x*t.TILE_SIZE+t.TILE_SIZE/2,e.y*t.TILE_SIZE+t.TILE_SIZE/2);var r=0;switch(e.dir){case"top":break;case"right":r=Math.PI/2;break;case"bottom":r=Math.PI;break;case"left":r=270*Math.PI/180}n.rotate(r),n.fillStyle="#33B8CA",n.fillRect(-t.TILE_SIZE/2,-t.TILE_SIZE/2,t.TILE_SIZE,t.EV_WALL_SIZE),n.restore()}(p,u),function(e){e.strokeStyle="#dddddd",e.lineWidth=1;for(var n=1;n=0?(s(this).html("Stop
Scoring Run"),e.init(),s("#rcjStartStop").addClass("running"),!1):(s(this).html("Start
Scoring Run"),clearInterval(e.stopWatch),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),e.robot&&e.robot.interpreter.terminate(),e.programPaused=!0,!1)})),s("#rcjLoP").off().on("click",(function(t){e.robot.interpreter.terminate(),e.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled");var o=r.default.getTilePose(e.lastCheckPoint,i.tiles[e.lastCheckPoint.next],e.prevCheckPointTile);return e.robot.pose=new n.Pose(o.x,o.y,o.theta),e.robot.initialPose=new n.Pose(o.x,o.y,o.theta),e.path=e.lastCheckPoint.index[0],e.lastPath=e.path,e.loPCounter+=1,e.loPSum+=1,e.nextCheckPoint&&e.loPCounter>=3&&s("#rcjNextCP").removeClass("disabled"),!1})),s("#rcjNextCP").off().on("click",(function(t){if(e.robot.interpreter.terminate(),e.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),e.nextCheckPoint){var o=r.default.getTilePose(e.nextCheckPoint,i.tiles[e.nextCheckPoint.next],e.prevNextCheckPoint);e.robot.pose=new n.Pose(o.x,o.y,o.theta),e.robot.initialPose=new n.Pose(o.x,o.y,o.theta),e.path=e.nextCheckPoint.index[0],e.lastPath=e.path,e.loPCounter=0,e.section+=1,e.lastCheckPoint=e.nextCheckPoint,e.setNextCheckPoint()}})),s("#rcjName").text(i.name),s("#rcjTeam").text(t.interpreter.name),s("#rcjTime").text("00:00:0")}return t.prototype.init=function(){this.path=0,this.lastPath=0,this.line=!0,clearInterval(this.stopWatch),this.mins=0,this.secs=0,this.csecs=0,this.running=!0,this.stopWatch=setInterval(this.timer.bind(this),100);var t=this.configData.tiles[this.configData.startTile.x+","+this.configData.startTile.y+",0"];this.initialPose=r.default.getTilePose(t,this.configData.tiles[t.next],null),this.lastTile=t,this.lastCheckPoint=t,this.robot&&(this.robot.initialPose=this.initialPose,this.robot.resetPose()),this.loPCounter=0,this.loPSum=0,this.section=0,this.victimsLocated=0,this.linePoints=0,this.obstaclePoints=0,this.totalScore=0,this.inAvoidanceMode=!1,this.countedTileIndices=[0],this.lastCheckPointIndex=0,this.rescueMulti=1},t.prototype.timer=function(){this.running&&(this.csecs++,10===this.csecs&&(this.secs++,this.csecs=0),60===this.secs&&(this.mins++,this.secs=0),s("#rcjTime").text(("00"+this.mins).slice(-2)+":"+("00"+this.secs).slice(-2)+":"+this.csecs),s("#rcjPath").text(-1===this.path?"wrong":"correct"),s("#rcjLastPath").text(this.lastPath),s("#rcjSection").text(this.section),s("#rcjLoPpS").text(this.loPCounter),s("#rcjLoPCount").text(this.loPSum),s("#rcjLine").text(this.line?"yes":"no"),this.mins>=this.MAX_TIME&&s("#rcjStartStop").trigger("click"),s("#rcjRescueMulti").text(Math.round(100*this.rescueMulti)/100),s("#rcjLinePoints").text(this.linePoints),s("#rcjObstaclePoints").text(this.obstaclePoints),s("#rcjTotalScore").text(this.totalScore))},t.prototype.countObstaclePoints=function(t){t&&!this.countedTileIndices.includes(t.index[0])&&(t.tileType.gaps>0&&(this.obstaclePoints+=this.POINTS_GAP),t.tileType.intersections>0&&(this.obstaclePoints+=this.POINTS_INTERSECTION),this.countedTileIndices.push(t.index[0]))},t.prototype.callAutoLoP=function(){s("#rcjLoP").trigger("click")},t.prototype.update=function(t){if(this.running)if(t instanceof n.RobotBaseMobile){var i=t;this.robot!=i&&(this.robot=i,this.initialPose=this.robot.initialPose),this.programPaused&&(this.programPaused=!1,s("#rcjLoP").removeClass("disabled"),s("#rcjNextCP").addClass("disabled")),this.pose=i.pose;var r=Math.floor((this.pose.x-10)/90),a=Math.floor((this.pose.y-10)/90),c=this.configData.tiles[r+","+a+",0"],h=c&&c.index[0];if(h==this.lastPath||h==this.lastPath+1){if(this.path=h,this.lastPath=h,this.line=i.F.lightValue<70,this.line&&(this.wasOnLineOnce=!0),c&&c.checkPoint||0==h){if(this.lastCheckPoint!=c){var l=this.loPCounter0&&1===this.configData.tiles[this.lastTile.next].items.obstacles?(this.inAvoidanceMode=!0,this.path+=1,this.lastPath=this.path,this.avoidanceGoalIndex=this.lastTile.index[0]+2):this.lastTile.items.obstacles>0?(this.inAvoidanceMode=!0,this.avoidanceGoalIndex=this.lastTile.index[0]+1):(-1!=this.path&&h&&this.callAutoLoP(),this.path=-1)),this.line=!1;this.totalScore=(this.linePoints+this.obstaclePoints)*this.rescueMulti,this.totalScore=e.round(this.totalScore,2)}else if(t instanceof o.CircleSimulationObject){var d=t;d.inEvacuationZone&&"#33B8CA"===d.color&&(d.selected=!0,s("#simDeleteObject").trigger("click"),this.rescueMulti*=this.POINTS_VICTIM_MULTI,this.victimsLocated+=1),d.inEvacuationZone&&"#000000"===d.color&&(d.selected=!0,s("#simDeleteObject").trigger("click"),this.victimsLocated>1?this.rescueMulti*=this.POINTS_VICTIM_MULTI:this.rescueMulti*=this.POINTS_DEADONLY_VICTIM_MULTI,this.victimsLocated+=1),this.victimsLocated>=3&&s("#rcjStartStop").trigger("click")}},t.prototype.setNextCheckPoint=function(){for(var t=this.configData.tiles[this.lastCheckPoint.next];t&&this.configData.tiles[t.next]&&(this.prevNextCheckPoint=t,!(t=this.configData.tiles[t.next]).checkPoint););t&&t.checkPoint?this.nextCheckPoint=t:(this.nextCheckPoint=null,this.prevNextCheckPoint=null)},t.prototype.openClose=function(){var t=s("#simDiv").position();t.left=12,s("#rcjScoringWindow").toggleSimPopup(t)},t.prototype.destroy=function(){s("#rcjStartStop").html("Start
Scoring Run"),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),clearInterval(this.stopWatch),this.stopWatch=null,s("#rcjPath").text(""),s("#rcjLastPath").text(""),s("#rcjSection").text(""),s("#rcjLoPpS").text(""),s("#rcjLoPCount").text(""),s("#rcjLine").text(""),s("#rcjName").text(""),s("#rcjTeam").text(""),s("#rcjTime").text("00:00:0"),s("#rcjRescueMulti").text("")},t}();i.RcjScoringTool=c;var h=function(){function t(t){this.DEFAULT_TRAIL_WIDTH=10,this.DEFAULT_TRAIL_COLOR="#000000",this.customBackgroundLoaded=!1,this.ground=new o.Ground(0,0,0,0),this.imgBackgroundList=[],this.imgPath="/css/img/simBackgrounds/",this.playground={x:0,y:0,w:0,h:0},this._colorAreaList=[],this._obstacleList=[],this._rcjList=[],this._markerList=[],this._redrawColorAreas=!1,this._redrawObstacles=!1,this._redrawMarkers=!1,this._robots=[],this._uniqueObjectId=0,this._scoring=!1,this.sim=t,this.uCanvas=document.createElement("canvas"),this.uCtx=this.uCanvas.getContext("2d",{willReadFrequently:!0}),this.udCanvas=document.createElement("canvas"),this.udCtx=this.udCanvas.getContext("2d",{willReadFrequently:!0}),this.bCtx=s("#backgroundLayer")[0].getContext("2d"),this.dCtx=s("#drawLayer")[0].getContext("2d"),this.aCtx=s("#arucoMarkerLayer")[0].getContext("2d"),this.oCtx=s("#objectLayer")[0].getContext("2d"),this.rCtx=s("#robotLayer")[0].getContext("2d"),this.rcjCtx=s("#rcjLayer")[0].getContext("2d")}return Object.defineProperty(t.prototype,"scoring",{get:function(){return this._scoring},set:function(t){this._scoring=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uniqueObjectId",{get:function(){return++this._uniqueObjectId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"robots",{get:function(){return this._robots},set:function(t){this.clearList(this._robots),this._robots=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"obstacleList",{get:function(){return this._obstacleList},set:function(t){this.clearList(this._obstacleList),this._obstacleList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rcjList",{get:function(){return this._rcjList},set:function(t){this.clearList(this._rcjList),this._rcjList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"colorAreaList",{get:function(){return this._colorAreaList},set:function(t){this.clearList(this._colorAreaList),this._colorAreaList=t,this.redrawColorAreas=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"markerList",{get:function(){return this._markerList},set:function(t){this.clearList(this._markerList),this._markerList=t,this.redrawMarkers=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawObstacles",{get:function(){return this._redrawObstacles},set:function(t){this._redrawObstacles=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawColorAreas",{get:function(){return this._redrawColorAreas},set:function(t){this._redrawColorAreas=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawMarkers",{get:function(){return this._redrawMarkers},set:function(t){this._redrawMarkers=t},enumerable:!1,configurable:!0}),t.prototype.addColorArea=function(t){this.addSimulationObject(this.colorAreaList,t,o.SimObjectType.ColorArea),this.redrawColorAreas=!0},t.prototype.addImportColorAreaList=function(t){var i=this,e=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.ColorArea,t.p,null,t.color],t.params,!1));e.push(s)})),this.colorAreaList=e},t.prototype.addImportObstacle=function(t){var i=this,e=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));e.push(s)})),this.obstacleList=e},t.prototype.addImportRcjLabel=function(t){var i=this,e=[];t.forEach((function(t){var s=new o.RcjSimulationLabel(i.uniqueObjectId,i,i.sim.selectionListener,o.SimObjectType.ColorArea,t.x,t.y,t.checkPoint?"checkPoint":t.start?"start":null,t.index[0]);e.push(s)})),this.rcjList=e},t.prototype.addImportMarkerList=function(t){var i=this,e=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.Marker,t.p,null,t.color],t.params,!1));s.markerId=t.markerId,e.push(s)})),this.markerList=e},t.prototype.addObstacle=function(t){this.addSimulationObject(this.obstacleList,t,o.SimObjectType.Obstacle),this.redrawObstacles=!0},t.prototype.addSimulationObject=function(t,i,e,r){var a=s("#robotLayer");a.attr("tabindex",0),a.trigger("focus");var n=Math.random()*(this.ground.w-300)+100,c=Math.random()*(this.ground.h-200)+100,h=o.SimObjectFactory.getSimObject(this.uniqueObjectId,this,this.sim.selectionListener,i,e,{x:n,y:c},this.backgroundImg.width);i==o.SimObjectShape.Marker&&r&&(h.markerId=r),t.push(h),h.selected=!0},t.prototype.changeColorWithColorPicker=function(t){var i=this.obstacleList.concat(this.colorAreaList).filter((function(t){return t.selected}));1==i.length&&(i[0].color=t,i[0].type===o.SimObjectType.Obstacle?this.redrawObstacles=!0:this.redrawColorAreas=!0)},t.prototype.clearList=function(t){t.forEach((function(t){t.destroy()})),t.length=0},t.prototype.deleteSelectedObject=function(){var t=this;function i(i){for(var e=0;e.pace").show(),this.robots=[],a.RobotFactory.createRobots(r,n,c,this.sim.selectionListener,this.robotType).then((function(t){if(d.robots=t.robots,d.robotClass=t.robotClass,d.setRobotPoses(h),d.initViews(),u){d.removeRcjScoringTool(),g.imgBackgroundList=[],g.currentBackground=0,g.obstacleList.length>0&&(g.obstacleList=[]),g.colorAreaList.length>0&&(g.colorAreaList=[]);var i=".svg";e.isIE()&&(i=".png"),g.loadBackgroundImages((function(){g.robots[0].mobile?(s(".simMobile").show(),g.images=g.loadImages(["roadWorks","pattern"],["roadWorks"+i,"wallPattern.png"],(function(){g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0];var t=new o.RectangleSimulationObject(0,g,g.sim.selectionListener,o.SimObjectType.Obstacle,{x:7*g.backgroundImg.width/9,y:g.backgroundImg.height-2*g.backgroundImg.width/9},g.backgroundImg.width);g.obstacleList.push(t),g.centerBackground(!0),g.initEvents(),g.sim.initColorPicker(a.RobotBase.colorRange),g.showFullyLoadedSim(l),g.sim.start()}))):(s(".simMobile").hide(),g.images={},g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0],g.centerBackground(!0),g.initEvents(),g.showFullyLoadedSim(l),g.sim.start())}))}d.showFullyLoadedSim(l),d.sim.start()}))):(this.robots.forEach((function(t,i){g.rcjScoringTool&&t.addObserver(g.rcjScoringTool),t.replaceState(r[i]),t.reset()})),this.showFullyLoadedSim(l)),this.robots.forEach((function(t,i){t.time=0}))},t.prototype.showFullyLoadedSim=function(t){this.obstacleList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.markerList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.colorAreaList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),s("#canvasDiv").fadeIn("slow"),s("#simDiv>.pace").fadeOut("fast"),"function"==typeof t&&t()},t.prototype.initViews=function(){var t=s("#systemValuesView"),i=s("#robotIndex");t.html("");var e="",o=this.robots[0]instanceof n.RobotBaseMobile?this.robots[0].chassis.geom.color:"#ffffff";if(e+='",t.append('
'+e+"
"),i.off("change.sim"),this.robots.length>1){var r=this;i.on("change.sim",(function(){var t=Number(s(this).val());r.robots[t].selected=!0,r.sim.selectionListener.fire(null)}))}},t.prototype.initEvents=function(){var t=this,i=0;s(window).off("resize.sim").on("resize.sim",(function(e,s){i>3||"loaded"==s?(t.centerBackground(!1),i=0):i++})),s("#robotLayer").off("keydown.sim").on("keydown.sim",this.handleKeyEvent.bind(this))},t.prototype.loadBackgroundImages=function(t){var i,s;s=e.isIE()?".png":".svg";for(var o=(i=this.robots[0].mobile?this.robots[0].imgList.map((function(t){return t.endsWith("jpg")?t:"".concat(t).concat(s)})):[this.robotType+"Background"+s]).length,r=this,a=function(){if(0==--o&&(t(),e.isLocalStorageAvailable()&&r.robots[0].mobile)){var i=localStorage.getItem("customBackground");if(i){try{JSON.parse(i)}catch(t){localStorage.setItem("customBackground",JSON.stringify({image:i,timestamp:(new Date).getTime()})),i=localStorage.getItem("customBackground")}var s=JSON.parse(i);if((new Date).getTime()-s.timestamp>54432e5)localStorage.removeItem("customBackground");else{var a=s.image,n=new Image;n.src="data:image/png;base64,"+a,r.imgBackgroundList.push(n),r.customBackgroundLoaded=!0}}}},n=0;n0;){a[0].updateSensor(e.uCtx,r,a),a.shift()}})),this.draw(t,i)},t.prototype.toggleTrail=function(){this.robots.forEach((function(t){t.hasTrail=!t.hasTrail,t.pose.xOld=t.pose.x,t.pose.yOld=t.pose.y}))},t.prototype.resetPoseAndDrawings=function(){this.robots.forEach((function(t){return t.resetPose()})),this.dCtx.canvas.width=this.dCtx.canvas.width,this.udCtx.canvas.width=this.udCtx.canvas.width,this.rcjCtx.canvas.width=this.rcjCtx.canvas.width},t.prototype.addMarker=function(t){this.addSimulationObject(this.markerList,o.SimObjectShape.Marker,o.SimObjectType.Marker,t),this._redrawMarkers=!0},t.prototype.setRcjScoringTool=function(t,i){this.rcjScoringTool=new c(t,i),this.scoring=!0;var e=this;s("#simCompetition").show(),s("#simCompetition").off(),s("#simCompetition").onWrap("click",(function(){e.rcjScoringTool.openClose()})),this.obstacleList.forEach((function(t){t.addObserver&&"function"==typeof t.addObserver&&t.addObserver(e.rcjScoringTool)}))},t.prototype.removeRcjScoringTool=function(){this.rcjScoringTool&&this.rcjScoringTool.destroy(),this.rcjScoringTool=null,this.scoring=!1,s("#simCompetition").hide(),s("#simCompetition").off()},t}();i.SimulationScene=h})); +var __spreadArray=this&&this.__spreadArray||function(t,i,e){if(e||2===arguments.length)for(var s,o=0,r=i.length;o=0?(s(this).html("Stop
Scoring Run"),o.init(),o.resetObstaclesCallback(),s("#rcjStartStop").addClass("running"),!1):(s(this).html("Start
Scoring Run"),clearInterval(o.stopWatch),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),o.robot&&o.robot.interpreter.terminate(),o.programPaused=!0,!1)})),s("#rcjLoP").off().on("click",(function(t){o.robot.interpreter.terminate(),o.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled");var e=r.default.getTilePose(o.lastCheckPoint,i.tiles[o.lastCheckPoint.next],o.prevCheckPointTile);return o.robot.pose=new n.Pose(e.x,e.y,e.theta),o.robot.initialPose=new n.Pose(e.x,e.y,e.theta),o.path=o.lastCheckPoint.index[0],o.lastPath=o.path,o.loPCounter+=1,o.loPSum+=1,o.nextCheckPoint&&o.loPCounter>=3&&s("#rcjNextCP").removeClass("disabled"),!1})),s("#rcjNextCP").off().on("click",(function(t){if(o.robot.interpreter.terminate(),o.programPaused=!0,s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),o.nextCheckPoint){var e=r.default.getTilePose(o.nextCheckPoint,i.tiles[o.nextCheckPoint.next],o.prevNextCheckPoint);o.robot.pose=new n.Pose(e.x,e.y,e.theta),o.robot.initialPose=new n.Pose(e.x,e.y,e.theta),o.path=o.nextCheckPoint.index[0],o.lastPath=o.path,o.loPCounter=0,o.section+=1,o.lastCheckPoint=o.nextCheckPoint,o.setNextCheckPoint()}})),s("#rcjName").text(i.name),s("#rcjTeam").text(t.interpreter.name),s("#rcjTime").text("00:00:0")}return t.prototype.init=function(){this.path=0,this.lastPath=0,this.line=!0,clearInterval(this.stopWatch),this.mins=0,this.secs=0,this.csecs=0,this.running=!0,this.stopWatch=setInterval(this.timer.bind(this),100);var t=this.configData.tiles[this.configData.startTile.x+","+this.configData.startTile.y+",0"];this.initialPose=r.default.getTilePose(t,this.configData.tiles[t.next],null),this.lastTile=t,this.lastCheckPoint=t,this.robot&&(this.robot.initialPose=this.initialPose,this.robot.resetPose()),this.loPCounter=0,this.loPSum=0,this.section=0,this.victimsLocated=0,this.linePoints=0,this.obstaclePoints=0,this.totalScore=0,this.inAvoidanceMode=!1,this.countedTileIndices=[0],this.lastCheckPointIndex=0,this.rescueMulti=1},t.prototype.timer=function(){this.running&&(this.csecs++,10===this.csecs&&(this.secs++,this.csecs=0),60===this.secs&&(this.mins++,this.secs=0),s("#rcjTime").text(("00"+this.mins).slice(-2)+":"+("00"+this.secs).slice(-2)+":"+this.csecs),s("#rcjPath").text(-1===this.path?"wrong":"correct"),s("#rcjLastPath").text(this.lastPath),s("#rcjSection").text(this.section),s("#rcjLoPpS").text(this.loPCounter),s("#rcjLoPCount").text(this.loPSum),s("#rcjLine").text(this.line?"yes":"no"),this.mins>=this.MAX_TIME&&s("#rcjStartStop").trigger("click"),s("#rcjRescueMulti").text(Math.round(100*this.rescueMulti)/100),s("#rcjLinePoints").text(this.linePoints),s("#rcjObstaclePoints").text(this.obstaclePoints),s("#rcjTotalScore").text(this.totalScore))},t.prototype.countObstaclePoints=function(t){t&&!this.countedTileIndices.includes(t.index[0])&&(t.tileType.gaps>0&&(this.obstaclePoints+=this.POINTS_GAP),t.tileType.intersections>0&&(this.obstaclePoints+=this.POINTS_INTERSECTION),this.countedTileIndices.push(t.index[0]))},t.prototype.callAutoLoP=function(){s("#rcjLoP").trigger("click")},t.prototype.update=function(t){if(this.running)if(t instanceof n.RobotBaseMobile){var i=t;this.robot!=i&&(this.robot=i,this.initialPose=this.robot.initialPose),this.programPaused&&(this.programPaused=!1,s("#rcjLoP").removeClass("disabled"),s("#rcjNextCP").addClass("disabled")),this.pose=i.pose;var r=Math.floor((this.pose.x-10)/90),a=Math.floor((this.pose.y-10)/90),c=this.configData.tiles[r+","+a+",0"],h=c&&c.index[0];if(h==this.lastPath||h==this.lastPath+1){if(this.path=h,this.lastPath=h,this.line=i.F.lightValue<70,this.line&&(this.wasOnLineOnce=!0),c&&c.checkPoint||0==h){if(this.lastCheckPoint!=c){var l=this.loPCounter0&&1===this.configData.tiles[this.lastTile.next].items.obstacles?(this.inAvoidanceMode=!0,this.path+=1,this.lastPath=this.path,this.avoidanceGoalIndex=this.lastTile.index[0]+2):this.lastTile.items.obstacles>0?(this.inAvoidanceMode=!0,this.avoidanceGoalIndex=this.lastTile.index[0]+1):(-1!=this.path&&h&&this.callAutoLoP(),this.path=-1)),this.line=!1;this.totalScore=(this.linePoints+this.obstaclePoints)*this.rescueMulti,this.totalScore=e.round(this.totalScore,2)}else if(t instanceof o.CircleSimulationObject){var d=t;d.inEvacuationZone&&"#33B8CA"===d.color&&(d.selected=!0,s("#simDeleteObject").trigger("click"),this.rescueMulti*=this.POINTS_VICTIM_MULTI,this.victimsLocated+=1),d.inEvacuationZone&&"#000000"===d.color&&(d.selected=!0,s("#simDeleteObject").trigger("click"),this.victimsLocated>1?this.rescueMulti*=this.POINTS_VICTIM_MULTI:this.rescueMulti*=this.POINTS_DEADONLY_VICTIM_MULTI,this.victimsLocated+=1),this.victimsLocated>=3&&s("#rcjStartStop").trigger("click")}},t.prototype.setNextCheckPoint=function(){for(var t=this.configData.tiles[this.lastCheckPoint.next];t&&this.configData.tiles[t.next]&&(this.prevNextCheckPoint=t,!(t=this.configData.tiles[t.next]).checkPoint););t&&t.checkPoint?this.nextCheckPoint=t:(this.nextCheckPoint=null,this.prevNextCheckPoint=null)},t.prototype.openClose=function(){var t=s("#simDiv").position();t.left=12,s("#rcjScoringWindow").toggleSimPopup(t)},t.prototype.destroy=function(){s("#rcjStartStop").html("Start
Scoring Run"),s("#rcjStartStop").removeClass("running"),s("#rcjLoP").addClass("disabled"),s("#rcjNextCP").addClass("disabled"),clearInterval(this.stopWatch),this.stopWatch=null,s("#rcjPath").text(""),s("#rcjLastPath").text(""),s("#rcjSection").text(""),s("#rcjLoPpS").text(""),s("#rcjLoPCount").text(""),s("#rcjLine").text(""),s("#rcjName").text(""),s("#rcjTeam").text(""),s("#rcjTime").text("00:00:0"),s("#rcjRescueMulti").text("")},t}();i.RcjScoringTool=c;var h=function(){function t(t){this.DEFAULT_TRAIL_WIDTH=10,this.DEFAULT_TRAIL_COLOR="#000000",this.customBackgroundLoaded=!1,this.ground=new o.Ground(0,0,0,0),this.imgBackgroundList=[],this.imgPath="/css/img/simBackgrounds/",this.playground={x:0,y:0,w:0,h:0},this._colorAreaList=[],this._obstacleList=[],this._rcjList=[],this._markerList=[],this._redrawColorAreas=!1,this._redrawObstacles=!1,this._redrawMarkers=!1,this._robots=[],this._uniqueObjectId=0,this._scoring=!1,this.sim=t,this.uCanvas=document.createElement("canvas"),this.uCtx=this.uCanvas.getContext("2d",{willReadFrequently:!0}),this.udCanvas=document.createElement("canvas"),this.udCtx=this.udCanvas.getContext("2d",{willReadFrequently:!0}),this.bCtx=s("#backgroundLayer")[0].getContext("2d"),this.dCtx=s("#drawLayer")[0].getContext("2d"),this.aCtx=s("#arucoMarkerLayer")[0].getContext("2d"),this.oCtx=s("#objectLayer")[0].getContext("2d"),this.rCtx=s("#robotLayer")[0].getContext("2d"),this.rcjCtx=s("#rcjLayer")[0].getContext("2d")}return Object.defineProperty(t.prototype,"scoring",{get:function(){return this._scoring},set:function(t){this._scoring=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uniqueObjectId",{get:function(){return++this._uniqueObjectId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"robots",{get:function(){return this._robots},set:function(t){this.clearList(this._robots),this._robots=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"obstacleList",{get:function(){return this._obstacleList},set:function(t){this.clearList(this._obstacleList),this._obstacleList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rcjList",{get:function(){return this._rcjList},set:function(t){this.clearList(this._rcjList),this._rcjList=t,this.redrawObstacles=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"colorAreaList",{get:function(){return this._colorAreaList},set:function(t){this.clearList(this._colorAreaList),this._colorAreaList=t,this.redrawColorAreas=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"markerList",{get:function(){return this._markerList},set:function(t){this.clearList(this._markerList),this._markerList=t,this.redrawMarkers=!0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawObstacles",{get:function(){return this._redrawObstacles},set:function(t){this._redrawObstacles=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawColorAreas",{get:function(){return this._redrawColorAreas},set:function(t){this._redrawColorAreas=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"redrawMarkers",{get:function(){return this._redrawMarkers},set:function(t){this._redrawMarkers=t},enumerable:!1,configurable:!0}),t.prototype.addColorArea=function(t){this.addSimulationObject(this.colorAreaList,t,o.SimObjectType.ColorArea),this.redrawColorAreas=!0},t.prototype.addImportColorAreaList=function(t){var i=this,e=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.ColorArea,t.p,null,t.color],t.params,!1));e.push(s)})),this.colorAreaList=e},t.prototype.addImportObstacle=function(t){var i=this,e=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));e.push(s)})),this.obstacleList=e},t.prototype.addSomeObstacles=function(t){var i=this,e=this;t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.Obstacle,t.p,null,t.color],t.params,!1));e.obstacleList.push(s)}))},t.prototype.addImportRcjLabel=function(t){var i=this,e=[];t.forEach((function(t){var s=new o.RcjSimulationLabel(i.uniqueObjectId,i,i.sim.selectionListener,o.SimObjectType.ColorArea,t.x,t.y,t.checkPoint?"checkPoint":t.start?"start":null,t.index[0]);e.push(s)})),this.rcjList=e},t.prototype.addImportMarkerList=function(t){var i=this,e=[];t.forEach((function(t){var s=o.SimObjectFactory.getSimObject.apply(o.SimObjectFactory,__spreadArray([t.id,i,i.sim.selectionListener,t.shape,o.SimObjectType.Marker,t.p,null,t.color],t.params,!1));s.markerId=t.markerId,e.push(s)})),this.markerList=e},t.prototype.addObstacle=function(t){this.addSimulationObject(this.obstacleList,t,o.SimObjectType.Obstacle),this.redrawObstacles=!0},t.prototype.addSimulationObject=function(t,i,e,r){var a=s("#robotLayer");a.attr("tabindex",0),a.trigger("focus");var n=Math.random()*(this.ground.w-300)+100,c=Math.random()*(this.ground.h-200)+100,h=o.SimObjectFactory.getSimObject(this.uniqueObjectId,this,this.sim.selectionListener,i,e,{x:n,y:c},this.backgroundImg.width);i==o.SimObjectShape.Marker&&r&&(h.markerId=r),t.push(h),h.selected=!0},t.prototype.changeColorWithColorPicker=function(t){var i=this.obstacleList.concat(this.colorAreaList).filter((function(t){return t.selected}));1==i.length&&(i[0].color=t,i[0].type===o.SimObjectType.Obstacle?this.redrawObstacles=!0:this.redrawColorAreas=!0)},t.prototype.clearList=function(t){t.forEach((function(t){t.destroy()})),t.length=0},t.prototype.deleteSelectedObject=function(){var t=this;function i(i){for(var e=0;e.pace").show(),this.robots=[],a.RobotFactory.createRobots(r,n,c,this.sim.selectionListener,this.robotType).then((function(t){if(d.robots=t.robots,d.robotClass=t.robotClass,d.setRobotPoses(h),d.initViews(),u){d.removeRcjScoringTool(),g.imgBackgroundList=[],g.currentBackground=0,g.obstacleList.length>0&&(g.obstacleList=[]),g.colorAreaList.length>0&&(g.colorAreaList=[]);var i=".svg";e.isIE()&&(i=".png"),g.loadBackgroundImages((function(){g.robots[0].mobile?(s(".simMobile").show(),g.images=g.loadImages(["roadWorks","pattern"],["roadWorks"+i,"wallPattern.png"],(function(){g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0];var t=new o.RectangleSimulationObject(0,g,g.sim.selectionListener,o.SimObjectType.Obstacle,{x:7*g.backgroundImg.width/9,y:g.backgroundImg.height-2*g.backgroundImg.width/9},g.backgroundImg.width);g.obstacleList.push(t),g.centerBackground(!0),g.initEvents(),g.sim.initColorPicker(a.RobotBase.colorRange),g.showFullyLoadedSim(l),g.sim.start()}))):(s(".simMobile").hide(),g.images={},g.ground=new o.Ground(10,10,g.imgBackgroundList[g.currentBackground].width,g.imgBackgroundList[g.currentBackground].height),g.backgroundImg=g.imgBackgroundList[0],g.centerBackground(!0),g.initEvents(),g.showFullyLoadedSim(l),g.sim.start())}))}d.showFullyLoadedSim(l),d.sim.start()}))):(this.robots.forEach((function(t,i){g.rcjScoringTool&&t.addObserver(g.rcjScoringTool),t.replaceState(r[i]),t.reset()})),this.showFullyLoadedSim(l)),this.robots.forEach((function(t,i){t.time=0}))},t.prototype.showFullyLoadedSim=function(t){this.obstacleList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.markerList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),this.colorAreaList.forEach((function(t){t.removeMouseEvents(),t.addMouseEvents()})),s("#canvasDiv").fadeIn("slow"),s("#simDiv>.pace").fadeOut("fast"),"function"==typeof t&&t()},t.prototype.initViews=function(){var t=s("#systemValuesView"),i=s("#robotIndex");t.html("");var e="",o=this.robots[0]instanceof n.RobotBaseMobile?this.robots[0].chassis.geom.color:"#ffffff";if(e+='",t.append('
'+e+"
"),i.off("change.sim"),this.robots.length>1){var r=this;i.on("change.sim",(function(){var t=Number(s(this).val());r.robots[t].selected=!0,r.sim.selectionListener.fire(null)}))}},t.prototype.initEvents=function(){var t=this,i=0;s(window).off("resize.sim").on("resize.sim",(function(e,s){i>3||"loaded"==s?(t.centerBackground(!1),i=0):i++})),s("#robotLayer").off("keydown.sim").on("keydown.sim",this.handleKeyEvent.bind(this))},t.prototype.loadBackgroundImages=function(t){var i,s;s=e.isIE()?".png":".svg";for(var o=(i=this.robots[0].mobile?this.robots[0].imgList.map((function(t){return t.endsWith("jpg")?t:"".concat(t).concat(s)})):[this.robotType+"Background"+s]).length,r=this,a=function(){if(0==--o&&(t(),e.isLocalStorageAvailable()&&r.robots[0].mobile)){var i=localStorage.getItem("customBackground");if(i){try{JSON.parse(i)}catch(t){localStorage.setItem("customBackground",JSON.stringify({image:i,timestamp:(new Date).getTime()})),i=localStorage.getItem("customBackground")}var s=JSON.parse(i);if((new Date).getTime()-s.timestamp>54432e5)localStorage.removeItem("customBackground");else{var a=s.image,n=new Image;n.src="data:image/png;base64,"+a,r.imgBackgroundList.push(n),r.customBackgroundLoaded=!0}}}},n=0;n0;){a[0].updateSensor(e.uCtx,r,a),a.shift()}})),this.draw(t,i)},t.prototype.toggleTrail=function(){this.robots.forEach((function(t){t.hasTrail=!t.hasTrail,t.pose.xOld=t.pose.x,t.pose.yOld=t.pose.y}))},t.prototype.resetPoseAndDrawings=function(){this.robots.forEach((function(t){return t.resetPose()})),this.dCtx.canvas.width=this.dCtx.canvas.width,this.udCtx.canvas.width=this.udCtx.canvas.width,this.rcjCtx.canvas.width=this.rcjCtx.canvas.width},t.prototype.addMarker=function(t){this.addSimulationObject(this.markerList,o.SimObjectShape.Marker,o.SimObjectType.Marker,t),this._redrawMarkers=!0},t.prototype.setRcjScoringTool=function(t,i,e){this.rcjScoringTool=new c(t,i,e),this.scoring=!0;var o=this;s("#simCompetition").show(),s("#simCompetition").off(),s("#simCompetition").onWrap("click",(function(){o.rcjScoringTool.openClose()})),this.obstacleList.forEach((function(t){t.addObserver&&"function"==typeof t.addObserver&&t.addObserver(o.rcjScoringTool)}))},t.prototype.removeRcjScoringTool=function(){this.rcjScoringTool&&this.rcjScoringTool.destroy(),this.rcjScoringTool=null,this.scoring=!1,s("#simCompetition").hide(),s("#simCompetition").off()},t}();i.SimulationScene=h})); //# sourceMappingURL=simulation.scene.js.map //# sourceMappingURL=simulation.scene.js.map diff --git a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.objects.ts b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.objects.ts index 9cbbee0a1c..de5f8d9b78 100644 --- a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.objects.ts +++ b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.objects.ts @@ -656,6 +656,7 @@ export class CircleSimulationObject extends BaseSimulationObject implements IMov corners: Corner[] = []; private collisions: Point[] = []; private lastMoveBumped: boolean = false; + private lastMoveBumpedOld: boolean = false; private lastMove: Point; private observers: IObserver[] = []; inEvacuationZone: boolean = false; @@ -870,6 +871,10 @@ export class CircleSimulationObject extends BaseSimulationObject implements IMov this.x += dx; this.y += dy; this.updateCorners(); + if (this.movable) { + this.lastMoveBumpedOld = false; + this.lastMoveBumped = false; + } //TODO redraw } } @@ -912,8 +917,7 @@ export class CircleSimulationObject extends BaseSimulationObject implements IMov return false; } this.collisions.push(dist); - if (this.lastMoveBumped) { - //this.lastMoveBumped = false; + if (this.lastMoveBumpedOld) { return false; } return true; @@ -923,6 +927,8 @@ export class CircleSimulationObject extends BaseSimulationObject implements IMov if (!this.movable) { return; } + this.lastMoveBumpedOld = this.lastMoveBumped; + this.lastMoveBumped = false; let locationColor = uCtx.getImageData(this.x, this.y, 1, 1).data; this.inEvacuationZone = locationColor.toString() === [0, 0, 0, 255].toString(); @@ -981,7 +987,6 @@ export class CircleSimulationObject extends BaseSimulationObject implements IMov this.moveTo({ x: this.x + diffP.x, y: this.y + diffP.y }); } } else { - this.lastMoveBumped = false; this.moveTo({ x: this.x + diffP.x, y: this.y + diffP.y }); } } diff --git a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.roberta.ts b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.roberta.ts index 6e8685e32e..924bdaf1a6 100644 --- a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.roberta.ts +++ b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.roberta.ts @@ -17,7 +17,7 @@ import * as HUEBEE from 'huebee'; // @ts-ignore import * as Blockly from 'blockly'; import * as NN_CTRL from 'nn.controller'; -import { SimulationScene } from 'simulation.scene'; +import { IObservableSimulationObject, SimulationScene } from 'simulation.scene'; import { SelectionListener } from 'robot.base'; import { BaseSimulationObject, @@ -30,6 +30,7 @@ import { } from 'simulation.objects'; import { Pose } from 'robot.base.mobile'; import { Simulation } from 'progSim.controller'; +import * as SIMATH from 'simulation.math'; export class SimulationRoberta implements Simulation { private static _instance: SimulationRoberta; @@ -1011,15 +1012,25 @@ export class SimulationRoberta implements Simulation { let victims = configData.victims; let rcjVictimsList = []; let zone: Rectangle = { - x: Math.min(evacuationZone[0], evacuationZone[2]) * sim.TILE_SIZE, - y: Math.min(evacuationZone[1], evacuationZone[3]) * sim.TILE_SIZE, - w: (Math.max(evacuationZone[0], evacuationZone[2]) - Math.min(evacuationZone[0], evacuationZone[2]) + 1) * sim.TILE_SIZE, - h: (Math.max(evacuationZone[1], evacuationZone[3]) - Math.min(evacuationZone[1], evacuationZone[3]) + 1) * sim.TILE_SIZE, + x: Math.min(evacuationZone[0], evacuationZone[2]) * sim.TILE_SIZE - sim.TILE_SIZE / 2, + y: Math.min(evacuationZone[1], evacuationZone[3]) * sim.TILE_SIZE - sim.TILE_SIZE / 2, + w: (Math.max(evacuationZone[0], evacuationZone[2]) - Math.min(evacuationZone[0], evacuationZone[2]) + 1) * sim.TILE_SIZE + sim.TILE_SIZE, + h: (Math.max(evacuationZone[1], evacuationZone[3]) - Math.min(evacuationZone[1], evacuationZone[3]) + 1) * sim.TILE_SIZE + sim.TILE_SIZE, }; const createVictim = (color) => { + let p = { x: zone.x + Math.random() * zone.w, y: zone.y + Math.random() * zone.h }; + let i = 0; + while (i < rcjVictimsList.length) { + if (SIMATH.getDistance(p, rcjVictimsList[i].p) < 200) { + p = { x: zone.x + Math.random() * zone.w, y: zone.y + Math.random() * zone.h }; + i = 0; + } else { + i++; + } + } let victim = { id: sim.scene.uniqueObjectId, - p: { x: zone.x + Math.random() * zone.w, y: zone.y + Math.random() * zone.h }, + p: p, params: [7, 1], // 7 is the radius, 1 is movable = true theta: 0, color: color, @@ -1047,6 +1058,24 @@ export class SimulationRoberta implements Simulation { image.height = canvas.height; return image; }; + let evacuationVictimsZone = []; + const resetVictims = () => { + let obstaclesToDelete: BaseSimulationObject[] = sim.scene.obstacleList.filter((obstacle) => { + return obstacle.movable; + }); + obstaclesToDelete.forEach((obstacle) => { + obstacle.selected = true; + (obstacle as any as IObservableSimulationObject).removeObserver(sim.scene.rcjScoringTool); + sim.scene.deleteSelectedObject(); + }); + let newVictims = getRcjVictims(evacuationVictimsZone); + sim.scene.addSomeObstacles(newVictims); + sim.scene.obstacleList.forEach((obstacle) => { + if (obstacle['addObserver'] && typeof obstacle['addObserver'] === 'function') { + (obstacle as CircleSimulationObject).addObserver(sim.scene.rcjScoringTool); + } + }); + }; preloadAll(imgArray).then( function (images) { let ctx = canvas.getContext('2d'); @@ -1057,14 +1086,13 @@ export class SimulationRoberta implements Simulation { let evacuationBottom = []; let evacuationLeft = []; let importObstacles = []; - let evacuationVctimsZone = []; imgArray.forEach((img, index) => { if (img['tileType']['image'].startsWith('ev')) { let ev = img['tileType']['image'].replace('.png', ''); switch (ev) { case 'ev1': - evacuationVctimsZone.push(img['x']); - evacuationVctimsZone.push(img['y']); + evacuationVictimsZone.push(img['x']); + evacuationVictimsZone.push(img['y']); // evacuation zone tile without walls break; case 'ev2': // one wall @@ -1236,12 +1264,12 @@ export class SimulationRoberta implements Simulation { let image = createBackgroundImage(); sim.scene.imgBackgroundList.push(image); sim.setBackground(sim.scene.imgBackgroundList.length - 1); - sim.scene.addImportObstacle(importObstacles.concat(getRcjVictims(evacuationVctimsZone))); + sim.scene.addImportObstacle(importObstacles.concat(getRcjVictims(evacuationVictimsZone))); sim.scene.addImportRcjLabel(rcjLabel); sim.scene.drawRcjLabel(); sim.importPoses = [[startPose, startPose]]; sim.scene.setRobotPoses(sim.importPoses); - sim.scene.setRcjScoringTool(sim.scene.robots[0], configData); + sim.scene.setRcjScoringTool(sim.scene.robots[0], configData, resetVictims); $('#simCompetition').show(); resolve(result); } else { diff --git a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts index b64450be0a..1feae19f11 100644 --- a/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts +++ b/OpenRobertaWeb/src/app/simulation/simulationLogic/simulation.scene.ts @@ -76,10 +76,12 @@ export class RcjScoringTool implements IObserver { private rescueMulti: number; private lastCheckPointIndex: number; private wasOnLineOnce: boolean = false; + private resetObstaclesCallback: Function; - constructor(robot: RobotBase, configData: any) { + constructor(robot: RobotBase, configData: any, resetObstaclesCallback: Function) { this.configData = configData; this.robot = robot as RobotBaseMobile; + this.resetObstaclesCallback = resetObstaclesCallback; this.init(); let rcj = this; $('#rcjStartStop') @@ -88,6 +90,7 @@ export class RcjScoringTool implements IObserver { if ($(this).text().indexOf('Start') >= 0) { $(this).html('Stop
Scoring Run'); rcj.init(); + rcj.resetObstaclesCallback(); $('#rcjStartStop').addClass('running'); return false; } else { @@ -427,7 +430,7 @@ export class SimulationScene { private readonly aCtx: CanvasRenderingContext2D; private readonly udCanvas: HTMLCanvasElement; readonly uCanvas: HTMLCanvasElement; - private rcjScoringTool: RcjScoringTool; + rcjScoringTool: RcjScoringTool; private _scoring: boolean = false; constructor(sim: SimulationRoberta) { @@ -564,6 +567,24 @@ export class SimulationScene { this.obstacleList = newObstacleList; } + addSomeObstacles(importObstacleList: any[]) { + let that = this; + importObstacleList.forEach((obj) => { + let newObject = SimObjectFactory.getSimObject( + obj.id, + this, + this.sim.selectionListener, + obj.shape, + SimObjectType.Obstacle, + obj.p, + null, + obj.color, + ...obj.params + ); + that.obstacleList.push(newObject); + }); + } + addImportRcjLabel(importRcjLabelList: any[]) { let newRcjList = []; importRcjLabelList.forEach((obj) => { @@ -1225,8 +1246,8 @@ export class SimulationScene { this._redrawMarkers = true; } - setRcjScoringTool(robot: RobotBase, configData) { - this.rcjScoringTool = new RcjScoringTool(robot, configData); + setRcjScoringTool(robot: RobotBase, configData, resetObstacles: Function) { + this.rcjScoringTool = new RcjScoringTool(robot, configData, resetObstacles); this.scoring = true; let scene = this; $('#simCompetition').show();