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 {
|
||||
|
||||
static create(card) {
|
||||
const gameWindow = document.querySelector('#main');
|
||||
let div = document.createElement('div');
|
||||
div.setAttribute('class','card');
|
||||
gameWindow.appendChild(div);
|
||||
const div = document.createElement('div');
|
||||
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
|
||||
const svg = this.createPath(card.shape,card.color,card.filling,card.outline);
|
||||
div.setAttribute('class','card');
|
||||
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);
|
||||
}
|
||||
|
||||
div.appendChild(svg);
|
||||
// Loop to add svg card.number times
|
||||
for(let i = 0; i < card.number; i++) {
|
||||
div.appendChild(svg.cloneNode(true))
|
||||
console.log("+SVG: ",svg);
|
||||
}
|
||||
|
||||
createSVG(shape,color,filling,outline) {
|
||||
if(shape === null) shape = "oval";
|
||||
if(color === null) color = "#000000";
|
||||
if(filling === null) filling = "fill";
|
||||
gameWindow.appendChild(div);
|
||||
}
|
||||
|
||||
// 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");
|
||||
static createPath(shape,color,filling,outline,step) {
|
||||
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
||||
|
||||
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('stroke',`#${color}`);
|
||||
path.setAttribute('fill',`#${color}`);
|
||||
path.setAttribute('stroke-width','18');
|
||||
|
||||
// Add svg attributes for shape outline
|
||||
if(outline !== null){
|
||||
Object.keys(OUTLINE_SPEC[outline]).forEach(function(k){
|
||||
path.setAttribute(k,OUTLINE_SPEC[outline[k]]);
|
||||
Object.keys(OUTLINE_SPEC.rect).forEach(function(k){
|
||||
path.setAttribute(k,OUTLINE_SPEC.rect[k]);
|
||||
});
|
||||
|
||||
path.setAttribute("stroke","#000000");
|
||||
path.setAttribute('stroke','#000000');
|
||||
}
|
||||
|
||||
path.setAttribute("stroke",color);
|
||||
path.setAttribute("fill",color);
|
||||
path.setAttribute("mask","none");
|
||||
|
||||
svg.appendChild(path);
|
||||
// Diff between two paths in svg
|
||||
if (step === 0) {
|
||||
path.setAttribute('mask',`url(#mask-${filling})`);
|
||||
} else {
|
||||
path.setAttribute('fill', 'none');
|
||||
}
|
||||
|
||||
return svg;
|
||||
return path;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue