view.player.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of runner Show documentation
Show all versions of runner Show documentation
Runner / Testbed to locally run Games created using the CodinGame engine toolkit.
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["cg-player"]=e():t["cg-player"]=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=n(r(2)),a=n(r(4)),i=n(r(8));var u=function(t){var e,r,n,u,c,s,f,l,p,h=t.viewer,d=t.viewerUrl,y=t.customDemo,g=null,v=null,m=[],w=new Promise(function(t){e=t}),x=new Promise(function(t){r=t}),b={},E=function(t){return b[t]||[]},L=!1,O={ready:function(){L||(L=!0,C({type:"libraries",libraries:t.libraries}),C({type:"baseUrl",baseUrl:window.location.origin}),C({type:"loggedUserId",loggedUserId:l}),W(),(h||d)&&C({type:"viewer",viewer:h,viewerUrl:d,customDemo:y}),e())},resize:function(t){g.parentElement.style.paddingTop=t.iframeHeight,R("resize",t)},progress:function(t){m.forEach(function(e){return e(t.frame,t.progress,t.playing,t.isSubFrame,t.isTurnBasedGame,t.atEnd)}),n=t.atEnd,u=t.playing},viewerOptions:function(t){var e,r;c=t.playerColors,s=t.canSwapPlayers,f=t.gameName,e=A(),C({type:"gameParams",gameParams:(r=z())[e]||(r[e]={})})},parsedGameInfo:function(t){R("parsedGameInfo",t)},play:function(t){u=!0,R("play",t.data)},pause:function(t){u=!1,R("pause",t.data)},gameParams:function(e){!function(e){var r=z();r[A()]=e;try{window.localStorage.setItem(t.localStorageKey,JSON.stringify(r))}catch(t){log.error("Error while saving player settings to localStorage.")}}(e.gameParams)},analyticsOpenReplay:function(t){R("analyticsOpenReplay",t)},error:function(t){R("error",t.error)}};return{createIframe:function(e){return(g=document.createElement("iframe")).src=t.src,g.setAttribute("allowfullscreen",""),g.sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox",g.style.position="absolute",g.style.left=0,g.style.top=0,g.style.width="100%",g.style.height="100%",g.style.border=0,g.style.display="block",e.style.position="relative",e.innerHTML="",e.appendChild(g),window.addEventListener("message",M),C({type:"ready"}),g},setViewer:function(t){return P.apply(this,arguments)},setLoggedUserId:function(t){l=t},setCurrentLanguage:function(t){p=t,W()},sendFrames:function(t,e){return S.apply(this,arguments)},setOptions:function(t){return _.apply(this,arguments)},setFrame:j,first:function(){return I.apply(this,arguments)},play:U,pause:F,setSpeed:function(t){return T.apply(this,arguments)},on:function(t,e){b[t]=[].concat((0,a.default)(E(t)),[e])},off:function(t,e){b[t]=E(t).filter(function(t){return t!==e})},waitReady:D,destroy:function(){window.removeEventListener("message",M)},subscribe:function(t){m=[].concat((0,a.default)(m),[t])},unsubscribe:function(t){m=m.filter(function(e){return e!==t})},clear:function(){m=[]},getFrameCount:function(){return v?v.frames.length:0},isPlaying:function(){return u},isAtEnd:function(){return n},canSwapPlayers:function(){return s},getPlayerColors:function(){return c},isGameLoaded:function(){return null!=v}};function P(){return(P=(0,i.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return h=e,t.next=3,D();case 3:C({type:"viewer",viewer:h});case 4:case"end":return t.stop()}},t)}))).apply(this,arguments)}function S(){return(S=(0,i.default)(o.default.mark(function t(e,n){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return x=new Promise(function(t){r=t}),v=e,t.next=4,D();case 4:if(C({type:"frames",gameInfo:null}),!e.agents){t.next=10;break}return t.next=8,Promise.all(e.agents.map(function(t){return H(t)}));case 8:t.next=12;break;case 10:return t.next=12,H(e);case 12:C({type:"frames",gameInfo:e,isUserGame:n}),r(),u?U():F();case 15:case"end":return t.stop()}},t)}))).apply(this,arguments)}function _(){return(_=(0,i.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,D();case 2:C({type:"options",options:e});case 3:case"end":return t.stop()}},t)}))).apply(this,arguments)}function j(t,e){return k.apply(this,arguments)}function k(){return(k=(0,i.default)(o.default.mark(function t(e,r){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,x;case 2:C({type:"frame",frame:e,progress:r});case 3:case"end":return t.stop()}},t)}))).apply(this,arguments)}function I(){return(I=(0,i.default)(o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,j(0);case 2:case"end":return t.stop()}},t)}))).apply(this,arguments)}function U(){return G.apply(this,arguments)}function G(){return(G=(0,i.default)(o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return u=!0,t.next=3,x;case 3:C({type:"play"});case 4:case"end":return t.stop()}},t)}))).apply(this,arguments)}function F(){return N.apply(this,arguments)}function N(){return(N=(0,i.default)(o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return u=!1,t.next=3,x;case 3:C({type:"pause"});case 4:case"end":return t.stop()}},t)}))).apply(this,arguments)}function T(){return(T=(0,i.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,D();case 2:C({type:"speed",speed:e});case 3:case"end":return t.stop()}},t)}))).apply(this,arguments)}function A(){return(f||(h||d).split("").reduce(function(t,e){return(t=(t<<5)-t+e.charCodeAt(0))&t},0).toString()).toLowerCase().replace(/ /g,"")}function C(t){null!=g&&null!=g.contentWindow&&g.contentWindow.postMessage(t,"*")}function M(t){t.source===g.contentWindow&&null!=O[t.data.type]&&O[t.data.type](t.data)}function R(t,e){E(t).forEach(function(t){return t(e)})}function D(){return K.apply(this,arguments)}function K(){return(K=(0,i.default)(o.default.mark(function t(){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",w);case 1:case"end":return t.stop()}},t)}))).apply(this,arguments)}function W(){C({type:"language",lang:p})}function z(){var e={};try{var r=window.localStorage.getItem(t.localStorageKey);null==r?window.localStorage.setItem(t.localStorageKey,"{}"):e=JSON.parse(r)}catch(t){log.error("Error while accessing player settings from localStorage.")}return e}function H(t){return J.apply(this,arguments)}function J(){return(J=(0,i.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null==e.avatarUrl){t.next=11;break}return t.prev=1,t.next=4,Y(e.avatarUrl);case 4:e.avatarUrl=t.sent,t.next=11;break;case 7:t.prev=7,t.t0=t.catch(1),console.error("Failed to load avatar!",e.avatarUrl),e.avatarUrl=null;case 11:case"end":return t.stop()}},t,null,[[1,7]])}))).apply(this,arguments)}function Y(t){return new Promise(function(e,r){var n=new window.Image;n.crossOrigin="anonymous",n.onload=function(){var t=document.createElement("canvas"),r=t.getContext("2d");t.width=n.width,t.height=n.height,r.drawImage(n,0,0,n.width,n.height),e(t.toDataURL())},n.onerror=function(){r(new Error)},n.src=t})}};e.default=u},function(t,e){t.exports=function(t){return t&&t.__esModule?t:{default:t}}},function(t,e,r){t.exports=r(3)},function(t,e,r){var n=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r,n){var o=e&&e.prototype instanceof y?e:y,a=Object.create(o.prototype),i=new _(n||[]);return a._invoke=function(t,e,r){var n=f;return function(o,a){if(n===p)throw new Error("Generator is already running");if(n===h){if("throw"===o)throw a;return k()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=O(i,r);if(u){if(u===d)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var c=s(t,e,r);if("normal"===c.type){if(n=r.done?h:l,c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=h,r.method="throw",r.arg=c.arg)}}}(t,r,i),a}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f="suspendedStart",l="suspendedYield",p="executing",h="completed",d={};function y(){}function g(){}function v(){}var m={};m[a]=function(){return this};var w=Object.getPrototypeOf,x=w&&w(w(j([])));x&&x!==r&&n.call(x,a)&&(m=x);var b=v.prototype=y.prototype=Object.create(m);function E(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function L(t){var e;this._invoke=function(r,o){function a(){return new Promise(function(e,a){!function e(r,o,a,i){var u=s(t[r],t,o);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"==typeof f&&n.call(f,"__await")?Promise.resolve(f.__await).then(function(t){e("next",t,a,i)},function(t){e("throw",t,a,i)}):Promise.resolve(f).then(function(t){c.value=t,a(c)},function(t){return e("throw",t,a,i)})}i(u.arg)}(r,o,e,a)})}return e=e?e.then(a,a):a()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=s(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,d;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function j(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o=0;--a){var i=this.tryEntries[a],u=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(c&&s){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:j(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=n}catch(t){Function("r","regeneratorRuntime = r")(n)}},function(t,e,r){var n=r(5),o=r(6),a=r(7);t.exports=function(t){return n(t)||o(t)||a()}},function(t,e){t.exports=function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e
© 2015 - 2025 Weber Informatics LLC | Privacy Policy