Changes to cardSize

feature/clientSideSimplify
Nathan Steel 1 year ago
parent fc2784fec8
commit 1f3758faed

@ -59,14 +59,14 @@ function calculateDeckPositions(){
// Set position for player deck // Set position for player deck
case gameData.playerId: case gameData.playerId:
gameData.position[key] = [canvas.width-cardWidth*1.5-40, canvas.height-cardHeight*1.5-60]; // X/Y gameData.position[key] = [canvas.width-cardWidth-40, canvas.height-cardHeight-60]; // X/Y
gameData.size[key] = [cardWidth*1.5, cardHeight*1.5]; gameData.size[key] = [cardWidth, cardHeight];
break; break;
// Same for opponent. This will need redoing when 2v2,4v1,etc. are added // Same for opponent. This will need redoing when 2v2,4v1,etc. are added
case gameData.opponentId: case gameData.opponentId:
gameData.position[key] = [40, 60]; // X/Y gameData.position[key] = [40, 60]; // X/Y
gameData.size[key] = [cardWidth*1.5, cardHeight*1.5]; gameData.size[key] = [cardWidth, cardHeight];
break; break;
} }
@ -89,10 +89,10 @@ function calculateHandPositions(){
let positionInHand = gameData.listPosition[key]; let positionInHand = gameData.listPosition[key];
gameData.position[key] = [ gameData.position[key] = [
canvas.width/2 - (cardWidth * (cardsInHand - (positionInHand+1)) - (cardMargin * (positionInHand+1))) canvas.width/2 - ((cardWidth * handScale) * (cardsInHand - (positionInHand+1)) - (cardMargin * (positionInHand+1)))
,canvas.height-cardWidth*1.5-20 ,canvas.height-(cardHeight * handScale)-20
]; ];
gameData.size[key] = [cardWidth, cardHeight]; gameData.size[key] = [cardWidth * handScale, cardHeight * handScale];
break; break;
// Opponent, currently done in fakeHand // Opponent, currently done in fakeHand
@ -102,10 +102,11 @@ function calculateHandPositions(){
} }
// TODO: Move this function elsewhere, not really a draw function // TODO: Move this function elsewhere, not really a draw function
function calculateCardSpacing(){ function calculateCardSpacing(positionInt, size, standardSize){
let scaleMultiplier = size/standardSize;
return positionInt * scaleMultiplier;
// TEMP: these spaces should live elsewhere (likely global)
let namePosition = 5;
} }
@ -162,16 +163,12 @@ function drawDeck(entity){
} }
function drawCardInHand(entity){ function drawCardInHand(entity){
console.log('Draw card in hand');
console.log(gameData.position[entity]);
console.log(gameData.size[entity]);
// TODO: Tapped, Attacking, Targettable, Activatable borders // TODO: Tapped, Attacking, Targettable, Activatable borders
// TODO: Change card colour based on its colours // TODO: Change card colour based on its colours
// TODO: Not for hand, but cards on board need flight, etc. // TODO: Not for hand, but cards on board need flight, etc.
// Draw the deck shape // Draw the card shape
let shape = new Shape({ let shape = new Shape({
x: gameData.position[entity][0], x: gameData.position[entity][0],
y: gameData.position[entity][1], y: gameData.position[entity][1],
@ -209,26 +206,29 @@ function drawCardImage(entity){
// Create the clipping shape // Create the clipping shape
let cardImageContainer = new Shape({ let cardImageContainer = new Shape({
shape: 'unit', shape: 'unit',
x: positionX+height/3, x: positionX+width*.5, // Center (probably change to an int in future)
y: positionY+width/2, y: positionY+calculateCardSpacing(65, height, cardHeight),
width: width*.9, width: calculateCardSpacing(100, width, cardWidth),
height: height*.9 height: calculateCardSpacing(150, height, cardHeight)
}); });
// Save canvas drawing, start the clip // Save canvas drawing, start the clip
cardImageContainer.startClip(); cardImageContainer.startClip();
// Print the image to canvas, within the clipping mask
positionX = gameData.position[entity][0];
positionY = gameData.position[entity][1];
width = gameData.size[entity][0];
height = gameData.size[entity][1];
// Draw the image into the clipping mask // Draw the image into the clipping mask
// image, dx,dy,dw,dh // image, dx,dy,dw,dh
// image, sx,sy, sw,sh,dx,dy,dw,dh // image, sx,sy, sw,sh,dx,dy,dw,dh
// TODO: give cards/cardData a sprite position and use it [0,0], [1,0], [1,4], etc... // TODO: give cards/cardData a sprite position and use it [0,0], [1,0], [1,4], etc...
let spriteSheetX = 80;//*cardSprite[entity][0]; let spriteSheetX = 80;//*cardSprite[entity][0];
let spriteSheetY = 120;//*cardSprite[entity][1]; let spriteSheetY = 120;//*cardSprite[entity][1];
ctx.drawImage(cardArt, spriteSheetX,spriteSheetY, 80,120,positionX,positionY,width,height); ctx.drawImage(cardArt, spriteSheetX,spriteSheetY
,80
,120
,positionX
,positionY
,width
,height
);
// Restore the canvas draw post clip applied, to get everything else back too // Restore the canvas draw post clip applied, to get everything else back too
cardImageContainer.endClip(); cardImageContainer.endClip();
@ -378,11 +378,11 @@ function drawFakeHand(){
,0 // Y Position From in Spritesheet ,0 // Y Position From in Spritesheet
,80 // Width of image selection from Spritesheet ,80 // Width of image selection from Spritesheet
,120 // Height of image selection from Spritesheet ,120 // Height of image selection from Spritesheet
,canvas.width/2 - (cardWidth * (itemListLength - (i+1)) - (cardMargin * (i+1))) ,canvas.width/2 - ((cardWidth*handScale) * (itemListLength - (i+1)) - (cardMargin * (i+1)))
// X // X
,20 // Y ,20 // Y
,cardWidth // Width ,cardWidth*handScale // Width
,cardHeight // Height ,cardHeight*handScale // Height
); );
} }
break; break;

@ -1,8 +1,8 @@
const socket = io({autoConnect: false}); const socket = io({autoConnect: false});
const canvas = document.getElementById('canvas');; const canvas = document.getElementById('canvas');;
const cardWidth = 80; const cardWidth = 120; // 240px ~2.5 inch WAS 80 x3 (halfed for display)
const cardHeight = 120; const cardHeight = 168; // 336px ~3.5 inch WAS 120 x2.8 (halfed for display)
const cardArt = new Image(); const cardArt = new Image();
const cardBackArt = new Image(); const cardBackArt = new Image();
@ -36,3 +36,4 @@ const maxShield = 2;
const cardMargin = 10; const cardMargin = 10;
const handScale = .75;

Loading…
Cancel
Save