-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaperJSClient.js
5043 lines (4898 loc) · 219 KB
/
paperJSClient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//NOTE: PaperJS requires ES5. I ended up writing everything myself in ES5 as I didn't know about Babel at the time
//I also didn't know about modules, so I ended up writing all of the code in the same file. I used regions to try and maintain order.
//#region Intialize Globals
function initializeVariables() {
aspectRatio = (canvasHeight > canvasWidth) ? canvasHeight / canvasWidth : canvasWidth / canvasHeight;
isHighAspectRatio = aspectRatio >= 2;
marginAmount = marginPercent * canvasWidth;
marginAmountMobile = 0;
isMobile = canvasWidth <= mobileMaxWidth;
DEFAULT_FONT_SIZE = isMobile ? canvasWidth * .035 : canvasWidth * .024;
SMALLER_FONT_SIZE = DEFAULT_FONT_SIZE * .8;
if (25 <= marginAmount) marginAmount = 25;
else marginAmount = maxMarginAmountMobileInside;
if (SMALLER_FONT_SIZE <= maxMarginAmountMobileInside) marginAmountMobileInside = SMALLER_FONT_SIZE;
else marginAmountMobileInside = maxMarginAmountMobileInside;
}
//#region Lists of Users with Specific Issues
// var usernamesWhoCannotPlayOnTurn = ['Dan', 'Ann'];
//#endregion
//#region Get from Server
var queryString = Qs.parse(location.search,
{
ignoreQueryPrefix: true,
});
var isTurnToPlay = false, exposedHandLocation, hand, exposedHand, exposedHandSpot, canvasWidth, canvasHeight, declarerCanPlayFromExposed = false;
var isExposedTop, isExposedBottom, isExposedLeft, isExposedRight;
var playedCards = [];
var roundStartPlayer;
var northSouthTrickCount, eastWestTrickCount;
var trumpSuit;
var roundWinners = [];
var cardPlayTimerDurationValue;
var doubleMultiplier;
var scoring, isAppleDevice, roundWinSounds, colorThemeSources, colorThemeValues;
//#endregion
//#region Location and Size
var minExposedHandSize;
var exposedHandSizeFactor;
var highAspectRatioScaleFactor = .8;
var playAreaShrinkFactor;
var aspectRatio, isHighAspectRatio;
var cardWidth, cardHeight, cardName, resize, handWidthSpacingPercentOfCardWidth, exposedHandCardWidthSpacingScaleFactor, exposedHandCardHeightSpacingScaleFactor, isMaxHeight;
var fullSizeCardWidthPercentOfCavasWidth, mobileCardWidthPercentOfCavasWidth, fullSizecardHeightMaxPercent, mobilecardHeightMaxPercent
var hiddenCardsTop, hiddenCardsLeft, hiddenCardsRight, lengthOfHiddenHand;
var thinkingLocation = null, previousThinkingLocation = null, cardsToAnimate = [], frameCountForCardThinkingAnimation = 0, frameCountForSuitThinkingAnimation = 0;
var topPlayArea, bottomPlayArea, rightPlayArea, leftPlayArea, playAreaSquare;
var exposedHandLeftStartX, exposedHandRightStartX, exposedHandBottomStartY, exposedHandTopStartY;
var topOfCardsY, handWidth;
var isMobile, radius, bottomHandY, spot;
var preferences
var exposedHandWidth, exposedHandHeight, exposedHandWidthSpacing, exposedHandHeightSpacing, exposedHandCardHeight, exposedHandCardWidth, heightAvailable, widthAvailable, numberOfSpacesBetweenCards, numberOfSuits;
var canvasEdgeMargin = 5;
var mobileMaxWidth = 479;
var declarerUiYOffset, declarerHandHeightFactor;
var amountOfBottomHandShownOffset, nonHandCardHideFactor;
var heightTakenUpByTopHand, heightTakenUpByBottomHand, widthTakenUpBySideHands;
var needToScaleExposedHandMobile = true;
var greenSpaceAvailable, greenSpaceCenter, marginAmountMobileInside;
var handLengths = {};
// var shouldReDrawHidden = true
//#endregion
//#region Deck Creation
var waitToLoadNewTheme, cardsLoadedCount = 0, currentTheme;
var shouldDisplayPlayAreaCards = true;
var needToResizeOnPlay;
var isFirstTimeDisplayingPlayAreaCards;
var isFirstTimeDisplayingExposedHand, isFirstTimeDisplayingExposedHandMobile;
var checkCardLoadInterval;
var alreadyRotated = false;
var shouldUseHeight = false;
var hands = [];
var deck = [], playAreaAsPaperObj;
var cardWidthPercentOfCavasWidth;
var cardHeightMaxPercent;
var cardWidthFactor = .6666666666666666 //0.7142;
var marginPercent = .02;
var marginAmount;
var handSpacing;
var loadComplete = false;
var topPlayAreaCard, bottomPlayAreaCard, leftPlayAreaCard, rightPlayAreaCard;
var smallCardWidth;
var smallCardHeight;
var exposedHandShrinkAmountMobile = .6;
var widthFactorTopBottomMobile = 0;
var widthFactorLeftRightMobile = 0;
var exposedHandSideXOffset = 0;
var enoughHeightToDisplay;
var enoughWidthToDisplay;
var standardDescendingCardOrder = [suits.spades, suits.hearts, suits.clubs, suits.diamonds];
var standardAscendingCardOrder = [suits.diamonds, suits.clubs, suits.hearts, suits.spades];
//#endregion
//#region Text Stuff
var arrowTop, arrowBottom, arrowLeft, arrowRight;
var exposedHandXOffset = 0;
var texts = {};
var maxMarginAmountMobileInside;
var dealInformation, dealInformationLeftHalf, dealInformationRightHalf;
var gameInformation, gameInformationLeftHalf, gameInformationRightHalf;
var gameInfoLayoutChangeThreshold;
var gameInformationWeHeader, gameInformationTheyHeader, gameInformationFirstGameWe, gameInformationFirstGameThey, gameInformationSecondGameWe, gameInformationSecondGameThey, gameInformationThirdGameWe, gameInformationThirdGameThey;
var gameInformationHorizontalDividerLineGameTwoStart, gameInformationHorizontalDividerLineGameThreeStart;
var shouldDrawInstructions = true;
var bordersFillColor = '#e9ecef';
var bordersStrokeColor = '#fff'
var playerLabelColor;
var belowTheLines;
//For usernames
var maxChars = 8;
var maxWidth = 1400;
var tricksNeeded = "0";
var borderRadius = 10;
var DEFAULT_FONT_FAMILY = "Courier New";
var DEFAULT_FONT_SIZE;
var SMALLER_FONT_SIZE;
var maxFontSizeRatio;
var textsToWrite, contractRaster;
var seating, declarersSpot;
var northName, southName, eastName, westName;
var topName, bottomName, leftName, rightName;
var contract;
var suitScaleFactor = 0.00398174;
var lastTrickOneImg = null, lastTrickTwoImg = null, lastTrickThreeImg = null, lastTrickFourImg = null;
var playAreaCenter, playAreaTopLeft, playAreaTopRight, playAreaBottomLeft, playAreaBottomRight;
var lastRoundStartPlayer;
var textsContractRow, textsDeclarerRow, textsTricksNeededRow, textsLastTrickRow;
var gameInformationDividerLine, gameInformationHorizontalDividerLineGameOneStart;
//#endregion
//#region Animation Stuff
var animationDeceleration = .96;
var animationDeclerationThreshold = 22.5;
var cardPlayAnimationSpeeds = {
slow: {
animationStartSpeedLowerIsFaster: 15,
animationStartRotationSpeed: 28.796,
},
medium: {
animationStartSpeedLowerIsFaster: 12,
animationStartRotationSpeed: 43.201,
},
fast: {
animationStartSpeedLowerIsFaster: 8,
animationStartRotationSpeed: 57.606,
}
}
var clubThinking, diamondThinking, heartThinking, spadeThinking;
var disableCardThinkingAnimation = false;
var thinkingLocationTemp = null;
var roundEndAnimationWaitDuration;
var skipRoundEndAnimationWaitDuration;
var waitForRoundEnd = true;
var needToSleepBeforeRoundEnd = true;
var hasEnteredRoundEndSleep = false;
var rotationPoint;
var cardToPlayDestination, cardToPlayAsNumber, cardToPlayHandLocation;
var cardPlayAnimation = false;
var vector;
var isLastPersonToPlay = false;
var playAreaAnimationDuration;
var rotationAccelleration, rotationDecellerationRate, rotationStartSpeedInDegrees, rotationDecellerationStart;
var animationStartSpeedLowerIsFaster;
var animationStartRotationSpeed;
var hasSentAnimationCompletion;
var cardToPlay, playedCardToShow = null, playedCardRotation = 0, previousLayerIndex = null;
var roundEndAnimation = false, roundWinner = null;
var topCard, bottomCard, leftCard, rightCard, actualDestination;
var startSpeedRoundEndStart = 1000, accelerationRoundEndStart = .1
var topVector, bottomVector, leftVector, rightVector, startSpeedRoundEnd = startSpeedRoundEndStart, accelerationRoundEnd = accelerationRoundEndStart;
var topDestination, bottomDestination, leftDestination, rightDestination;
var roundEndAnimationComplete = true;
var cardsToRemoveFromThinkingAnimation = [];
var hasRequestedRoundStartPlayer = false;
//#endregion
//#region Initialization of Event Handler Variables
var hitOptions = {
segments: false,
stroke: false,
fill: false,
tolerance: 5,
};
var randomCardAsNumber;
var scaleOnClickAmount;
var handScaleAmount;
var animateEveryNthFrame; //must be a factor of 30;
var thinkingScaleAmount;
var segment;
var movePath = false;
var previousRotation, newCenter;
var i = 0;
var clickedOnItem;
var cardRotation;
var isFromHand, isFromExposedHand;
var roundedCardWidth;
var roundedCardHeight;
var shouldChangePlayableCards = true;
var lastClickedCard = null;
var doubleClickInterval = 250;
//#endregion
//#region Sounds
var sounds = {roundWinSounds: {}};
var soundVolumes = {
shotgunLoad: .33,
boomerang: .868,
dealSummaryLostMusic: .66,
dealSummaryWonMusic: .66,
saucisse: .75,
imAlive: .8,
roundWon: .25,
cardPlayDuring: .75,
};
//#endregion
//#region UI Stuff
var declarerUIHandScaleFactor;
//#endregion
//#region Automatic Card Playing
var cardsAsNumbers = [];
var firstPlayerStartTimeBonus = 5;
var firstPlayer;
var autoBidTimer;
//#endregion
//#endregion
//#region Event Handlers (Moving Cards)
function onMouseEnter(event) {
// console.log(event.target.name);
if (roundEndAnimation || event.target.name === undefined || event.target.name === null ) return null;
//#region Setting thinking to null if conditions right
var cardAsNumber = getCardAsNumberFromName(event.target.name);
var isInExposedHand = declarerCanPlayFromExposed ? true : false;
var handToCheck = isInExposedHand ? exposedHand : hand ;
if (isTurnToPlay && isInHand(cardAsNumber, handToCheck)) {
disableCardThinkingAnimation = true;
randomCardAsNumber = null;
}
//#endregion
if (!isMobile && isTurnToPlay ) {
movePath = false;
var hitResult = project.hitTest(event.point, hitOptions);
if (!hitResult || !event.target || event.target.name === null) return null;
var originalBottomLeft = event.target.bounds.bottomLeft;
var originalCenter = event.target.bounds.center;
event.target.scale(handScaleAmount);
if (hand.flatten(2).includes(getCardAsNumberFromName(hitResult.item.name))) {
event.target.bounds.bottomLeft = originalBottomLeft;
}
else {
event.target.bounds.center = originalCenter;
}
}
}
function checkScrollDown(event) {
if (!isMobile) return;
if (event === undefined || event === null) return;
var leftBound = 0;
var rightBound = canvasWidth;
var topBound = gameInformation.bounds.top;
var bottomBound = gameInformation.bounds.bottom;
var isInsideX = event.downPoint.x >= leftBound && event.downPoint.x <= rightBound;
if (!isInsideX) return;
var isInsideY = event.downPoint.y >= topBound && event.downPoint.y <= bottomBound;
if (isInsideX && isInsideY && isMobile) globals.scrollDown();
}
function checkScrollUp(event) {
if (!isMobile) return;
if (event === undefined || event === null) return;
var leftBound = 0;
var rightBound = canvasWidth;
var topBound = dealInformation.bounds.top;
var bottomBound = dealInformation.bounds.bottom;
var isInsideX = event.downPoint.x >= leftBound && event.downPoint.x <= rightBound;
if (!isInsideX) return;
var isInsideY = event.downPoint.y >= topBound && event.downPoint.y <= bottomBound;
if (isInsideX && isInsideY && isMobile) globals.scrollUp();
}
function onMouseDown(event) {
// checkScrollDown(event);
// checkScrollUp(event);
if (roundEndAnimation) return null;
var hitResult = project.hitTest(event.point, hitOptions);
if (!hitResult) return null;
handleDoubleClick(hitResult);
//#region Scaling PlayArea Card up To See better
if (pointsAreColocated(topPlayArea.position, hitResult.item.position, 2) || pointsAreColocated(bottomPlayArea.position, hitResult.item.position, 2) || pointsAreColocated(leftPlayArea.position, hitResult.item.position, 2) || pointsAreColocated(rightPlayArea.position, hitResult.item.position, 2)) {
previousLayerIndex = getItemLayerIndex(hitResult.item);
project.activeLayer.addChild(hitResult.item);
var amountToScale = scaleOnClickAmount / playAreaShrinkFactor;
hitResult.item.scale(amountToScale);
playedCardToShow = hitResult.item;
playedCardRotation = hitResult.item.rotation;
return;
}
//#endregion
//#region Setting up potential play
if (!isTurnToPlay) return null;
isFromHand = hand.flatten(2).includes(getCardAsNumberFromName(hitResult.item.name));
isFromExposedHand = exposedHand && exposedHand.flatten(2).includes(getCardAsNumberFromName(hitResult.item.name));
clickedOnItem = hitResult.item;
if (hitResult.item) cardName = hitResult.item.name;
if (!isExposedBottom && hitResult.item.name != null) {
cardRotation = hitResult.item.rotation;
newCenter = event.downPoint;
segment = null;
if (!hitResult || cardRotation !== 0) return;
hitResult.item.fullySelected = false;
previousRotation = hitResult.item.rotation;
project.activeLayer.addChild(hitResult.item);
// var clickedOnItem = deck[cardValuesOrder.findIndex(function (card) {return card.toLowerCase() === hitResult.item.name.toLowerCase()})];
if (clickedOnItem) {
clickedOnItem.rotation = 0;
if (i == 0) {
clickedOnItem.position = newCenter;
}
}
if (hitResult) {
if (hitResult.type == "segment") {
segment = hitResult.segment;
}
}
movePath = hitResult.type == "fill";
if (movePath) {
project.activeLayer.addChild(hitResult.item);
}
}
//#endregion
}
function onMouseDrag(event) {
var hitResult = project.hitTest(event.point, hitOptions);
if (hitResult === null && !clickedOnItem) {
return globals.touchStartHandler(event);
}
globals.removeTouchHandler(event);
if (roundEndAnimation) return null;
if (!isTurnToPlay) return null;
if (exposedHandLocation !== 'bottom' && cardRotation == 0 && clickedOnItem && clickedOnItem.name !== undefined) {
if (hitResult && hitResult.item && hitResult.item.name || (hitResult && pointsAreColocated(hitResult.item.bounds.center, event.point, 25))) {
if (hitResult && hitResult.item && hitResult.item.name && hitResult.item === clickedOnItem) {
project.activeLayer.addChild(hitResult.item);
hitResult.item.position += event.delta;
if (clickedOnItem) {
clickedOnItem.rotation = 0;
if (i == 0) {
clickedOnItem.position = newCenter;
}
i++;
}
}
}
else {
clickedOnItem = null;
if (hitResult && hitResult.item.name) redisplayHandArray(hitResult.item.name);
}
}
}
function onMouseUp(event) {
i = 0;
var hitResult = project.hitTest(event.point, hitOptions);
//#region Scaling Card Down if Scaled up for Vision
if (playedCardToShow) {
var desiredSize;
if (Math.round(playedCardRotation) === 0 || Math.round(playedCardRotation) === 180) {
desiredSize = isMobile ? smallCardHeight : cardHeight * playAreaShrinkFactor;
}
else {
desiredSize = isMobile ? smallCardWidth : cardWidth * playAreaShrinkFactor;
}
if (isHighAspectRatio) desiredSize *= highAspectRatioScaleFactor;
playedCardToShow.scale(desiredSize / playedCardToShow.bounds.height);
project.activeLayer.insertChild(previousLayerIndex, playedCardToShow);
playedCardToShow = null;
previousLayerIndex = null;
}
//#endregion
//#region Playing Card or Not
if (!hitResult || !clickedOnItem || !isTurnToPlay || roundEndAnimation) return null;
if (isValidPlay(hitResult)) {
if (hitResult.item) {
var cardAsNumber = getCardAsNumberFromName(hitResult.item.name);
if (typeof cardAsNumber !== 'number' || cardAsNumber === -1) return null;
var card = deck[cardAsNumber];
card.scale(isMobile ? (smallCardHeight / card.bounds.height) : (cardHeight / card.bounds.height));
if (isFromHand) card.position = bottomPlayArea.bounds.center;
if (isFromExposedHand) card.position = topPlayArea.bounds.center;
project.activeLayer.addChild(card);
globals.playCard(cardAsNumber);
}
return;
}
if (clickedOnItem && clickedOnItem.name || hitResult && hitResult.item.name) redisplayHandArray( !!clickedOnItem ? clickedOnItem.name : hitResult.item.name);
clickedOnItem = null;
//#endregion
}
function onMouseLeave(event) {
if (!event || !event.target) return null;
disableCardThinkingAnimation = false;
if (roundEndAnimation) return null;
if (!isTurnToPlay) return null;
var roundedEventHeight = Math.round(event.target.bounds.height * 100) / 100;
var roundedEventWidth = Math.round(event.target.bounds.width * 100) / 100;
if (roundedCardHeight !== roundedEventHeight || roundedCardWidth !== roundedEventWidth) {
redisplayHandArray(event.target.name);
return;
}
}
function onResize(isClientResize, cardsToLoad) {
// if (roundEndAnimation === true) return;
// topPlayAreaCard = null, bottomPlayAreaCard = null, rightPlayAreaCard = null, leftPlayAreaCard = null;
if (!loadComplete) return;
globals.saveInfoDivLocations();
globals.loadInfoDivLocations(exposedHandLocation);
setTimeout(function () {
globals.toggleDealInfoFullSize(isMobile);
}, 333);
// if (isClientResize) globals.resetInfoDivLocations();
project.clear();
shouldChangePlayableCards = true;
resetDisplayVariables();
initializeVariables();
if (cardHeight / canvasHeight >= cardHeightMaxPercent) {
cardHeight = cardHeightMaxPercent * canvasHeight;
cardWidth = cardHeight / 1.5;
shouldUseHeight = true;
}
generateDeckFromImages(cardsToLoad);
if (cardsToLoad) {
setTimeout(function () {
displayStuff(isClientResize);
}, waitToLoadNewTheme);
}
else displayStuff(isClientResize, null);
}
function displayStuff (isClientResize, cardsToLoad) {
display();
if (!isMobile && isClientResize) globals.callSetCanvasColors(cardsToLoad);
previousThinkingLocation = null;
}
function handleDoubleClick(hitResult) {
if (hitResult.item && hitResult.item.name) {
var cardNameAsString = hitResult.item.name;
if (lastClickedCard === cardNameAsString) {
globals.playCard(getCardAsNumberFromName(cardNameAsString))
lastClickedCard = null;
}
lastClickedCard = cardNameAsString;
setTimeout(function() {
lastClickedCard = null;
}, doubleClickInterval);
}
}
function onFrame(event) {
if (thinkingLocation) {
if (previousThinkingLocation !== thinkingLocation) {
previousThinkingLocation = thinkingLocation;
setCardsToAnimate();
setupSuitsForPlayAreaThinking();
frameCountForCardThinkingAnimation = 0;
frameCountForSuitThinkingAnimation = 0;
}
if (!disableCardThinkingAnimation || !isTurnToPlay) animateThinking();
animatePlayAreaThinking();
}
if(cardPlayAnimation && cardToPlayAsNumber !== undefined && cardToPlayAsNumber !== null && cardToPlayHandLocation) {
if (preferences.shouldAnimateCardPlay) animateCardPlay();
else {
skipCardPlayAnimation();
}
}
if (roundEndAnimation && waitForRoundEnd === true) {
if (needToSleepBeforeRoundEnd === true && hasEnteredRoundEndSleep === false) {
hasEnteredRoundEndSleep = true;
sleep(isLastPersonToPlay || !preferences.shouldAnimateCardPlay ? roundEndAnimationWaitDuration : 0).then(function () {
resetTimerLabels();
needToSleepBeforeRoundEnd = false;
});
}
else if (needToSleepBeforeRoundEnd === false) {
if (!preferences.shouldAnimateRoundEnd) waitForRoundEnd = false;
if (preferences.shouldAnimateRoundEnd) animateRoundEnd();
else {
skipRoundEndAnimation();
}
}
}
}
//#endregion
//#region Mobile Only Displaying Stuff
function displayHandsMobile() {
displayHandMobile(hand, exposedHandLocation.toLowerCase() !== cardDisplayLocations.bottom ? cardDisplayLocations.bottom : cardDisplayLocations.top);
displayHiddenHands();
if (!exposedHand) return;
var params = getParametersToDrawExposedHandMobile();
displayExposedHandMobile(params.startPoint, params.endPoint, params.desiredHeight, params.desiredSpacing, params.x);
}
function getParametersToDrawExposedHandMobile(){
var startPoint = topPlayArea.bounds.top - marginAmount * 3;
var endPoint = bottomPlayArea.bounds.bottom + marginAmount * 3;
var desiredHeight = getDesiredWidthOfCard(startPoint, endPoint, true);
var desiredSpacing = getSpacingForHand(startPoint, endPoint, desiredHeight * 2 / 3);
var x = desiredHeight / 4;
if (isExposedRight) {
x = canvasWidth - desiredHeight / 4;
}
return {
startPoint: startPoint,
endPoint: endPoint,
desiredHeight: desiredHeight,
desiredSpacing: desiredSpacing,
x: x,
}
}
function displayExposedHandMobile(startPoint, endPoint, desiredHeight, desiredSpacing, x) {
if (exposedHand === undefined || exposedHand === null) return;
var shouldWait = false;
var flatExposed = exposedHand.flatten(2);
for (var i = 0; i < flatExposed.length; i++) {
var card = deck[flatExposed[i]];
if (card.bounds.height === 0) {
shouldWait = true;
break;
}
}
if (isFirstTimeDisplayingExposedHandMobile && shouldWait) {
setTimeout(function () {
displayExposedHandMobile(startPoint, endPoint, desiredHeight, desiredSpacing, x);
}, checkCardLoadInterval);
}
else {
isFirstTimeDisplayingExposedHandMobile = false;
positionExposedHandsMobile(startPoint, endPoint, desiredHeight, desiredSpacing, x);
// setThinkingLocation();
}
}
function positionExposedHandsMobile(startPoint, endPoint, desiredHeight, desiredSpacing, x) {
if (exposedHand && isExposedLeft) {
placeCardsStartingAtPoint(exposedHand.flatten(2), x, startPoint, desiredHeight, smallCardHeight, desiredSpacing, 90, drawDirections.toBottom, orientationPoints.topRight, false, true);
}
else if (exposedHand && isExposedRight) {
placeCardsStartingAtPoint(exposedHand.flatten(2), x, endPoint, desiredHeight, smallCardHeight, desiredSpacing, 90, drawDirections.toTop, orientationPoints.bottomLeft, false, true);
}
else if (exposedHand && isExposedTop) {
displayHandMobile(exposedHand, exposedHandLocation);
}
else if (exposedHand && isExposedBottom) {
displayHandMobile(exposedHand, exposedHandLocation);
}
}
//#region Displaying Hand and ExposedHand
//right side up exposedhand but more space
function displayHandMobile(cardArray, location) {
if (cardArray === undefined || cardArray === null || location === undefined || location === null) return null;
//Setup for Card Placement
var widthFactor;
var exposedHandCardWidth, exposedHandCardHeight;
var previousX, previousY;
var expectedHandHeight;
var cardCount = cardArray.flatten(2).length;
var previousXStart, previousYStart, xSpacing, yLocation;
var k = 0;
//#region reversing suit order if drawing exposedhand on the right
if (location.toLowerCase() === cardDisplayLocations.right && isExposedRight && JSON.stringify(cardArray === JSON.stringify(exposedHand))) {
exposedHand.reverse();
}
//#endregion
//#region ExposedHand Top and Bottom Setup
if (location.toLowerCase() === cardDisplayLocations.top || location.toLowerCase() === cardDisplayLocations.bottom) {
exposedHandCardWidth = smallCardWidth;
exposedHandCardHeight = smallCardHeight;
widthFactor = widthFactorTopBottomMobile;
xSpacing = exposedHandCardWidth / 2;
if (location.toLowerCase() === cardDisplayLocations.top && isExposedTop) {
yLocation = exposedHandCardHeight / 2;
widthFactor = widthFactorTopBottomMobile;
}
else if (location.toLowerCase() === cardDisplayLocations.bottom && isExposedBottom) {
yLocation = canvasHeight + exposedHandCardHeight / nonHandCardHideFactor;
widthFactor = widthFactorTopBottomMobile;
}
else if (location.toLowerCase() === cardDisplayLocations.top && isExposedBottom) {
widthFactor = widthFactorTopBottomMobile;
xSpacing = exposedHandCardWidth / 2;
yLocation = exposedHandCardHeight / 2;
}
else if (location.toLowerCase() === cardDisplayLocations.top) {
widthFactor = widthFactorTopBottomMobile;
xSpacing = cardWidth / 2;
yLocation = cardHeight / 2;
}
else if (location.toLowerCase() === cardDisplayLocations.bottom) {
widthFactor = widthFactorTopBottomMobile;
xSpacing = cardWidth / 2;
yLocation = canvasHeight + amountOfBottomHandShownOffset;
}
}
//#endregion
//#region ExposedHand Left and Right Setup
else if (location.toLowerCase() === cardDisplayLocations.left || location.toLowerCase() === cardDisplayLocations.right) {
//#region Getting Start Y location
widthFactor = widthFactorLeftRightMobile;
expectedHandHeight = getExpectedHandHeight(smallCardWidth, cardCount, widthFactor);
ySpacing = cardWidth / 2;
previousYStart = greenSpaceCenter - expectedHandHeight / 2 - smallCardWidth / 3;
//#endregion
//#region Getting xLocation
if (location.toLowerCase() === cardDisplayLocations.left) xLocation = exposedHandLocation.toLowerCase() === location.toLowerCase() ? - smallCardHeight / nonHandCardHideFactor : - smallCardHeight / nonHandCardHideFactor;
else xLocation = exposedHandLocation.toLowerCase() === location.toLowerCase() ? canvasWidth + smallCardHeight / nonHandCardHideFactor : canvasWidth + smallCardHeight / nonHandCardHideFactor;
//#endregion
}
//#endregion
//this centers the top and bottom hands
widthOfHand = (cardCount - 1) * widthFactor + xSpacing * 2;
previousXStart = (widthOfHand >= canvasWidth) ? 0 : (canvasWidth - widthOfHand) / 2;
//#region Place the cards
for (var i = 0; i < cardCount; i++) {
var cardAsNumber = cardArray.flatten(2)[i];
//shrinking the card
if (location.toLowerCase() === exposedHandLocation.toLowerCase() || location.toLowerCase() === cardDisplayLocations.top && isExposedBottom) {
var card = deck[cardAsNumber];
if (needToScaleExposedHandMobile || location.toLowerCase() === exposedHandLocation.toLowerCase() && Math.round(smallCardHeight) !== Math.round(card.bounds.height) && Math.round(smallCardHeight) !== Math.round(card.bounds.width) ) {
card.scale(exposedHandShrinkAmountMobile);
}
}
//#region setting previousX and y
if (i === 0 ) {
previousX = previousXStart;
previousY = previousYStart;
}
else {
previousX = previousXStart + widthFactor * k;
previousY = previousYStart + widthFactor * k;
}
//#endregion
//#region Actually positioning the card
if (location.toLowerCase() === cardDisplayLocations.top || location.toLowerCase() === cardDisplayLocations.bottom) {
deck[cardAsNumber].position.x = previousX + xSpacing;
deck[cardAsNumber].position.y = yLocation;
}
else {
deck[cardAsNumber].position.y = previousY + ySpacing;
deck[cardAsNumber].position.x = xLocation;
deck[cardAsNumber].rotation = 0;
deck[cardAsNumber].rotate(location.toLowerCase() === cardDisplayLocations.left ? 90 : -90);
}
//#endregion
k++;
project.activeLayer.addChild(deck[cardAsNumber]);
}
//#endregion
//Setting Flag for scaling of exposedhand
if (location.toLowerCase() === exposedHandLocation.toLowerCase() || location.toLowerCase() === cardDisplayLocations.top && isExposedBottom) {
needToScaleExposedHandMobile = false;
}
//Relayering Exposed Hand on Right Side
if (isExposedRight && location.toLowerCase() === cardDisplayLocations.right) {
reverseHandLayerOrder(cardArray);
resizeCards(cardArray, smallCardHeight);
}
changePlayableCards();
}
//#endregion
//#region Displaying Hidden Cards Mobile
function getHiddenStartingPointMobile(cardCount, location) {
var hiddenCardHeight = smallCardHeight;
var hiddenCardWidth = smallCardWidth;
var widthTakenUpBySideHandsOffset = -hiddenCardHeight * 1.66;
widthTakenUpBySideHands = hiddenCardHeight - (hiddenCardHeight / 2 - (widthTakenUpBySideHandsOffset / nonHandCardHideFactor));
marginAmountMobile = (canvasWidth - hiddenCardHeight * 2 - widthTakenUpBySideHands * 2) / 4;
lengthOfHiddenHand = smallCardWidth + ((cardCount - 1) * widthFactorLeftRightMobile);
var leftRightY = greenSpaceCenter - lengthOfHiddenHand / 2 + hiddenCardWidth / 2;
var xOffset = (smallCardHeight * 2 - lengthOfHiddenHand) / 2 + 3 * widthFactorLeftRightMobile;
if (location.toLowerCase() === cardDisplayLocations.top) {
return {x: leftPlayArea.position.x - hiddenCardHeight / 2 + xOffset, y: -hiddenCardHeight / 3};
}
else if (location.toLowerCase() === cardDisplayLocations.left || location.toLowerCase() === cardDisplayLocations.bottomLeft) {
return {x: widthTakenUpBySideHandsOffset / nonHandCardHideFactor, y: leftRightY};
}
else if (location.toLowerCase() === cardDisplayLocations.right || location.toLowerCase() === cardDisplayLocations.bottomRight) {
return {x: canvasWidth - widthTakenUpBySideHandsOffset / nonHandCardHideFactor, y: leftRightY};
}
}
//#endregion
//#endregion
//#region Full-size Only Displaying Stuff
function displayCards() {
displayHandAsLine();
if (exposedHand !== null) displayExposedHand();
alreadyRotated = true;
}
//#region displayExposedHand Functions
function displayExposedHand () {
if (exposedHand === undefined || exposedHand === null) return;
cardWidth *= exposedHandSizeFactor;
cardHeight *= exposedHandSizeFactor;
resize = false;
exposedHandCardHeight = cardHeight;
exposedHandCardWidth = cardWidth;
calculateExposedHandHeightAndWidth();
enoughHeightToDisplay = setHeightAvailable(exposedHandLocation);
enoughWidthToDisplay = setWidthAvailable(exposedHandLocation);
resizeExposedHandCards();
positionCards(exposedHand, exposedHandCardHeight, exposedHandLocation);
cardWidth /= exposedHandSizeFactor;
cardHeight /= exposedHandSizeFactor;
changePlayableCards();
}
//#region calculateExposedHandHeightAndWidth Functions
function calculateExposedHandHeightAndWidth() {
numberOfSuits = getNumberOfSuits(exposedHand);
numberOfSpacesBetweenCards = getNumberOfSpacesBetweenCards(exposedHand);
exposedHandWidthSpacing = cardWidth / exposedHandCardWidthSpacingScaleFactor;
exposedHandHeightSpacing = cardHeight / exposedHandCardHeightSpacingScaleFactor;
if (isExposedTop || isExposedBottom) {
exposedHandWidth = cardWidth * numberOfSuits + ((numberOfSuits - 1) * exposedHandWidthSpacing);
exposedHandHeight = cardHeight + (numberOfSpacesBetweenCards * exposedHandHeightSpacing);
}
else if (isExposedLeft || isExposedRight) {
exposedHandWidth = cardHeight + (numberOfSpacesBetweenCards * exposedHandHeightSpacing);
exposedHandHeight = cardWidth * numberOfSuits + ((numberOfSuits - 1) * exposedHandWidthSpacing);
}
else {
throw "exposedHandLocation is invalid: " + exposedHandLocation;
}
}
function getNumberOfSuits(hand) {
if (hand === undefined || hand === null) return;
var numberOfSuits = 0;
for (var i = 0; i < hand.length; i++) {
var suit = hand[i];
for (var j = 0; j < suit.length; j++) {
var card = suit[j];
if (card >= 0 && card <= 51) {
numberOfSuits++;
break;
}
}
}
return numberOfSuits;
}
function getNumberOfSpacesBetweenCards(hand) {
if (hand === undefined || hand === null) return;
var longestSuitLength = 0;
for (var i = 0; i < hand.length; i++) {
var suit = hand[i];
if (suit[0] >= 0 && suit[0] <= 51) {
if (suit.length > longestSuitLength) {
longestSuitLength = suit.length;
}
}
}
return longestSuitLength - 1;
}
//#endregion
function setHeightAvailable(location) {
if (location.toLowerCase() === 'top') {
heightAvailable = topPlayArea.bounds.topLeft.y - marginAmount;
return heightAvailable >= exposedHandHeight;
}
else if (location.toLowerCase() === 'bottom') {
heightAvailable = canvasHeight - (bottomPlayArea.bounds.bottomRight.y + marginAmount);
return heightAvailable >= exposedHandHeight;
}
else if (location.toLowerCase() === 'left'){
heightAvailable = leftPlayArea.bounds.topLeft.x;
;
return heightAvailable >= exposedHandWidth;
}
else if (location.toLowerCase() === 'right') {
heightAvailable = canvasWidth - rightPlayArea.bounds.topRight.x;
return heightAvailable >= exposedHandWidth;
}
else {
throw "exposedHandLocation is invalid: " + exposedHandLocation;
}
}
function setWidthAvailable(location) {
if (location.toLowerCase() === 'top') {
widthAvailable = canvasWidth;
return widthAvailable >= exposedHandWidth;
}
else if (location.toLowerCase() === 'bottom') {
widthAvailable = canvasWidth;
return widthAvailable >= exposedHandWidth;
}
else if (location.toLowerCase() === 'left'){
widthAvailable = bottomPlayArea.bounds.bottomRight.y;
return widthAvailable >= exposedHandHeight;
}
else if (location.toLowerCase() === 'right') {
widthAvailable = bottomPlayArea.bounds.bottomRight.y;
return widthAvailable >= exposedHandHeight;
}
else {
throw "exposedHandLocation is invalid: " + exposedHandLocation;
}
}
function resizeExposedHandCards() {
// console.log('resizeExposedHandCards------------------------');
resize = true;
var proposedHeight1 = 10000, proposedHeight2 = 10000;
if (!enoughWidthToDisplay) {
var proposedWidth = widthAvailable / ((numberOfSuits - 1) / exposedHandCardWidthSpacingScaleFactor + numberOfSuits);
proposedHeight1 = proposedWidth * (1 / cardWidthFactor);
}
if (!enoughHeightToDisplay) {
proposedHeight2 = heightAvailable / ((1 + (numberOfSpacesBetweenCards / 5.5)) + (cardWidthFactor / exposedHandCardWidthSpacingScaleFactor));
}
if (!enoughHeightToDisplay || !enoughWidthToDisplay) exposedHandCardHeight = proposedHeight1 >= proposedHeight2 ? proposedHeight2 : proposedHeight1;
else exposedHandCardHeight = cardHeight;
exposedHandCardWidth = exposedHandCardHeight * cardWidthFactor;
exposedHandWidthSpacing = exposedHandCardWidth / exposedHandCardWidthSpacingScaleFactor;
exposedHandHeightSpacing = exposedHandCardHeight / exposedHandCardHeightSpacingScaleFactor;
if (isExposedBottom || isExposedTop) {
exposedHandHeight = exposedHandCardHeight + (getNumberOfSpacesBetweenCards(exposedHand) * exposedHandHeightSpacing);
exposedHandWidth = exposedHandCardWidth * numberOfSuits + ((numberOfSuits - 1) * exposedHandWidthSpacing);
}
else if (isExposedLeft || isExposedRight) {
exposedHandWidth = exposedHandCardHeight + (getNumberOfSpacesBetweenCards(exposedHand) * exposedHandHeightSpacing);
exposedHandHeight = exposedHandCardWidth * numberOfSuits + ((numberOfSuits - 1) * exposedHandWidthSpacing);
}
if (exposedHandCardHeight / cardHeight >= minExposedHandSize) resizeCards(exposedHand, exposedHandCardHeight, cardHeight / exposedHandSizeFactor);
}
function positionCards(cardsArray, height, location) {
if (cardsArray === undefined || cardsArray === null) return null;
if (exposedHandCardHeight / cardHeight >= minExposedHandSize) {
placeCardsInColumns(cardsArray, height, location);
}
else {
if (isExposedTop) {
var y = topPlayArea.bounds.top - marginAmount;
var startPoint = leftPlayArea.bounds.left;
var endPoint = rightPlayArea.bounds.right;
var desiredHeight = getDesiredWidthOfCard(startPoint, endPoint, true);
var desiredSpacing = getSpacingForHand(startPoint, endPoint, desiredHeight * 2 / 3);
placeCardsStartingAtPoint(exposedHand, startPoint, y, desiredHeight, cardHeight / exposedHandSizeFactor, desiredSpacing, 0, drawDirections.toRight, orientationPoints.bottomLeft);
}
else if (isExposedBottom) {
var y = bottomPlayArea.bounds.bottom + marginAmount;
var startPoint = leftPlayArea.bounds.left;
var endPoint = rightPlayArea.bounds.right;
var desiredHeight = getDesiredWidthOfCard(startPoint, endPoint, true);
var desiredSpacing = getSpacingForHand(startPoint, endPoint, desiredHeight * 2 / 3);
placeCardsStartingAtPoint(exposedHand, startPoint, y, desiredHeight, cardHeight / exposedHandSizeFactor, desiredSpacing, 0, drawDirections.toRight, orientationPoints.topLeft);
}
else if (isExposedLeft) {
var x = leftPlayArea.bounds.topLeft.x - marginAmount;
var startPoint = topPlayArea.bounds.top;
var endPoint = bottomPlayArea.bounds.bottom;
var desiredHeight = getDesiredWidthOfCard(startPoint, endPoint, true);
var desiredSpacing = getSpacingForHand(startPoint, endPoint, desiredHeight * 2 / 3);
placeCardsStartingAtPoint(exposedHand.flatten(2).reverse(), x, endPoint, desiredHeight, cardHeight / exposedHandSizeFactor, desiredSpacing, 90, drawDirections.toTop, orientationPoints.bottomRight, true);
}
else if (isExposedRight) {
var x = rightPlayArea.bounds.right + marginAmount;
var startPoint = topPlayArea.bounds.top;
var endPoint = bottomPlayArea.bounds.bottom;
var desiredHeight = getDesiredWidthOfCard(startPoint, endPoint, true);
var desiredSpacing = getSpacingForHand(startPoint, endPoint, desiredHeight * 2 / 3);
placeCardsStartingAtPoint(exposedHand, x, endPoint, desiredHeight, cardHeight / exposedHandSizeFactor, desiredSpacing, -90, drawDirections.toTop, orientationPoints.bottomLeft);
}
}
}
function getCenteringOffset(cardCount, desiredWidth, spacing) {
if (cardCount === undefined || cardCount === null || desiredWidth === undefined || desiredWidth === null || spacing === undefined || spacing === null) return 0;
var fullSizeHandWidth = getHandWidth(13, desiredWidth, spacing);
var currentHandWidth = getHandWidth(cardCount, desiredWidth, spacing);
return Math.abs(currentHandWidth - fullSizeHandWidth) / 2;
}
function placeCardsStartingAtPoint(handArray, startingX, startingY, desiredCardHeight, currentCardHeight, spacing, rotation, drawDirection, orientationPoint, reverseLayingOrder, centerAroundStartingPoints) {
// console.log('desiredCardHeight in placeCardsStartingAtPoint =', desiredCardHeight);
if (handArray === undefined || handArray === null || startingX === undefined || startingX === null || startingY === undefined || startingY === null) return;
desiredCardHeight = (desiredCardHeight == undefined) ? cardHeight : desiredCardHeight;
spacing = (spacing == undefined) ? cardWidth * handWidthSpacingPercentOfCardWidth : spacing;
orientationPoint = (orientationPoint == undefined) ? orientationPoints.center : orientationPoint;
currentCardHeight = (currentCardHeight == undefined) ? cardHeight : currentCardHeight;
centerAroundStartingPoints = (centerAroundStartingPoints == undefined) ? false : centerAroundStartingPoints;
var reverseLayingOrder = (reverseLayingOrder == undefined) ? false : reverseLayingOrder;
var flatHand = handArray.flatten(2);
var desiredAsDecimalPercentageOfNormalHeight = desiredCardHeight / currentCardHeight;
var desiredCardHeight = desiredAsDecimalPercentageOfNormalHeight * currentCardHeight;
var desiredCardWidth = desiredCardHeight * cardWidthFactor;
var widthAdjustment = desiredCardWidth / 2;
var heightAdjustment = desiredCardHeight / 2;
var centeringAmount = 0;
if (rotation === 90 || rotation === -90) {
widthAdjustment = desiredCardHeight / 2;
heightAdjustment = desiredCardWidth / 2;
}
for (var i = 0; i < flatHand.length; i++) {
var cardAsNumber = flatHand[i];
var card;
if (typeof cardAsNumber === 'object') {
card = cardAsNumber;
card.rotation = 0;
}
else card = deck[cardAsNumber];
// card.scale(desiredAsDecimalPercentageOfNormalHeight);
var heightToUse = (card && card.bounds && card.bounds.height === 0) ? currentCardHeight : card.bounds.height;
card.scale(desiredCardHeight / heightToUse);
if (card.rotation !== rotation) {
card.rotation = 0;
card.rotate(rotation, card.bounds[orientationPoint]);
}
if (centerAroundStartingPoints) centeringAmount = getCenteringOffset(flatHand.length, desiredCardHeight * 2 / 3, spacing);
if (drawDirection === drawDirections.toTop) {
if (orientationPoint === orientationPoints.topLeft) {
card.position.x = startingX + widthAdjustment;
card.position.y = startingY - i * spacing + heightAdjustment - centeringAmount;
}
else if (orientationPoint === orientationPoints.topRight) {
card.position.x = startingX - widthAdjustment;
card.position.y = startingY - i * spacing + heightAdjustment - centeringAmount;
}
else if (orientationPoint === orientationPoints.bottomLeft) {
card.position.x = startingX + widthAdjustment;
card.position.y = startingY - i * spacing - heightAdjustment - centeringAmount;
}
else if (orientationPoint === orientationPoints.bottomRight) {
card.position.x = startingX - widthAdjustment;
card.position.y = startingY - i * spacing - heightAdjustment - centeringAmount;
}
else if (orientationPoint === orientationPoints.center) {
card.position.x = startingX;
card.position.y = startingY - i * spacing - centeringAmount;
}
}
else if (drawDirection === drawDirections.toBottom) {
if (orientationPoint === orientationPoints.topLeft) {
card.position.x = startingX + widthAdjustment;
card.position.y = startingY + i * spacing + heightAdjustment + centeringAmount;
}
else if (orientationPoint === orientationPoints.topRight) {
card.position.x = startingX - widthAdjustment;
card.position.y = startingY + i * spacing + heightAdjustment + centeringAmount;
}
else if (orientationPoint === orientationPoints.bottomLeft) {
card.position.x = startingX + widthAdjustment;
card.position.y = startingY + i * spacing - heightAdjustment + centeringAmount;
}
else if (orientationPoint === orientationPoints.bottomRight) {
card.position.x = startingX - widthAdjustment;
card.position.y = startingY + i * spacing - heightAdjustment + centeringAmount;
}
else if (orientationPoint === orientationPoints.center) {
card.position.x = startingX;
card.position.y = startingY + i * spacing + centeringAmount;
}
}
else if (drawDirection === drawDirections.toLeft) {
if (orientationPoint === orientationPoints.topLeft) {
card.position.x = startingX - i * spacing + widthAdjustment - centeringAmount;
card.position.y = startingY + heightAdjustment;
}
else if (orientationPoint === orientationPoints.topRight) {
card.position.x = startingX - i * spacing - widthAdjustment - centeringAmount;
card.position.y = startingY + heightAdjustment;
}
else if (orientationPoint === orientationPoints.bottomLeft) {
card.position.x = startingX - i * spacing + widthAdjustment - centeringAmount;
card.position.y = startingY - heightAdjustment;
}
else if (orientationPoint === orientationPoints.bottomRight) {
card.position.x = startingX - i * spacing - widthAdjustment - centeringAmount;
card.position.y = startingY - heightAdjustment;
}
else if (orientationPoint === orientationPoints.center) {
card.position.x = startingX - i * spacing - centeringAmount;
card.position.y = startingY;
}
}
else if (drawDirection === drawDirections.toRight) {
if (orientationPoint === orientationPoints.topLeft) {
card.position.x = startingX + i * spacing + widthAdjustment + centeringAmount;
card.position.y = startingY + heightAdjustment;
}
else if (orientationPoint === orientationPoints.topRight) {
card.position.x = startingX + i * spacing - widthAdjustment + centeringAmount;
card.position.y = startingY + heightAdjustment;
}
else if (orientationPoint === orientationPoints.bottomLeft) {
card.position.x = startingX + i * spacing + widthAdjustment + centeringAmount;
card.position.y = startingY - heightAdjustment;
}
else if (orientationPoint === orientationPoints.bottomRight) {
card.position.x = startingX + i * spacing - widthAdjustment + centeringAmount;