diff --git a/src/renderers/_base.ts b/src/renderers/_base.ts index 065c5fe..a3f23b4 100644 --- a/src/renderers/_base.ts +++ b/src/renderers/_base.ts @@ -4262,7 +4262,17 @@ export abstract class RendererBase { baseOpacity = this.json.board.strokeOpacity; } - for (const marker of this.json.board.markers) { + const allMarkers = this.json.board.markers.filter(m => m.type !== "fences"); + const fences = (this.json.board.markers.filter(m => m.type === "fences") as unknown[]) as {type: "fences", sides: {[k: string]: any}[]}[]; + if (fences.length > 0) { + for (const decl of fences) { + for (const side of decl.sides) { + allMarkers.push({type: "fence", ...side}); + } + } + } + + for (const marker of allMarkers) { if (! ((preGridLines && marker.belowGrid === true) || (!preGridLines && (marker.belowGrid === undefined || marker.belowGrid === false)) || (preGridLines && marker.type === "halo"))) { continue; } @@ -5587,9 +5597,9 @@ export abstract class RendererBase { const txtWidth = tmptxt.bbox().w; tmptxt.remove(); // set the actual width of the nested svg - const realWidth = Math.max(areaWidth, txtWidth*1.05) + const {x: vbx, y:vby, w: vbw, h: vbh} = nested.viewbox(); + const realWidth = Math.max(vbw, txtWidth); nested.width(realWidth); - const {x: vbx, y:vby, h: vbh} = nested.viewbox(); nested.viewbox(vbx, vby, realWidth, vbh); const txt = nested.text(area.label).addClass(`aprender-area-label`); txt.font({size: textHeight, anchor: "start", fill: "#000"}) diff --git a/src/schemas/schema.d.ts b/src/schemas/schema.d.ts index c33722c..7c74d4a 100644 --- a/src/schemas/schema.d.ts +++ b/src/schemas/schema.d.ts @@ -556,6 +556,55 @@ export interface APRenderRep { */ dashed?: number[]; } + | { + /** + * Only works for the `squares*` and rect-of-hex board styles. Draws a thick line between two adjacent cells. It doesn't check adjacency, but the results will not be what you expect otherwise. + */ + type: "fences"; + /** + * @minItems 1 + */ + sides: [ + { + cell: { + row: number; + col: number; + }; + side: "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW"; + /** + * The colour of the fence. Can be either a number (which will be interpreted as a built-in player colour) or a hexadecimal colour string. + */ + colour?: PositiveInteger | Colourstrings; + /** + * Expressed as a multiple of the base stroke width + */ + width?: number; + /** + * A valid `dasharray` appropriate for the game's display. + */ + dashed?: number[]; + }, + ...{ + cell: { + row: number; + col: number; + }; + side: "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW"; + /** + * The colour of the fence. Can be either a number (which will be interpreted as a built-in player colour) or a hexadecimal colour string. + */ + colour?: PositiveInteger | Colourstrings; + /** + * Expressed as a multiple of the base stroke width + */ + width?: number; + /** + * A valid `dasharray` appropriate for the game's display. + */ + dashed?: number[]; + }[] + ]; + } | { /** * A way of incorporating a glyph from the legend into the board itself. Currently only works in the `default` and `stacking-offset` renderer. diff --git a/src/schemas/schema.json b/src/schemas/schema.json index ea49985..7bf1302 100644 --- a/src/schemas/schema.json +++ b/src/schemas/schema.json @@ -950,6 +950,65 @@ "required": ["type", "cell", "side"], "additionalProperties": false }, + { + "properties": { + "type": { + "description": "Only works for the `squares*` and rect-of-hex board styles. Draws a thick line between two adjacent cells. It doesn't check adjacency, but the results will not be what you expect otherwise.", + "enum": ["fences"] + }, + "sides": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "cell": { + "type": "object", + "properties": { + "row": { + "type": "integer", + "minimum": 0 + }, + "col": { + "type": "integer", + "minimum": 0 + } + }, + "required": ["row", "col"], + "additionalProperties": false + }, + "side": { + "enum": ["N", "NE", "E", "SE", "S", "SW", "W", "NW"] + }, + "colour": { + "description": "The colour of the fence. Can be either a number (which will be interpreted as a built-in player colour) or a hexadecimal colour string.", + "anyOf": [ + {"$ref": "#/definitions/positiveInteger"}, + {"$ref": "#/definitions/colourstrings"} + ], + "default": "#000" + }, + "width": { + "description": "Expressed as a multiple of the base stroke width", + "type": "number", + "default": 6 + }, + "dashed": { + "description": "A valid `dasharray` appropriate for the game's display.", + "type": "array", + "items": { + "type": "number" + } + } + }, + "required": ["cell", "side"], + "additionalProperties": false + } + } + }, + "required": ["type", "sides"], + "additionalProperties": false + }, { "properties": { "type": {