/*! * traviso.js - v0.1.5 * Copyright (c) 2021, Hakan Karlidag - @axaq * www.travisojs.com * * Compiled: Thu, 15 Jul 2021 13:16:01 UTC * * traviso.js is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license */ var TRAVISO=function(t,e){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(t,e)};function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){return(o=Object.assign||function(t){for(var e,i=1,n=arguments.length;ii)return o}return n+(o-n)*(t-e)/(i-e)},s=function(t){var e=Math.sqrt(t.x*t.x+t.y*t.y);return{x:t.x/e,y:t.y/e}},h=function(t,e){var i,n,o=t.y,r=t.x,a=e.length,s=!1;for(i=0,n=a-1;io!=e[n][1]>o&&r<(e[n][0]-e[i][0])*(o-e[i][1])/(e[n][1]-e[i][1])+e[i][0]&&(s=!s);return s},l=function(t,e){return Math.sqrt((e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y))},c={O:0,S:1,SW:2,W:3,NW:4,N:5,NE:6,E:7,SE:8},g=["idle","idle_s","idle_sw","idle_w","idle_nw","idle_n","idle_ne","idle_e","idle_se","move_s","move_sw","move_w","move_nw","move_n","move_ne","move_e","move_se"],p={ASTAR_ORTHOGONAL:0,ASTAR_DIAGONAL:1},u=!0;function f(t){u&&self.console.log("TRAVISO: "+t)}function d(t){return void 0===t&&(t=!0),u=t}var _=function(t,i,n){var o=t.mapData.objects[i];if(o){var r=null,a=o.textureNames[n];if(a&&a.length>0){r=[];for(var s=0;s0?t:.5},enumerable:!1,configurable:!0}),i.prototype.changeVisualToDirection=function(t,e,i,n,o,r){if(void 0===e&&(e=!1),void 0===i&&(i=!1),void 0===n&&(n=!1),void 0===o&&(o=null),void 0===r&&(r=null),this.changeVisual(e?g[t+8]:function(t){return g[t]}(t),i,n,o,r))this.currentDirection=t;else{if(!this.changeVisual("idle",i,n,o,r))throw new Error("no 'idle' visual defined as backup for object type "+this.type);this.currentDirection=c.O}},i.prototype.changeVisual=function(t,e,i,n,o){return void 0===e&&(e=!1),void 0===i&&(i=!1),void 0===n&&(n=null),void 0===o&&(o=null),!!this._textures[t]&&(this.currentInteractionOffset=this._interactionOffsets[t],this._container.textures!==this._textures[t]||i?(this._container.textures=this._textures[t],!e&&this._textures[t].length>1?(this._container.loop=!i,i&&n&&(this.onContainerAnimCompleteCallback=n,this._container.onComplete=this.onContainerAnimComplete_binded),r(o)&&o>0&&(this.animSpeed=o),this._container.gotoAndPlay(0)):this._container.gotoAndStop(0),this._engine.objectUpdateCallback&&this._engine.objectUpdateCallback(this),!0):(this._container.loop=!i,r(o)&&o>0&&(this.animSpeed=o),!0))},i.prototype.onContainerAnimComplete=function(){setTimeout(this.onContainerAnimComplete_delayed_binded,100)},i.prototype.onContainerAnimComplete_delayed=function(){this.onContainerAnimCompleteCallback(this),this.onContainerAnimCompleteCallback=null},i.prototype.destroy=function(){this._container&&(this._engine=null,this._textures=null,this._container.onComplete=null,this._container=null)},i}(e.Container),b=function(t){function i(i,n){var o=t.call(this)||this;o._isHighlighted=!1,o.onHighlightTweenEnd_binded=o.onHighlightTweenEnd.bind(o),o._engine=i,o.type=n;var r=o._engine.tileHalfHeight,a=o._engine.tileHalfWidth;o.vertices=[[-a,0],[0,-r],[a,0],[0,r]];var s=function(t,i){var n=t.mapData.tiles[i];if(n)return{m:n.movable,t:n.path?[e.Texture.from(n.path)]:[]};if(t.mapData.singleGroundImage)return{m:parseInt(i)>0,t:[]};throw new Error("TRAVISO: No info defined for tile type: "+i)}(o._engine,o.type);if(o.isMovableTo=s.m,s.t.length>0&&(o._tileGraphics=new e.AnimatedSprite(s.t),o._tileGraphics.anchor.x=.5,o._tileGraphics.anchor.y=.5,o.addChild(o._tileGraphics),o._tileGraphics.gotoAndStop(parseInt(o.type))),o._engine.mapData.tileHighlightImage)o._highlightedOverlay=new e.Sprite(e.Texture.from(o._engine.mapData.tileHighlightImage.path)),o._highlightedOverlay.anchor.x=.5,o._highlightedOverlay.anchor.y=.5,o.addChild(o._highlightedOverlay);else{o._highlightedOverlay=new e.Graphics,o._highlightedOverlay.clear(),o._highlightedOverlay.lineStyle(o._engine.tileHighlightStrokeAlpha<=0?0:2,o._engine.tileHighlightStrokeColor,o._engine.tileHighlightStrokeAlpha),o._highlightedOverlay.beginFill(o._engine.tileHighlightFillColor,o._engine.tileHighlightFillAlpha),o._highlightedOverlay.moveTo(o.vertices[0][0],o.vertices[0][1]);for(var h=1;h=0){var g=t.tweens;if(g||(g=[]),c.overwrite){for(var p=0;p0&&!this._activeForTweens&&(this._activeForTweens=!0)}},t.prototype.removeTween=function(t,e){var i=!1;if(t&&e){var n=this._tweenTargets.indexOf(t);if(!(n>=0))throw new Error("No tween target defined for this object");if(!(this._tweenTargets[n].tweens&&this._tweenTargets[n].tweens.length>0))throw new Error("No tween defined for this object");var o=this._tweenTargets[n].tweens,r=o.indexOf(e);if(!(r>=0))throw new Error("No tween defined for this object");e.onComplete=null,e.easingFunc=null,e.target=null,o.splice(r,1),0===o.length&&(this._tweenTargets.splice(n,1),i=!0),0===this._tweenTargets.length&&(this._activeForTweens=!1)}return i},t.prototype.killTweensOf=function(t){var e=!1,i=this._tweenTargets.indexOf(t);if(i>=0){if(this._tweenTargets[i].tweens&&this._tweenTargets[i].tweens.length>0){for(var n=this._tweenTargets[i].tweens,o=0;o=0||(this._movables[this._movables.length]=t,this._movables.length>0&&!this._activeForMovables&&(this._activeForMovables=!0))},t.prototype.removeMovable=function(t){var e=this._movables.indexOf(t);return-1!==e&&(t.speedUnit={x:0,y:0},this._movables.splice(e,1)),0===this._movables.length&&(this._activeForMovables=!1),-1!==e},t.prototype.removeAllMovables=function(){this._activeForMovables=!1;for(var t=this._movables.length,e=0;e=n.totalFrames&&(n.onComplete&&n.onComplete(),this.removeTween(o,n)&&(i--,t--),a--)}}}},t.prototype.destroy=function(){f("MoveEngine destroy"),this._processFrame=!1,this._ticker&&this._ticker.stop(),this.removeAllMovables(),this.removeAllTweens(),this._movables=null,this._tweenTargets=null,this._engine=null,this._ticker=null},t}(),w=function(){function t(t,e,i){this.x=t,this.y=e,this.weight=i,this.mapPos={c:t,r:e}}return t.prototype.toString=function(){return"["+String(this.x)+" "+String(this.y)+"]"},t.prototype.getCost=function(t){return t&&t.x!==this.x&&t.y!==this.y?1.41421*this.weight:this.weight},t.prototype.isWall=function(){return 0===this.weight},t}(),S=function(){function t(t){this.content=[],this.scoreFunction=t}return t.prototype.push=function(t){this.content.push(t),this.sinkDown(this.content.length-1)},t.prototype.pop=function(){var t=this.content[0],e=this.content.pop();return this.content.length>0&&(this.content[0]=e,this.bubbleUp(0)),t},t.prototype.size=function(){return this.content.length},t.prototype.rescoreElement=function(t){this.sinkDown(this.content.indexOf(t))},t.prototype.sinkDown=function(t){for(var e=this.content[t];t>0;){var i=(t+1>>1)-1,n=this.content[i];if(!(this.scoreFunction(e)0?a:null},t.prototype.getAdjacentOpenCells=function(t,e,i,n){var o,r,a=[];for(o=e;o>e-n;o--)for(r=t;r0;){var h=a.pop();if(h===i)return this.pathTo(h);h.closed=!0;for(var l=this.neighbors(h),c=0,g=l.length;c0&&t.add(this._config.assetsToLoad),t.load(this.assetsAndDataLoaded.bind(this))},i.prototype.assetsAndDataLoaded=function(t){var e,i,n,o=t.resources.mapData.data;r(o.initialControllableLocation)?r(o.initialControllableLocation.columnIndex)&&r(o.initialControllableLocation.rowIndex)||(f("Map-data file warning: 'initialControllableLocation' exists but it is not defined properly."),o.initialControllableLocation=null):f("Map-data file warning: No 'initialControllableLocation' defined. Ignore this warning if you are adding it later manually."),o.tileHighlightImage&&!o.tileHighlightImage.path&&(f("Map-data file warning: 'tileHighlightImage' exists but its 'path' is not defined properly."),o.tileHighlightImage=null),o.singleGroundImage&&!o.singleGroundImage.path&&(f("Map-data file warning: 'singleGroundImage' exists but its 'path' is not defined properly."),o.singleGroundImage=null);var a,s,h,l,c,g,p,u,d=o.groundMap;for(o.groundMapData=[],e=0;e0)for(g[l]=[],p=0;p>1,y:this._posFrame.h>>1},this.createMap(),this.repositionContent(this._config.initialPositionFrame),this.enableInteraction(),this._config.engineInstanceReadyCallback&&this._config.engineInstanceReadyCallback(this)},i.prototype.createMap=function(){this._config.backgroundColor&&(this._bg=new e.Graphics,this.addChild(this._bg)),this._config.useMask&&(this._mapMask=new e.Graphics,this.addChild(this._mapMask)),this._mapContainer=new e.Container,this.addChild(this._mapContainer),this._groundContainer=new e.Container,this._mapContainer.addChild(this._groundContainer),this._objContainer=new e.Container,this._mapContainer.addChild(this._objContainer);var t,i,n,o,r=this.mapData.groundMapData,a=this.mapData.objectsMapData,s=this.mapData.initialControllableLocation;for(this._mapSizeR=r.length,this._mapSizeC=r[0].length,this.mapData.singleGroundImage&&(t=new e.Sprite(e.Texture.from(this.mapData.singleGroundImage.path)),this._groundContainer.addChild(t),t.scale.set(this.mapData.singleGroundImage.scale||1)),this._tileArray=[],this._objArray=[],i=0;i=0;n--)this._tileArray[i][n]=null,r[i][n]&&"0"!==r[i][n]?((o=new b(this,r[i][n])).position.x=this.getTilePosXFor(i,n),o.position.y=this.getTilePosYFor(i,n),o.mapPos={c:n,r:i},this._tileArray[i][n]=o,this._groundContainer.addChild(o),o.isMovableTo||this._pathFinding.setCell(n,i,0)):this._pathFinding.setCell(n,i,0);var h,l=!1;for(i=0;i=0;n--)this._objArray[i][n]=null,a[i][n]&&"0"!==a[i][n]&&((h=new m(this,a[i][n])).position.x=this.getTilePosXFor(i,n),h.position.y=this.getTilePosYFor(i,n)+this.tileHalfHeight,h.mapPos={c:n,r:i},!l&&h.isFloorObject&&(l=!0),this._objContainer.addChild(h),this.addObjRefToLocation(h,h.mapPos),s&&s.columnIndex===n&&s.rowIndex===i&&(this._currentControllable=h));if(l){var c=void 0,g=void 0;for(i=0;i=0;n--)if(c=this._objArray[i][n])for(g=0;g>1)-this.getTilePosXFor(e,t)*this._currentScale,o=this._externalCenter.y-this.getTilePosYFor(e,t)*this._currentScale;this.centralizeToPoint(n,o,i)},i.prototype.centralizeToCurrentFocusLocation=function(t){this.centralizeToLocation(this._currentFocusLocation.c,this._currentFocusLocation.r,t)},i.prototype.centralizeToCurrentExternalCenter=function(t){this._externalCenter&&(this._currentFocusLocation={c:this._mapSizeC>>1,r:this._mapSizeR>>1},this.centralizeToPoint(this._externalCenter.x,this._externalCenter.y,t))},i.prototype.centralizeToPoint=function(t,e,i){this._tileArray&&(t-=this._mapVisualWidthScaled>>1,r(i)&&i||!r(i)&&this._config.instantCameraRelocation?(this._mapContainer.position.x=t,this._mapContainer.position.y=e):this.moveEngine.addTween(this._mapContainer.position,.5,{x:t,y:e},0,"easeInOut",!0))},i.prototype.setZoomParameters=function(t,e,i,n,o){void 0===t&&(t=.5),void 0===e&&(e=1.5),void 0===i&&(i=5),void 0===n&&(n=0),void 0===o&&(o=!1),this._config.minScale=t,this._config.maxScale=e,this._config.minZoom=-1,this._config.maxZoom=1,this._config.zoomIncrement=r(i)?i<=1?0:2/(i-1):.5,this._config.initialZoomLevel=n,this._config.instantCameraZoom=o},i.prototype.setScale=function(t,e){tthis._config.maxScale&&(t=this._config.maxScale),this._currentScale=t,this._mapVisualWidthScaled=this._mapVisualWidthReal*this._currentScale,r(e)&&e||!r(e)&&this._config.instantCameraZoom?this._mapContainer.scale.set(this._currentScale):this.moveEngine.addTween(this._mapContainer.scale,.5,{x:this._currentScale,y:this._currentScale},0,"easeInOut",!0)},i.prototype.zoomTo=function(t,e){var i=a(t=t||0,this._config.minZoom,this._config.maxZoom,this._config.minScale,this._config.maxScale,!0);i=Math.round(10*i)/10,this._currentZoom=a(i,this._config.minScale,this._config.maxScale,this._config.minZoom,this._config.maxZoom,!0),this._externalCenter=this._externalCenter?this._externalCenter:{x:this._mapVisualWidthScaled>>1,y:0};var n=this._mapContainer.position.x+(this._mapVisualWidthScaled>>1)-this._externalCenter.x,o=this._mapContainer.position.y-this._externalCenter.y,s=this._currentScale;this.setScale(i,e);var h=this._currentScale/s;this.centralizeToPoint(this._externalCenter.x+n*h,this._externalCenter.y+o*h,r(e)&&e||!r(e)&&this._config.instantCameraZoom)},i.prototype.zoomOut=function(t){this.zoomTo(this._currentZoom-this._config.zoomIncrement,t)},i.prototype.zoomIn=function(t){this.zoomTo(this._currentZoom+this._config.zoomIncrement,t)},i.prototype.getCurrentControllable=function(){return this._currentControllable},i.prototype.setCurrentControllable=function(t){this._currentControllable=t},i.prototype.addObjRefToLocation=function(t,e){var i,n;for(i=e.c;ie.r-t.rowSpan;n--)this.addObjRefToSingleLocation(t,{c:i,r:n})},i.prototype.addObjRefToSingleLocation=function(t,e){this._objArray[e.r][e.c]||(this._objArray[e.r][e.c]=[]),this._objArray[e.r][e.c].indexOf(t)<0&&this._objArray[e.r][e.c].push(t),t.isMovableTo||this._pathFinding.setDynamicCell(e.c,e.r,0)},i.prototype.removeObjRefFromLocation=function(t,e){var i,n;for(i=e.c;ie.r-t.rowSpan;n--)this.removeObjRefFromSingleLocation(t,{c:i,r:n})},i.prototype.removeObjRefFromSingleLocation=function(t,e){if(this._objArray[e.r][e.c]){var i=this._objArray[e.r][e.c].indexOf(t);if(i>-1&&this._objArray[e.r][e.c].splice(i,1),0===this._objArray[e.r][e.c].length)this._pathFinding.setDynamicCell(e.c,e.r,1),this._objArray[e.r][e.c]=null;else for(var n=this._objArray[e.r][e.c],o=n.length,r=0;r0&&this.changeObjAlphasInLocation(1,{c:e.c-1,r:e.r}),e.c>0&&e.r0&&this.changeObjAlphasInLocation(.7,{c:i.c-1,r:i.r}),i.c>0&&i.r=0;n--)if(e=this._objArray[i][n])for(o=0;oo&&(a=n===r?c.NW:nt.currentPathStep;(this.moveEngine.removeMovable(t),e?t.changeVisualToDirection(t.currentDirection,!1):this._config.checkPathOnEachTile?this.checkAndMoveObjectToLocation(t,t.currentPath[0].mapPos):(t.currentPath.splice(t.currentPath.length-1,1),this.moveObjThrough(t,t.currentPath)),this._currentControllable===t)&&this._tileArray[t.mapPos.r][t.mapPos.c].setHighlighted(!1,!this._config.tileHighlightAnimated);e&&this._config.objectReachedDestinationCallback&&this._config.objectReachedDestinationCallback(t)},i.prototype.checkForFollowCharacter=function(t){if(this._config.followCharacter&&this._currentControllable===t){this._currentFocusLocation={c:t.mapPos.c,r:t.mapPos.r};var e=this._externalCenter.x-t.position.x*this._currentScale,i=this._externalCenter.y-t.position.y*this._currentScale;this.moveEngine.addTween(this._mapContainer.position,.1,{x:e,y:i},0,"easeOut",!0)}},i.prototype.checkForTileChange=function(t){this._config.objectUpdateCallback&&this._config.objectUpdateCallback(t);for(var e={x:t.position.x,y:t.position.y-this.tileHalfHeight},i=this._tileArray[t.currentTargetTile.mapPos.r][t.currentTargetTile.mapPos.c],n=[],o=0;o1&&this._config.otherObjectsOnTheNextTileCallback&&this._config.otherObjectsOnTheNextTileCallback(t,r)}},i.prototype.getPath=function(t,e){if(this._pathFinding)return this._pathFinding.solve(t.c,t.r,e.c,e.r);throw new Error("Path finding hasn't been initialized yet!")},i.prototype.checkAndMoveObjectToTile=function(t,e,i){return void 0===i&&(i=null),!!e.isMovableTo&&this.checkAndMoveObjectToLocation(t,e.mapPos,i)},i.prototype.checkAndMoveObjectToLocation=function(t,e,i){void 0===i&&(i=null);var n=this.getPath(t.mapPos,e);return!!n&&(this.moveObjThrough(t,n,i),n.length>0)},i.prototype.moveCurrentControllableToLocation=function(t,e){if(void 0===e&&(e=null),!this._currentControllable)throw new Error("TRAVISO: _currentControllable is not defined!");return this.checkAndMoveObjectToLocation(this._currentControllable,t,e)},i.prototype.moveCurrentControllableToObj=function(t,e){if(void 0===e&&(e=null),!this._currentControllable)throw new Error("TRAVISO: _currentControllable is not defined!");if(t.currentInteractionOffset){var i={c:t.mapPos.c+t.currentInteractionOffset.c,r:t.mapPos.r+t.currentInteractionOffset.r};if(this.checkAndMoveObjectToLocation(this._currentControllable,i,e))return!0}for(var n,o,r,a,s=this._pathFinding.getAdjacentOpenCells(t.mapPos.c,t.mapPos.r,t.columnSpan,t.rowSpan),h=3e3,l=0;lthis._posFrame.x+this._posFrame.w||t.y>this._posFrame.y+this._posFrame.h)},i.prototype.onMouseDown=function(t){var e=t.data.global;!this._dragging&&this.isInteractionInMask(e)&&(this._dragging=!0,this._dragInitStartingX=this._dragPrevStartingX=e.x,this._dragInitStartingY=this._dragPrevStartingY=e.y)},i.prototype.onMouseMove=function(t){if(this._dragging&&this._config.mapDraggable){var e=t.data.global;this._mapContainer.position.x+=e.x-this._dragPrevStartingX,this._mapContainer.position.y+=e.y-this._dragPrevStartingY,this._dragPrevStartingX=e.x,this._dragPrevStartingY=e.y}},i.prototype.onMouseUp=function(t){if(this._dragging){this._dragging=!1;var e=t.data.global.x-this._dragInitStartingX,i=t.data.global.y-this._dragInitStartingY;Math.abs(e)<5&&Math.abs(i)<5&&this.checkForTileClick(t.data)}},i.prototype.repositionContent=function(t){void 0===t&&(t=null),f("EngineView repositionContent"),t=t||this._posFrame||{x:0,y:0,w:800,h:600},this.position.x=t.x,this.position.y=t.y,this._externalCenter={x:t.w>>1,y:t.h>>1},this.centralizeToCurrentFocusLocation(!0),this._bg&&(this._bg.clear(),this._bg.beginFill(this._config.backgroundColor,1),this._bg.drawRect(0,0,t.w,t.h),this._bg.endFill()),this._mapMask&&this._mapContainer&&(this._mapMask.clear(),this._mapMask.beginFill(0),this._mapMask.drawRect(0,0,t.w,t.h),this._mapMask.endFill(),this._mapContainer.mask=this._mapMask),this._posFrame=t},i.prototype.destroy=function(){var t,e,i,n;for(f("EngineView destroy"),this.disableInteraction(),this.moveEngine.destroy(),this.moveEngine=null,e=0;e=0;i--){if((t=this._tileArray[e][i])&&t.destroy(),this._tileArray[e][i]=null,t=this._objArray[e][i])for(n=0;n-1){var e=["\n %c %c %c Traviso.js - 0.1.5 %c %c http://www.travisojs.com/ %c \n\n","background: #18bc9c; padding:5px 0;","background: #18bc9c; padding:5px 0;","color: #18bc9c; background: #030307; padding:5px 0;","background: #18bc9c; padding:5px 0;","background: #5ad2ba; padding:5px 0;","background: #18bc9c; padding:5px 0;"];(t=self.console).log.apply(t,e)}else self.console&&self.console.log("Traviso.js 0.1.5 - http://www.travisojs.com/");A=!0}}(),f("Traviso initiated. (Version: 0.1.5)"))};return t.DIRECTIONS=c,t.EngineView=P,t.ObjectView=m,t.PF_ALGORITHMS=p,t.TileView=b,t.VERSION=x,t.dotProduct=function(t,e){return t.x*e.x+t.y*e.y},t.enableDisableLogging=d,t.existy=r,t.getDist=l,t.getEngineInstance=function(t,e){return void 0===e&&(e=null),k(e),new P(t)},t.getUnit=s,t.isInPolygon=h,t.mathMap=a,t.skipHello=function(){A=!0},t.trace=f,Object.defineProperty(t,"__esModule",{value:!0}),t}({},PIXI); //# sourceMappingURL=traviso.min.js.map