@code-dot-org/craft
Version:
Top-down 2D game engine for the Craft app type. See NOTICE for restrictions on use.
1 lines • 293 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var o in i)("object"==typeof exports?exports:e)[o]=i[o]}}(window,function(){return function(e){var t={};function i(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,o){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(o,n,function(t){return e[t]}.bind(null,n));return o},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=11)}([function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(8),a=i(1),r=i(3),s=i(5),l=i(4),c=i(6);e.exports=function(){function e(t,i,o,a,s,l){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.queue=new n(t),this.controller=t,this.game=t.game,this.position=new r(a,s),this.type=i,this.facing=l,this.offset=[-22,-12],this.identifier=o,this.healthPoint=3,this.underTree={state:!1,treeIndex:-1}}return o(e,[{key:"tick",value:function(){this.queue.tick()}},{key:"reset",value:function(){}},{key:"canMoveThrough",value:function(){return!1}},{key:"canPlaceBlock",value:function(){return!1}},{key:"canTriggerPressurePlates",value:function(){return!1}},{key:"shouldUpdateSelectionIndicator",value:function(){return!1}},{key:"setMovePosition",value:function(e){this.position=e}},{key:"getSortOrderOffset",value:function(){return 5}},{key:"addCommand",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.queue.addCommand(e,t),this.queue.begin()}},{key:"addAnimation",value:function(){var e;return(e=this.getAnimationManager()).add.apply(e,arguments)}},{key:"getAnimationManager",value:function(){return this.animationRig?this.animationRig.animations:this.sprite.animations}},{key:"getWalkAnimation",value:function(){return"walk"+this.controller.levelView.getDirectionName(this.facing)}},{key:"getIdleAnimation",value:function(){return"idle"+this.controller.levelView.getDirectionName(this.facing)}},{key:"playMoveForwardAnimation",value:function(e,t,i,o){var n,r=this,s=this.controller.levelView,l=e[1]+(t===a.North?1:0);this.sprite.sortOrder=this.controller.levelView.yToIndex(l)+1,s.playBlockSound(o),s.playScaledSpeed(this.getAnimationManager(),this.getWalkAnimation()),setTimeout(function(){(n=r.controller.levelView.addResettableTween(r.sprite).to({x:r.offset[0]+40*e[0],y:r.offset[1]+40*e[1]},300,Phaser.Easing.Linear.None)).onComplete.add(function(){s.playScaledSpeed(r.getAnimationManager(),r.getIdleAnimation()),i.succeeded()}),n.start()},50/this.controller.tweenTimeScale)}},{key:"walkableCheck",value:function(){}},{key:"updateHidingTree",value:function(){var e=this.controller.levelView;if(this.underTree.state){var t=this.underTree.treeIndex,i=this.controller.levelEntity.entityMap;e.isUnderTree(t,this.position)||(function(e,t,i){var o=!0,n=!1,a=void 0;try{for(var r,s=t[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var l=r.value[1];if(l!==e&&l.underTree.treeIndex===i)return!0}}catch(e){n=!0,a=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw a}}return!1}(this,i,t)||e.changeTreeAlpha(t,1),this.underTree={state:!1,treeIndex:-1})}else for(var o=e.trees,n=0;n<o.length;n++)if(e.isUnderTree(n,this.position)){e.changeTreeAlpha(n,.8),this.underTree={state:!0,treeIndex:n};break}}},{key:"updateHidingBlock",value:function(e){var t=this.controller.levelView,i=this.controller.levelModel.actionPlane;this.isOnBlock||function(e,o){var n=r.south(o),a=i.getBlockAt(n);if(a&&!a.isTransparent){var s=t.actionPlaneBlocks[t.coordinatesToIndex(n)];null!==s&&e.controller.levelView.addResettableTween(s).to({alpha:.8},300,Phaser.Easing.Linear.None).start()}}(this,this.position),void 0!==e&&function(e,i){var o=r.south(i);if(o.y<10){var n=t.actionPlaneBlocks[t.coordinatesToIndex(o)];null!==n&&e.controller.levelView.addResettableTween(n).to({alpha:1},300,Phaser.Easing.Linear.None).start()}}(this,e)}},{key:"doMoveForward",value:function(e,t){var i=this.controller.levelModel,o=this.position;this.position=t;var n=i.groundPlane.getBlockAt(this.position).blockType;this.playMoveForwardAnimation(t,this.facing,e,n,function(){}),this.updateHidingTree(),this.updateHidingBlock(o)}},{key:"bump",value:function(e){var t=this,i=this.controller.levelView.getDirectionName(this.facing);this.controller.levelView.playScaledSpeed(this.getAnimationManager(),"bump"+i);var o=this.controller.levelModel.getMoveForwardPosition(this),n=this.controller.levelEntity.getEntityAt(o);null!==n&&(this.queue.startPushHighPriorityCommands(),this.controller.events.forEach(function(e){return e({eventType:s.WhenTouched,targetType:t.type,targetIdentifier:t.identifier,eventSenderIdentifier:n.identifier})}),this.queue.endPushHighPriorityCommands()),this.controller.delayPlayerMoveBy(400,800,function(){e.succeeded()})}},{key:"callBumpEvents",value:function(e){for(var t=this,i=1;i<e.length;i++)"frontEntity"===e[i]&&(this.controller.events.forEach(function(o){return o({eventType:s.WhenTouched,targetType:e[i+1].type,eventSenderIdentifier:t.identifier,targetIdentifier:e[i+1].identifier})}),i++)}},{key:"moveDirection",value:function(e,t){this.controller.levelModel.turnToDirection(this,t),this.moveForward(e,!1)}},{key:"moveForward",value:function(e){(!(arguments.length>1&&void 0!==arguments[1])||arguments[1])&&this.controller.addCommandRecord("moveForward",this.type,e.repeat);var t=this.controller.levelModel.getMoveForwardPosition(this),i=this.controller.levelModel.canMoveForward(this);if(i[0]){var o=r.directionToOffsetPosition(this.facing),n=r.directionToOffsetPosition(a.opposite(this.facing)),s=this.handleMoveOnPressurePlate(o);this.doMoveForward(e,t),s||this.handleMoveOffPressurePlate(n),this.handleMoveOffIronDoor(n),this.handleMoveAwayFromPiston(n)}else this.bump(e),this.callBumpEvents(i)}},{key:"moveBackward",value:function(e){(!(arguments.length>1&&void 0!==arguments[1])||arguments[1])&&this.controller.addCommandRecord("moveBackward",this.type,e.repeat);var t=this.controller.levelModel.getMoveDirectionPosition(this,2),i=this.controller.levelModel.canMoveBackward(this);if(i[0]){var o=r.directionToOffsetPosition(a.opposite(this.facing)),n=r.directionToOffsetPosition(this.facing),s=this.handleMoveOnPressurePlate(o);this.doMoveBackward(e,t),s||this.handleMoveOffPressurePlate(n),this.handleMoveOffIronDoor(n),this.handleMoveAwayFromPiston(n)}else this.bump(e),this.callBumpEvents(i)}},{key:"canPlaceBlockOver",value:function(){return{canPlace:!1,plane:""}}},{key:"moveAway",value:function(e,t){this.controller.addCommandRecord("moveAway",this.type,e.repeat);var i=t.position,o=[],n=function(e,t,i){return r.absoluteDistanceSquare(t[1],e)<r.absoluteDistanceSquare(i[1],e)?i:t},s=r.absoluteDistanceSquare(i,this.position);i.x<=this.position.x&&this.controller.levelModel.canMoveDirection(this,a.East)[0]&&(o=[a.East,r.east(this.position)]),i.x>=this.position.x&&this.controller.levelModel.canMoveDirection(this,a.West)[0]&&(o=o.length>0?n(i,o,[a.West,r.west(this.position)]):[a.West,r.west(this.position)]),i.y>=this.position.y&&this.controller.levelModel.canMoveDirection(this,a.North)[0]&&(o=o.length>0?n(i,o,[a.North,r.north(this.position)]):[a.North,r.north(this.position)]),i.y<=this.position.y&&this.controller.levelModel.canMoveDirection(this,a.South)[0]&&(o=o.length>0?n(i,o,[a.South,r.south(this.position)]):[a.South,r.south(this.position)]),0===o.length||s>=r.absoluteDistanceSquare(i,o[1])?e.succeeded():this.moveDirection(e,o[0])}},{key:"moveToward",value:function(e,t){this.controller.addCommandRecord("moveToward",this.type,e.repeat);var i=t.position,o=[],n=function(e,t,i){return r.absoluteDistanceSquare(t[1],e)>r.absoluteDistanceSquare(i[1],e)?i:t};return i.x>=this.position.x&&this.controller.levelModel.canMoveDirection(this,a.East)[0]&&(o=[a.East,r.east(this.position)]),i.x<=this.position.x&&this.controller.levelModel.canMoveDirection(this,a.West)[0]&&(o=o.length>0?n(i,o,[a.West,r.west(this.position)]):[a.West,r.west(this.position)]),i.y<=this.position.y&&this.controller.levelModel.canMoveDirection(this,a.North)[0]&&(o=o.length>0?n(i,o,[a.North,r.north(this.position)]):[a.North,r.north(this.position)]),i.y>=this.position.y&&this.controller.levelModel.canMoveDirection(this,a.South)[0]&&(o=o.length>0?n(i,o,[a.South,r.south(this.position)]):[a.South,r.south(this.position)]),1===r.absoluteDistanceSquare(this.position,i)?(this.position.x<i.x?this.facing=a.East:this.position.x>i.x?this.facing=a.West:this.position.y<i.y?this.facing=a.South:this.position.y>i.y&&(this.facing=a.North),this.updateAnimationDirection(),this.bump(e),!1):0===o.length?(e.succeeded(),!1):(this.moveDirection(e,o[0]),!0)}},{key:"moveTo",value:function(e,t){var i=this;if(1===r.absoluteDistanceSquare(t.position,this.position))t.position.y-this.position.y==-1?this.moveDirection(e,a.North):t.position.y-this.position.y==1?this.moveDirection(e,a.South):t.position.x-this.position.x==1?this.moveDirection(e,a.East):this.moveDirection(e,a.West);else if(this.moveToward(e,t)){var o=new l(this.controller,function(){},function(){i.moveTo(o,t)},this.identifier);this.addCommand(o)}else this.bump(e)}},{key:"turn",value:function(e,t){(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&this.controller.addCommandRecord("turn",this.type,e.repeat),-1===t&&this.controller.levelModel.turnLeft(this),1===t&&this.controller.levelModel.turnRight(this),this.updateAnimationDirection(),this.controller.delayPlayerMoveBy(200,800,function(){e.succeeded()})}},{key:"turnRandom",value:function(e){this.controller.addCommandRecord("turnRandom",this.type,e.repeat);var t=0===function(e,t){return Math.floor(Math.random()*(t-e+1))+e}(0,1)?1:-1;this.turn(e,t,!1)}},{key:"use",value:function(e,t){var i=this,o="lookAtCam"+this.controller.levelView.getDirectionName(this.facing);this.controller.levelView.playScaledSpeed(this.getAnimationManager(),o),this.queue.startPushHighPriorityCommands(),this.controller.events.forEach(function(e){return e({eventType:s.WhenUsed,targetType:i.type,eventSenderIdentifier:t.identifier,targetIdentifier:i.identifier})}),this.queue.endPushHighPriorityCommands(),e.succeeded()}},{key:"drop",value:function(e,t){var i=this;this.controller.addCommandRecord("drop",this.type,e.repeat),this.controller.levelView.playItemDropAnimation(this.position,t,function(){if(e.succeeded(),i.controller.levelModel.usePlayer){var t=i.controller.levelModel.player.queue.currentCommand;t&&t.waitForOtherQueue&&t.succeeded()}})}},{key:"attack",value:function(e){var t=this;this.controller.addCommandRecord("attack",this.type,e.repeat);var i=this.controller.levelView.getDirectionName(this.facing);this.controller.levelView.playScaledSpeed(this.getAnimationManager(),"attack"+i),setTimeout(function(i){var o=i.controller.levelEntity.getEntityAt(i.controller.levelModel.getMoveForwardPosition(i));if(o){var n=new l(i.controller,function(){},function(){o.takeDamage(n)},o);o.addCommand(n)}setTimeout(function(t,i,n){null!==i&&(o.queue.startPushHighPriorityCommands(),t.events.forEach(function(e){return e({eventType:s.WhenAttacked,targetType:i.type,eventSenderIdentifier:n.identifier,targetIdentifier:i.identifier})}),o.queue.endPushHighPriorityCommands()),e.succeeded()},300/t.controller.tweenTimeScale,i.controller,o,i)},200/this.controller.tweenTimeScale,this)}},{key:"pushBack",value:function(e,t,i,o){var n=this,a=this.controller.levelModel,s=r.forward(this.position,t);if(a.isPositionEmpty(s)[0]){this.updateHidingBlock(this.position),this.position=s,this.updateHidingTree();var l=this.controller.levelView.addResettableTween(this.sprite).to({x:this.offset[0]+40*this.position[0],y:this.offset[1]+40*this.position[1]},i,Phaser.Easing.Linear.None);l.onComplete.add(function(){setTimeout(function(){e.succeeded(),void 0!==o&&o(n)},i/n.controller.tweenTimeScale)}),l.start()}else e.succeeded(),void 0!==o&&o(this)}},{key:"takeDamage",value:function(e){var t=this,i=this.controller.levelView,o=i.getDirectionName(this.facing);this.healthPoint>1?(i.playScaledSpeed(this.getAnimationManager(),"hurt"+o),setTimeout(function(){t.healthPoint--,e.succeeded()},1500/this.controller.tweenTimeScale)):(this.healthPoint--,this.getAnimationManager().stop(null,!0),this.controller.levelView.playScaledSpeed(this.getAnimationManager(),"die"+o),setTimeout(function(){var e=t.controller.levelView.addResettableTween(t.sprite).to({alpha:0},300,Phaser.Easing.Linear.None);e.onComplete.add(function(){t.controller.levelEntity.destroyEntity(t.identifier)}),e.start()},1500/this.controller.tweenTimeScale))}},{key:"playRandomIdle",value:function(e){var t,i="";switch(t=this.controller.levelView.getDirectionName(e),Math.trunc(5*Math.random())+1){case 1:i+="idle";break;case 2:i+="lookLeft";break;case 3:i+="lookRight";break;case 4:i+="lookAtCam";break;case 5:i+="lookDown"}i+=t,this.controller.levelView.playScaledSpeed(this.getAnimationManager(),i)}},{key:"updateAnimationDirection",value:function(){var e=this.controller.levelView.getDirectionName(this.facing);this.controller.levelView.playScaledSpeed(this.getAnimationManager(),"idle"+e)}},{key:"getDistance",value:function(e){return r.absoluteDistanceSquare(this.position,e.position)}},{key:"blowUp",value:function(e,t){var i=a.South;t[0]>this.position[0]?(i=a.West,this.facing=a.East,this.updateAnimationDirection()):t[0]<this.position[0]?(i=a.East,this.facing=a.West,this.updateAnimationDirection()):t[1]>this.position[1]?(i=a.North,this.facing=a.South,this.updateAnimationDirection()):t[1]<this.position[1]&&(i=a.South,this.facing=a.North,this.updateAnimationDirection()),this.pushBack(e,i,150,function(t){var i=new l(t.controller,function(){},function(){t.controller.destroyEntity(i,t.identifier)},t.identifier);t.queue.startPushHighPriorityCommands(),t.addCommand(i,e.repeat),t.queue.endPushHighPriorityCommands()})}},{key:"hasPermissionToWalk",value:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return(e.isWalkable||void 0!==t&&t.isOnBlock&&!e.isEmpty)&&(void 0===t||t.canMoveThrough())&&"water"!==i.blockType&&"lava"!==i.blockType}},{key:"handleMoveOffPressurePlate",value:function(e){var t=this,i=r.add(this.position,e),o="pressurePlateDown"===this.controller.levelModel.actionPlane.getBlockAt(i).blockType,n=this.controller.levelModel.actionPlane.getBlockAt(this.position),a=!1;if(void 0!==n&&n.isWalkable||(a=!0),this.controller.levelEntity.entityMap.forEach(function(e){e.identifier!==t.identifier&&e.canTriggerPressurePlates()&&t.controller.positionEquivalence(e.position,i)&&(a=!0)}),o&&!a){this.controller.audioPlayer.play("pressurePlateClick");var s=new c("pressurePlateUp");this.controller.levelModel.actionPlane.setBlockAt(i,s,e[0],e[1])}}},{key:"handleMoveOnPressurePlate",value:function(e){var t=r.add(this.position,e);if("pressurePlateUp"===this.controller.levelModel.actionPlane.getBlockAt(t).blockType){this.controller.audioPlayer.play("pressurePlateClick");var i=new c("pressurePlateDown");return this.controller.levelModel.actionPlane.setBlockAt(t,i),!0}return!1}},{key:"handleMoveOffIronDoor",value:function(e){var t=r.add(this.position,e);if(this.controller.levelModel.inBounds(t)){var i="doorIron"===this.controller.levelModel.actionPlane.getBlockAt(t).blockType,o="doorIron"===this.controller.levelModel.actionPlane.getBlockAt(this.position).blockType;i&&!o&&this.controller.levelModel.actionPlane.findDoorToAnimate(new r(-1,-1))}}},{key:"handleMoveAwayFromPiston",value:function(e){var t=this,i=r.add(this.position,e);r.getOrthogonalPositions(i).forEach(function(e){if(t.controller.levelModel.actionPlane.inBounds(e)){var i=t.controller.levelModel.actionPlane.getBlockAt(e);i.blockType.startsWith("piston")&&i.isPowered&&t.controller.levelModel.actionPlane.activatePiston(e)}})}},{key:"handleGetOnRails",value:function(e){this.getOffTrack=!1,this.handleMoveOffPressurePlate(new r(0,0)),this.controller.levelView.playTrack(this.position,e,!0,this,null)}}]),e}()},function(e,t,i){"use strict";var o=Object.freeze({North:0,East:1,South:2,West:3,opposite:function(e){switch(e){case o.North:return o.South;case o.South:return o.North;case o.East:return o.West;case o.West:return o.East}},left:function(e){return this.turn(e,"left")},right:function(e){return this.turn(e,"right")},turnDirection:function(e,t){switch(e){case o.North:return t===o.East?"right":"left";case o.South:return t===o.West?"right":"left";case o.East:return t===o.South?"right":"left";case o.West:return t===o.North?"right":"left"}},turn:function(e,t){return(e+4+("right"===t?1:-1))%4},directionToOffset:function(e){switch(e){case o.North:return[0,-1];case o.South:return[0,1];case o.East:return[1,0];case o.West:return[-1,0]}},directionToRelative:function(e){switch(e){case o.North:return"Up";case o.South:return"Down";case o.East:return"Right";case o.West:return"Left"}}});e.exports=o},function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(9);e.exports=function(){function e(t,i,o,a){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.GameController=t,this.Game=t.game,this.HighlightCallback=i,this.state=n.NOT_STARTED,this.target=o,this.onFinish=a,this.repeat=!1}return o(e,[{key:"tick",value:function(){}},{key:"begin",value:function(){this.HighlightCallback&&this.HighlightCallback(),this.state=n.WORKING}},{key:"isStarted",value:function(){return this.state!==n.NOT_STARTED}},{key:"isFinished",value:function(){return this.isSucceeded()||this.isFailed()}},{key:"isSucceeded",value:function(){return this.state===n.SUCCESS}},{key:"isFailed",value:function(){return this.state===n.FAILURE}},{key:"succeeded",value:function(){this.state=n.SUCCESS}},{key:"failed",value:function(){this.state=n.FAILURE}}]),e}()},function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(1),a=[n.North,n.East,n.South,n.West];e.exports=function(){function e(t,i){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.x=t,this.y=i,this[0]=t,this[1]=i}return o(e,null,[{key:"add",value:function(t,i){return new e(t[0]+i[0],t[1]+i[1])}},{key:"subtract",value:function(t,i){return new e(t[0]-i[0],t[1]-i[1])}},{key:"equals",value:function(e,t){return e[0]===t[0]&&e[1]===t[1]}},{key:"directionToOffsetPosition",value:function(t){var i=n.directionToOffset(t);if(i)return e.fromArray(i)}},{key:"isAdjacent",value:function(t,i){return a.map(e.directionToOffsetPosition).some(function(o){return e.equals(e.add(t,o),i)})}},{key:"forward",value:function(t,i){return e.add(t,e.directionToOffsetPosition(i))}},{key:"north",value:function(t){return e.forward(t,n.North)}},{key:"east",value:function(t){return e.forward(t,n.East)}},{key:"south",value:function(t){return e.forward(t,n.South)}},{key:"west",value:function(t){return e.forward(t,n.West)}},{key:"getOrthogonalPositions",value:function(t){return a.map(function(i){return e.forward(t,i)})}},{key:"manhattanDistance",value:function(e,t){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}},{key:"absoluteDistanceSquare",value:function(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}},{key:"getSurroundingPositions",value:function(t){return e.getOrthogonalPositions(t).concat([e.north(e.east(t)),e.north(e.west(t)),e.south(e.east(t)),e.south(e.west(t))])}},{key:"fromArray",value:function(t){return new e(t[0],t[1])}}]),e}()},function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(2);e.exports=function(e){function t(e,i,o,n,a){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,i,n,a));return r.actionCallback=o,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,n),o(t,[{key:"tick",value:function(){}},{key:"begin",value:function(){(function e(t,i,o){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,i);if(void 0===n){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,i,o)}if("value"in n)return n.value;var r=n.get;return void 0!==r?r.call(o):void 0})(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"begin",this).call(this),this.actionCallback()}}]),t}()},function(e,t,i){"use strict";e.exports=Object.freeze({WhenTouched:0,WhenUsed:1,WhenSpawned:2,WhenAttacked:3,WhenNight:4,WhenDay:5,WhenNightGlobal:6,WhenDayGlobal:7,WhenRun:8})},function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(1),a=n.North,r=n.South,s=n.East,l=n.West;e.exports=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.blockType=t,this.isEntity=!1,this.isWalkable=!1,this.isPlacable=!1,this.isDestroyable=!0,this.isUsable=!0,this.isEmpty=!1,this.isEmissive=!1,this.isTransparent=!1,this.isRedstone=!1,this.isPowered=!1,this.isConnectedToRedstone=!1,this.isRedstoneBattery=!1,this.isOpen=!1,this.isRail=!1,this.isSolid=!0,this.isWeaklyPowerable=!0,this.isStickable=!0,this.isActivatedConduit=!1,""===t&&(this.isWalkable=!0,this.isDestroyable=!1,this.isEmpty=!0,this.isPlacable=!0,this.isUsable=!1,this.isWeaklyPowerable=!1),this.getIsMiniblock()&&(this.isEntity=!0,this.isWalkable=!0,this.isDestroyable=!1,this.isPlacable=!0,this.isUsable=!1,this.isTransparent=!0),t.match("torch")&&(this.isWalkable=!0,this.isPlacable=!0,this.isStickable=!1),"rails"===t.substring(0,5)&&(this.isWeaklyPowerable="railsRedstoneTorch"===t,this.isStickable="railsRedstoneTorch"!==t,this.isEntity=!0,this.isWalkable=!0,this.isUsable=!0,this.isDestroyable=!0,this.isTransparent=!0,this.isRail="railsRedstoneTorch"!==t,this.isConnectedToRedstone=/^rails(RedstoneTorch|Unpowered|Powered)/.test(t),this.isRedstoneBattery="railsRedstoneTorch"===t,this.connectionA=void 0,this.connectionB=void 0),"sheep"===t&&(this.isEntity=!0,this.isDestroyable=!1,this.isUsable=!0),"invisible"===t&&(this.isDestroyable=!1,this.isUsable=!1,this.isWeaklyPowerable=!1,this.isEmissive=!0),t.startsWith("glass")&&(this.isSolid=!1),t.startsWith("ice")&&(this.isSolid=!1),"creeper"===t&&(this.isEntity=!0),"bedrock"===t&&(this.isDestroyable=!1),"lava"===t&&(this.isEmissive=!0,this.isWalkable=!0,this.isPlacable=!0),"magmaUnderwater"!==t&&"magmaDeep"!==t||(this.isEmissive=!0),"bubbleColumn"===t&&(this.isSolid=!1,this.isTransparent=!0,this.isEntity=!0),"conduit"===t&&(this.isSolid=!1,this.isEntity=!0),"water"===t&&(this.isPlacable=!0),"torch"===t&&(this.isEmissive=!0,this.isEntity=!0,this.isWalkable=!0,this.isUsable=!0,this.isDestroyable=!1,this.isTransparent=!0),"cropWheat"===t&&(this.isEntity=!0,this.isWalkable=!0,this.isUsable=!0,this.isDestroyable=!1,this.isTransparent=!0),"tnt"===t&&(this.isUsable=!0,this.isDestroyable=!0),"door"===t&&(this.isWeaklyPowerable=!1,this.isSolid=!1,this.isEntity=!0,this.isWalkable=!1,this.isUsable=!0,this.isDestroyable=!1,this.isTransparent=!0,this.isStickable=!1),"doorIron"===t&&(this.isWeaklyPowerable=!1,this.isSolid=!1,this.isEntity=!0,this.isWalkable=!1,this.isDestroyable=!1,this.isTransparent=!0,this.isConnectedToRedstone=!0,this.isStickable=!1),t.startsWith("redstoneWire")&&(this.isEntity=!0,this.isWalkable=!0,this.isUsable=!0,this.isDestroyable=!0,this.isTransparent=!0,this.isRedstone=!0,this.isStickable=!1),t.startsWith("pressurePlate")&&(this.isWeaklyPowerable="pressurePlateUp"!==t,this.isEntity=!0,this.isWalkable=!0,this.isDestroyable=!1,this.isTransparent=!0,this.isConnectedToRedstone=!0,this.isRedstoneBattery="pressurePlateUp"!==t,this.isStickable=!1),"glowstone"===t&&(this.isEntity=!0),"bedFoot"!==t&&"bedHead"!==t||(this.isEntity=!0),t.startsWith("piston")&&(this.isWeaklyPowerable=!1,this.isSolid=!1,this.isDestroyable=!1,this.isConnectedToRedstone=!t.startsWith("pistonArm"),("On"===t.substring(t.length-2,t.length)||t.startsWith("pistonArm")||"OnSticky"===t.substring(t.length-8,t.length))&&(this.isEntity=!0)),(t.startsWith("flower")||/coral/i.test(t)&&!/Block/.test(t)||"seaGrass"===t||"kelp"===t||"seaPickles"===t)&&(this.isWalkable=!0,this.isEntity=!0),"seaPickles"!==t&&"seaLantern"!==t&&"magmaBlock"!==t||(this.isEmissive=!0)}return o(e,[{key:"isFlat",value:function(){return this.isRail||this.isRedstone||this.blockType.startsWith("pressurePlate")}},{key:"notValidOnGroundPlane",value:function(){return this.blockType.startsWith("rails")||this.blockType.startsWith("redstone")}},{key:"skipsDestructionOverlay",value:function(){return this.isRedstone||"torch"===this.blockType||"railsRedstoneTorch"===this.blockType}},{key:"shouldRenderOnGroundPlane",value:function(){return this.isFlat()}},{key:"getIsPowerableRail",value:function(){return this.isRail&&this.isConnectedToRedstone}},{key:"getIsHorizontal",value:function(){return this.blockType.match("East|West")}},{key:"getIsVertical",value:function(){return this.blockType.match("North|South")}},{key:"getIsStickyPiston",value:function(){return"Sticky"===this.blockType.substring(this.blockType.length-6,this.blockType.length)}},{key:"canHoldCharge",value:function(){return this.isSolid}},{key:"getIsMiniblock",value:function(){return e.isMiniblock(this.blockType)}},{key:"getIsChestblock",value:function(){return e.isChestblock(this.blockType)}},{key:"getIsTree",value:function(){return!!this.blockType.match(/^tree/)}},{key:"getIsDoor",value:function(){return this.blockType.startsWith("door")}},{key:"getIsConduit",value:function(){return this.blockType.startsWith("conduit")}},{key:"getIsLiquid",value:function(){return"water"===this.blockType||"magmaUnderwater"===this.blockType||"lava"===this.blockType}},{key:"getCanFall",value:function(){return"sand"===this.blockType||"gravel"===this.blockType}},{key:"getIsPlaceableInLiquid",value:function(){return!(this.isRedstone||this.getIsPiston()||this.isRail||"torch"===this.blockType||"railsRedstoneTorch"===this.blockType||"pressurePlateUp"===this.blockType)}},{key:"getIsPiston",value:function(){return this.blockType.startsWith("piston")}},{key:"getIsPistonArm",value:function(){return this.blockType.startsWith("pistonArm")}},{key:"getIsPushable",value:function(){return""!==this.blockType&&!this.isDestroyableUponPush()}},{key:"isDestroyableUponPush",value:function(){return this.blockType.startsWith("redstone")||this.blockType.startsWith("door")||this.blockType.startsWith("railsRedstone")||this.blockType.startsWith("pressure")}},{key:"needToRefreshRedstone",value:function(){return!!(this.isRedstone||""===this.blockType||this.isConnectedToRedstone&&!this.blockType.startsWith("piston"))}},{key:"getPistonDirection",value:function(){if(this.blockType.startsWith("piston"))switch(this.blockType.substring(6,7)){case"D":return r;case"U":return a;case"L":return l;case"R":return s}}},{key:"getIsEmptyOrEntity",value:function(){return this.isEmpty||this.isEntity}}],[{key:"getCanFall",value:function(t){return new e(t).getCanFall()}},{key:"getIsPlaceableInLiquid",value:function(t){return new e(t).getIsPlaceableInLiquid()}},{key:"isWalkable",value:function(t){return new e(t).isWalkable}},{key:"isMiniblock",value:function(e){return e.endsWith("Miniblock")}},{key:"isChestblock",value:function(e){return e.endsWith("Chest")}},{key:"isFlat",value:function(t){return new e(t).isFlat()}},{key:"skipsDestructionOverlay",value:function(t){return new e(t).skipsDestructionOverlay()}},{key:"notValidOnGroundPlane",value:function(t){return new e(t).notValidOnGroundPlane()}},{key:"getMiniblockFrame",value:function(t){if("railsRedstoneTorch"===t)return"redstoneTorch";if(t.startsWith("rails"))return"railNormal";if(t.endsWith("Chest"))return"chest";if(!t.startsWith("glass")&&!t.startsWith("ice")){if("redstoneWire"===t.substring(0,12))return"redstoneDust";if(e.isMiniblock(t))return t.replace("Miniblock","");var i=t;switch(i){case"treeAcacia":case"treeBirch":case"treeJungle":case"treeOak":case"treeSpruce":case"treeSpruceSnowy":i="log"+i.substring(4);break;case"stone":i="cobblestone";break;case"oreCoal":i="coal";break;case"oreDiamond":i="diamond";break;case"oreIron":i="ingotIron";break;case"oreLapis":i="lapisLazuli";break;case"oreGold":i="ingotGold";break;case"oreEmerald":i="emerald";break;case"oreRedstone":i="redstoneDust";break;case"grass":i="dirt";break;case"tnt":i="gunPowder"}return i}}}]),e}()},function(e,t,i){"use strict";var o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var i=[],o=!0,n=!1,a=void 0;try{for(var r,s=e[Symbol.iterator]();!(o=(r=s.next()).done)&&(i.push(r.value),!t||i.length!==t);o=!0);}catch(e){n=!0,a=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw a}}return i}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=i(1);e.exports.convertActionPlaneEntitiesToConfig=function(t){var i=t.gridWidth&&t.gridHeight?[t.gridWidth,t.gridHeight]:[10,10],n=o(i,2),a=n[0],r=n[1];[t.actionPlane].forEach(function(i){for(var o=0;o<i.length;o++){var n=o%a,s=Math.floor(o/r),l=e.exports.convertNameToEntity(i[o],n,s);l&&(t.entities=t.entities||[],t.entities.push(l),i[o]="")}})},e.exports.randomInt=function(e,t){return Math.floor(Math.random()*(t-e))+e};var a={Up:n.North,Down:n.South,Left:n.West,Right:n.East};e.exports.convertNameToEntity=function(e,t,i){if(e.match(/^(sheep|zombie|ironGolem|creeper|cod|cow|chicken|dolphin|ghast|boat|salmon|squid|tropicalFish|seaTurtle)(Right|Left|Up|Down|$)/)){var o=e.match(/(.*)(Right|Left|Up|Down)/),r=o?a[o[2]]:n.East;return[o?o[1]:e,t,i,r]}}},function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(9);e.exports=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.gameController=t,this.game=t.game,this.reset(),this.repeatCommands=[],this.setUnshiftState=!1,this.highPriorityCommands=[]}return o(e,[{key:"addCommand",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.repeat=t,this.whileCommandQueue?this.whileCommandQueue.addCommand(e):this.setUnshiftState?this.highPriorityCommands.push(e):this.commandList_.push(e)}},{key:"setWhileCommandInsertState",value:function(e){this.whileCommandQueue=e}},{key:"begin",value:function(){this.state=n.WORKING}},{key:"reset",value:function(){this.state=n.NOT_STARTED,this.currentCommand=null,this.commandList_=[],this.highPriorityCommands=[],this.whileCommandQueue&&this.whileCommandQueue.reset(),this.repeatCommands=[],this.whileCommandQueue=null}},{key:"startPushHighPriorityCommands",value:function(){this.setUnshiftState=!0,this.highPriorityCommands=[]}},{key:"endPushHighPriorityCommands",value:function(){for(var e=this.highPriorityCommands.length-1;e>=0;e--)this.commandList_.unshift(this.highPriorityCommands[e]);this.setUnshiftState=!1}},{key:"tick",value:function(){if(this.state===n.WORKING){if(!this.currentCommand){if(0===this.commandList_.length){0===this.repeatCommands.length&&(this.state=n.SUCCESS),this.gameController.startPushRepeatCommand();for(var e=0;e<this.repeatCommands.length;e++)this.repeatCommands[e][1]>0?(this.repeatCommands[e][0](),this.repeatCommands[e][1]--):-1===this.repeatCommands[e][1]?this.repeatCommands[e][0]():this.repeatCommands.splice(e,1);return void this.gameController.endPushRepeatCommand()}this.currentCommand=this.commandList_.shift()}this.currentCommand.isStarted()?this.currentCommand.tick():this.currentCommand.begin(),this.currentCommand.isSucceeded()?(this.currentCommand.onFinish&&this.currentCommand.onFinish(),this.currentCommand=null):this.currentCommand.isFailed()&&(this.state=n.FAILURE)}}},{key:"getLength",value:function(){return this.commandList_?this.commandList_.length:0}},{key:"isStarted",value:function(){return this.state!==n.NOT_STARTED}},{key:"isFinished",value:function(){return this.isSucceeded()||this.isFailed()}},{key:"isSucceeded",value:function(){return this.state===n.SUCCESS}},{key:"isFailed",value:function(){return this.state===n.FAILURE}},{key:"addRepeatCommands",value:function(e,t){if(-1===t)for(var i=0;i<this.repeatCommands.length;i++)if(-1===this.repeatCommands[i][1]){this.repeatCommands.splice(i,1);break}this.repeatCommands.push([e,t]),this.begin()}}]),e}()},function(e,t,i){"use strict";e.exports=Object.freeze({NOT_STARTED:0,WORKING:1,SUCCESS:2,FAILURE:3})},function(e,t,i){"use strict";var o=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();var n=i(0),a=i(1);e.exports=function(e){function t(e,i,o,n,a,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var s=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,i,o,n,a,r));return s.offset=[-22,-28],s.prepareSprite(),s.sprite.sortOrder=s.controller.levelView.yToIndex(s.position.y),s}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,n),o(t,[{key:"getFrameForDirection",value:function(){switch(this.facing){case a.North:return"Boat_05";case a.South:return"Boat_01";case a.East:return"Boat_07";case a.West:return"Boat_03"}}},{key:"prepareSprite",value:function(){var e=this.controller.levelView.actionGroup,i=this.getFrameForDirection();this.sprite=e.create(0,0,"player"+this.controller.player.name,i),this.sprite.x=this.offset[0]+40*this.position.x,this.sprite.y=this.offset[1]+40*this.position.y,t.addBobTween(this.game,this.sprite)}}],[{key:"addBobTween",value:function(e,t){return e.add.tween(t).to({y:"3"},1e3,Phaser.Easing.Sinusoidal.InOut,!0,0,-1,!0)}}]),t}()},function(e,t,i){"use strict";var o=i(12),n=i(1),a=i(5),r=i(7);e.exports={GameController:o,FacingDirection:n,EventType:a,utils:r}},function(e,t,i){"use strict";var o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var i=[],o=!0,n=!1,a=void 0;try{for(var r,s=e[Symbol.iterator]();!(o=(r=s.next()).done)&&(i.push(r.value),!t||i.length!==t);o=!0);}catch(e){n=!0,a=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw a}}return i}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}();function a(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var r=i(8),s=i(4),l=i(5),c=i(1),h=i(3),u=i(13),d=i(18),p=i(20),f=i(34),y=i(7).convertNameToEntity,m=i(35),v=400,g=400,k=function(){function e(t){var i=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.DEBUG=t.debug,window.PhaserGlobal={disableAudio:!0,disableWebAudio:!0,hideBanner:!this.DEBUG},this.codeOrgAPI=m.get(this);var o=t.Phaser;this.game=new o.Game({forceSetTimeOut:t.forceSetTimeOut,width:v,height:g,renderer:o.AUTO,parent:t.containerId,state:"earlyLoad",preserveDrawingBuffer:!0}),this.specialLevelType=null,this.queue=new r(this),this.OnCompleteCallback=null,this.assetRoot=t.assetRoot,this.audioPlayer=t.audioPlayer,this.afterAssetsLoaded=t.afterAssetsLoaded,this.assetLoader=new f(this),this.earlyLoadAssetPacks=t.earlyLoadAssetPacks||[],this.earlyLoadNiceToHaveAssetPacks=t.earlyLoadNiceToHaveAssetPacks||[],this.resettableTimers=[],this.timeouts=[],this.timeout=0,this.initializeCommandRecord(),this.score=0,this.useScore=!1,this.scoreText=null,this.onScoreUpdate=t.onScoreUpdate,this.events=[],this.assumedSlowMotion=1.5,this.initialSlowMotion=t.customSlowMotion||this.assumedSlowMotion,this.tweenTimeScale=1.5/this.initialSlowMotion,this.playerDelayFactor=1,this.dayNightCycle=!1,this.player=null,this.agent=null,this.timerSprite=null,this.game.state.add("earlyLoad",{preload:function(){i.game.load.resetLocked=!0,i.assetLoader.loadPacks(i.earlyLoadAssetPacks)},create:function(){i.assetLoader.loadPacks(i.earlyLoadNiceToHaveAssetPacks),i.game.load.start()}}),this.game.state.add("levelRunner",{preload:this.preload.bind(this),create:this.create.bind(this),update:this.update.bind(this),render:this.render.bind(this)})}return n(e,[{key:"getIsDirectPlayerControl",value:function(){return this.levelData.isEventLevel||this.levelData.isAgentLevel}},{key:"loadLevel",value:function(e){this.levelData=Object.freeze(e),this.levelEntity=new p(this),this.levelModel=new u(this.levelData,this),this.levelView=new d(this),this.specialLevelType=e.specialLevelType,this.timeout=e.levelVerificationTimeout,void 0!==e.useScore&&(this.useScore=e.useScore),this.timeoutResult=e.timeoutResult,this.onDayCallback=e.onDayCallback,this.onNightCallback=e.onNightCallback,this.game.state.start("levelRunner")}},{key:"reset",value:function(){var e=this;this.dayNightCycle=!1,this.queue.reset(),this.levelEntity.reset(),this.levelModel.reset(),this.levelView.reset(this.levelModel),this.levelEntity.loadData(this.levelData),this.player=this.levelModel.player,this.agent=this.levelModel.agent,this.resettableTimers.forEach(function(e){e.stop(!0)}),this.timeouts.forEach(function(e){clearTimeout(e)}),this.timerSprite&&this.timerSprite.kill(),this.timerSprite=null,this.timeouts=[],this.resettableTimers.length=0,this.events.length=0,this.score=0,this.useScore&&this.updateScore(),this.getIsDirectPlayerControl()||this.events.push(function(t){t.eventType===l.WhenUsed&&"sheep"===t.targetType&&e.codeOrgAPI.drop(null,"wool",t.targetIdentifier),t.eventType===l.WhenTouched&&"creeper"===t.targetType&&(e.codeOrgAPI.flashEntity(null,t.targetIdentifier),e.codeOrgAPI.explodeEntity(null,t.targetIdentifier))}),this.initializeCommandRecord()}},{key:"preload",value:function(){this.game.load.resetLocked=!0,this.game.time.advancedTiming=this.DEBUG,this.game.stage.disableVisibilityChange=!0,this.assetLoader.loadPacks(this.levelData.assetPacks.beforeLoad)}},{key:"create",value:function(){var e=this;this.levelView.create(this.levelModel),this.game.time.slowMotion=this.initialSlowMotion,this.addCheatKeys(),this.assetLoader.loadPacks(this.levelData.assetPacks.afterLoad),this.game.load.image("timer",this.assetRoot+"images/placeholderTimer.png"),this.game.load.onLoadComplete.addOnce(function(){e.afterAssetsLoaded&&e.afterAssetsLoaded()}),this.levelEntity.loadData(this.levelData),this.game.load.start()}},{key:"run",value:function(){var e=this;this.events.forEach(function(e){return e({eventType:l.WhenRun,targetIdentifier:void 0})});var t=!0,i=!1,o=void 0;try{for(var n,a=this.levelEntity.entityMap[Symbol.iterator]();!(t=(n=a.next()).done);t=!0){var r=n.value[1];this.events.forEach(function(e){return e({eventType:l.WhenSpawned,targetType:r.type,targetIdentifier:r.identifier})}),r.queue.begin()}}catch(e){i=!0,o=e}finally{try{!t&&a.return&&a.return()}finally{if(i)throw o}}if(!isNaN(this.timeout)&&this.timeout>0){this.timerSprite=this.game.add.sprite(-50,390,"timer");var s=this.levelView.addResettableTween(this.timerSprite).to({x:-450,alpha:.5},this.timeout,Phaser.Easing.Linear.None);s.onComplete.add(function(){e.endLevel(e.timeoutResult(e.levelModel))}),s.start()}}},{key:"followingPlayer",value:function(){return!!this.levelData.gridDimensions&&!this.checkMinecartLevelEndAnimation()}},{key:"update",value:function(){this.queue.tick(),this.levelEntity.tick(),this.levelModel.usePlayer&&this.player.updateMovement(),this.levelModel.usingAgent&&this.agent.updateMovement(),this.levelView.update(),(this.getIsDirectPlayerControl()||this.player.queue.state>1)&&this.checkSolution()}},{key:"addCheatKeys",value:function(){var e,t=this;if(this.levelModel.usePlayer){var i=(a(e={},Phaser.Keyboard.UP,c.North),a(e,Phaser.Keyboard.W,c.North),a(e,Phaser.Keyboard.RIGHT,c.East),a(e,Phaser.Keyboard.D,c.East),a(e,Phaser.Keyboard.DOWN,c.South),a(e,Phaser.Keyboard.S,c.South),a(e,Phaser.Keyboard.LEFT,c.West),a(e,Phaser.Keyboard.A,c.West),a(e,Phaser.Keyboard.SPACEBAR,-2),e),o=function(){return null!==document.activeElement&&["INPUT","TEXTAREA"].includes(document.activeElement.tagName)};Object.keys(i).forEach(function(e){var n=i[e];t.game.input.keyboard.addKey(e).onDown.add(function(){o()||(t.player.movementState=n,t.player.updateMovement())}),t.game.input.keyboard.addKey(e).onUp.add(function(){o()||(t.player.movementState===n&&(t.player.movementState=-1),t.player.updateMovement())}),t.game.input.keyboard.removeKeyCapture(e)})}}},{key:"handleEndState",value:function(e){this.OnCompleteCallback&&(this.OnCompleteCallback(e,this.levelModel),this.OnCompleteCallback=null)}},{key:"render",value:function(){this.DEBUG&&this.game.debug.text(this.game.time.fps||"--",2,14,"#00ff00"),this.levelView.render()}},{key:"scaleFromOriginal",value:function(){var e=this.levelData.gridDimensions||[10,10],t=o(e,2);return[t[0]/10,t[1]/10]}},{key:"getScreenshot",value:function(){return this.game.canvas.toDataURL("image/png")}},{key:"initializeCommandRecord",value:function(){var e=["moveAway","moveToward","moveForward","turn","turnRandom","explode","wait","flash","drop","spawn","destroy","playSound","attack","addScore"];this.commandRecord=new Map,this.repeatCommandRecord=new Map,this.isRepeat=!1;for(var t=0;t<e.length;t++)this.commandRecord.set(e[t],new Map),this.commandRecord.get(e[t]).set("count",0),this.repeatCommandRecord.set(e[t],new Map),this.repeatCommandRecord.get(e[t]).set("count",0)}},{key:"startPushRepeatCommand",value:function(){this.isRepeat=!0}},{key:"endPushRepeatCommand",value:function(){this.isRepeat=!1}},{key:"addCommandRecord",value:function(e,t,i){var o=i?this.repeatCommandRecord:this.commandRecord;if(o.has(e)){var n=o.get(e);if(n.set("count",n.get("count")+1),n.has(t)?n.set(t,n.get(t)+1):n.set(t,1),this.DEBUG){var a=i?"Repeat ":"Command :";console.log(a+e+" executed in mob type : "+t+" updated count : "+n.get(t))}}}},{key:"getCommandCount",value:function(e,t,i){var o=i?this.repeatCommandRecord:this.commandRecord;if(o.has(e)){var n=o.get(e);return void 0===t?n.get("count"):n.has(t)?n.get(t):0}return 0}},{key:"getEntity",value:function(e){void 0===e&&(e="Player");var t=this.levelEntity.entityMap.get(e);return void 0===t&&console.log("Debug GetEntity: there is no entity : "+e+"\n"),t}},{key:"getEntities",value:function(e){return this.levelEntity.getEntitiesOfType(e)}},{key:"isType",value:function(e){return"string"==typeof e&&"Player"!==e&&"PlayerAgent"!==e}},{key:"printErrorMsg",value:function(e){this.DEBUG&&this.game.debug.text(e)}},{key:"moveAway",value:function(e,t){var i=this,o=e.target;if(void 0===o){var n=this.levelEntity.entityMap,a=function(){var o=d[1],n=new s(i,function(){},function(){i.moveAway(n,t)},o.identifier);o.addCommand(n,e.repeat)},r=!0,l=!1,c=void 0;try{for(var h,u=n[Symbol.iterator]();!(r=(h=u.next()).done);r=!0){var d=h.value;a()}}catch(e){l=!0,c=e}finally{try{!r&&u.return&&u.return()}finally{if(l)throw c}}e.succeeded()}else{var p=this.isType(o),f=this.isType(t);if(o===t)return this.printErrorMsg("Debug MoveAway: Can't move away entity from itself\n"),void e.succeeded();if(p||f)if(p&&!f){var y=this.getEntities(o),m=this.getEntity(t);if(void 0!==m)for(var v=function(){if(y[g].identifier===m.identifier)return"continue";var o=new s(i,function(){},function(){i.moveAway(o,t)},y[g].identifier);y[g].addCommand(o,e.repeat)},g=0;g<y.length;g++)v();e.succeeded()}else if(!p&&f){var k=this.getEntity(o),b=this.getEntities(t);if(b.length>0){for(var w=[Number.MAX_VALUE,-1],P=0;P<b.length;P++)if(k.identifier!==b[P].identifier){var _=k.getDistance(b[P]);_<w[0]&&(w=[_,P])}-1!==w[1]&&k.moveAway(e,b[w[1]])}else e.succeeded()}else!function(){var n=i.getEntities(o),a=i.getEntities(t);if(a.length>0&&n.length>0){for(var r=function(t){for(var o=n[t],r=[Number.MAX_VALUE,-1],l=0;l<a.length;l++)if(a[t].identifier!==o.identifier){var c=o.getDistance(a[l]);c<r[0]&&(r=[c,l])}if(-1!==r){var h=new s(i,function(){},function(){i.moveAway(h,a[r[1]].identifier)},o.identifier);o.addCommand(h,e.repeat)}else e.succeeded()},l=0;l<n.length;l++)r(l);e.succeeded()}}();else{var S=this.getEntity(o),A=this.getEntity(t);if(S===A)return void e.succeeded();S.moveAway(e,A)}}}},{key:"moveToward",value:function(e,t){var i=this,o=e.target;if(void 0===o){var n=this.levelEntity.entityMap,a=function(){var o=d[1],n=new s(i,function(){},function(){i.moveToward(n,t)},o.identifier);o.addCommand(n,e.repeat)},r=!0,l=!1,c=void 0;try{for(var h,u=n[Symbol.iterator]();!(r=(h=u.next()).done);r=!0){var d=h.value;a()}}catch(e){l=!0,c=e}finally{try{!r&&u.return&&u.return()}finally{if(l)throw c}}e.succeeded()}else{var p=this.isType(o),f=this.isType(t);if(o===t)return void e.succeeded();if(p||f)if(p&&!f){var y=this.getEntities(o),m=this.getEntity(t);if(void 0!==m){for(var v=function(o){if(y[o].identifier===m.identifier)return"continue";var n=new s(i,function(){},function(){i.moveToward(n,t)},y[o].identifier);y[o].addCommand(n,e.repeat)},g=0;g<y.length;g++)v(g);e.succeeded()}}else if(!p&&f){var k=this.getEntity(o),b=this.getEntities(t);if(b.length>0){var w=[Number.MAX_VALUE,-1];for(g=0;g<b.length;g++)if(b[g].identifier!==k.identifier){var P=k.getDistance(b[g]);P<w[0]&&(w=[P,g])}-1!==w[1]?k.moveToward(e,b[w[1]]):e.succeeded()}else e.succeeded()}else!function(){var n=i.getEntities(o),a=i.getEntities(t);if(a.length>0&&n.length>0){for(var r=function(t){for(var o=n[t],r=[Number.MAX_VALUE,-1],l=0;l<a.length;l++)if(a[t].identifier!==o.identifier){var c=o.getDistance(a[l]);c<r[0]&&(r=[c,l])}if(-1!==r[1]){var h=new s(i,function(){},function(){i.moveToward(h,a[r[1]].identifier)},o.identifier);o.addCommand(h,e.repeat)}},l=0;l<n.length;l++)r(l);e.succeeded()}}();else{var _=this.getEntity(o),S=this.getEntity(t);_.moveToward(e,S)}}}},{key:"positionEquivalence",value:function(e,t){return e[0]===t[0]&&e[1]===t[1]}},{key:"execute",value:function(e,t){for(var i=arguments.length,o=Array(i>2?i-2:0),n=2;n<i;n++)o[n-2]=arguments[n];var a=this,r=e.target;if(this.isType(r)){for(var l=this.getEntities(r),c=function(i){var n=new s(a,function(){},function(){a.execute.apply(a,[n,t].concat(o))},l[i].identifier);l[i].addCommand(n,e.repeat)},h=0;h<l.length;h++)c(h);e.succeeded()}else if(void 0===r){var u=this.levelEntity.entityMap,d=function(i){var n=i[1],r=new s(a,function(){},function(){a.execute.apply(a,[r,t].concat(o))},n.identifier);n.addCommand(r,e.repeat)},p=!0,f=!1,y=void 0;try{for(var m,v=u[Symbol.iterator]();!(p=(m=v.next()).done);p=!0){d(m.value)}}catch(e){f=!0,y=e}finally{try{!p&&v.return&&v.return()}finally{if(f)throw y}}e.succeeded()}else{var g=this.getEntity(r);g[t].apply(g,[e].concat(o))}}},{key:"moveForward",value:function(e){this.execute(e,"moveForward")}},{key:"moveBackward",value:function(e){this.execute(e,"moveBackward")}},{key:"moveDirection",value:function(e,t){var i=this.levelModel.player;this.levelModel.shouldRide(t)?(i.handleGetOnRails(t),e.succeeded()):this.execute(e,"moveDirection",t)}},{key:"turn",value:function(e,t){this.execute(e,"turn",t)}},{key:"turnRandom",value:function(e){this.execute(e,"turnRandom")}},{key:"flashEntity",value:function(e){var t=this,i=e.target;if(this.isType(i)){for(var o=this.getEntities(i),n=function(i){var n=new s(t,function(){},function(){t.flashEntity(n)},o[i].identifier);o[i].addCommand(n,e.repeat)},a=0;a<o.length;a++)n(a);e.succeeded()}else if(void 0===i){var r=this.levelEntity.entityMap,l=function(i){var o=i[1],n=new s(t,function(){},function(){t.flashEntity(n)},o.identifier);o.addCommand(n,e.repeat)},c=!0,h=!1,u=void 0;try{for(var d,p=r[Symbol.ite