Skip to content

Commit

Permalink
Add 'spacing' option to pieces area
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Dec 13, 2024
1 parent 2c25ab5 commit 53173a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/renderers/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8342,6 +8342,10 @@ export abstract class RendererBase {
let placeY = boardBottom + padding;
for (let iArea = 0; iArea < areas.length; iArea++) {
const area = areas[iArea];
let hpad = 0;
if (area.spacing !== undefined) {
hpad = this.cellsize * area.spacing;
}
const numPieces = area.pieces.length;
let desiredWidth = boardWidth;
if (area.width !== undefined) {
Expand All @@ -8350,7 +8354,7 @@ export abstract class RendererBase {
const numRows = Math.ceil(numPieces / desiredWidth);
const textHeight = this.cellsize / 3; // 10; // the allowance for the label
const cellsize = this.cellsize * 0.75;
const areaWidth = cellsize * desiredWidth;
const areaWidth = (cellsize * desiredWidth) + (hpad * (desiredWidth-1));
const areaHeight = (textHeight * 2) + (cellsize * numRows);
let markWidth = 0;
let markColour: string|undefined;
Expand All @@ -8374,8 +8378,8 @@ export abstract class RendererBase {
if ( (piece === null) || (piece === undefined) ) {
throw new Error(`Could not find the requested piece (${p}). Each piece in the stack *must* exist in the \`legend\`.`);
}
const newx = col * cellsize + cellsize / 2;
const newy = (textHeight * 2) + (row * cellsize) + cellsize / 2;
const newx = (col * (cellsize + hpad)) + (cellsize / 2);
const newy = (textHeight * 2) + (row * cellsize) + (cellsize / 2);
const use = usePieceAt({svg: nested, piece, cellsize, x: newx, y: newy, scalingFactor: 1});
if (this.options.boardClick !== undefined) {
use.click((e: Event) => {this.options.boardClick!(-1, -1, p); e.stopPropagation();});
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ export interface AreaPieces {
* Optional. Places a coloured bar to the left of the area, used to indicate ownership.
*/
ownerMark?: PositiveInteger | Colourfuncs | Colourstrings;
/**
* With some piece types, you need extra space between them. Expressed as a percentage of cell size, this will insert some padding between pieces.
*/
spacing?: number;
}
/**
* This is a special area currently only used for the DVGC games and incorporates a `pieces`-style area into the game board itself. It is currently only designed for two-player use with 180 degree rotation. The area is clickable, as are the pieces within. You must tell the renderer which area belongs to which player.
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,10 @@
{"$ref": "#/$defs/colourfuncs"},
{"$ref": "#/$defs/colourstrings"}
]
},
"spacing": {
"description": "With some piece types, you need extra space between them. Expressed as a percentage of cell size, this will insert some padding between pieces.",
"type": "number"
}
},
"required": ["type", "pieces", "label"],
Expand Down

0 comments on commit 53173a3

Please sign in to comment.