UNPKG

roguelike-pumpkin-patch

Version:
1 lines 16.3 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.RPP=e():t.RPP=e()}(self,(function(){return(()=>{"use strict";var t={865:(t,e,i)=>{i.r(e),i.d(e,{Display:()=>s,EventManager:()=>a,FOV:()=>u,PathFinder:()=>c,Random:()=>l});var n=function(){return(n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},o="pumpkin-tile";const r=function(){function t(t,e,i){this.element=document.createElement("div"),this.element.classList.add(o);var n=t.content,r=void 0===n?"":n,s=t.color,a=void 0===s?"":s,l=t.background,h=void 0===l?"":l,c=t.className,u=void 0===c?"":c,p=t.classList,f=void 0===p?[]:p;!function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(i[n[o]]=t[n[o]])}}(t,["content","color","background","className","classList"]),this.content=r,this.color=a,this.background=h,f.length>0?this.classList=f:this.className=u,this.tileWidth=(null==i?void 0:i.tileWidth)?i.tileWidth:16,this.tileHeight=(null==i?void 0:i.tileHeight)?i.tileHeight:this.tileWidth,this.position=e}return Object.defineProperty(t.prototype,"content",{get:function(){return this._content},set:function(t){if(this.confirmContentElement(),this._content!==t){if("string"==typeof t)this.contentElement.innerHTML=t;else{for(;this.contentElement.lastElementChild;)this.contentElement.removeChild(this.contentElement.lastElementChild);this.contentElement.appendChild(t)}this._content=t}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"background",{get:function(){return this._background},set:function(t){t!==this._background&&(this._background=t,this.element.style.backgroundColor=t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){return this._color},set:function(t){t!==this._color&&(this._color=t,this.element.style.color=t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this._position},set:function(t){this._position=n({},t),this.element.style.left=t.x*this.tileWidth+"px",this.element.style.top=t.y*this.tileHeight+"px"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"tileWidth",{get:function(){return this._tileWidth},set:function(t){this._tileWidth=t,this.element.style.width=t+"px"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"tileHeight",{get:function(){return this._tileHeight},set:function(t){this._tileHeight=t,this.element.style.height=t+"px"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"className",{get:function(){return this.classList.join(" ")},set:function(t){this.classList=t?t.split(" "):[]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"classList",{get:function(){return function(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),o=0;for(e=0;e<i;e++)for(var r=arguments[e],s=0,a=r.length;s<a;s++,o++)n[o]=r[s];return n}([o],this._classList)},set:function(t){var e=this;this._classList||(this._classList=[]),t.length===this._classList.length&&t.every((function(t,i){return t===e._classList[i]}))||(this._classList=t,this.element.className=this.classList.join(" "))},enumerable:!1,configurable:!0}),t.prototype.setOptions=function(t){var e=t.content,i=void 0===e?"":e,n=t.background,o=void 0===n?"":n,r=t.color,s=void 0===r?"":r,a=t.className,l=void 0===a?"":a,h=t.classList;this.content=i,this.background=o,this.color=s,h?this.classList=h:this.className=l},t.prototype.updateOptions=function(t){var e=t.content,i=t.background,n=t.color,o=t.className,r=t.classList;void 0!==e&&(this.content=e),void 0!==i&&(this.background=i),void 0!==n&&(this.color=n),r&&r.length>0?this.classList=r:void 0!==o&&(this.className=o)},t.prototype.confirmContentElement=function(){this.contentElement||(this.contentElement=document.createElement("div"),this.element.appendChild(this.contentElement))},t}();const s=function(){function t(t){var e=t.target,i=t.width,n=void 0===i?1:i,o=t.height,r=void 0===o?1:o,s=t.tileWidth,a=t.tileHeight;!function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(i[n[o]]=t[n[o]])}}(t,["target","width","height","tileWidth","tileHeight"]),this.target=e,this.target.className?this.target.classList.add("pumpkin-container"):this.target.className="pumpkin-container",this.element=document.createElement("div"),this.element.className="pumpkin-display",this.element.setAttribute("aria-hidden","true"),this.dimensions={width:n,height:r},this.tileSize={tileWidth:s||16,tileHeight:a||s||16},this.applyDefaultStyles(),this.target.appendChild(this.element)}return Object.defineProperty(t.prototype,"tileSize",{get:function(){return this._tileSize},set:function(t){var e;this._tileSize=t,this.element.style.fontSize=t.tileHeight+"px",null===(e=this.tiles)||void 0===e||e.forEach((function(e){e.tileWidth=t.tileWidth,e.tileHeight=t.tileHeight,e.position=e.position})),this.resetSize()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dimensions",{get:function(){return{width:this._width,height:this._height}},set:function(t){t.width!==this._width&&t.height!==this._height&&(this._width=t.width,this._height=t.height,this.allocateDisplay(),this.resetSize(),this.moveToCenter())},enumerable:!1,configurable:!0}),t.prototype.resetSize=function(){this._width&&this._height&&this.tileSize&&(this.element.style.width=this._width*this.tileSize.tileWidth+"px",this.element.style.height=this._height*this.tileSize.tileHeight+"px")},t.prototype.centerDisplay=function(t,e){this.centerPosition=void 0===t||void 0===e?void 0:{x:t,y:e},this.moveToCenter()},t.prototype.moveToCenter=function(){if(this.centerPosition){var t=(this.centerPosition.x+.5)/this.dimensions.width,e=(this.centerPosition.y+.5)/this.dimensions.height;this.element.style.transform="translate("+100*-t+"%,"+100*-e+"%)"}else this.element.style.transform=""},t.prototype.allocateDisplay=function(){var t=this;this.tiles&&this.tiles.forEach((function(e){t.element.removeChild(e.element)})),this.tiles=[];for(var e=0;e<this._height;e++)for(var i=0;i<this._width;i++){var n=new r({content:""},{x:i,y:e},this.tileSize);this.tiles.push(n),this.element.appendChild(n.element)}},t.prototype.getTile=function(t,e){if(t>=0&&t<this._width&&e>=0&&e<this._height){var i=t+e*this._width;return this.tiles[i]}},t.prototype.formatTileOptions=function(t){return"string"==typeof t||t instanceof HTMLElement?{content:t}:t},t.prototype.setTile=function(t,e,i){var n=this.getTile(t,e);n&&n.setOptions(this.formatTileOptions(i))},t.prototype.updateTile=function(t,e,i){var n=this.getTile(t,e);n&&n.updateOptions(this.formatTileOptions(i))},t.prototype.calculateDimensions=function(t){void 0===t&&(t=this.target.getBoundingClientRect());var e=Math.abs(t.right-t.left),i=Math.abs(t.bottom-t.top);return{width:Math.floor(e/this.tileSize.tileWidth),height:Math.floor(i/this.tileSize.tileHeight)}},t.prototype.calculateTileSize=function(t){void 0===t&&(t=this.target.getBoundingClientRect());var e=Math.abs(t.right-t.left),i=Math.abs(t.bottom-t.top),n={tileWidth:e/this.dimensions.width,tileHeight:i/this.dimensions.height},o=Math.min(n.tileWidth,n.tileHeight);return{tileWidth:o,tileHeight:o}},t.prototype.applyDefaultStyles=function(){var t="pumpkin-default-styles";if(!document.getElementById(t)){var e=document.createElement("style");e.id=t,e.type="text/css",e.appendChild(document.createTextNode("\n.pumpkin-container {\n position: relative;\n overflow: hidden;\n background-color: #000000;\n color: #ffffff;\n}\n\n.pumpkin-display {\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n}\n\n.pumpkin-tile {\n position: absolute;\n}\n\n.pumpkin-tile > * {\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n z-index: 10;\n}\n"));var i=document.head,n=document.querySelector("style, link");i.insertBefore(e,n)}},t}();const a=function(){function t(t){t||(t={});var e=t.type,i=void 0===e?"simple":e;this.type=i,this.queue=[],this.time=0}return t.prototype.add=function(t){var e={};if(t instanceof Function?e.callback=t:"act"in t?e.actor=t:Object.assign(e,t),void 0===e.repeats&&e.actor&&(e.repeats=!0),"complex"===this.type){e.delay||(e.delay=1);var i=e.delay+this.time;if(0===this.queue.length||this.queue[this.queue.length-1].time<=i)this.queue.push({event:e,time:i});else for(var n=0;n<this.queue.length;n++)if(i<this.queue[n].time){this.queue.splice(n,0,{event:e,time:i});break}}else this.queue.push({event:e,time:0})},t.prototype.advance=function(){return t=this,e=void 0,n=function(){var t;return function(t,e){var i,n,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(o=2&r[0]?n.return:r[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,r[1])).done)return o;switch(n=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],n=0}finally{i=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}(this,(function(e){switch(e.label){case 0:if(0===this.queue.length)throw new Error("Event queue is empty.");return t=this.queue.shift(),this.time=t.time,"number"==typeof t.event.repeats&&t.event.repeats--,t.event.repeats&&this.add(t.event),t.event.callback?[4,t.event.callback()]:[3,2];case 1:e.sent(),e.label=2;case 2:return t.event.actor?[4,t.event.actor.act()]:[3,4];case 3:e.sent(),e.label=4;case 4:return[2]}}))},new((i=void 0)||(i=Promise))((function(o,r){function s(t){try{l(n.next(t))}catch(t){r(t)}}function a(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}l((n=n.apply(t,e||[])).next())}));var t,e,i,n},t.prototype.remove=function(t){var e=this,i=[];this.queue.forEach((function(e,n){e.event.actor===t&&i.push(n)})),i.reverse(),i.forEach((function(t){e.queue.splice(t,1)}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),t}(),l=function(){function t(t,e){t||(t=Date.now()),this.seed=Math.floor(t),this.weyl=0,this.x=0,this.base=e||1e5;for(var i=0;i<10;i++)this.getRandom()}return t.prototype.getRandom=function(){return this.x*=this.x,this.x+=this.weyl+=this.seed,this.x=(this.x>>>32|this.x<<32)>>>0,this.x%this.base/this.base},t.prototype.getNumber=function(t,e,i){return void 0===i&&Number.isInteger(t)&&Number.isInteger(e)&&(i=!0),i?Math.floor(this.getRandom()*(e+1-t))+Math.ceil(t):this.getRandom()*(e-t)+t},t.prototype.getRandomElement=function(t){return t[this.getNumber(0,t.length-1,!0)]},t.prototype.getWeightedElement=function(t){var e=0,i=!0;t.forEach((function(t){e+=t.weight,i=i&&Number.isInteger(t.weight)}));for(var n=this.getNumber(i?1:0,e,i),o=0;o<t.length;o++)if((n-=t[o].weight)<=0)return t[o].option;throw new Error("No match found.")},t}();var h=function(){for(var t=0,e=0,i=arguments.length;e<i;e++)t+=arguments[e].length;var n=Array(t),o=0;for(e=0;e<i;e++)for(var r=arguments[e],s=0,a=r.length;s<a;s++,o++)n[o]=r[s];return n};const c=function(){function t(t){var e=t.canPass,i=t.metric,n=t.maxIterations,o=t.weight;!function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(i[n[o]]=t[n[o]])}}(t,["canPass","metric","maxIterations","weight"]),this.canPass=e,i||(i=function(t,e){return Math.abs(e[1]-t[1])+Math.abs(e[0]-t[0])}),o||(o=function(t){return 1}),this.maxIterations=n,this.metric=i,this.weight=o}return t.prototype.findPath=function(t,e,i){var n=this;void 0===i&&(i=!1);for(var o=[],r=this.maxIterations?this.maxIterations:40*this.metric(t,e),s=0,a=[{position:h(t),steps:0,distanceFromGoal:this.metric(t,e),previousLocation:null}],l=[],c=[0,1,1.2];s<r&&!this.contains(a,e);)s++,a.forEach((function(t){for(var o=-1;o<2;o++)for(var r=-1;r<2;r++)if(!i||0===o||0===r){var s=[t.position[0]+o,t.position[1]+r],h=c[Math.abs(o)+Math.abs(r)]*n.weight(s);if(n.canPass(s)){var u=n.getLocation(a,s),p=n.getLocation(l,s);u||p?(u&&u.steps>t.steps+h&&(u.steps=t.steps+h,u.previousLocation=t),p&&p.steps>t.steps+h&&(p.steps=t.steps+h,p.previousLocation=t)):l.push({position:s,steps:t.steps+h,distanceFromGoal:n.metric(s,e),previousLocation:t})}}})),l.sort((function(t,e){return e.steps+e.distanceFromGoal-(t.steps+t.distanceFromGoal)})),a.push(l.pop());var u=this.getLocation(a,e);if(this.contains(a,e))for(s=0;(u.position[0]!==t[0]||u.position[1]!==t[1])&&s<r;)s++,o.push(u.position),u=u.previousLocation;return o.reverse()},t.prototype.isEqual=function(t,e){return t.position[0]===e.position[0]&&t.position[1]===e.position[1]},t.prototype.contains=function(t,e){var i=this;return Array.isArray(e)?t.some((function(t){return t.position[0]===e[0]&&t.position[1]===e[1]})):t.some((function(t){return i.isEqual(t,e)}))},t.prototype.getLocation=function(t,e){for(var i=0,n=t;i<n.length;i++){var o=n[i];if(o.position[0]===e[0]&&o.position[1]===e[1])return o}},t}(),u=function(){function t(t,e){this.canSee=t,this.range=e||8}return t.prototype.look=function(t,e){var i=e||this.range;this.canSee(t);for(var n=[],o=[],r=0,s=0,a=1;a<=i;a++){for(var l=0;l<4;l++)for(var h=-a;h<=a;h++){0===l?(r=h,s=a):1===l?(s=h,r=a):2===l?(r=h,s=-a):(s=h,r=-a);var c=[t[0]+r,t[1]+s];if(!(this.distance(t,c)>i)){var u=this.angleTo(t,c),p=this.angularSize(t,c)/2,f=!1;this.isInShadows(u,n)&&this.isInShadows(u+p,n)&&this.isInShadows(u-p,n)&&(f=!0),!f&&this.canSee(c)||o.push({startAngle:u-p,endAngle:u+p})}}for(;o.length>0;)this.combineShadow(n,o.pop());if(1===n.length&&n[0].endAngle-n[0].startAngle>=360)return}},t.prototype.angleTo=function(t,e){var i=e[1]-t[1],n=e[0]-t[0],o=180*Math.atan2(i,n)/Math.PI;return o>=0?o:o+360},t.prototype.angularSize=function(t,e){var i=this.distance(t,e);return 360*Math.atan(1/(2*i))/Math.PI},t.prototype.distance=function(t,e){return Math.sqrt(Math.pow(e[1]-t[1],2)+Math.pow(e[0]-t[0],2))},t.prototype.isInShadows=function(t,e){for(var i=t-360,n=0,o=e;n<o.length;n++){var r=o[n];if(t<=r.endAngle&&t>=r.startAngle||i<=r.endAngle&&i>=r.startAngle)return!0}return!1},t.prototype.combineShadow=function(t,e){for(var i=[],n=0;n<t.length;n++){var o=t[n];e.startAngle<o.endAngle&&e.endAngle>o.startAngle&&(e.startAngle=Math.min(o.startAngle,e.startAngle),e.endAngle=Math.max(o.endAngle,e.endAngle),i.push(n))}if(i.length>0){var r=t[i.shift()];for(r.startAngle=e.startAngle,r.endAngle=e.endAngle,n=i.length-1;n>=0;n--)t.splice(i[n],1)}else t.push(e)},t}()}},e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}return i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(865)})()}));