Skip to content

Commit 53173a3

Browse files
committed
Add 'spacing' option to pieces area
1 parent 2c25ab5 commit 53173a3

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/renderers/_base.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8342,6 +8342,10 @@ export abstract class RendererBase {
83428342
let placeY = boardBottom + padding;
83438343
for (let iArea = 0; iArea < areas.length; iArea++) {
83448344
const area = areas[iArea];
8345+
let hpad = 0;
8346+
if (area.spacing !== undefined) {
8347+
hpad = this.cellsize * area.spacing;
8348+
}
83458349
const numPieces = area.pieces.length;
83468350
let desiredWidth = boardWidth;
83478351
if (area.width !== undefined) {
@@ -8350,7 +8354,7 @@ export abstract class RendererBase {
83508354
const numRows = Math.ceil(numPieces / desiredWidth);
83518355
const textHeight = this.cellsize / 3; // 10; // the allowance for the label
83528356
const cellsize = this.cellsize * 0.75;
8353-
const areaWidth = cellsize * desiredWidth;
8357+
const areaWidth = (cellsize * desiredWidth) + (hpad * (desiredWidth-1));
83548358
const areaHeight = (textHeight * 2) + (cellsize * numRows);
83558359
let markWidth = 0;
83568360
let markColour: string|undefined;
@@ -8374,8 +8378,8 @@ export abstract class RendererBase {
83748378
if ( (piece === null) || (piece === undefined) ) {
83758379
throw new Error(`Could not find the requested piece (${p}). Each piece in the stack *must* exist in the \`legend\`.`);
83768380
}
8377-
const newx = col * cellsize + cellsize / 2;
8378-
const newy = (textHeight * 2) + (row * cellsize) + cellsize / 2;
8381+
const newx = (col * (cellsize + hpad)) + (cellsize / 2);
8382+
const newy = (textHeight * 2) + (row * cellsize) + (cellsize / 2);
83798383
const use = usePieceAt({svg: nested, piece, cellsize, x: newx, y: newy, scalingFactor: 1});
83808384
if (this.options.boardClick !== undefined) {
83818385
use.click((e: Event) => {this.options.boardClick!(-1, -1, p); e.stopPropagation();});

src/schemas/schema.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,10 @@ export interface AreaPieces {
10911091
* Optional. Places a coloured bar to the left of the area, used to indicate ownership.
10921092
*/
10931093
ownerMark?: PositiveInteger | Colourfuncs | Colourstrings;
1094+
/**
1095+
* With some piece types, you need extra space between them. Expressed as a percentage of cell size, this will insert some padding between pieces.
1096+
*/
1097+
spacing?: number;
10941098
}
10951099
/**
10961100
* 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.

src/schemas/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@
703703
{"$ref": "#/$defs/colourfuncs"},
704704
{"$ref": "#/$defs/colourstrings"}
705705
]
706+
},
707+
"spacing": {
708+
"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.",
709+
"type": "number"
706710
}
707711
},
708712
"required": ["type", "pieces", "label"],

0 commit comments

Comments
 (0)