jspsych-tangram 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspsych-tangram",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Tangram tasks for jsPsych: prep and construct.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -77,15 +77,14 @@ function constructFromSpec(
77
77
  // ===== default first edges in UNIT coords ( +y is UP here ) =================
78
78
  // Copied from your `default_pilot_rotations`. We invert y above for canvas.
79
79
  const FIRST_EDGES_UNITS: Record<TanKind, [Vec, Vec]> = {
80
- "small-triangle": [P(0, 0), P(0.5, 0.5)],
80
+ "smalltriangle": [P(0, 0), P(0.5, 0.5)],
81
81
  "parallelogram": [P(0, 0), P(0.5, 0)],
82
- "large-triangle": [P(0, 0), P(0.5, -0.5)],
83
- "med-triangle": [P(0, 0), P(0.5, 0)],
82
+ "largetriangle": [P(0, 0), P(0.5, -0.5)],
83
+ "medtriangle": [P(0, 0), P(0.5, 0)],
84
84
  "square": [P(0, 0), P(0.5, 0)],
85
85
  };
86
86
 
87
87
  // ===== canonical half-edge primitives ===================
88
- // TODO: Sean we need to talk about aligning this with your Python implementation
89
88
  // Unchanging primitive tangram pieces - these are constants, not configurable
90
89
  const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
91
90
  // Sequences copied verbatim from your Python tanprimitives_halfedges()
@@ -104,8 +103,8 @@ const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
104
103
  color: "#f43f5e",
105
104
  },
106
105
  {
107
- id: "prim:small",
108
- kind: "small-triangle",
106
+ id: "prim:smalltriangle",
107
+ kind: "smalltriangle",
109
108
  sideLens: [HALFDIAGONAL, HALFDIAGONAL, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT],
110
109
  angles: [180, 45, 180, 90, 180, 45],
111
110
  color: "#f59e0b",
@@ -118,15 +117,15 @@ const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
118
117
  color: "#10b981",
119
118
  },
120
119
  {
121
- id: "prim:med",
122
- kind: "med-triangle",
120
+ id: "prim:medtriangle",
121
+ kind: "medtriangle",
123
122
  sideLens: [HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL],
124
123
  angles: [180, 180, 180, 45, 180, 90, 180, 45],
125
124
  color: "#3b82f6",
126
125
  },
127
126
  {
128
- id: "prim:large",
129
- kind: "large-triangle",
127
+ id: "prim:largetriangle",
128
+ kind: "largetriangle",
130
129
  sideLens: [
131
130
  HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL,
132
131
  HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT
@@ -5,10 +5,10 @@ export type Poly = Vec[];
5
5
  // Canonical tans
6
6
  export type TanKind =
7
7
  | "square"
8
- | "small-triangle"
8
+ | "smalltriangle"
9
9
  | "parallelogram"
10
- | "med-triangle"
11
- | "large-triangle";
10
+ | "medtriangle"
11
+ | "largetriangle";
12
12
 
13
13
  // 2×2 interaction axes
14
14
  export type PlacementTarget = "workspace" | "silhouette";
@@ -55,6 +55,7 @@ export type SilhouetteSpec = {
55
55
 
56
56
  export type Sector = {
57
57
  id: string;
58
+ tangramId: string;
58
59
  silhouette: SilhouetteSpec;
59
60
  };
60
61
 
@@ -571,7 +571,7 @@ export class InteractionTracker {
571
571
  // Build sector-tangram map
572
572
  const sectorTangramMap = this.controller.state.cfg.sectors.map(s => ({
573
573
  sectorId: s.id,
574
- tangramId: s.id // In our system, sector ID == tangram ID
574
+ tangramId: s.tangramId
575
575
  }));
576
576
 
577
577
  // Build blueprint order
@@ -3,32 +3,6 @@ import { CONFIG } from "@/core/config/config";
3
3
  import type { Blueprint, CompositeBlueprint, PrimitiveBlueprint, TanKind, Vec } from "@/core/domain/types";
4
4
  import { primitiveBlueprintsHalfEdge } from "@/core/domain/primitives";
5
5
 
6
- /**
7
- * Convert anchor coordinates to pixel coordinates
8
- * @param anchorX - X coordinate in anchor units (integer)
9
- * @param anchorY - Y coordinate in anchor units (integer)
10
- * @returns Pixel coordinates
11
- */
12
- export function anchorToPixels(anchorX: number, anchorY: number): Vec {
13
- return {
14
- x: anchorX * CONFIG.layout.grid.stepPx,
15
- y: anchorY * CONFIG.layout.grid.stepPx
16
- };
17
- }
18
-
19
- /**
20
- * Convert pixel coordinates to anchor coordinates
21
- * @param pixelX - X coordinate in pixels
22
- * @param pixelY - Y coordinate in pixels
23
- * @returns Anchor coordinates (rounded to nearest grid point)
24
- */
25
- export function pixelsToAnchor(pixelX: number, pixelY: number): Vec {
26
- return {
27
- x: Math.round(pixelX / CONFIG.layout.grid.stepPx),
28
- y: Math.round(pixelY / CONFIG.layout.grid.stepPx)
29
- };
30
- }
31
-
32
6
  /**
33
7
  * Convert anchor-based composite definition to pixel-based composite with custom grid step
34
8
  * @param anchorComposite - Composite defined with anchor coordinates
@@ -84,10 +58,10 @@ const ANCHOR_COMPOSITES = [
84
58
  label: "Parallelogram+Parallelogram"
85
59
  },
86
60
  {
87
- id: "comp:small-triangle+med-triangle",
61
+ id: "comp:smalltriangle+medtriangle",
88
62
  parts: [
89
- { kind: "small-triangle" as TanKind, anchorOffset: { x: -2, y: -2 } },
90
- { kind: "med-triangle" as TanKind, anchorOffset: { x: 0, y: 0 } },
63
+ { kind: "smalltriangle" as TanKind, anchorOffset: { x: -2, y: -2 } },
64
+ { kind: "medtriangle" as TanKind, anchorOffset: { x: 0, y: 0 } },
91
65
  ],
92
66
  label: "SmallTriangle+MedTriangle"
93
67
  },
@@ -40,7 +40,7 @@ export interface TangramSpec {
40
40
  tangramID: string;
41
41
  setLabel: string;
42
42
  solutionTans: Array<{
43
- name: string; // TanKind as string (e.g., "small-triangle")
43
+ name: string; // TanKind as string (e.g., "smalltriangle")
44
44
  vertices: number[][]; // Array of [x, y] coordinate pairs
45
45
  }>;
46
46
  }
@@ -51,15 +51,12 @@ export function startConstructionTrial(
51
51
  // Canonical piece names we accept
52
52
  const CANON = new Set([
53
53
  "square",
54
- "small-triangle",
54
+ "smalltriangle",
55
55
  "parallelogram",
56
- "med-triangle",
57
- "large-triangle",
56
+ "medtriangle",
57
+ "largetriangle",
58
58
  ]);
59
59
 
60
- // Sector IDs in alphabetical order
61
- const SECTOR_IDS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'];
62
-
63
60
  // Convert JSON plugin parameters to internal Sector[] format
64
61
  console.log('[ConstructionApp] Starting tangram conversion...');
65
62
  console.log('[ConstructionApp] Received tangrams:', params.tangrams);
@@ -92,12 +89,14 @@ export function startConstructionTrial(
92
89
  });
93
90
 
94
91
  // Assign sector ID from alphabetical sequence
95
- const sectorId = SECTOR_IDS[index] ?? `S${index}`;
92
+ const sectorId = `sector${index}`;
93
+
96
94
  console.log(`[ConstructionApp] Assigned sector ID: ${sectorId}`);
97
95
  console.log(`[ConstructionApp] Final mask has ${mask.length} polygons`);
98
96
 
99
97
  const sector = {
100
98
  id: sectorId,
99
+ tangramId: tangramSpec.tangramID,
101
100
  silhouette: {
102
101
  id: sectorId,
103
102
  mask,
@@ -60,6 +60,7 @@ export function startPrepTrial(
60
60
  // Create blank prep sectors (no silhouettes)
61
61
  const prepSectors: Sector[] = Array.from({ length: numQuickstashSlots }, (_, i) => ({
62
62
  id: `prep-sector-${i}`,
63
+ tangramId: `prep-sector-${i}`, // dummy value since prep mode doesn't have tangrams
63
64
  silhouette: {
64
65
  id: `prep-silhouette-${i}`,
65
66
  mask: []