-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__game-scripts.js
More file actions
1 lines (1 loc) · 31.6 KB
/
Copy path__game-scripts.js
File metadata and controls
1 lines (1 loc) · 31.6 KB
1
pc.extend(pc,function(){var TweenManager=function(t){this._app=t,this._tweens=[],this._add=[]};TweenManager.prototype={add:function(t){return this._add.push(t),t},update:function(t){for(var i=0,e=this._tweens.length;i<e;)this._tweens[i].update(t)?i++:(this._tweens.splice(i,1),e--);if(this._add.length){for(let t=0;t<this._add.length;t++)this._tweens.indexOf(this._add[t])>-1||this._tweens.push(this._add[t]);this._add.length=0}}};var Tween=function(t,i,e){pc.events.attach(this),this.manager=i,e&&(this.entity=null),this.time=0,this.complete=!1,this.playing=!1,this.stopped=!0,this.pending=!1,this.target=t,this.duration=0,this._currentDelay=0,this.timeScale=1,this._reverse=!1,this._delay=0,this._yoyo=!1,this._count=0,this._numRepeats=0,this._repeatDelay=0,this._from=!1,this._slerp=!1,this._fromQuat=new pc.Quat,this._toQuat=new pc.Quat,this._quat=new pc.Quat,this.easing=pc.Linear,this._sv={},this._ev={}},_parseProperties=function(t){var i;return t instanceof pc.Vec2?i={x:t.x,y:t.y}:t instanceof pc.Vec3?i={x:t.x,y:t.y,z:t.z}:t instanceof pc.Vec4||t instanceof pc.Quat?i={x:t.x,y:t.y,z:t.z,w:t.w}:t instanceof pc.Color?(i={r:t.r,g:t.g,b:t.b},void 0!==t.a&&(i.a=t.a)):i=t,i};Tween.prototype={to:function(t,i,e,s,n,r){return this._properties=_parseProperties(t),this.duration=i,e&&(this.easing=e),s&&this.delay(s),n&&this.repeat(n),r&&this.yoyo(r),this},from:function(t,i,e,s,n,r){return this._properties=_parseProperties(t),this.duration=i,e&&(this.easing=e),s&&this.delay(s),n&&this.repeat(n),r&&this.yoyo(r),this._from=!0,this},rotate:function(t,i,e,s,n,r){return this._properties=_parseProperties(t),this.duration=i,e&&(this.easing=e),s&&this.delay(s),n&&this.repeat(n),r&&this.yoyo(r),this._slerp=!0,this},start:function(){var t,i,e,s;if(this.playing=!0,this.complete=!1,this.stopped=!1,this._count=0,this.pending=this._delay>0,this._reverse&&!this.pending?this.time=this.duration:this.time=0,this._from){for(t in this._properties)this._properties.hasOwnProperty(t)&&(this._sv[t]=this._properties[t],this._ev[t]=this.target[t]);this._slerp&&(this._toQuat.setFromEulerAngles(this.target.x,this.target.y,this.target.z),i=void 0!==this._properties.x?this._properties.x:this.target.x,e=void 0!==this._properties.y?this._properties.y:this.target.y,s=void 0!==this._properties.z?this._properties.z:this.target.z,this._fromQuat.setFromEulerAngles(i,e,s))}else{for(t in this._properties)this._properties.hasOwnProperty(t)&&(this._sv[t]=this.target[t],this._ev[t]=this._properties[t]);this._slerp&&(i=void 0!==this._properties.x?this._properties.x:this.target.x,e=void 0!==this._properties.y?this._properties.y:this.target.y,s=void 0!==this._properties.z?this._properties.z:this.target.z,void 0!==this._properties.w?(this._fromQuat.copy(this.target),this._toQuat.set(i,e,s,this._properties.w)):(this._fromQuat.setFromEulerAngles(this.target.x,this.target.y,this.target.z),this._toQuat.setFromEulerAngles(i,e,s)))}return this._currentDelay=this._delay,this.manager.add(this),this},pause:function(){this.playing=!1},resume:function(){this.playing=!0},stop:function(){this.playing=!1,this.stopped=!0},delay:function(t){return this._delay=t,this.pending=!0,this},repeat:function(t,i){return this._count=0,this._numRepeats=t,this._repeatDelay=i||0,this},loop:function(t){return t?(this._count=0,this._numRepeats=1/0):this._numRepeats=0,this},yoyo:function(t){return this._yoyo=t,this},reverse:function(){return this._reverse=!this._reverse,this},chain:function(){for(var t=arguments.length;t--;)t>0?arguments[t-1]._chained=arguments[t]:this._chained=arguments[t];return this},update:function(t){if(this.stopped)return!1;if(!this.playing)return!0;if(!this._reverse||this.pending?this.time+=t*this.timeScale:this.time-=t*this.timeScale,this.pending){if(!(this.time>this._currentDelay))return!0;this._reverse?this.time=this.duration-(this.time-this._currentDelay):this.time-=this._currentDelay,this.pending=!1}var i=0;(!this._reverse&&this.time>this.duration||this._reverse&&this.time<0)&&(this._count++,this.complete=!0,this.playing=!1,this._reverse?(i=this.duration-this.time,this.time=0):(i=this.time-this.duration,this.time=this.duration));var e,s,n=0===this.duration?1:this.time/this.duration,r=this.easing(n);for(var h in this._properties)this._properties.hasOwnProperty(h)&&(e=this._sv[h],s=this._ev[h],this.target[h]=e+(s-e)*r);if(this._slerp&&this._quat.slerp(this._fromQuat,this._toQuat,r),this.entity&&(this.entity._dirtifyLocal(),this.element&&this.entity.element&&(this.entity.element[this.element]=this.target),this._slerp&&this.entity.setLocalRotation(this._quat)),this.fire("update",t),this.complete){var a=this._repeat(i);return a?this.fire("loop"):(this.fire("complete",i),this.entity&&this.entity.off("destroy",this.stop,this),this._chained&&this._chained.start()),a}return!0},_repeat:function(t){if(this._count<this._numRepeats){if(this._reverse?this.time=this.duration-t:this.time=t,this.complete=!1,this.playing=!0,this._currentDelay=this._repeatDelay,this.pending=!0,this._yoyo){for(var i in this._properties){var e=this._sv[i];this._sv[i]=this._ev[i],this._ev[i]=e}this._slerp&&(this._quat.copy(this._fromQuat),this._fromQuat.copy(this._toQuat),this._toQuat.copy(this._quat))}return!0}return!1}};var BounceOut=function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},BounceIn=function(t){return 1-BounceOut(1-t)};return{TweenManager:TweenManager,Tween:Tween,Linear:function(t){return t},QuadraticIn:function(t){return t*t},QuadraticOut:function(t){return t*(2-t)},QuadraticInOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)},CubicIn:function(t){return t*t*t},CubicOut:function(t){return--t*t*t+1},CubicInOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)},QuarticIn:function(t){return t*t*t*t},QuarticOut:function(t){return 1- --t*t*t*t},QuarticInOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)},QuinticIn:function(t){return t*t*t*t*t},QuinticOut:function(t){return--t*t*t*t*t+1},QuinticInOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)},SineIn:function(t){return 0===t?0:1===t?1:1-Math.cos(t*Math.PI/2)},SineOut:function(t){return 0===t?0:1===t?1:Math.sin(t*Math.PI/2)},SineInOut:function(t){return 0===t?0:1===t?1:.5*(1-Math.cos(Math.PI*t))},ExponentialIn:function(t){return 0===t?0:Math.pow(1024,t-1)},ExponentialOut:function(t){return 1===t?1:1-Math.pow(2,-10*t)},ExponentialInOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))},CircularIn:function(t){return 1-Math.sqrt(1-t*t)},CircularOut:function(t){return Math.sqrt(1- --t*t)},CircularInOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},BackIn:function(t){var i=1.70158;return t*t*((i+1)*t-i)},BackOut:function(t){var i=1.70158;return--t*t*((i+1)*t+i)+1},BackInOut:function(t){var i=2.5949095;return(t*=2)<1?t*t*((i+1)*t-i)*.5:.5*((t-=2)*t*((i+1)*t+i)+2)},BounceIn:BounceIn,BounceOut:BounceOut,BounceInOut:function(t){return t<.5?.5*BounceIn(2*t):.5*BounceOut(2*t-1)+.5},ElasticIn:function(t){var i,e=.1;return 0===t?0:1===t?1:(!e||e<1?(e=1,i=.1):i=.4*Math.asin(1/e)/(2*Math.PI),-e*Math.pow(2,10*(t-=1))*Math.sin((t-i)*(2*Math.PI)/.4))},ElasticOut:function(t){var i,e=.1;return 0===t?0:1===t?1:(!e||e<1?(e=1,i=.1):i=.4*Math.asin(1/e)/(2*Math.PI),e*Math.pow(2,-10*t)*Math.sin((t-i)*(2*Math.PI)/.4)+1)},ElasticInOut:function(t){var i,e=.1,s=.4;return 0===t?0:1===t?1:(!e||e<1?(e=1,i=.1):i=s*Math.asin(1/e)/(2*Math.PI),(t*=2)<1?e*Math.pow(2,10*(t-=1))*Math.sin((t-i)*(2*Math.PI)/s)*-.5:e*Math.pow(2,-10*(t-=1))*Math.sin((t-i)*(2*Math.PI)/s)*.5+1)}}}()),function(){pc.AppBase.prototype.addTweenManager=function(){this._tweenManager=new pc.TweenManager(this),this.on("update",(function(t){this._tweenManager.update(t)}))},pc.AppBase.prototype.tween=function(t){return new pc.Tween(t,this._tweenManager)},pc.Entity.prototype.tween=function(t,i){var e=this._app.tween(t);return e.entity=this,this.once("destroy",e.stop,e),i&&i.element&&(e.element=i.element),e},pc.Entity.prototype.localMoveTo=function(t,i,e=pc.QuadraticOut){return this.tween(this.getLocalPosition()).to(t,i,e).start()},pc.Entity.prototype.localMoveBy=function(t,i,e=pc.SineOut){return this.tween(this.getLocalPosition()).by(t,i,e).start()},pc.Entity.prototype.moveTo=function(t,i){return this.tween(this.getPosition()).to(t,i,pc.SineOut).start()},pc.Entity.prototype.moveBy=function(t,i){return this.tween(this.getPosition()).by(t,i,pc.SineOut).start()},pc.Entity.prototype.rotateTo=function(t,i,e=pc.CircularOut){return this.tween(this.getLocalEulerAngles()).rotate(t,i,e).start()},pc.Entity.prototype.setOpacity=function(t){this.element&&(this.element.material,this.element.opacity=t)},pc.Entity.prototype.setOpacityCascade=function(t){this.setOpacity(t);for(let i=0;i<this.children.length;i++)this.children[i].setOpacityCascade&&this.children[i].setOpacityCascade(t)},pc.Entity.prototype.opacityToCascade=function(t,i,e){let s={v:t};return this.setOpacityCascade(t),this.tween(s).to({v:i},e,pc.SineOut).on("update",(()=>{this.setOpacityCascade(s.v)})).start()},pc.Entity.prototype.opacityTo=function(t,i,e){if(!this.element.material)return;let s={v:t};return this.setOpacity(t),this.tween(s).to({v:i},e,pc.SineOut).on("update",(()=>{this.setOpacity(s.v)})).start()},pc.Entity.prototype.setTextureFromURL=function(t){let i="t_"+t,e=pc.app.assets.find(i,"texture");if(null===e){pc.app.loader.getHandler("texture").crossOrigin="anonymous";var s=new pc.Asset(i,"texture",{url:t});pc.app.assets.add(s),s.on("load",(t=>{this.element.texture=t.resource})),pc.app.assets.load(s)}else this.element.texture=e.resource},pc.Entity.prototype.blink=function(t,i,e,s){for(let n=0;n<s;n++)setTimeout((()=>{this.setOpacity(t)}),e*n*2),setTimeout((()=>{this.setOpacity(i)}),e*(2*n+1))};var t=pc.AppBase.getApplication();t&&t.addTweenManager()}();var Background=pc.createScript("background");Background.attributes.add("startPosX",{type:"number",default:1}),Background.attributes.add("endPosX",{type:"number",default:1}),Background.attributes.add("durationTime",{type:"number",default:1}),Background.prototype.initialize=function(){this.entity.setLocalPosition(this.startPosX,0,0),this.tween=this.entity.tween(this.entity.getLocalPosition()).to(new pc.Vec3(this.endPosX,0,0),this.durationTime,pc.Linear).loop(!0).yoyo(!0),this.tween.start()};var UserBalance=pc.createScript("userBalance");UserBalance.attributes.add("userBalanceText",{type:"entity"}),UserBalance.attributes.add("userName",{type:"entity"}),UserBalance.prototype.initialize=function(){UserBalance.instance=this,this.userBalance=0},UserBalance.prototype.setUserName=function(e){this.userName.element.text=e},UserBalance.prototype.getUserBalance=function(){return this.userBalance},UserBalance.prototype.setBalance=function(e){this.userBalance=e;let t={value:Number(this.userBalanceText.element.text)},a=this.userBalanceText.element,n=this.entity.tween(t).to({value:e},.3,pc.Linear);n.on("update",(function(e){let n=parseFloat(t.value.toFixed(0));a.text=`${n}`})),n.start()},UserBalance.prototype.update=function(e){};var DummyServer=pc.createScript("dummyServer");DummyServer.prototype.initialize=function(){DummyServer.instance=this,this.betAmount=-1,this.userBalance=0,this.gameDeck=null,this.gameOdds=null},DummyServer.prototype.login=async function(){return this.userBalance=getRandomInt(1e3,5e3),{id:"userName",balance:this.userBalance}},DummyServer.prototype.isValidGame=function(e){let t=[0,0,0,0];e.reduce(((e,t)=>(console.log(e),e[t.type]++,e)),t);let r=!0;return t.forEach((e=>{e>4&&(r=!1)})),this.gameOdds=[0,0,0,0],!0===r&&(this.gameOdds=t.map((e=>0===e?1:1===e?2:2===e?3:3===e?5:10))),r},DummyServer.prototype.initGame=function(){let e;do{this.gameDeck=getDeck(),this.gameDeck=shuffle(this.gameDeck),e=this.gameDeck.slice(0,7),console.log(e)}while(!1===this.isValidGame(e));return{cards:e,odds:this.gameOdds}},DummyServer.prototype.getWinner=function(e){let t=-1;return e.forEach(((e,r)=>{e>=8&&(t=r)})),t},DummyServer.prototype.startGame=function(e,t){let r=[0,0,0,0],i=this.gameDeck.slice(7,this.gameDeck.length),s=-1;for(let e=0;e<i.length;++e){if(r[i[e].type]++,s=this.getWinner(r),s>=0)break}this.userBalance=this.userBalance-e,this.betAmount=e;let a=t===s,n=0;return!0===a&&(n=e*this.gameOdds[s]),this.userBalance=this.userBalance+n,{balance:this.userBalance,betAmount:this.betAmount,profit:n,raceCards:i,playerHorse:t,winner:s,isWin:a}};var GlobalFunction=pc.createScript("globalFunction");function getRandomInt(o,r){return o=Math.ceil(o),r=Math.floor(r),Math.floor(Math.random()*(r-o))+o}var CardType={Clubs:0,Spades:1,Diamonds:2,Hearts:3},CardNumber={Two:2,Three:3,Four:4,Five:5,Six:6,Seven:7,Eight:8,Nine:9,Ten:10,Jack:11,Queen:12,King:13};function shuffle(o){var r,e,n;for(n=o.length-1;n>0;n--)r=Math.floor(Math.random()*(n+1)),e=o[n],o[n]=o[r],o[r]=e;return o}function getDeck(){let o=[],r=Object.values(JSON.parse(JSON.stringify(CardType))),e=Object.values(JSON.parse(JSON.stringify(CardNumber)));for(const n of r)for(const r of e){let e={type:n,number:r};o.push(e)}return o}function getOColor(){return new pc.Color(1,136/255,116/255,1)}function getEColor(){return rgbToColor(86,98,181,255)}function getQColor(){return new pc.Color(168/255,216/255,131/255,1)}function getPlayerColor(){return new pc.Color(0,1,159/255,1)}function getRedColor(){return rgbToColor(221,42,63,255)}function getGreenColor(){return rgbToColor(0,148,68,255)}function getBlueColor(){return rgbToColor(0,169,215,255)}function getBlackColor(){return rgbToColor(0,0,0,255)}function getWhiteColor(){return rgbToColor(255,255,255,255)}function setButton(o,r,e){o.button.on("touchend",r,e),o.button.on("mouseup",r,e)}function rgbToColor(o,r,e,n){return new pc.Color(o/255,r/255,e/255,n/255)}function getCommaText(o){return o.toLocaleString("en-US")}function changeTexture(o,r){o.element.texture=r.resource}var CardFront=pc.createScript("cardFront");CardFront.attributes.add("numberText",{type:"entity"}),CardFront.attributes.add("typeImage",{type:"entity"}),CardFront.attributes.add("fruitImage",{type:"asset",assetType:"texture",array:!0}),CardFront.prototype.initialize=function(){},CardFront.prototype.setCardType=function(t){let e=this.fruitImage[t].resource;this.typeImage.element.texture=e,this.numberText.element.color=t<2?getBlackColor():getRedColor()},CardFront.prototype.setPlayerColor=function(){this.entity.element.color=getPlayerColor()},CardFront.prototype.resetColor=function(){this.entity.element.color=getWhiteColor()},CardFront.prototype.setCardNumber=function(t){let e=t;1===t?e="A":11===t?e="J":12===t?e="Q":13===t&&(e="K"),this.numberText.element.text=`${e}`},CardFront.prototype.setCard=function(t,e){this.setCardType(t),this.setCardNumber(e)};async function loadJsonFromUrl(n){return new Promise((e=>{this.loadJsonFromRemote(n,(function(n){console.log(n);let o=JSON.stringify(n),s=JSON.parse(o);e(s)}))}))}async function delay(n){return new Promise((e=>setTimeout((()=>{e(n)}),n)))}async function loadJsonFromRemote(n,e){var o=new XMLHttpRequest;o.addEventListener("load",(function(){e(JSON.parse(this.response))})),o.open("GET",n),o.send()}var Middle=pc.createScript("middle");Middle.prototype.initialize=function(){Middle.instance=this,this.idleTimer=null},Middle.prototype.postInitialize=function(){this.setReady()},Middle.prototype.update=function(e){},Middle.prototype.startRace=async function(e,t){HorseController.instance.reset(),HorseController.instance.setPlayerCard(t);for(let t=0;t<e.length;++t){RaceCards.instance.setCard(e[t].type,e[t].number),await delay(300);let i=HorseController.instance.moveCard(e[t].type,!0);if(RaceHistory.instance.addType(e[t].type),await delay(300),i>=8)break}},Middle.prototype.setIdle=function(){},Middle.prototype.dispenseCard=async function(e){},Middle.prototype.setCard=function(e,t){},Middle.prototype.setResult=async function(e,t){},Middle.prototype.setReady=function(){};var Card=pc.createScript("card");Card.attributes.add("cardRoot",{type:"entity"}),Card.attributes.add("cardFront",{type:"entity"}),Card.prototype.initialize=function(){},Card.prototype.setCard=function(t,r){this.cardRoot.enabled=!0,this.cardRoot.setLocalEulerAngles(0,0,0),this.cardFront.script.cardFront.setCard(t,r)},Card.prototype.setPlayerCard=function(t){!0===t?this.cardFront.script.cardFront.setPlayerColor():this.cardFront.script.cardFront.resetColor()},Card.prototype.setReady=function(){this.cardRoot.enabled=!0,this.cardFront.script.cardFront.resetColor(),this.cardRoot.setLocalEulerAngles(0,180,0)},Card.prototype.setHide=function(t){this.cardRoot.enabled=!t};var GameController=pc.createScript("gameController");GameController.prototype.initialize=function(){GameController.instance=this},GameController.prototype.postInitialize=function(){this.init(),this.setIdle()},GameController.prototype.init=async function(){let e=await DummyServer.instance.login();console.log(e),UserBalance.instance.setBalance(e.balance),UserBalance.instance.setUserName(e.id)},GameController.prototype.update=function(e){},GameController.prototype.betStart=function(){BetController.instance.reset(),Middle.instance.setReady(),Bottom.instance.setBet()},GameController.prototype.startGame=async function(e){Bottom.instance.betUi.enabled=!1;let t=DummyServer.instance.initGame();await Middle.instance.dispenseCard(t.cards),Bottom.instance.setOdds(t.odds),await delay(1e3),Bottom.instance.setBet()},GameController.prototype.betGame=async function(e,t){let n=DummyServer.instance.startGame(e,t);console.log(n),await Middle.instance.startRace(n.raceCards,n.playerHorse),await Bottom.instance.setResultGame(n.isWin,n.winner,n.profit),await delay(500),UserBalance.instance.setBalance(n.balance),await delay(3e3),this.setIdle()},GameController.prototype.setIdle=function(){Middle.instance.setIdle(),Bottom.instance.setIdle()};var Bottom=pc.createScript("bottom");Bottom.attributes.add("startButton",{type:"entity"}),Bottom.attributes.add("start_active",{type:"asset",assetType:"texture"}),Bottom.attributes.add("start_deactive",{type:"asset",assetType:"texture"}),Bottom.attributes.add("betUi",{type:"entity"}),Bottom.prototype.initialize=function(){Bottom.instance=this,this.setButton(this.startButton,this.onClickStart),this.winEffectTimer=null,this.bellToggle=!1},Bottom.prototype.postInitialize=function(){this.disableAll(),BetButtonController.instance.setBetButton()},Bottom.prototype.initBetButton=function(){},Bottom.prototype.setOdds=function(t){},Bottom.prototype.resetOdds=function(){},Bottom.prototype.setButton=function(t,e){t.button.on("touchend",e,this),t.button.on("mouseup",e,this)},Bottom.prototype.onClickStart=function(){AudioController.instance.playSound("Click"),GameController.instance.startGame(),this.changeButtonState(this.startButton,!1),this.changeTexture(this.startButton,this.start_active)},Bottom.prototype.onClickPlayer=function(t){this.activePlayerBtn(!1),AudioController.instance.playSound("Click"),GameController.instance.betGame(BetController.instance.betAmount,t)},Bottom.prototype.changeTexture=function(t,e){t.element.texture=e.resource},Bottom.prototype.changeButtonState=function(t,e){t.button.active=e},Bottom.prototype.disableAll=function(){clearTimeout(this.winEffectTimer),this.changeButtonState(this.startButton,!1),this.changeTexture(this.startButton,this.start_deactive),Result.instance.hideResult(),this.betUi.enabled=!1},Bottom.prototype.setBet=function(){this.disableAll(),this.changeTexture(this.startButton,this.start_active),this.betUi.enabled=!0,this.changeButtonState(this.startButton,!1),this.activePlayerBtn(!1)},Bottom.prototype.setIdle=function(){this.disableAll(),this.resetOdds(),setTimeout((()=>{this.changeButtonState(this.startButton,!0)}),1e3)},Bottom.prototype.setStartGame=async function(){this.disableAll(),this.changeTexture(this.startButton,this.start_active),console.log(this.betUi),this.betUi.enabled=!1,this.activePlayerBtn(!0)},Bottom.prototype.activePlayerBtn=function(t){},Bottom.prototype.setResultGame=function(t,e,o){console.log("setResultGame",t,o),setTimeout((()=>{this.disableAll(),Result.instance.setResult(t,e,o)}),1e3)};var AudioController=pc.createScript("audioController");AudioController.attributes.add("soundSource",{type:"entity"}),AudioController.prototype.initialize=function(){AudioController.instance=this,this.isMute=!0,this.soundSource.sound.volume=0},AudioController.prototype.setMute=function(o){this.isMute=o,this.isMute?this.soundSource.sound.volume=0:this.soundSource.sound.volume=.55},AudioController.prototype.playSound=function(o){!0!==this.isMute&&this.soundSource.sound.play(o)};var BetController=pc.createScript("betController");BetController.attributes.add("betButton",{type:"entity",array:!0}),BetController.attributes.add("okButton",{type:"entity"}),BetController.attributes.add("cancelButton",{type:"entity"}),BetController.attributes.add("clearButton",{type:"entity"}),BetController.attributes.add("betAmountText",{type:"entity"}),BetController.attributes.add("errorText",{type:"entity"}),BetController.prototype.initialize=function(){BetController.instance=this,this.timer=null,this.betAmount=0,this.errorText.enabled=!1,setButton(this.cancelButton,this.onBetCancel,this),setButton(this.okButton,this.onBetOk,this),setButton(this.clearButton,this.onBetClear,this)},BetController.prototype.reset=function(){this.betAmount=0,this.updateText(),this.resetAllButton()},BetController.prototype.resetAllButton=function(){this.betButton.forEach((t=>t.element.color=new pc.Color(.5,.5,.5,1)))},BetController.prototype.betChange=function(t){let e=this.betAmount+t;return e>UserBalance.instance.getUserBalance()?(this.showErrorMsg(),!1):(this.errorText.enabled=!1,this.betAmount=e,this.updateText(),!0)},BetController.prototype.updateText=function(){let t=getCommaText(this.betAmount);this.betAmountText.element.text=`${t}`},BetController.prototype.onBetClear=function(){AudioController.instance.playSound("Click"),console.log("BetController.prototype.onBetClear"),this.betAmount=0,this.updateText()},BetController.prototype.onBetOk=function(){AudioController.instance.playSound("Click"),console.log("BetController.prototype.betOk"),0!==this.betAmount&&Bottom.instance.setStartGame()},BetController.prototype.onBetCancel=function(){AudioController.instance.playSound("Click"),GameController.instance.setIdle()},BetController.prototype.showErrorMsg=function(){this.errorText.enabled=!0,clearTimeout(this.timer),this.timer=setTimeout((()=>{this.errorText.enabled=!1}),1e3)};var NumButton=pc.createScript("numButton");NumButton.attributes.add("betAmount",{type:"number"}),NumButton.prototype.initialize=function(){let t=this.entity.children[0],n=this.betAmount,e=getCommaText(n);t.element.text=`+${e}`,setButton(this.entity,this.onClick,this)},NumButton.prototype.onClick=function(){AudioController.instance.playSound("Click");BetController.instance.betChange(this.betAmount)};var SoundButton=pc.createScript("soundButton");SoundButton.attributes.add("onImg",{type:"entity"}),SoundButton.attributes.add("offImg",{type:"entity"}),SoundButton.prototype.initialize=function(){SoundButton.instance=this,this.isMute=!0,this.setButton(this.entity,this.onClick)},SoundButton.prototype.onClick=function(){this.isMute=!this.isMute,this.onImg.enabled=!1,this.offImg.enabled=!1,this.isMute?this.offImg.enabled=!0:this.onImg.enabled=!0,AudioController.instance.setMute(this.isMute)},SoundButton.prototype.setButton=function(t,n){t.element.on("touchend",n,this),t.element.on("mouseup",n,this)};var Player=pc.createScript("player");Player.attributes.add("winLose",{type:"entity"}),Player.attributes.add("pair",{type:"entity"}),Player.attributes.add("cards",{type:"entity",array:"true"}),Player.attributes.add("nonSelImg",{type:"asset",assetType:"texture"}),Player.attributes.add("selImg",{type:"asset",assetType:"texture"}),Player.attributes.add("winImg",{type:"asset",assetType:"texture"}),Player.attributes.add("loseImg",{type:"asset",assetType:"texture"}),Player.attributes.add("draw",{type:"asset",assetType:"texture"}),Player.prototype.initialize=function(){},Player.prototype.reset=function(){this.winLose.enabled=!1,this.pair.element.text="?",changeTexture(this.entity,this.nonSelImg),this.cards.forEach((e=>{e.script.card.setHide(!0)}))},Player.prototype.selectPlayer=function(){changeTexture(this.entity,this.selImg)},Player.prototype.showCard=function(e){AudioController.instance.playSound("moveCard"),this.cards[e].script.card.setReady()},Player.prototype.setCard=function(e){let t=0;AudioController.instance.playSound("flipCard");for(let a=0;a<e.length;++a)this.cards[a].script.card.setCard(e[a].type,e[a].number),t+=e[a].number;1==e.length&&(this.pair.element.text=""+t%10)},Player.prototype.setResult=async function(e,t,a,r){await delay(100),this.pair.element.text=t?`Pair\n${e}`:`${e}\n(${a})`,await delay(100),null!==r&&(this.winLose.enabled=!0,0===r?(AudioController.instance.playSound("pWin"),changeTexture(this.winLose,this.winImg)):1===r?(AudioController.instance.playSound("pDraw"),changeTexture(this.winLose,this.draw)):(AudioController.instance.playSound("pLose"),changeTexture(this.winLose,this.loseImg)))};var BetButton=pc.createScript("betButton");BetButton.attributes.add("buttonIdx",{type:"number"}),BetButton.attributes.add("winNumber",{type:"number"}),BetButton.attributes.add("tieNumber",{type:"number"}),BetButton.attributes.add("winImage",{type:"entity"}),BetButton.attributes.add("tieImage",{type:"entity"}),BetButton.attributes.add("buttonText",{type:"entity"}),BetButton.prototype.initialize=function(){setButton(this.entity,this.onClick,this)},BetButton.prototype.numberToColor=function(t){return 1===t?getRedColor():2===t?getGreenColor():getBlueColor()},BetButton.prototype.setButton=function(t,e,o){this.buttonIdx=t,this.winNumber=e,this.tieNumber=o,this.winImage.element.color=this.numberToColor(e),console.log("color : "+this.winImage.element.color),this.tieImage.element.color=this.numberToColor(0===o?e:o);let n="";n=`${e} WIN`,0!==o&&(n+=`\n${o} TIE`),this.buttonText.element.text=n},BetButton.prototype.resetOdds=function(){},BetButton.prototype.setOdds=function(t){},BetButton.prototype.onClick=function(){this.activeButton(!1),this.changeButtonImage(!0)},BetButton.prototype.activeButton=function(t){this.entity.button.active=t},BetButton.prototype.changeButtonImage=function(t){console.log(getEColor()),this.entity.element.color=getEColor(),console.log("color : "+this.entity.element.color)};var HorseController=pc.createScript("horseController");HorseController.attributes.add("horse",{type:"entity",array:"true"}),HorseController.prototype.initialize=function(){HorseController.instance=this,this.step=[0,0,0,0],this.startPositionX=-5,this.stepSize=110},HorseController.prototype.postInitialize=function(){this.reset(),this.setReady()},HorseController.prototype.update=function(t){},HorseController.prototype.moveCard=function(t,o){return!0===o?this.step[t]++:(this.step[t]--,this.step[t]<0&&(this.step[t]=0)),this.updatePosition(this.horse[t],this.step[t]),AudioController.instance.playSound("moveCard"),this.step[t]},HorseController.prototype.updatePosition=function(t,o){let e=t.getLocalPosition();t.setLocalPosition(this.startPositionX+this.stepSize*o,e.y,0)},HorseController.prototype.setPlayerCard=function(t){this.horse[t].script.card.setPlayerCard(!0)},HorseController.prototype.setReady=function(){for(let t=0;t<this.horse.length;++t)this.horse[t].script.card.setHide(!0)},HorseController.prototype.dispenseCard=async function(){for(let t=0;t<this.horse.length;++t)this.horse[t].script.card.setHide(!1),AudioController.instance.playSound("flipCard"),await delay(200)},HorseController.prototype.reset=function(){this.horse.forEach((t=>{let o=t.getLocalPosition();t.setLocalPosition(this.startPositionX,o.y,0),t.script.card.setPlayerCard(!1)})),this.step=[0,0,0,0]};var TopCardController=pc.createScript("topCardController");TopCardController.attributes.add("topCards",{type:"entity",array:"true"}),TopCardController.prototype.initialize=function(){TopCardController.instance=this},TopCardController.prototype.postInitialize=function(){this.setReady()},TopCardController.prototype.setReady=function(){for(let t=0;t<this.topCards.length;++t)this.topCards[t].script.card.setHide(!0)},TopCardController.prototype.dispenseCard=async function(t){for(let r=0;r<t.length;++r)this.topCards[r].script.card.setReady(),this.topCards[r].script.card.setCard(t[r].type,t[r].number),AudioController.instance.playSound("flipCard"),await delay(200)};var RaceCards=pc.createScript("raceCards");RaceCards.attributes.add("hideCard",{type:"entity"}),RaceCards.attributes.add("openCard",{type:"entity"}),RaceCards.prototype.initialize=function(){RaceCards.instance=this},RaceCards.prototype.postInitialize=function(){this.setReady()},RaceCards.prototype.update=function(t){},RaceCards.prototype.setReady=function(){this.hideCard.script.card.setHide(!0),this.openCard.script.card.setHide(!0)},RaceCards.prototype.dispenseCard=function(){this.hideCard.script.card.setHide(!1)},RaceCards.prototype.setCard=function(t,e){AudioController.instance.playSound("flipCard"),this.openCard.script.card.setHide(!1),this.openCard.script.card.setCard(t,e)};var RaceHistory=pc.createScript("raceHistory");RaceHistory.attributes.add("typeImage",{type:"asset",assetType:"texture",array:!0}),RaceHistory.attributes.add("imageRoot",{type:"entity"}),RaceHistory.prototype.initialize=function(){RaceHistory.instance=this,this.historyElement=this.imageRoot.children,this.cardNumber=0},RaceHistory.prototype.initialize=function(){RaceHistory.instance=this,this.historyElement=this.imageRoot.children},RaceHistory.prototype.reset=function(){RaceHistory.instance=this,this.historyElement.forEach((t=>t.enabled=!1)),this.cardNumber=0},RaceHistory.prototype.addType=function(t){this.historyElement[this.cardNumber].enabled=!0,changeTexture(this.historyElement[this.cardNumber],this.typeImage[t]),this.cardNumber++},RaceHistory.prototype.update=function(t){};var Result=pc.createScript("result");Result.attributes.add("win",{type:"entity"}),Result.attributes.add("lose",{type:"entity"}),Result.prototype.initialize=function(){Result.instance=this},Result.prototype.typeToString=function(e){let t="";switch(e){case 0:t="Clubs";break;case 1:t="Spades";break;case 2:t="Diamonds";break;default:t="Hearts"}return t},Result.prototype.setResult=function(e,t,i){let n=e?this.win:this.lose,s=`The winner is ace of ${this.typeToString(t)}`;n.children[0].element.text=s,!0===e?(AudioController.instance.playSound("Win"),this.win.enabled=!0,n.children[2].element.text=`+${i}`):(AudioController.instance.playSound("Lose"),this.lose.enabled=!0)},Result.prototype.hideResult=function(){this.win.enabled=!1,this.lose.enabled=!1};var BetButtonController=pc.createScript("betButtonController");BetButtonController.prototype.initialize=function(){BetButtonController.instance=this},BetButtonController.prototype.setBetButton=function(){let t=[{idx:0,win:1,tie:0},{idx:1,win:2,tie:0},{idx:2,win:3,tie:0},{idx:3,win:1,tie:2},{idx:4,win:1,tie:3},{idx:5,win:2,tie:1},{idx:6,win:2,tie:3},{idx:7,win:3,tie:1},{idx:8,win:3,tie:2}],i=0;console.log(this.entity.children),this.entity.children.forEach((e=>{e.children.forEach((e=>{let n=t[i];e.script.betButton.setButton(n.idx,n.win,n.tie),i++}))}))};var NumberController=pc.createScript("numberController");NumberController.prototype.initialize=function(){NumberController.instance=this,this.start=!1,this.interval=0,this.accTime=0,this.prevNumber=0},NumberController.prototype.update=function(t){!0===this.start&&(this.accTime+=t,this.accTime>=this.interval&&(this.prevNumber=this.generateRandomNumber(this.prevNumber),this.setNumber(this.prevNumber),this.accTime=0))},NumberController.prototype.generateRandomNumber=function(t){for(;;){var e=getRandomInt(1,4);if(e!==t)return e}},NumberController.prototype.setNumber=function(t){this.entity.element.text=`${t}`},NumberController.prototype.startRand=function(){this.start=!0,this.interval=.1,this.prevNumber=0},NumberController.prototype.stopRandLoop=async function(){for(let t=0;t<9;++t){this.interval+=.06;let t=1e3*this.interval;await delay(t)}},NumberController.prototype.stopRand=async function(t){await this.stopRandLoop(),this.start=!1;let e=this.interval-this.accTime;console.log(e),await delay(1e3*e),this.setNumber(t)};