Skip to content

Commit

Permalink
Tweaked ids and classes ready for live testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Dec 30, 2023
1 parent ac5af95 commit 3a106f5
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 45 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
],
"dependencies": {
"@svgdotjs/svg.js": "^3.1.2",
"@types/fnv-plus": "^1.3.2",
"ajv": "^8.12.0",
"fnv-plus": "^1.3.1",
"honeycomb-grid": "4.1.1",
"json-stringify-deterministic": "^1.0.12",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down
21 changes: 21 additions & 0 deletions src/common/glyph2uid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fnv from "fnv-plus";
import stringify from "json-stringify-deterministic";
import { Glyph } from "../schemas/schema";

export const glyph2uid = (g: Glyph): string => {
const parts: string[] = ["aprender", "glyph"];

fnv.seed("aprender");
const hash = fnv.hash(stringify(g));
parts.push(hash.hex());

return parts.join("-");
}

export const x2uid = (x: any): string => {
fnv.seed("aprender");
const hash = fnv.hash(stringify(x));
return hash.hex();
}

export default glyph2uid;
90 changes: 51 additions & 39 deletions src/renderers/_base.ts

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/renderers/freespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { APRenderRep } from "../schemas/schema";
import { IRendererOptionsIn, RendererBase, IKey } from "./_base";
import { IPoint } from "../grids/_base";
import { rotate, usePieceAt } from "../common/plotting";
import { x2uid} from "../common/glyph2uid";

export interface IPiecesArea {
type: "pieces";
Expand Down Expand Up @@ -81,7 +82,7 @@ export class FreespaceRenderer extends RendererBase {

// clickable background field
const field = this.rootSvg.nested().id("pieces").viewbox(ox - borderBuffer, oy - borderBuffer, width + (borderBuffer*2), height + (borderBuffer*2)).move(ox, oy);
field.rect(width, height).move(ox, oy).fill(backFill).back();
field.rect(width, height).id("aprender-backfill").move(ox, oy).fill(backFill).back();
if (this.options.boardClick !== undefined) {
const originX = field.x() as number;
const originY = field.y() as number;
Expand Down Expand Up @@ -194,7 +195,7 @@ export class FreespaceRenderer extends RendererBase {
if ( ("dashed" in note) && (note.dashed !== undefined) && (Array.isArray(note.dashed)) && (note.dashed.length > 0) ) {
strokeData.dasharray = (note.dashed).join(" ");
}
notes.path(note.path as string).stroke(strokeData).fill({color: fill, opacity: fillOpacity});
notes.path(note.path as string).addClass(`aprender-annotation-${x2uid(note)}`).stroke(strokeData).fill({color: fill, opacity: fillOpacity});
} else if (note.type === "glyph") {
const key = note.glyph as string;
const piece = field.root().findOne("#" + key) as Svg;
Expand Down Expand Up @@ -243,6 +244,7 @@ export class FreespaceRenderer extends RendererBase {
const [{x: x1, y: y1}, {x: x2, y: y2}] = marker.points

const text = field.text(marker.label)
.addClass(`aprender-marker-${x2uid(marker)}`)
.font({size: fontsize, fill: colour, anchor: "middle"})
.attr("alignment-baseline", "hanging")
.attr("dominant-baseline", "hanging")
Expand Down Expand Up @@ -304,7 +306,7 @@ export class FreespaceRenderer extends RendererBase {
if ( ("dashed" in marker) && (marker.dashed !== undefined) && (Array.isArray(marker.dashed)) && (marker.dashed.length > 0) ) {
strokeData.dasharray = (marker.dashed).join(" ");
}
field.path(marker.path).stroke(strokeData).fill({color: fill, opacity: fillOpacity});
field.path(marker.path).addClass(`aprender-marker-${x2uid(marker)}`).stroke(strokeData).fill({color: fill, opacity: fillOpacity});
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/stackingTiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class StackingTilesRenderer extends RendererBase {
if (idx > 0) {
const color = this.options.colours[idx - 1];
const tile = group.rect(tileWidth, tileHeight)
.addClass(`aprender-tile-${idx}`)
.move(x, y)
.fill(color)
.stroke({width: tileHeight * 0.2, color: "#fff"});
Expand All @@ -124,6 +125,7 @@ export class StackingTilesRenderer extends RendererBase {
// overflow piece (there should only be one)
} else {
group.line(x, y + (tileHeight / 2), x + tileWidth, y + (tileHeight / 2))
.addClass("aprender-tile-overflow")
.fill("#000")
.stroke({width: tileHeight, color: "#000", dasharray: "4"});
}
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export interface APRenderRep {
/**
* The colour of the shaded area. Can be either a number (which will be interpreted as a built-in player colour) or a hexadecimal colour string.
*/
colour?: PositiveInteger | Colourstrings;
colour: PositiveInteger | Colourstrings;
/**
* 1 is fully opaque. 0 is fully transparent.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@
"default": 0.25
}
},
"required": ["type", "points"],
"required": ["type", "points", "colour"],
"additionalProperties": false
},
{
Expand Down
2 changes: 1 addition & 1 deletion test/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"markers-outline": {
"name": "Markers: Outlines",
"description": "Only works for boards composed of polygons and not just lines (most commonly hex fields). Highlights the cell with the given colour.",
"render": `{"renderer":"sowing-numerals","board":{"style":"sowing","width":9,"height":2,"showEndPits":true,"markers":[{"type":"edge","edge":"N","colour":2},{"type":"edge","edge":"S","colour":1},{"type":"outline","colour":1,"points":[{"row":2,"col":1}]},{"type":"outline","colour":2,"points":[{"row":2,"col":0}]}]},"pieces":"9,9,9,9,9,9,9,9,9\\n9,9,9,9,9,9,9,9,9\\n0,0"`,
"render": `{"renderer":"sowing-numerals","board":{"style":"sowing","width":9,"height":2,"showEndPits":true,"markers":[{"type":"edge","edge":"N","colour":2},{"type":"edge","edge":"S","colour":1},{"type":"outline","colour":1,"points":[{"row":2,"col":1}]},{"type":"outline","colour":2,"points":[{"row":2,"col":0}]}]},"pieces":"9,9,9,9,9,9,9,9,9\\n9,9,9,9,9,9,9,9,9\\n0,0"}`,
},
"markers-lines": {
"name": "Markers: Lines",
Expand Down

0 comments on commit 3a106f5

Please sign in to comment.