Skip to content

Commit

Permalink
render VP in card and text
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-demos-stefan-untitled-board-game-ubg-card.js,AUTO-COMMIT-src-components-widgets-ubg-cards-entry.html,AUTO-COMMIT-src-components-widgets-ubg-cards-entry.js,AUTO-COMMIT-src-components-widgets-ubg-cards.js,
  • Loading branch information
onsetsu committed Sep 19, 2023
1 parent 748c45e commit a6fc0d4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
14 changes: 14 additions & 0 deletions demos/stefan/untitled-board-game/ubg-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ export default class Card {
this.versions.last.cost = cost;
}

getBaseVP() {
return this.versions.last.baseVP;
}

setBaseVP(baseVP) {
this.ensureUnprintedVersion();

if (!baseVP) {
delete this.versions.last.baseVP;
} else {
this.versions.last.baseVP = baseVP;
}
}

getText() {
return this.versions.last.text;
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/widgets/ubg-cards-entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
#cost {
color: goldenrod;
}
#vp {
color: violet;
}
#name {
font-weight: 600;
}
Expand All @@ -152,6 +155,7 @@
<i id='type'></i>
<span id='element'></span>
<span id='cost'></span>
<span id='vp'></span>
<span id='name'></span>
<span id='text'></span>
<span id='art'></span>
Expand Down
1 change: 1 addition & 0 deletions src/components/widgets/ubg-cards-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default class UBGCardEntry extends Morph {
this.renderElement(v);

this.get('#cost').innerHTML = v.cost || '/';
this.get('#vp').innerHTML = card.getBaseVP() || '-';

this.get('#name').innerHTML = card.versions.last.name || 'no name yet';
this.get('#text').innerHTML = card.versions.last.text || 'no text';
Expand Down
54 changes: 54 additions & 0 deletions src/components/widgets/ubg-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ const SORT_BY = {
NAME: 'name'
};

const VP_FILL = 'violet';
const VP_STROKE = '#9400d3'; // darkviolet

export default class Cards extends Morph {
async initialize() {

Expand Down Expand Up @@ -1172,6 +1175,8 @@ export default class Cards extends Morph {
// cost
const coinCenter = coinLeftCenter.addXY(costCoinRadius, 0);
this.renderCost(doc, cardDesc, coinCenter, costCoinRadius)
const vpCenter = coinCenter.addY(costCoinRadius * 2.75);
this.renderBaseVP(doc, cardDesc, vpCenter, costCoinRadius)
}

renderCost(doc, cardDesc, pos, coinRadius) {
Expand All @@ -1197,6 +1202,45 @@ export default class Cards extends Morph {
}
}

renderBaseVP(doc, cardDesc, pos, coinRadius) {
const COST_SIZE = coinRadius / 4;
const vpDesc = cardDesc.getBaseVP();

if (!vpDesc) {
return;
}

const cost = Array.isArray(vpDesc) ? vpDesc.first : vpDesc;

const coinCenter = pos;
doc::withGraphicsState(() => {
doc.setGState(new doc.GState({ opacity: 0.9 }));
// doc.setFillColor('#b8942d');
doc.setDrawColor(148, 0, 211);
doc.setLineWidth(0.2 * COST_SIZE)
// doc.circle(...coinCenter.toPair(), coinRadius, 'DF');
doc.setFillColor('violet');
// doc.rect(coinCenter.x - coinRadius, coinCenter.y - coinRadius, 2 * coinRadius, 2 * coinRadius, 'DF');

// diamond shape
const diagonal = coinRadius * Math.sqrt(2)
const right = coinCenter.addX(diagonal).toPair()
const down = pt(-diagonal, diagonal).toPair()
const left = pt(-diagonal, -diagonal).toPair()
const up = pt(diagonal, -diagonal).toPair()
const rightAgain = pt(diagonal, diagonal).toPair()
doc.lines([down, left, up, rightAgain], ...right, [1,1], 'DF', true)
});

if (cost !== undefined) {
doc::withGraphicsState(() => {
doc.setFontSize(12 * COST_SIZE);
doc.setTextColor('#000000');
doc.text('' + cost, ...coinCenter.toPair(), { align: 'center', baseline: 'middle' });
});
}
}

// #important
async renderRuleText(doc, ruleBox, rulesText = '', {
insetTextBy = 2,
Expand Down Expand Up @@ -1240,6 +1284,13 @@ ${smallElementIcon(others[2], lively.pt(11, 7))}
</svg>`;
}

function printVP(vp) {
return `<span style="font-size: 1em; transform: translate(.5em, 0) rotate(45deg);"><svg viewbox="0 0 10 10" overflow="visible" style="height: 1em; width: 1em;" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="10" height="10" fill="${VP_FILL}" stroke="${VP_STROKE}"></rect>
<text x="50%" y="50%" text-anchor="middle" dy="0.35em" transform="rotate(-45, 5, 5)" style="font: .5em sans-serif; text-shadow: initial;">${vp}</text>
</svg></span>`;
}

let printedRules = rulesText;
printedRules = printedRules.replace(/t3x(fire|water|earth|wind|gray)/gmi, 'tap 3x$1');
printedRules = printedRules.replace(/(^|\n)tap 3x(fire|water|earth|wind|gray)([^\n]*)/gi, function replacer(match, p1, pElement, pText, offset, string, groups) {
Expand All @@ -1259,6 +1310,9 @@ ${smallElementIcon(others[2], lively.pt(11, 7))}
printedRules = printedRules.replace(/(fire|water|earth|wind|gray)/gmi, function replacer(match, pElement, offset, string, groups) {
return element(pElement);
});
printedRules = printedRules.replace(/(\d+|\*|d+\*|\d+x|x)VP/gmi, function replacer(match, vp, offset, string, groups) {
return printVP(vp);
});
printedRules = printedRules.replace(/\(([*0-9x+-]*)\)/gmi, function replacer(match, p1, offset, string, groups) {
return coin(p1);
});
Expand Down

0 comments on commit a6fc0d4

Please sign in to comment.