fuck createPath func works (at 70%)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
8fc9817dc4
commit
4b77c1f3bd
@ -1,46 +1,60 @@
|
|||||||
class CardToHtml {
|
class CardToHtml {
|
||||||
|
|
||||||
static create(card) {
|
static create(card) {
|
||||||
const gameWindow = document.querySelector('#main');
|
const gameWindow = document.querySelector('#main');
|
||||||
let div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||||
|
|
||||||
div.setAttribute('class','card');
|
div.setAttribute('class','card');
|
||||||
gameWindow.appendChild(div);
|
svg.setAttribute('class','item');
|
||||||
|
svg.setAttribute('height','160');
|
||||||
|
svg.setAttribute('width','80');
|
||||||
|
svg.setAttribute('viewBox','0 0 200 400');
|
||||||
|
|
||||||
|
// Create paths + add to svg
|
||||||
|
for(let j = 0; j < 2; j++) {
|
||||||
|
const path = this.createPath(card.shape,card.color,card.filling,card.outline,j);
|
||||||
|
svg.appendChild(path);
|
||||||
|
}
|
||||||
|
|
||||||
const svg = this.createPath(card.shape,card.color,card.filling,card.outline);
|
// Loop to add svg card.number times
|
||||||
|
for(let i = 0; i < card.number; i++) {
|
||||||
|
div.appendChild(svg.cloneNode(true))
|
||||||
|
console.log("+SVG: ",svg);
|
||||||
|
}
|
||||||
|
|
||||||
div.appendChild(svg);
|
gameWindow.appendChild(div);
|
||||||
}
|
}
|
||||||
|
|
||||||
createSVG(shape,color,filling,outline) {
|
static createPath(shape,color,filling,outline,step) {
|
||||||
if(shape === null) shape = "oval";
|
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
||||||
if(color === null) color = "#000000";
|
|
||||||
if(filling === null) filling = "fill";
|
|
||||||
|
|
||||||
// Can be optimized by just adding svg as string -> svg is constant
|
|
||||||
// class="item" height="160" width="80" viewBox="0 0 200 400"
|
|
||||||
const svg = document.createElement('svg');
|
|
||||||
svg.setAttribute("class","item");
|
|
||||||
svg.setAttribute("height","160");
|
|
||||||
svg.setAttribute("width","80");
|
|
||||||
svg.setAttribute("viewBox","0 0 200 400");
|
|
||||||
|
|
||||||
const path = document.createElement('path');
|
if(shape === null) shape = 'oval';
|
||||||
|
if(color === null) color = '000000';
|
||||||
|
if(filling === null) filling = 'fill';
|
||||||
|
|
||||||
|
// Add lots of attributes
|
||||||
path.setAttribute("d",SHAPE_PATH[shape]);
|
path.setAttribute("d",SHAPE_PATH[shape]);
|
||||||
|
path.setAttribute('stroke',`#${color}`);
|
||||||
|
path.setAttribute('fill',`#${color}`);
|
||||||
|
path.setAttribute('stroke-width','18');
|
||||||
|
|
||||||
|
// Add svg attributes for shape outline
|
||||||
if(outline !== null){
|
if(outline !== null){
|
||||||
Object.keys(OUTLINE_SPEC[outline]).forEach(function(k){
|
Object.keys(OUTLINE_SPEC.rect).forEach(function(k){
|
||||||
path.setAttribute(k,OUTLINE_SPEC[outline[k]]);
|
path.setAttribute(k,OUTLINE_SPEC.rect[k]);
|
||||||
});
|
});
|
||||||
|
|
||||||
path.setAttribute("stroke","#000000");
|
path.setAttribute('stroke','#000000');
|
||||||
}
|
}
|
||||||
|
|
||||||
path.setAttribute("stroke",color);
|
// Diff between two paths in svg
|
||||||
path.setAttribute("fill",color);
|
if (step === 0) {
|
||||||
path.setAttribute("mask","none");
|
path.setAttribute('mask',`url(#mask-${filling})`);
|
||||||
|
} else {
|
||||||
svg.appendChild(path);
|
path.setAttribute('fill', 'none');
|
||||||
|
}
|
||||||
|
|
||||||
return svg;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue