How to use drawStack method in storybook-root

Best JavaScript code snippet using storybook-root

Game.js

Source:Game.js Github

copy

Full Screen

1import './App.css';2import React from 'react'3import Button from 'react-bootstrap/Button'4import firebase from './firebase.js'5import Card from './Card'6import 'bootstrap/dist/css/bootstrap.min.css';7import PropTypes from "prop-types";8class Game extends React.Component {9 constructor(props) {10 super(props);11 this.discardCard = this.discardCard.bind(this);12 this.drawCard = this.drawCard.bind(this);13 this.shuffleDeck = this.shuffleDeck.bind(this);14 this.takeKick = this.takeKick.bind(this);15 this.takeWeakness = this.takeWeakness.bind(this);16 this.discardHand = this.discardHand.bind(this)17 this.state = {18 game: {},19 saving: false20 };21 };22 static propTypes = {23 match: PropTypes.object.isRequired,24 player: PropTypes.number.isRequired25 }26 shuffleDeck(gameCode, playerNumber) {27 var player = this.state.game.Players[playerNumber];28 var gameDB = firebase.database().ref().child('Game').child(gameCode);29 gameDB.child('Saving').set('True').then(() => {30 var playerdb = gameDB.child('Players').child(playerNumber)31 var drawStack = player.DrawStack;32 var discard = player.Discard;33 if (discard) {34 var newStack = [];35 if (drawStack && drawStack.constructor === Array) {36 newStack = [...drawStack,...discard];37 } else {38 newStack = discard;39 }40 playerdb.child('DrawStack').set(this.shuffle(newStack));41 playerdb.child('Discard').remove().then(() => {42 gameDB.child('Saving').set('False')43 });44 }45 });46 }47 shuffle(array) {48 var currentIndex = array.length, temporaryValue, randomIndex;49 50 // While there remain elements to shuffle...51 while (0 !== currentIndex) {52 53 // Pick a remaining element...54 randomIndex = Math.floor(Math.random() * currentIndex);55 currentIndex -= 1;56 57 // And swap it with the current element.58 temporaryValue = array[currentIndex];59 array[currentIndex] = array[randomIndex];60 array[randomIndex] = temporaryValue;61 }62 63 return array;64 }65 discardHand(gameCode, playerNumber) {66 var player = this.state.game.Players[playerNumber];67 var list = [];68 for(var i = 0; i < player.Hand.length; i++) {69 list[i] = player.Hand[i].CardId;70 }71 72 for(var t = 0; t < list.length; t++) {73 this.discardCard(gameCode, playerNumber, list[t]);74 }75 }76 discardCard(gameCode, playerNumber, cardId) {77 if (cardId !== 0) {78 var gameDB = firebase.database().ref().child('Game').child(gameCode);79 gameDB.child('Saving').set('True').then(() => {80 var player = this.state.game.Players[playerNumber];81 var playerdb = firebase.database().ref().child('Game').child(gameCode).child('Players').child(playerNumber);82 var newDiscard = [];83 if (player.Discard) {84 newDiscard = player.Discard;85 newDiscard[player.Discard.length] =player.Hand.find((x) => x.CardId === cardId);86 } else {87 newDiscard = [player.Hand.find((x) => x.CardId === cardId)];88 }89 90 for( var i = 0; i < player.Hand.length; i++){ 91 if (player.Hand[i].CardId === cardId) {92 player.Hand.splice(i,1);93 i = 100;94 }95 }96 playerdb.child('Discard').set(newDiscard);97 playerdb.child('Hand').set(player.Hand).then(() => {98 gameDB.child('Saving').set('False')99 });;100 });101 }102 }103 checkSave () {104 return this.state.game.Saving === 'True';105 }106 drawCard(gameCode, playerNumber) {107 var gameDB = firebase.database().ref().child('Game').child(gameCode);108 gameDB.child('Saving').set('True').then(() => {109 var player = this.state.game.Players[playerNumber];110 var playerdb = firebase.database().ref().child('Game').child(gameCode).child('Players').child(playerNumber);111 if (player.DrawStack && player.DrawStack.constructor === Array) {112 if (player.Hand) {113 player.Hand[player.Hand.length] = player.DrawStack.pop(); 114 } else {115 player.Hand = [player.DrawStack.pop()];116 }117 playerdb.child('DrawStack').set(player.DrawStack);118 playerdb.child('Hand').set(player.Hand).then(() => {119 gameDB.child('Saving').set('False')120 });121 } else {122 gameDB.child('Saving').set('False');123 }124 });125}126takeKick(gameCode, playerNumber) {127 var gameDB = firebase.database().ref().child('Game').child(gameCode);128 gameDB.child('Saving').set('True').then(() => {129 var player = this.state.game.Players[playerNumber];130 var playerdb = firebase.database().ref().child('Game').child(gameCode).child('Players').child(playerNumber);131 if (player.Discard && player.Discard.constructor === Array) {132 player.Discard[player.Discard.length] = this.state.game.Kicks[0];133 } else {134 player.Discard = [];135 player.Discard[0] = this.state.game.Kicks[0];136 }137 playerdb.child('Discard').set(player.Discard).then(() => {138 gameDB.child('Saving').set('False')139 });140});141}142takeWeakness(gameCode, playerNumber) {143 var gameDB = firebase.database().ref().child('Game').child(gameCode);144 gameDB.child('Saving').set('True').then(() => {145 var player = this.state.game.Players[playerNumber];146 var playerdb = firebase.database().ref().child('Game').child(gameCode).child('Players').child(playerNumber);147 if (player.Discard && player.Discard.constructor === Array) {148 player.Discard[player.Discard.length] = this.state.game.Weakness[0];149 } else {150 player.Discard = [];151 player.Discard[0] = this.state.game.Weakness[0];152 }153 playerdb.child('Discard').set(player.Discard).then(() => {154 gameDB.child('Saving').set('False')155 });156});157}158 shuffleArray(array) {159 let curId = array.length;160 // There remain elements to shuffle161 while (0 !== curId) {162 // Pick a remaining element163 let randId = Math.floor(Math.random() * curId);164 curId -= 1;165 // Swap it with the current element.166 let tmp = array[curId];167 array[curId] = array[randId];168 array[randId] = tmp;169 }170 return array;171 }172 componentDidMount() {173 const { match: { params } } = this.props;174 var gameCode = params.gameCode;175 this.setState(176 {177 gameCode: gameCode,178 playerNumber: params.player -1179 }180 );181 const game = firebase.database().ref().child('Game').child(gameCode);182 console.log(gameCode);183 game.on('value', (snapshot) =>{184 let games = snapshot.val();185 this.setState({186 game: games187 });188 });189 }190 render() {191 const { match: { params } } = this.props;192 var gameCode = params.gameCode;193 var player = Number(params.player) - 1;194 var user = this.state.game?.Players ? this.state.game.Players[player] : 0;195 var vp = 0;196 if (user) {197 if (user.Discard && user.Discard.constructor === Array) {198 user.Discard.forEach((x) => {199 vp += x.VictoryPoints;200 });201 } 202 if (user.Hand && user.Hand.constructor === Array) {203 user.Hand.forEach((x) => {204 vp += x.VictoryPoints;205 });206 } 207 if (user.DrawStack && user.DrawStack.constructor === Array) {208 user.DrawStack.forEach((x) => {209 vp += x.VictoryPoints;210 });211 } 212 }213 var newPurchaseRow = [];214 if (this.state.game.PurchaseRow) {215 this.state.game.PurchaseRow?.map((p)=> {216 newPurchaseRow.push(p);217 })218 if (newPurchaseRow.length < 5) {219 220 var mainDeck = this.state.game.MainDeck;221 if (mainDeck) {222 var nextCard = mainDeck.length - 1;223 var cardFromDeck = mainDeck[nextCard];224 newPurchaseRow.push(cardFromDeck);225 firebase.database().ref().child('Game').child(gameCode).child('PurchaseRow').set(newPurchaseRow);226 firebase.database().ref().child('Game').child(gameCode).child('MainDeck').child(nextCard).remove();227 }228 229 }230 }231 return (232 <div>233 <div class="purchaseRow col-md-12">234 <div class="row">235 {this.state.game.PurchaseRow?.map((p)=> {236 return( 237 <div class="col-md-2 m-0">238 <Card gameCode={gameCode} player={player} card={p} canBuy={true}></Card>239 </div>240 )241 })}242 <div class="super-villian col-md-2 m-0">{ this.state.game.SuperVillian ? <Card gameCode={gameCode} player={player} card={this.state.game.SuperVillian} canBuy={true}></Card> : null }243 </div>244 </div>245 </div>246 <div class="playerHand">247 <div class="row">248 {console.log(player)} 249 {user && user.Hand ? 250 user.Hand?.map((p)=> {251 return( 252 <div class="col-md-2 m-0">253 <Card card={p}></Card>254 <Button disabled={this.state.game.Saving === 'True'} onClick={this.discardCard.bind(this, gameCode, player,p.CardId) }>Discard</Button>255 </div>256 )257 }): null}258 259 </div>260 <div class="row">261 {user ? <div class="col-md-3 card">262 <div class="card-header">263 {user.Persona.CardName}264 <div class="float-right">{vp}</div>265 </div>266 <div class="card-body">267 {user.Persona.CardText}268 </div>269 <div class="card-footer">270 <Button disabled={this.state.game.Saving === 'True'} onClick={this.drawCard.bind(this, gameCode, player)}>Draw Card ({user.DrawStack?.length})</Button>271 <Button disabled={this.state.game.Saving === 'True'} onClick={this.shuffleDeck.bind(this, gameCode, player)}>Shuffle Discard</Button>272 <Button disabled={this.state.game.Saving === 'True'} onClick={this.discardHand.bind(this, gameCode, player)}>Discard Hand</Button>273 </div>274 </div>: null}275 <div class="form-group col-md-2">276 <Button class="p-2 m-2 col-md-12" disabled={this.state.game.Saving === 'True'} onClick={this.takeKick.bind(this, gameCode, player)}>Take Kick</Button>277 <Button class="p-2 m-2 col-md-12" disabled={this.state.game.Saving === 'True'} onClick={this.takeWeakness.bind(this, gameCode, player)}>Take Weakness</Button>278 </div>279 </div>280 </div>281 </div>282 )283 }284}...

Full Screen

Full Screen

Router.js

Source:Router.js Github

copy

Full Screen

1/**2 * @author Ed Spencer3 * @private4 *5 * The Router is an ordered set of route definitions that decode a url into a controller function to execute. Each6 * route defines a type of url to match, along with the controller function to call if it is matched. The Router is7 * usually managed exclusively by an {@link Ext.app.Application Application}, which also uses a8 * {@link Ext.app.History History} instance to find out when the browser's url has changed.9 *10 * Routes are almost always defined inside a {@link Ext.app.Controller Controller}, as opposed to on the Router itself.11 * End-developers should not usually need to interact directly with the Router as the Application and Controller12 * classes manage everything automatically. See the {@link Ext.app.Controller Controller documentation} for more13 * information on specifying routes.14 */15Ext.define('Ext.app.Router', {16 requires: ['Ext.app.Route'],17 config: {18 /**19 * @cfg {Array} routes The set of routes contained within this Router.20 * @readonly21 */22 routes: [],23 /**24 * @cfg {Object} defaults Default configuration options for each Route connected to this Router.25 */26 defaults: {27 action: 'index'28 }29 },30 constructor: function(config) {31 this.initConfig(config);32 },33 /**34 * Connects a url-based route to a controller/action pair plus additional params.35 * @param {String} url The url to recognize.36 * @param {Object} [params] Additional parameters.37 */38 connect: function(url, params) {39 params = Ext.apply({url: url}, params || {}, this.getDefaults());40 var route = Ext.create('Ext.app.Route', params);41 this.getRoutes().push(route);42 return route;43 },44 /**45 * Recognizes a url string connected to the Router, return the controller/action pair plus any additional46 * config associated with it.47 * @param {String} url The url to recognize.48 * @return {Object/undefined} If the url was recognized, the controller and action to call, else `undefined`.49 */50 recognize: function(url) {51 var routes = this.getRoutes(),52 length = routes.length,53 i, result;54 for (i = 0; i < length; i++) {55 result = routes[i].recognize(url);56 if (result !== undefined) {57 return result;58 }59 }60 return undefined;61 },62 /**63 * Convenience method which just calls the supplied function with the Router instance. Example usage:64 *65 * Ext.Router.draw(function(map) {66 * map.connect('activate/:token', {controller: 'users', action: 'activate'});67 * map.connect('home', {controller: 'index', action: 'home'});68 * });69 *70 * @param {Function} fn The fn to call71 */72 draw: function(fn) {73 fn.call(this, this);74 },75 /**76 * @private77 */78 clear: function() {79 this.setRoutes([]);80 }81}, function() {82 //<deprecated product=touch since=2.0>83 /**84 * Restores compatibility for the old `Ext.Router.draw` syntax. This needs to be here because apps often include85 * _routes.js_ just after _app.js_, so this is our only opportunity to hook this in. There is a small piece of code86 * inside Application's {@link Ext.app.Application#onDependenciesLoaded onDependenciesLoaded} that sets up the other end of this.87 * @singleton88 * @private89 */90 Ext.Router = {};91 var drawStack = [];92 /**93 * Application's {@link Ext.app.Application#onDependenciesLoaded onDependenciesLoaded} has a deprecated-wrapped line that calls this. Basic idea is that once an94 * app has been instantiated we set that at Ext.Router's `appInstance` and then redirect any calls to95 * {@link Ext.app.Router#draw Ext.Router.draw} to that app's Router. We keep a `drawStack` above so that we can call {@link Ext.app.Router#draw Ext.Router.draw} one or96 * more times before the application is even instantiated and it will simply link it up once everything is97 * present.98 */99 Ext.Router.setAppInstance = function(app) {100 Ext.Router.appInstance = app;101 if (drawStack.length > 0) {102 Ext.each(drawStack, Ext.Router.draw);103 }104 };105 Ext.Router.draw = function(mapperFn) {106 Ext.Logger.deprecate(107 'Ext.Router.map is deprecated, please define your routes inline inside each Controller. ' +108 'Please see the 1.x -> 2.x migration guide for more details.'109 );110 var app = Ext.Router.appInstance,111 router;112 if (app) {113 router = app.getRouter();114 mapperFn(router);115 } else {116 drawStack.push(mapperFn);117 }118 };119 //</deprecated>...

Full Screen

Full Screen

PlayArea.js

Source:PlayArea.js Github

copy

Full Screen

1import React from 'react'2import DiscardPile from './DiscardPile'3import DrawStack from './DrawStack'4function PlayArea(props) {5 function handleDiscardPileClick() {6 props.onDiscardPileClick();7 }8 function handleDrawStackClick() {9 props.onDrawStackClick();10 }11 return (12 <div>13 <div className="space-x-3 flex justify-center align-center items-center playingCards faceImages simpleCards">14 {/*<div className="pr-3">Discard Pile ({props.discardPile.length})</div>*/}15 <DrawStack16 onDrawStackClick={handleDrawStackClick}17 drawStack={props.drawStack}18 paused={props.paused}19 />20 <DiscardPile21 onDiscardPileClick={handleDiscardPileClick}22 discardPile={props.discardPile}23 paused={props.paused}24 lastPlayedCards={props.lastPlayedCards}25 />26 {/*<div className="pl-3" >Draw Stack ({props.drawStack.length})</div>*/}27 </div>28 </div>29 )30}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful