jspsych-tangram 0.0.3 → 0.0.5
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/dist/construct/index.browser.js +23 -63
- package/dist/construct/index.browser.js.map +1 -1
- package/dist/construct/index.browser.min.js +11 -15
- package/dist/construct/index.browser.min.js.map +1 -1
- package/dist/construct/index.cjs +23 -63
- package/dist/construct/index.cjs.map +1 -1
- package/dist/construct/index.js +23 -63
- package/dist/construct/index.js.map +1 -1
- package/dist/index.cjs +26 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -64
- package/dist/index.js.map +1 -1
- package/dist/prep/index.browser.js +16 -14
- package/dist/prep/index.browser.js.map +1 -1
- package/dist/prep/index.browser.min.js +1 -1
- package/dist/prep/index.browser.min.js.map +1 -1
- package/dist/prep/index.cjs +16 -14
- package/dist/prep/index.cjs.map +1 -1
- package/dist/prep/index.js +16 -14
- package/dist/prep/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/components/board/GameBoard.tsx +4 -1
- package/src/core/domain/primitives.ts +9 -10
- package/src/core/domain/types.ts +4 -3
- package/src/core/engine/state/BaseGameController.ts +0 -1
- package/src/core/io/InteractionTracker.ts +1 -1
- package/src/core/io/quickstash.ts +3 -29
- package/src/core/types/plugin-interfaces.ts +1 -1
- package/src/plugins/tangram-construct/ConstructionApp.tsx +13 -58
- package/src/plugins/tangram-construct/index.ts +1 -1
- package/src/plugins/tangram-prep/PrepApp.tsx +1 -0
- package/src/plugins/tangram-prep/index.ts +1 -1
- package/tangram-construct.min.js +11 -15
- package/tangram-prep.min.js +1 -1
- package/src/core/io/stims.ts +0 -107
package/src/core/io/stims.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// core/io/stims.ts
|
|
2
|
-
import type { Poly, Sector, Vec } from "@/core/domain/types";
|
|
3
|
-
|
|
4
|
-
/** Raw JSON shapes from dev/assets/stims_dev.json */
|
|
5
|
-
type RawTan = {
|
|
6
|
-
name: string;
|
|
7
|
-
verticesAtOrigin: Array<[number, number] | { x: number; y: number }>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type RawStim = {
|
|
11
|
-
solutionTans: RawTan[];
|
|
12
|
-
stimImgPath?: string;
|
|
13
|
-
stimSilhouetteImgPath?: string;
|
|
14
|
-
set?: string;
|
|
15
|
-
id?: string | number;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/** Canonical tangram names we accept as actual piece polys. */
|
|
19
|
-
const CANON = new Set([
|
|
20
|
-
"square",
|
|
21
|
-
"small-triangle",
|
|
22
|
-
"parallelogram",
|
|
23
|
-
"med-triangle",
|
|
24
|
-
"large-triangle",
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
// ----------------------- guards & converters -----------------------
|
|
28
|
-
function isPoint(a: unknown): a is [number, number] {
|
|
29
|
-
return Array.isArray(a) && a.length >= 2
|
|
30
|
-
&& typeof a[0] === "number" && typeof a[1] === "number";
|
|
31
|
-
}
|
|
32
|
-
function isPointObj(a: unknown): a is { x: number; y: number } {
|
|
33
|
-
return !!a && typeof a === "object"
|
|
34
|
-
&& "x" in (a as any) && "y" in (a as any)
|
|
35
|
-
&& typeof (a as any).x === "number" && typeof (a as any).y === "number";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function toVec(p: [number, number] | { x: number; y: number }): Vec {
|
|
39
|
-
// JSON vertices are authored in math coords (+y up). Convert to SVG (+y down).
|
|
40
|
-
if (isPoint(p)) return { x: p[0], y: -p[1] };
|
|
41
|
-
const obj = p as any;
|
|
42
|
-
return { x: obj.x, y: -obj.y };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// NOTE: We flip Y above so silhouettes render right-side-up in SVG.
|
|
46
|
-
function polyFromVertices(vertices: Array<[number, number] | { x: number; y: number }>): Poly {
|
|
47
|
-
// defensively map every element that looks like a point
|
|
48
|
-
const out: Vec[] = [];
|
|
49
|
-
for (const v of vertices) {
|
|
50
|
-
if (isPoint(v) || isPointObj(v)) out.push(toVec(v));
|
|
51
|
-
}
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ----------------------- normalization -----------------------
|
|
56
|
-
/**
|
|
57
|
-
* Accepts either an array of raw stims or an object with { stims: [...] }.
|
|
58
|
-
* Returns Sectors with silhouette.mask = array of polys (one per tan).
|
|
59
|
-
*/
|
|
60
|
-
export function normalizeStims(
|
|
61
|
-
src: unknown,
|
|
62
|
-
fallbackSectorIds: string[]
|
|
63
|
-
): Sector[] {
|
|
64
|
-
const rawList: RawStim[] = Array.isArray(src)
|
|
65
|
-
? (src as RawStim[])
|
|
66
|
-
: (src && typeof src === "object" && Array.isArray((src as any).stims))
|
|
67
|
-
? ((src as any).stims as RawStim[])
|
|
68
|
-
: [];
|
|
69
|
-
|
|
70
|
-
const sectors: Sector[] = [];
|
|
71
|
-
|
|
72
|
-
for (let i = 0; i < Math.min(fallbackSectorIds.length, rawList.length); i++) {
|
|
73
|
-
const raw = rawList[i];
|
|
74
|
-
if (!raw) continue;
|
|
75
|
-
|
|
76
|
-
// take only canonical piece shapes; ignore macros
|
|
77
|
-
const polys: Poly[] = [];
|
|
78
|
-
for (const tan of raw.solutionTans ?? []) {
|
|
79
|
-
if (!tan || !CANON.has(tan.name)) continue;
|
|
80
|
-
if (Array.isArray(tan.verticesAtOrigin) && tan.verticesAtOrigin.length >= 3) {
|
|
81
|
-
polys.push(polyFromVertices(tan.verticesAtOrigin));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const id = fallbackSectorIds[i] ?? String(i);
|
|
86
|
-
sectors.push({
|
|
87
|
-
id,
|
|
88
|
-
silhouette: {
|
|
89
|
-
id,
|
|
90
|
-
mask: polys,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return sectors;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Fetch + normalize helper for dev path (e.g., "/dev/assets/stims_dev.json"). */
|
|
99
|
-
export async function loadStimSectorsFromUrl(
|
|
100
|
-
url: string,
|
|
101
|
-
sectorIds: string[]
|
|
102
|
-
): Promise<Sector[]> {
|
|
103
|
-
const res = await fetch(url);
|
|
104
|
-
if (!res.ok) throw new Error(`Failed to load stims: ${res.status} ${res.statusText}`);
|
|
105
|
-
const json = await res.json();
|
|
106
|
-
return normalizeStims(json, sectorIds);
|
|
107
|
-
}
|