castle-web-cli 0.4.90 → 0.4.92
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/agent.js +23 -4
- package/dist/metering.d.ts +21 -0
- package/dist/metering.js +75 -0
- package/dist/native/loop.js +1 -0
- package/dist/native/openrouter.d.ts +1 -0
- package/dist/native/openrouter.js +1 -0
- package/dist/native/types.d.ts +1 -0
- package/kits/basic-2d/editors/SceneEditor.jsx +39 -6
- package/kits/basic-2d/engine/scene.js +10 -2
- package/kits/physics-2d/behaviors/Collider.jsx +190 -153
- package/kits/physics-2d/editors/SceneEditor.jsx +42 -6
- package/kits/physics-2d/editors/SelectionOverlay.jsx +57 -28
- package/kits/physics-2d/engine/collider.js +123 -105
- package/kits/physics-2d/engine/scene.js +10 -2
- package/kits/physics-2d/physics/behaviors/RigidBody.jsx +3 -0
- package/kits/physics-2d/physics/matterBridge.js +73 -24
- package/package.json +1 -1
- package/kits/physics-2d/engine/behaviorExtensions.js +0 -28
- package/kits/physics-2d/physics/extensions/collider.js +0 -15
|
@@ -1,46 +1,23 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { AutoFields
|
|
4
|
-
import { computeAutoFit, getColliderRect,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
position: 'relative',
|
|
14
|
-
display: 'flex',
|
|
15
|
-
alignItems: 'center',
|
|
16
|
-
gap: 10,
|
|
17
|
-
minHeight: 28,
|
|
18
|
-
margin: '0 0 12px',
|
|
19
|
-
};
|
|
20
|
-
const dimToggleStyle = {
|
|
21
|
-
display: 'inline-flex',
|
|
22
|
-
alignItems: 'center',
|
|
23
|
-
background: 'none',
|
|
24
|
-
border: 'none',
|
|
25
|
-
padding: 0,
|
|
26
|
-
margin: 0,
|
|
2
|
+
import { NumberField, Panel, SelectField } from '../engine/ui';
|
|
3
|
+
import { AutoFields } from '../engine/autoInspector';
|
|
4
|
+
import { computeAutoFit, getColliderRect, getColliderShapes, intersects } from '../engine/collider';
|
|
5
|
+
|
|
6
|
+
// --- inspector styles ------------------------------------------------------
|
|
7
|
+
const rowGap = { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 6, marginBottom: 10 };
|
|
8
|
+
const chip = (active) => ({
|
|
9
|
+
padding: '3px 9px',
|
|
10
|
+
borderRadius: 6,
|
|
11
|
+
border: `1px solid ${active ? '#4aa3ff' : 'var(--castle-inspector-divider)'}`,
|
|
12
|
+
background: active ? 'rgba(74,163,255,0.15)' : 'transparent',
|
|
27
13
|
color: 'var(--castle-inspector-text)',
|
|
28
14
|
fontFamily: 'inherit',
|
|
29
|
-
fontSize:
|
|
15
|
+
fontSize: 12,
|
|
30
16
|
cursor: 'pointer',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
left: -14,
|
|
36
|
-
top: '50%',
|
|
37
|
-
transform: 'translateY(-50%)',
|
|
38
|
-
display: 'inline-flex',
|
|
39
|
-
alignItems: 'center',
|
|
40
|
-
fontSize: 11,
|
|
41
|
-
opacity: 0.65,
|
|
42
|
-
};
|
|
43
|
-
const autoFitLinkStyle = {
|
|
17
|
+
});
|
|
18
|
+
const addBtn = { ...chip(false), fontWeight: 700, padding: '3px 8px' };
|
|
19
|
+
const addMenu = { display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 10 };
|
|
20
|
+
const linkBtn = {
|
|
44
21
|
background: 'none',
|
|
45
22
|
border: 'none',
|
|
46
23
|
padding: 0,
|
|
@@ -49,156 +26,218 @@ const autoFitLinkStyle = {
|
|
|
49
26
|
fontSize: 13,
|
|
50
27
|
cursor: 'pointer',
|
|
51
28
|
};
|
|
52
|
-
const
|
|
29
|
+
const deleteBtn = { ...linkBtn, color: '#ff7a7a' };
|
|
30
|
+
const actionRow = { display: 'flex', justifyContent: 'space-between', alignItems: 'center', margin: '4px 0 12px' };
|
|
31
|
+
const noteStyle = { fontSize: 12, color: 'var(--castle-inspector-muted, #888)', margin: '2px 0 10px' };
|
|
32
|
+
|
|
33
|
+
// --- shape helpers ---------------------------------------------------------
|
|
34
|
+
const FULL_BOX = { type: 'box', x: 0.5, y: 0.5, w: 1, h: 1 };
|
|
35
|
+
// Sensible defaults (box-fractions) for each primitive the Add menu offers.
|
|
36
|
+
const SHAPE_DEFAULTS = {
|
|
37
|
+
box: { type: 'box', x: 0.5, y: 0.5, w: 0.6, h: 0.6 },
|
|
38
|
+
circle: { type: 'circle', x: 0.5, y: 0.5, r: 0.3 },
|
|
39
|
+
triangle: { type: 'triangle', points: [{ x: 0.5, y: 0.15 }, { x: 0.15, y: 0.85 }, { x: 0.85, y: 0.85 }] },
|
|
40
|
+
polygon: {
|
|
41
|
+
type: 'polygon',
|
|
42
|
+
points: [{ x: 0.5, y: 0.12 }, { x: 0.14, y: 0.42 }, { x: 0.3, y: 0.85 }, { x: 0.7, y: 0.85 }, { x: 0.86, y: 0.42 }],
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// The collider's shapes, materialized (default = one full box).
|
|
47
|
+
function currentShapes(component) {
|
|
48
|
+
return Array.isArray(component.shapes) && component.shapes.length > 0 ? component.shapes : [FULL_BOX];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Draw one resolved (world-space) collider shape as an outline.
|
|
52
|
+
function drawShape(ctx, s) {
|
|
53
|
+
if (s.type === 'circle') {
|
|
54
|
+
ctx.beginPath();
|
|
55
|
+
ctx.arc(s.cx, s.cy, s.radius, 0, Math.PI * 2);
|
|
56
|
+
ctx.stroke();
|
|
57
|
+
} else if (s.type === 'triangle' || s.type === 'polygon') {
|
|
58
|
+
if (!s.points || s.points.length < 2) return;
|
|
59
|
+
ctx.beginPath();
|
|
60
|
+
ctx.moveTo(s.points[0].x, s.points[0].y);
|
|
61
|
+
for (let k = 1; k < s.points.length; k++) ctx.lineTo(s.points[k].x, s.points[k].y);
|
|
62
|
+
ctx.closePath();
|
|
63
|
+
ctx.stroke();
|
|
64
|
+
} else {
|
|
65
|
+
ctx.strokeRect(s.x + 1, s.y + 1, s.width - 2, s.height - 2);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
53
68
|
|
|
54
69
|
export class Collider {
|
|
55
70
|
static behaviorName = 'Collider';
|
|
56
71
|
|
|
72
|
+
// A Collider is a LIST of shapes (`shapes`), each a fraction of the Layout box
|
|
73
|
+
// -- so it keeps its relative size when the box is resized. Unset `shapes` = one
|
|
74
|
+
// full-box shape. Only material fields live here; geometry is authored into
|
|
75
|
+
// `shapes` through the inspector.
|
|
57
76
|
static defaultProps = {
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
// "match the actor's Layout box" (see engine/collider.js manualRect and the
|
|
61
|
-
// effective values in the inspector). Defaulting them to a fixed number made
|
|
62
|
-
// every collider shrink to that number instead of tracking the actor.
|
|
63
|
-
radius: 0,
|
|
64
|
-
offsetX: 0,
|
|
65
|
-
offsetY: 0,
|
|
66
|
-
// `isTrigger` marks a sensor: it still reports overlaps (draws yellow, reads
|
|
67
|
-
// as a pass-through zone for pickup/goal logic) but does not block on its
|
|
68
|
-
// own -- collisions are data you act on. Kit modules can register MORE
|
|
69
|
-
// Collider fields from outside this file (the physics module adds
|
|
70
|
-
// bounciness/friction material); see engine/behaviorExtensions.js. That's
|
|
71
|
-
// why this file is byte-identical across kits -- the physics-only fields
|
|
72
|
-
// live in physics/extensions/, not here.
|
|
77
|
+
// `isTrigger` marks a sensor: reports overlaps (draws yellow, pass-through
|
|
78
|
+
// zone for pickup/goal logic) but doesn't block -- collisions are data.
|
|
73
79
|
isTrigger: false,
|
|
74
80
|
debug: false,
|
|
75
|
-
|
|
81
|
+
// Physics material, read by physics/matterBridge.js. `bounciness` =
|
|
82
|
+
// restitution (0 dead .. ~1 very bouncy); `friction` = surface friction;
|
|
83
|
+
// `density` sets mass (= density x total shape area); matter's default 0.001.
|
|
84
|
+
bounciness: 0,
|
|
85
|
+
friction: 0.1,
|
|
86
|
+
// `frictionStatic` is stiction -- resistance to *starting* to slide (matter
|
|
87
|
+
// default 0.5). `density` sets mass (= density x total shape area).
|
|
88
|
+
frictionStatic: 0.5,
|
|
89
|
+
density: 0.001,
|
|
76
90
|
};
|
|
77
91
|
|
|
78
92
|
constructor(props) {
|
|
79
93
|
this.props = props;
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
// Seed props when
|
|
83
|
-
//
|
|
84
|
-
// collider frames the art rather than the whole Layout box. Falls back to the
|
|
85
|
-
// unset (Layout-box) size when there's nothing to fit to -- no sprite, tile
|
|
86
|
-
// mode, or transparent art. The editor's addBehavior calls this (see
|
|
87
|
-
// editors/SceneEditor.jsx initialBehaviorProps).
|
|
96
|
+
// Seed props when first added: fit a single box to the sprite's opaque bounds
|
|
97
|
+
// (or the full box when there's nothing to fit to).
|
|
88
98
|
static initialProps(actor, ctx) {
|
|
89
99
|
const fit = computeAutoFit(actor, ctx?.sprites);
|
|
90
|
-
return fit ? { ...Collider.defaultProps,
|
|
100
|
+
return fit ? { ...Collider.defaultProps, shapes: [fit] } : { ...Collider.defaultProps };
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
draw(actor, scene, ctx, options) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
//
|
|
104
|
+
// A selected instance always shows its collider -- but the editor's selection
|
|
105
|
+
// overlay draws it, so skip here to avoid a double outline.
|
|
106
|
+
if (options.colliderOverlayIds?.includes(actor.id)) return;
|
|
107
|
+
// Otherwise draw when this actor's blueprint is selected in the hotbar (so
|
|
108
|
+
// all its instances light up), or when the per-collider debug flag is on
|
|
109
|
+
// (unselected actors in the editor, and during play).
|
|
110
|
+
const blueprintSelected =
|
|
111
|
+
Boolean(options.dimBlueprintPath) && actor.blueprint === options.dimBlueprintPath;
|
|
112
|
+
if (!blueprintSelected && !options.showDebugColliders && !this.props.debug) return;
|
|
113
|
+
const shapes = getColliderShapes(actor);
|
|
114
|
+
if (!shapes) return;
|
|
98
115
|
const isSensor = Boolean(this.props.isTrigger) || this.props.kind === 'pickup';
|
|
99
116
|
ctx.save();
|
|
100
117
|
ctx.strokeStyle = isSensor ? '#ffe17a' : '#8db7ff';
|
|
101
118
|
ctx.lineWidth = 2;
|
|
102
|
-
|
|
103
|
-
ctx.beginPath();
|
|
104
|
-
ctx.arc(geom.cx, geom.cy, geom.radius, 0, Math.PI * 2);
|
|
105
|
-
ctx.stroke();
|
|
106
|
-
} else {
|
|
107
|
-
ctx.strokeRect(geom.x + 1, geom.y + 1, geom.width - 2, geom.height - 2);
|
|
108
|
-
}
|
|
119
|
+
for (const s of shapes) drawShape(ctx, s);
|
|
109
120
|
ctx.restore();
|
|
110
121
|
}
|
|
111
122
|
|
|
112
123
|
static Inspector({ actor, component, sprites, setComponent, override }) {
|
|
113
|
-
const [
|
|
124
|
+
const [sel, setSel] = useState(0);
|
|
125
|
+
const [addOpen, setAddOpen] = useState(false);
|
|
114
126
|
const layout = actor?.components?.Layout ?? {};
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (key === 'height') return height;
|
|
136
|
-
return component[key] ?? 0;
|
|
127
|
+
const bw = layout.width || 1;
|
|
128
|
+
const bh = layout.height || 1;
|
|
129
|
+
|
|
130
|
+
const shapes = currentShapes(component);
|
|
131
|
+
const i = Math.min(sel, shapes.length - 1);
|
|
132
|
+
const shape = shapes[i];
|
|
133
|
+
const isCircle = shape.type === 'circle';
|
|
134
|
+
const isPoly = shape.type === 'triangle' || shape.type === 'polygon';
|
|
135
|
+
|
|
136
|
+
const writeShapes = (next) => setComponent({ shapes: next });
|
|
137
|
+
const patchSel = (patch) => writeShapes(shapes.map((s, k) => (k === i ? { ...s, ...patch } : s)));
|
|
138
|
+
const addShape = (type) => {
|
|
139
|
+
writeShapes([...shapes, { ...SHAPE_DEFAULTS[type] }]);
|
|
140
|
+
setSel(shapes.length);
|
|
141
|
+
setAddOpen(false);
|
|
142
|
+
};
|
|
143
|
+
const removeSel = () => {
|
|
144
|
+
const next = shapes.filter((_, k) => k !== i);
|
|
145
|
+
writeShapes(next.length ? next : [FULL_BOX]);
|
|
146
|
+
setSel(Math.max(0, i - 1));
|
|
137
147
|
};
|
|
138
|
-
const
|
|
139
|
-
|
|
148
|
+
const setType = (type) => {
|
|
149
|
+
if (type === 'circle') {
|
|
150
|
+
patchSel({ type: 'circle', x: shape.x ?? 0.5, y: shape.y ?? 0.5, r: Math.min(shape.w ?? 1, shape.h ?? 1) / 2, w: undefined, h: undefined });
|
|
151
|
+
} else {
|
|
152
|
+
const d = (shape.r ?? 0.5) * 2;
|
|
153
|
+
patchSel({ type: 'box', x: shape.x ?? 0.5, y: shape.y ?? 0.5, w: d, h: d, r: undefined });
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const widthPx = Math.round((shape.w ?? 1) * bw);
|
|
158
|
+
const heightPx = Math.round((shape.h ?? 1) * bh);
|
|
159
|
+
const radiusPx = Math.round((shape.r ?? 0.5) * Math.min(bw, bh));
|
|
160
|
+
const offXPx = Math.round(((shape.x ?? 0.5) - 0.5) * bw);
|
|
161
|
+
const offYPx = Math.round(((shape.y ?? 0.5) - 0.5) * bh);
|
|
162
|
+
|
|
163
|
+
const density = component.density > 0 ? component.density : 0.001;
|
|
164
|
+
|
|
165
|
+
// Auto-fit (box/circle) for the selected shape.
|
|
166
|
+
const autoFit = isPoly ? null : computeAutoFit(actor, sprites, isCircle);
|
|
167
|
+
const near = (a, b) => Math.abs((a ?? 0) - (b ?? 0)) < 0.01;
|
|
168
|
+
const fitted =
|
|
169
|
+
autoFit &&
|
|
170
|
+
near(autoFit.x, shape.x) &&
|
|
171
|
+
near(autoFit.y, shape.y) &&
|
|
172
|
+
(isCircle ? near(autoFit.r, shape.r) : near(autoFit.w, shape.w) && near(autoFit.h, shape.h));
|
|
140
173
|
|
|
141
174
|
return (
|
|
142
175
|
<Panel title="Collider" overridden={override?.anyOverridden()}>
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
{...overrideProps(override, 'shape')}
|
|
149
|
-
/>
|
|
150
|
-
<div style={dimHeaderRowStyle}>
|
|
151
|
-
<span style={dimCaretStyle}>
|
|
152
|
-
<Icon name={dimOpen ? 'chevron-down' : 'chevron-right'} />
|
|
153
|
-
</span>
|
|
154
|
-
<button type="button" onClick={() => setDimOpen((open) => !open)} style={dimToggleStyle}>
|
|
155
|
-
Dimensions
|
|
156
|
-
</button>
|
|
157
|
-
{autoFitPatch && !alreadyFitted ? (
|
|
158
|
-
<button type="button" onClick={() => setComponent(autoFitPatch)} style={autoFitLinkStyle}>
|
|
159
|
-
Auto-fit to sprite
|
|
176
|
+
{/* Shape list -- one chip per shape + an Add menu (compound is manual). */}
|
|
177
|
+
<div style={rowGap}>
|
|
178
|
+
{shapes.map((s, k) => (
|
|
179
|
+
<button key={k} type="button" onClick={() => setSel(k)} style={chip(k === i)}>
|
|
180
|
+
{s.type} {k + 1}
|
|
160
181
|
</button>
|
|
161
|
-
)
|
|
182
|
+
))}
|
|
183
|
+
<button type="button" onClick={() => setAddOpen((o) => !o)} style={addBtn} title="Add a shape">
|
|
184
|
+
+
|
|
185
|
+
</button>
|
|
162
186
|
</div>
|
|
163
|
-
{
|
|
164
|
-
<div style={
|
|
165
|
-
{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
187
|
+
{addOpen ? (
|
|
188
|
+
<div style={addMenu}>
|
|
189
|
+
{/* triangle/polygon are supported by the data model + runtime but not
|
|
190
|
+
offered in the UI yet (no on-canvas point editing). */}
|
|
191
|
+
{['box', 'circle'].map((t) => (
|
|
192
|
+
<button key={t} type="button" onClick={() => addShape(t)} style={chip(false)}>
|
|
193
|
+
{t}
|
|
194
|
+
</button>
|
|
195
|
+
))}
|
|
196
|
+
</div>
|
|
197
|
+
) : null}
|
|
198
|
+
|
|
199
|
+
{/* Selected shape */}
|
|
200
|
+
{isPoly ? (
|
|
201
|
+
<div style={noteStyle}>
|
|
202
|
+
{shape.type} · {shape.points?.length ?? 0} points (on-canvas point editing coming soon)
|
|
203
|
+
</div>
|
|
204
|
+
) : (
|
|
205
|
+
<>
|
|
206
|
+
<SelectField label="Shape" value={shape.type} onChange={setType} options={['box', 'circle']} />
|
|
207
|
+
{isCircle ? (
|
|
208
|
+
<NumberField label="Radius" value={radiusPx} onChange={(v) => patchSel({ r: v / Math.min(bw, bh) })} />
|
|
172
209
|
) : (
|
|
173
210
|
<>
|
|
174
|
-
<NumberField
|
|
175
|
-
|
|
176
|
-
value={width}
|
|
177
|
-
onChange={(value) => setComponent({ width: value })}
|
|
178
|
-
{...overrideProps(override, 'width')}
|
|
179
|
-
/>
|
|
180
|
-
<NumberField
|
|
181
|
-
label="Height"
|
|
182
|
-
value={height}
|
|
183
|
-
onChange={(value) => setComponent({ height: value })}
|
|
184
|
-
{...overrideProps(override, 'height')}
|
|
185
|
-
/>
|
|
211
|
+
<NumberField label="Width" value={widthPx} onChange={(v) => patchSel({ w: v / bw })} />
|
|
212
|
+
<NumberField label="Height" value={heightPx} onChange={(v) => patchSel({ h: v / bh })} />
|
|
186
213
|
</>
|
|
187
214
|
)}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
215
|
+
</>
|
|
216
|
+
)}
|
|
217
|
+
<NumberField label="Offset X" value={offXPx} onChange={(v) => patchSel({ x: 0.5 + v / bw })} />
|
|
218
|
+
<NumberField label="Offset Y" value={offYPx} onChange={(v) => patchSel({ y: 0.5 + v / bh })} />
|
|
219
|
+
<div style={actionRow}>
|
|
220
|
+
{autoFit && !fitted ? (
|
|
221
|
+
<button type="button" onClick={() => writeShapes(shapes.map((s, k) => (k === i ? autoFit : s)))} style={linkBtn}>
|
|
222
|
+
Auto-fit to sprite
|
|
223
|
+
</button>
|
|
224
|
+
) : (
|
|
225
|
+
<span />
|
|
226
|
+
)}
|
|
227
|
+
{shapes.length > 1 ? (
|
|
228
|
+
<button type="button" onClick={removeSel} style={deleteBtn}>
|
|
229
|
+
Delete shape
|
|
230
|
+
</button>
|
|
231
|
+
) : null}
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
{/* Material (collider-wide) */}
|
|
235
|
+
<NumberField label="Density" value={density} onChange={(v) => setComponent({ density: v })} />
|
|
197
236
|
<AutoFields
|
|
198
237
|
defaultProps={Collider.defaultProps}
|
|
199
238
|
component={component}
|
|
200
239
|
setComponent={setComponent}
|
|
201
|
-
exclude={['
|
|
240
|
+
exclude={['density']}
|
|
202
241
|
override={override}
|
|
203
242
|
/>
|
|
204
243
|
</Panel>
|
|
@@ -206,8 +245,6 @@ export class Collider {
|
|
|
206
245
|
}
|
|
207
246
|
}
|
|
208
247
|
|
|
209
|
-
// Re-exported for callers that need the rect / overlap test outside a
|
|
210
|
-
// scene (e.g. editors/SelectionOverlay.jsx
|
|
211
|
-
|
|
212
|
-
// implementation.
|
|
213
|
-
export { getColliderRect, getColliderShape, intersects };
|
|
248
|
+
// Re-exported for callers that need the rect / shapes / overlap test outside a
|
|
249
|
+
// running scene (e.g. editors/SelectionOverlay.jsx). See engine/collider.js.
|
|
250
|
+
export { getColliderRect, getColliderShapes, intersects };
|
|
@@ -797,7 +797,9 @@ function useSelectionGesture(args) {
|
|
|
797
797
|
const point = { x: raw.x + cam.x, y: raw.y + cam.y };
|
|
798
798
|
current.canvasRef.current.setPointerCapture(event.pointerId);
|
|
799
799
|
const scene = makeScene(current.sceneData, behaviorClasses, current.sprites, current.files);
|
|
800
|
-
const
|
|
800
|
+
const stack = scene.actorsAt(point.x, point.y);
|
|
801
|
+
const stackIds = stack.map((a) => a.id);
|
|
802
|
+
const actor = stack[0] ?? null;
|
|
801
803
|
const drag = {
|
|
802
804
|
pointerId: event.pointerId,
|
|
803
805
|
startPoint: point,
|
|
@@ -820,7 +822,7 @@ function useSelectionGesture(args) {
|
|
|
820
822
|
} else if (current.multiSelectMode) {
|
|
821
823
|
handleModePointerDown(drag, actor, current);
|
|
822
824
|
} else {
|
|
823
|
-
handleDefaultPointerDown(drag, actor, point, current);
|
|
825
|
+
handleDefaultPointerDown(drag, actor, point, current, stackIds);
|
|
824
826
|
}
|
|
825
827
|
drag.moveStarts = collectMoveStarts(current.sceneData, drag.movingActorIds);
|
|
826
828
|
dragRef.current = drag;
|
|
@@ -891,6 +893,13 @@ function useSelectionGesture(args) {
|
|
|
891
893
|
finalizeMarquee(drag, current);
|
|
892
894
|
} else if (drag.kind === 'idle' && !drag.movedFar && !drag.longPressFired) {
|
|
893
895
|
handleTap(drag, current);
|
|
896
|
+
} else if (
|
|
897
|
+
drag.kind === 'move' &&
|
|
898
|
+
!drag.movedFar &&
|
|
899
|
+
!drag.longPressFired &&
|
|
900
|
+
drag.cycleStack
|
|
901
|
+
) {
|
|
902
|
+
cycleSelection(drag, current);
|
|
894
903
|
}
|
|
895
904
|
current.marqueeRef.current = null;
|
|
896
905
|
dragRef.current = null;
|
|
@@ -1198,13 +1207,23 @@ function handleModePointerDown(drag, actor, current) {
|
|
|
1198
1207
|
drag.pendingMarquee = true;
|
|
1199
1208
|
}
|
|
1200
1209
|
}
|
|
1201
|
-
function handleDefaultPointerDown(drag, actor, point, current) {
|
|
1210
|
+
function handleDefaultPointerDown(drag, actor, point, current, stackIds) {
|
|
1202
1211
|
if (actor) {
|
|
1203
|
-
|
|
1212
|
+
const sel = current.selectedActorIds;
|
|
1213
|
+
if (sel.length === 1 && stackIds.length > 1 && stackIds.includes(sel[0])) {
|
|
1214
|
+
// Overlapping pile with a single selected actor under the cursor: keep it
|
|
1215
|
+
// selected so it stays draggable, and arm click-to-cycle so a stationary
|
|
1216
|
+
// click descends to the next actor beneath it (see cycleSelection).
|
|
1217
|
+
drag.movingActorIds = [...sel];
|
|
1218
|
+
drag.cycleStack = stackIds;
|
|
1219
|
+
} else if (sel.includes(actor.id)) {
|
|
1220
|
+
// Pressed an actor that's part of the current selection: keep the
|
|
1221
|
+
// selection so the whole group stays draggable.
|
|
1222
|
+
drag.movingActorIds = [...sel];
|
|
1223
|
+
} else {
|
|
1224
|
+
// Fresh pick: select the topmost actor under the cursor.
|
|
1204
1225
|
current.onSelectActorIds([actor.id]);
|
|
1205
1226
|
drag.movingActorIds = [actor.id];
|
|
1206
|
-
} else {
|
|
1207
|
-
drag.movingActorIds = [...current.selectedActorIds];
|
|
1208
1227
|
}
|
|
1209
1228
|
drag.kind = 'move';
|
|
1210
1229
|
drag.longPressTimer = window.setTimeout(() => {
|
|
@@ -1235,6 +1254,20 @@ function finalizeMarquee(drag, current) {
|
|
|
1235
1254
|
for (const id of hits) merged.add(id);
|
|
1236
1255
|
current.onSelectActorIds([...merged]);
|
|
1237
1256
|
}
|
|
1257
|
+
// A stationary click on a pile of overlapping actors advances the selection to
|
|
1258
|
+
// the next actor below the currently selected one, wrapping around at the
|
|
1259
|
+
// bottom. This lets repeated clicks in the same spot reach an actor buried under
|
|
1260
|
+
// others that would otherwise always win the topmost hit-test.
|
|
1261
|
+
function cycleSelection(drag, current) {
|
|
1262
|
+
const stack = drag.cycleStack;
|
|
1263
|
+
if (!stack || stack.length < 2) return;
|
|
1264
|
+
const sel = current.selectedActorIds;
|
|
1265
|
+
if (sel.length !== 1) return;
|
|
1266
|
+
const idx = stack.indexOf(sel[0]);
|
|
1267
|
+
if (idx === -1) return;
|
|
1268
|
+
const nextId = stack[(idx + 1) % stack.length];
|
|
1269
|
+
if (nextId !== sel[0]) current.onSelectActorIds([nextId]);
|
|
1270
|
+
}
|
|
1238
1271
|
function handleTap(drag, current) {
|
|
1239
1272
|
if (!drag.modeAtStart) return;
|
|
1240
1273
|
if (drag.startedOnActorId !== null) {
|
|
@@ -1357,6 +1390,9 @@ function useScenePlayLoop({
|
|
|
1357
1390
|
showGrid: !isPlaying && snap.enabled && editSelectedActorIds.length > 0,
|
|
1358
1391
|
gridSize: snap.gridSize,
|
|
1359
1392
|
showDebugColliders: false,
|
|
1393
|
+
// Selected actors' colliders are drawn by the selection overlay; tell
|
|
1394
|
+
// Collider.draw to skip them so a selected+debug collider isn't doubled.
|
|
1395
|
+
colliderOverlayIds: editSelectedActorIds,
|
|
1360
1396
|
showCropOutline: !isPlaying,
|
|
1361
1397
|
viewport: frameViewport,
|
|
1362
1398
|
useCamera: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { getColliderShapes } from '../behaviors/Collider';
|
|
3
3
|
import { cardSize, screenToCard } from '../engine/scene';
|
|
4
4
|
import { cx, Icon, styles, useElementSize } from '../engine/ui';
|
|
5
5
|
|
|
@@ -211,9 +211,9 @@ export function SelectionOverlay({
|
|
|
211
211
|
<div
|
|
212
212
|
className={styles.selChromeWorld}
|
|
213
213
|
style={{ transform: `translate(${-geometry.camX}px, ${-geometry.camY}px)` }}>
|
|
214
|
-
{colliderFrames.map((collider) => (
|
|
214
|
+
{colliderFrames.map((collider, i) => (
|
|
215
215
|
<div
|
|
216
|
-
key={collider.actorId}
|
|
216
|
+
key={`${collider.actorId}:${i}`}
|
|
217
217
|
className={cx(
|
|
218
218
|
styles.selColliderBox,
|
|
219
219
|
collider.isTrigger && styles.selColliderPickup
|
|
@@ -461,33 +461,62 @@ function getSelectedColliderFrames(sceneData, actorIds, sprites) {
|
|
|
461
461
|
const wanted = new Set(actorIds);
|
|
462
462
|
return sceneData.actors
|
|
463
463
|
.filter((actor) => wanted.has(actor.id))
|
|
464
|
-
.
|
|
464
|
+
.flatMap((actor) => {
|
|
465
465
|
const layout = actor.components.Layout;
|
|
466
466
|
const collider = actor.components.Collider;
|
|
467
|
-
const
|
|
468
|
-
if (!layout || !collider || !
|
|
469
|
-
|
|
470
|
-
//
|
|
471
|
-
// matches the physics body
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
467
|
+
const shapes = getColliderShapes(actor);
|
|
468
|
+
if (!layout || !collider || !shapes) return [];
|
|
469
|
+
const isTrigger = Boolean(collider.isTrigger) || collider.kind === 'pickup';
|
|
470
|
+
// One preview box per collider shape, from the shared geometry so the
|
|
471
|
+
// preview matches the physics body. A circle renders as a radius-sized
|
|
472
|
+
// square with border-radius; a triangle/polygon as its AABB (v1).
|
|
473
|
+
return shapes.map((s) => {
|
|
474
|
+
let kind = 'box';
|
|
475
|
+
let x;
|
|
476
|
+
let y;
|
|
477
|
+
let width;
|
|
478
|
+
let height;
|
|
479
|
+
if (s.type === 'circle') {
|
|
480
|
+
kind = 'circle';
|
|
481
|
+
x = s.cx - s.radius;
|
|
482
|
+
y = s.cy - s.radius;
|
|
483
|
+
width = s.radius * 2;
|
|
484
|
+
height = s.radius * 2;
|
|
485
|
+
} else if (s.type === 'triangle' || s.type === 'polygon') {
|
|
486
|
+
let x0 = Infinity;
|
|
487
|
+
let y0 = Infinity;
|
|
488
|
+
let x1 = -Infinity;
|
|
489
|
+
let y1 = -Infinity;
|
|
490
|
+
for (const p of s.points) {
|
|
491
|
+
if (p.x < x0) x0 = p.x;
|
|
492
|
+
if (p.y < y0) y0 = p.y;
|
|
493
|
+
if (p.x > x1) x1 = p.x;
|
|
494
|
+
if (p.y > y1) y1 = p.y;
|
|
495
|
+
}
|
|
496
|
+
x = x0;
|
|
497
|
+
y = y0;
|
|
498
|
+
width = x1 - x0;
|
|
499
|
+
height = y1 - y0;
|
|
500
|
+
} else {
|
|
501
|
+
x = s.x;
|
|
502
|
+
y = s.y;
|
|
503
|
+
width = s.width;
|
|
504
|
+
height = s.height;
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
actorId: actor.id,
|
|
508
|
+
shape: kind,
|
|
509
|
+
isTrigger,
|
|
510
|
+
x,
|
|
511
|
+
y,
|
|
512
|
+
width,
|
|
513
|
+
height,
|
|
514
|
+
rotation: layout.rotation ?? 0,
|
|
515
|
+
originX: layout.x + layout.width / 2 - x,
|
|
516
|
+
originY: layout.y + layout.height / 2 - y,
|
|
517
|
+
};
|
|
518
|
+
});
|
|
519
|
+
});
|
|
491
520
|
}
|
|
492
521
|
|
|
493
522
|
function getSharedRotation(layouts) {
|