jocly
Version:
Board games 3D/2D UI and AI web library
1 lines • 1.97 kB
JavaScript
;function _typeof(e){"@babel/helpers - typeof";return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ReceiveMessage(e){function t(t){t=t||{},window.parent.postMessage({joclyEmbeddedGameId:matchId,replyId:e.data.replyId,message:t},"*")}function a(e){console.warn("Embed error:",e),"object"==_typeof(e)&&(e={message:e.message,fileName:e.fileName,lineNumber:e.lineNumber,stack:e.stack}),t({type:"error",error:e})}if((e.origin||e.originalEvent.origin)==new URL(window.location).origin){var o=e.data.message;switch(o.type){case"init":matchId=o.id;var n=document.getElementById("area");Jocly.createMatch(o.gameName).then(function(e){function i(){e.game.AttachElement(n).then(function(){e.area=n;var a=o.options&&o.options.viewOptions;if(a){var i={mSkin:"skin",mNotation:"notation",mSounds:"sounds",mShowMoves:"showMoves",mAutoComplete:"autoComplete",mAnaglyph:"anaglyph"};for(var r in i)void 0!==a[i[r]]&&(e.game[r]=a[i[r]]);e.game.mViewOptions.switchable&&(e.game.mViewAs=a.viewAs)}e.game.GameInitView(),e.game.DisplayBoard(),t()}).catch(a)}gMatch=e,e.game.Load({playedMoves:o.playedMoves}),"complete"===document.readyState||"loaded"===document.readyState||"interactive"===document.readyState?i():window.addEventListener("DOMContentLoaded",function(){i()})}).catch(a);break;case"method":try{gMatch[o.methodName].apply(gMatch,o.args).then(function(){t({args:Array.from(arguments)})},a)}catch(e){a(e)}break;case"destroy":var i=gMatch.game.mPlayedMoves;gMatch.destroy().then(function(){t({playedMoves:i})})}}}function Resize(){var e=gMatch&&gMatch.game;e&&(e.mGeometry={width:window.innerWidth,height:window.innerHeight},e.GameDestroyView(),e.GameInitView(),e.DisplayBoard())}var matchId,gMatch;window.addEventListener("message",ReceiveMessage,!1),window.addEventListener("resize",Resize,!1);