new frames

This commit is contained in:
Kyle
2021-01-07 17:08:05 -08:00
parent d13e57dae6
commit 8a55e257b3
190 changed files with 153 additions and 15 deletions

View File

@@ -215,16 +215,30 @@ loadManaSymbols(['chaos'], [1, 10.2]);
function loadManaSymbols(manaSymbolPaths, size = [1, 1]) {
manaSymbolPaths.forEach(item => {
var manaSymbol = {};
manaSymbol.name = item.split('.')[0];
if (typeof item == 'string') {
manaSymbol.name = item.split('.')[0];
manaSymbol.path = item;
} else {
manaSymbol.name = item[0].split('.')[0];
manaSymbol.path = item[0];
}
if (manaSymbol.name.includes('/')) {
manaSymbol.name = manaSymbol.name.split('/');
manaSymbol.name = manaSymbol.name[manaSymbol.name.length - 1];
}
if (typeof item != 'string') {
manaSymbol.back = item[1];
manaSymbol.backs = item[2];
for (var i = 0; i < item[2]; i ++) {
loadManaSymbols([manaSymbol.path.replace(manaSymbol.name, 'back' + i + item[1])])
// console.log(manaSymbol.path.replace(manaSymbol.name, 'back' + i + item[1]))
}
}
manaSymbol.width = size[0];
manaSymbol.height = size[1];
manaSymbol.image = new Image();
manaSymbol.image.crossOrigin = 'anonymous';
var manaSymbolPath = '/img/manaSymbols/' + item;
var manaSymbolPath = '/img/manaSymbols/' + manaSymbol.path;
if (!manaSymbolPath.includes('.png')) {
manaSymbolPath += '.svg';
}
@@ -499,6 +513,9 @@ function writeText(textObject, targetContext) {
}
var splitText = rawText.replace(/\n/g, '{line}').replace('{flavor}', '{lns}{bar}{lns}{i}').replace(/{/g, splitString + '{').replace(/}/g, '}' + splitString).replace(/ /g, splitString + ' ' + splitString).split(splitString);
splitText = splitText.filter(item => item);
if (textManaCost && textObject.arcStart > 0) {
splitText.reverse();
}
splitText.push('');
//Manages the redraw loop
var drawingText = true;
@@ -512,6 +529,16 @@ function writeText(textObject, targetContext) {
var textShadowOffsetX = scaleWidth(textObject.shadowX) || 0;
var textShadowOffsetY = scaleHeight(textObject.shadowY) || 0;
var textShadowBlur = scaleHeight(textObject.shadowBlur) || 0;
var textArcRadius = scaleHeight(textObject.arcRadius) || 0;
if (textArcRadius > 0) {
//Buffers the canvases accordingly
var canvasMargin = 300 + textArcRadius;
paragraphCanvas.width = textWidth + 2 * canvasMargin;
paragraphCanvas.height = textHeight + 2 * canvasMargin;
lineCanvas.width = textWidth + 2 * canvasMargin;
lineCanvas.height = startingTextSize + 2 * canvasMargin;
}
var textArcStart = textObject.arcStart || 0;
//Variables for tracking text position/size/font
var currentX = 0;
var startingCurrentX = 0;
@@ -643,6 +670,10 @@ function writeText(textObject, targetContext) {
}
} else if (possibleCode.includes('permashift')) {
permaShift = [parseFloat(possibleCode.replace('permashift', '').split(',')[0]), parseFloat(possibleCode.split(',')[1])];
} else if (possibleCode.includes('arcradius')) {
textArcRadius = parseInt(possibleCode.replace('arcradius', '')) || 0;
} else if (possibleCode.includes('arcstart')) {
textArcStart = parseFloat(possibleCode.replace('arcstart', '')) || 0;
} else if (findManaSymbolIndex(possibleCode.replace('/', '')) > -1 || findManaSymbolIndex(possibleCode.replace('/', '').split('').reverse().join('')) > -1) {
var manaSymbol = manaSymbols[findManaSymbolIndex(possibleCode.replace('/', ''))] || manaSymbols[findManaSymbolIndex(possibleCode.replace('/', '').split('').reverse().join(''))];
var manaSymbolSpacing = textSize * 0.04 + textManaSpacing;
@@ -656,12 +687,28 @@ function writeText(textObject, targetContext) {
currentY = scaleY(textObject.manaPlacement.y[manaPlacementCounter] || 0);
manaPlacementCounter ++;
newLine = true;
} else if (textObject.manaLayout) {
}
//fake shadow begins
var fakeShadow = lineCanvas.cloneNode();
var fakeShadowContext = fakeShadow.getContext('2d');
fakeShadowContext.clearRect(0, 0, fakeShadow.width, fakeShadow.height);
fakeShadowContext.drawImage(manaSymbol.image, manaSymbolX, manaSymbolY, manaSymbolWidth, manaSymbolHeight);
var backImage = null;
if (manaSymbol.backs) {
backImage = manaSymbols[findManaSymbolIndex('back' + Math.floor(Math.random() * manaSymbol.backs) + manaSymbol.back)].image;
}
if (textArcRadius > 0) {
if (manaSymbol.backs) {
fakeShadowContext.drawImageArc(backImage, manaSymbolX, manaSymbolY, manaSymbolWidth, manaSymbolHeight, textArcRadius, textArcStart, currentX);
}
fakeShadowContext.drawImageArc(manaSymbol.image, manaSymbolX, manaSymbolY, manaSymbolWidth, manaSymbolHeight, textArcRadius, textArcStart, currentX);
} else {
if (manaSymbol.backs) {
fakeShadowContext.drawImage(backImage, manaSymbolX, manaSymbolY, manaSymbolWidth, manaSymbolHeight);
}
fakeShadowContext.drawImage(manaSymbol.image, manaSymbolX, manaSymbolY, manaSymbolWidth, manaSymbolHeight);
}
lineContext.drawImage(fakeShadow, 0, 0);
//fake shadow ends (thanks, safari)
currentX += manaSymbolWidth + manaSymbolSpacing * 2;
@@ -669,7 +716,7 @@ function writeText(textObject, targetContext) {
wordToWrite = word;
}
}
if (wordToWrite && lineContext.measureText(wordToWrite).width + currentX >= textWidth) {
if (wordToWrite && lineContext.measureText(wordToWrite).width + currentX >= textWidth && textArcRadius == 0) {
if (textOneLine && startingTextSize > 1) {
//doesn't fit... try again at a smaller text size?
startingTextSize -= 1;
@@ -693,13 +740,17 @@ function writeText(textObject, targetContext) {
newLine = false;
}
if (wordToWrite && (currentX != 0 || wordToWrite != ' ') && !textManaCost) {
if (textOutlineWidth >= 1) {
lineContext.strokeText(wordToWrite, currentX + canvasMargin, canvasMargin + textSize * textFontHeightRatio + lineY);
if (textArcRadius > 0) {
lineContext.fillTextArc(wordToWrite, currentX + canvasMargin, canvasMargin + textSize * textFontHeightRatio + lineY, textArcRadius, textArcStart, currentX, textOutlineWidth);
} else {
if (textOutlineWidth >= 1) {
lineContext.strokeText(wordToWrite, currentX + canvasMargin, canvasMargin + textSize * textFontHeightRatio + lineY);
}
lineContext.fillText(wordToWrite, currentX + canvasMargin, canvasMargin + textSize * textFontHeightRatio + lineY);
}
lineContext.fillText(wordToWrite, currentX + canvasMargin, canvasMargin + textSize * textFontHeightRatio + lineY);
currentX += lineContext.measureText(wordToWrite).width;
}
if (currentY > textHeight && textBounded && !textOneLine && startingTextSize > 1) {
if (currentY > textHeight && textBounded && !textOneLine && startingTextSize > 1 && textArcRadius == 0) {
//doesn't fit... try again at a smaller text size?
startingTextSize -= 1;
continue outerloop;
@@ -716,6 +767,30 @@ function writeText(textObject, targetContext) {
}
}
}
CanvasRenderingContext2D.prototype.fillTextArc = function(text, x, y, radius, startRotation, distance = 0, outlineWidth = 0) {
this.save();
this.translate(x - distance + scaleWidth(0.5), y + radius);
this.rotate(startRotation + widthToAngle(distance, radius));
for (var i = 0; i < text.length; i++) {
var letter = text[i];
if (outlineWidth >= 1) {
this.strokeText(letter, 0, -radius);
}
this.fillText(letter, 0, -radius);
this.rotate(widthToAngle(this.measureText(letter).width, radius));
}
this.restore();
}
CanvasRenderingContext2D.prototype.drawImageArc = function(image, x, y, width, height, radius, startRotation, distance = 0) {
this.save();
this.translate(x - distance + scaleWidth(0.5), y + radius);
this.rotate(startRotation + widthToAngle(distance, radius));
this.drawImage(image, 0, -radius, width, height);
this.restore();
}
function widthToAngle(width, radius) {
return width / radius;
}
//ART TAB
function uploadArt(imageSource, otherParams) {
art.src = imageSource;

3
js/frames/groupCustom.js Normal file
View File

@@ -0,0 +1,3 @@
loadFramePacks([
{name:'Cartoony - Sheepwave', value:'Cartoony'}
])

View File

@@ -1,4 +1,5 @@
loadFramePacks([
{name:'Kaldheim', value:'Kaldheim'},
{name:'Commander Legends', value:'CommanderLegends'},
{name:'Zendikar Rising', value:'ZendikarRising'},
{name:'M21', value:'M21'},

View File

@@ -0,0 +1,14 @@
//checks to see if it needs to run
if (!card.manaSymbols.includes('/js/frames/manaSymbolsCartoony.js')) {
card.manaSymbols.push('/js/frames/manaSymbolsCartoony.js');
}
if (findManaSymbolIndex('cw') == -1) {
loadManaSymbols([
['cartoony/cw.png', 'cw', 4], ['cartoony/cu.png', 'cu', 4], ['cartoony/cb.png', 'cb', 4], ['cartoony/cr.png', 'cr', 4], ['cartoony/cg.png', 'cg', 4],
['cartoony/c0.png', 'cc', 15], ['cartoony/c1.png', 'cc', 15], ['cartoony/c2.png', 'cc', 15], ['cartoony/c3.png', 'cc', 15], ['cartoony/c4.png', 'cc', 15],
['cartoony/c5.png', 'cc', 15], ['cartoony/c6.png', 'cc', 15], ['cartoony/c7.png', 'cc', 15], ['cartoony/c8.png', 'cc', 15], ['cartoony/c9.png', 'cc', 15],
['cartoony/c10.png', 'cc', 15], ['cartoony/c11.png', 'cc', 15], ['cartoony/c12.png', 'cc', 15], ['cartoony/c13.png', 'cc', 15], ['cartoony/c14.png', 'cc', 15],
['cartoony/c15.png', 'cc', 15], ['cartoony/c16.png', 'cc', 15], ['cartoony/c17.png', 'cc', 15], ['cartoony/c18.png', 'cc', 15], ['cartoony/c19.png', 'cc', 15],
['cartoony/cc.png', 'cc', 15], ['cartoony/ct.png', 'cdark', 1], ['cartoony/cx.png', 'cc', 15], ['cartoony/cy.png', 'cc', 15], ['cartoony/cz.png', 'cc', 15],
]);
}

32
js/frames/packCartoony.js Normal file
View File

@@ -0,0 +1,32 @@
//defines available frames
availableFrames = [{src:'/img/frames/m15/regular/m15FrameA.png', name:'unnamed'}];
//disables/enables the "Load Frame Version" button
document.querySelector('#loadFrameVersion').disabled = false;
//defines process for loading this version, if applicable
document.querySelector('#loadFrameVersion').onclick = async function() {
//resets things so that every frame doesn't have to
await resetCardIrregularities();
//sets card version
card.version = 'cartoony';
loadScript('/js/frames/manaSymbolsCartoony.js');
// notify('The Future version adds special mana symbols. To use them, place an "F" before the following mana symbols: wubrg, 0-20, x, and hybrid mana symbols.');
//art bounds
card.artBounds = {x:0.0767, y:0.1129, width:0.8476, height:0.4429};
autoFitArt();
//set symbol bounds
card.setSymbolBounds = {x:0.9213, y:0.5910, width:0.12, height:0.0410, vertical:'center', horizontal: 'right'};
resetSetSymbol();
//watermark bounds
card.watermarkBounds = {x:0.5, y:0.7762, width:0.75, height:0.2305};
resetWatermark();
//text
loadTextOptions({
mana: {name:'Mana Cost', text:'', y:0.01, oneLine:true, size:180/1638, manaCost:true, manaSpacing:-0.11, noVerticalCenter:true, arcRadius:2, arcStart:0.165},
title: {name:'Title', y:0.02, text:'', oneLine:true, font:'Acme-Regular', size:0.081, arcRadius:2, arcStart:-0.165, noVerticalCenter:true, outlineWidth:0.0048, color:'white'}, //, x:0.0854, width:0.8292, height:0.0543
type: {name:'Type', text:'', x:0.0854, y:0.5664, width:0.8292, height:0.0543, oneLine:true, font:'belerenb', size:0.0324},
rules: {name:'Rules Text', text:'', x:0.086, y:0.6303, width:0.828, height:0.2875, size:0.0362},
pt: {name:'Power/Toughness', text:'', x:0.7928, y:0.902, width:0.1367, height:0.0372, size:0.0372, font:'belerenbsc', oneLine:true, align:'center'}
});
}
//loads available frames
loadFramePack();

View File

@@ -1,14 +1,23 @@
//Create objects for common properties across available frames
var masks = [{src:'/img/frames/m15/regular/m15MaskPinline.png', name:'Pinline'}];
var bounds = {x:0.7627, y:0.8853, width:0.192, height:0.0753};
var masks = [{src:'/img/frames/kaldheim/maskDetails.png', name:'Details'}, {src:'/img/frames/kaldheim/maskPinline.png', name:'Pinline'}, {src:'/img/frames/kaldheim/maskTitle.png', name:'Title'}, {src:'/img/frames/kaldheim/maskType.png', name:'Type'}, {src:'/img/frames/kaldheim/maskTextbox.png', name:'Rules'}, {src:'/img/frames/kaldheim/maskBorder.png', name:'Border'}, {src:'/img/frames/kaldheim/maskFrame.png', name:'Frame'}];
var masks2 = [{src:'/img/frames/kaldheim/maskPTCorners.png', name:'Corners'}, {src:'/img/frames/kaldheim/maskPTCornersRight.png', name:'Corners (right)'}];
var bounds = {x:0.7627, y:0.8853, width:0.188, height:0.0724};
//defines available frames
availableFrames = [
{name:'White Frame', src:'/img/frames/kaldheim/frameW.png', masks:masks},
{name:'Blue Frame', src:'/img/frames/kaldheim/frameU.png', masks:masks},
{name:'Black Frame', src:'/img/frames/kaldheim/frameB.png', masks:masks},
{name:'Red Frame', src:'/img/frames/kaldheim/frameR.png', masks:masks},
{name:'White Power/Toughness', src:'/img/frames/kaldheim/ptW.png', bounds:bounds},
{name:'Blue Power/Toughness', src:'/img/frames/kaldheim/ptU.png', bounds:bounds},
{name:'Red Power/Toughness', src:'/img/frames/kaldheim/ptR.png', bounds:bounds}
{name:'Green Frame', src:'/img/frames/kaldheim/frameG.png', masks:masks},
{name:'Multicolored Frame', src:'/img/frames/kaldheim/frameM.png', masks:masks},
{name:'Artifact Frame', src:'/img/frames/kaldheim/frameA.png', masks:masks},
{name:'White Power/Toughness', src:'/img/frames/kaldheim/ptW.png', bounds:bounds, masks:masks2},
{name:'Blue Power/Toughness', src:'/img/frames/kaldheim/ptU.png', bounds:bounds, masks:masks2},
{name:'Black Power/Toughness', src:'/img/frames/kaldheim/ptB.png', bounds:bounds, masks:masks2},
{name:'Red Power/Toughness', src:'/img/frames/kaldheim/ptR.png', bounds:bounds, masks:masks2},
{name:'Green Power/Toughness', src:'/img/frames/kaldheim/ptG.png', bounds:bounds, masks:masks2},
{name:'Multicolored Power/Toughness', src:'/img/frames/kaldheim/ptM.png', bounds:bounds, masks:masks2},
{name:'Artifact Power/Toughness', src:'/img/frames/kaldheim/ptA.png', bounds:bounds, masks:masks2}
];
//disables/enables the "Load Frame Version" button
document.querySelector('#loadFrameVersion').disabled = false;
@@ -22,7 +31,7 @@ document.querySelector('#loadFrameVersion').onclick = async function() {
card.artBounds = {x:0.1047, y:0.1158, width:0.7907, height:0.462};
autoFitArt();
//set symbol bounds
card.setSymbolBounds = {x:0.9213, y:0.6081, width:0.12, height:0.0410, vertical:'center', horizontal: 'right'};
card.setSymbolBounds = {x:0.9213, y:0.6081, width:0.12, height:0.04, vertical:'center', horizontal: 'right'};
resetSetSymbol();
//watermark bounds
card.watermarkBounds = {x:0.5, y:0.7762, width:0.75, height:0.2305};
@@ -33,7 +42,7 @@ document.querySelector('#loadFrameVersion').onclick = async function() {
title: {name:'Title', text:'', x:0.0667, y:0.0591, width:0.8667, height:0.0543, oneLine:true, font:'belerenb', color:'white', size:0.0381, shadowX:0.0027, shadowY:0.002},
type: {name:'Type', text:'', x:0.0734, y:0.5829, width:0.8534, height:0.0543, oneLine:true, font:'belerenb', color:'white', size:0.0324, shadowX:0.0027, shadowY:0.002},
rules: {name:'Rules Text', text:'', x:0.086, y:0.6405, width:0.828, height:0.2739, size:0.0362},
pt: {name:'Power/Toughness', text:'', x:0.798, y:0.9039, width:0.1367, height:0.0372, size:0.0372, font:'belerenbsc', oneLine:true, align:'center'}
pt: {name:'Power/Toughness', text:'', x:0.7954, y:0.9029, width:0.1367, height:0.0372, size:0.0372, font:'belerenbsc', oneLine:true, align:'center'}
});
}
//loads available frames