@pinkaphant/kolmo 0.4.4 → 0.4.6
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/AGENTS.md +29 -0
- package/CLAUDE.md +8 -0
- package/README.md +67 -8
- package/bin/kolmo.mjs +456 -16
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.js +7 -5
- package/dist/engine/kolmoActions.js +24 -9
- package/dist/engine/kolmoActions.js.map +1 -1
- package/dist/engine/kolmoActor.js +19 -31
- package/dist/engine/kolmoActor.js.map +1 -1
- package/dist/engine/kolmoActorHelpers.d.ts +24 -0
- package/dist/engine/kolmoActorHelpers.js +64 -0
- package/dist/engine/kolmoActorHelpers.js.map +1 -0
- package/dist/engine/kolmoGame.js +4 -1
- package/dist/engine/kolmoGame.js.map +1 -1
- package/dist/engine/kolmoHud.js +34 -15
- package/dist/engine/kolmoHud.js.map +1 -1
- package/dist/engine/kolmoInput.d.ts +2 -0
- package/dist/engine/kolmoInput.js +12 -12
- package/dist/engine/kolmoInput.js.map +1 -1
- package/dist/engine/kolmoLongDrive.d.ts +1 -1
- package/dist/engine/kolmoLongDrive.js +10 -8
- package/dist/engine/kolmoLongDrive.js.map +1 -1
- package/dist/engine/kolmoPilotMesh.js +189 -48
- package/dist/engine/kolmoPilotMesh.js.map +1 -1
- package/dist/engine/kolmoTouchOverlay.d.ts +21 -0
- package/dist/engine/kolmoTouchOverlay.js +326 -0
- package/dist/engine/kolmoTouchOverlay.js.map +1 -0
- package/dist/engine/kolmoTouchState.d.ts +50 -0
- package/dist/engine/kolmoTouchState.js +210 -0
- package/dist/engine/kolmoTouchState.js.map +1 -0
- package/dist/engine/kolmoVehicleConfig.d.ts +2 -0
- package/dist/engine/kolmoVehicleConfig.js +8 -4
- package/dist/engine/kolmoVehicleConfig.js.map +1 -1
- package/dist/engine/kolmoVehicleDriver.d.ts +1 -0
- package/dist/engine/kolmoVehicleDriver.js +26 -50
- package/dist/engine/kolmoVehicleDriver.js.map +1 -1
- package/dist/engine/kolmoVehicleInner.js +31 -19
- package/dist/engine/kolmoVehicleInner.js.map +1 -1
- package/dist/engine/kolmoWorld.js +6 -2
- package/dist/engine/kolmoWorld.js.map +1 -1
- package/dist/engine/longDriveKit.d.ts +6 -1
- package/dist/engine/longDriveKit.js +8 -5
- package/dist/engine/longDriveKit.js.map +1 -1
- package/dist/engine/macroCellBuilder.d.ts +10 -0
- package/dist/engine/macroCellBuilder.js +101 -18
- package/dist/engine/macroCellBuilder.js.map +1 -1
- package/dist/engine/mainlandMacroCell.js +18 -9
- package/dist/engine/mainlandMacroCell.js.map +1 -1
- package/dist/importer/DomainWorkshopPanel.d.ts +3 -3
- package/dist/importer/DomainWorkshopPanel.js +148 -44
- package/dist/importer/DomainWorkshopPanel.js.map +1 -1
- package/dist/importer/GateHudBar.d.ts +2 -0
- package/dist/importer/GateHudBar.js +113 -35
- package/dist/importer/GateHudBar.js.map +1 -1
- package/dist/importer/GlbImportGate.js +16 -3
- package/dist/importer/GlbImportGate.js.map +1 -1
- package/dist/importer/LiveDrivePads.js +5 -3
- package/dist/importer/LiveDrivePads.js.map +1 -1
- package/dist/importer/Step1CalibrationPlinth.js +2 -2
- package/dist/importer/WheelRingHandles3D.js +2 -1
- package/dist/importer/WheelRingHandles3D.js.map +1 -1
- package/dist/importer/chopShopActions.js +20 -16
- package/dist/importer/chopShopActions.js.map +1 -1
- package/dist/importer/chopShopHandlers.js +16 -9
- package/dist/importer/chopShopHandlers.js.map +1 -1
- package/dist/importer/chopShopIoActions.d.ts +2 -0
- package/dist/importer/chopShopIoActions.js +33 -2
- package/dist/importer/chopShopIoActions.js.map +1 -1
- package/dist/importer/cylinderBooleanSlice.js.map +1 -1
- package/dist/importer/fusedWheelDetect.d.ts +2 -2
- package/dist/importer/fusedWheelDetect.js +227 -106
- package/dist/importer/fusedWheelDetect.js.map +1 -1
- package/dist/importer/fusedWheelFit.d.ts +6 -0
- package/dist/importer/fusedWheelFit.js +82 -1
- package/dist/importer/fusedWheelFit.js.map +1 -1
- package/dist/importer/gateStore.d.ts +2 -2
- package/dist/importer/gateStore.js +4 -3
- package/dist/importer/gateStore.js.map +1 -1
- package/dist/importer/glbNormalizer.js +5 -0
- package/dist/importer/glbNormalizer.js.map +1 -1
- package/dist/importer/importerWebMcpTools.js +3 -2
- package/dist/importer/importerWebMcpTools.js.map +1 -1
- package/dist/importer/index.d.ts +4 -2
- package/dist/importer/index.js +7 -3
- package/dist/importer/khrCarGeometryMass.d.ts +20 -0
- package/dist/importer/khrCarGeometryMass.js +125 -0
- package/dist/importer/khrCarGeometryMass.js.map +1 -0
- package/dist/importer/khrCarPlanHelpers.js +12 -22
- package/dist/importer/khrCarPlanHelpers.js.map +1 -1
- package/dist/importer/khrCarPlanner.js +52 -85
- package/dist/importer/khrCarPlanner.js.map +1 -1
- package/dist/importer/proceduralC12AndCraft.d.ts +18 -0
- package/dist/importer/proceduralC12AndCraft.js +302 -0
- package/dist/importer/proceduralC12AndCraft.js.map +1 -0
- package/dist/importer/proceduralDomainBuilders.d.ts +10 -0
- package/dist/importer/proceduralDomainBuilders.js +346 -0
- package/dist/importer/proceduralDomainBuilders.js.map +1 -0
- package/dist/importer/proceduralPersonAndProp.d.ts +8 -0
- package/dist/importer/proceduralPersonAndProp.js +303 -0
- package/dist/importer/proceduralPersonAndProp.js.map +1 -0
- package/dist/importer/starterScene.d.ts +3 -1
- package/dist/importer/starterScene.js +69 -13
- package/dist/importer/starterScene.js.map +1 -1
- package/dist/importer/universalGateBake.js +43 -11
- package/dist/importer/universalGateBake.js.map +1 -1
- package/dist/importer/useChopShopController.d.ts +3 -1
- package/dist/importer/useChopShopController.js +33 -18
- package/dist/importer/useChopShopController.js.map +1 -1
- package/dist/importer/useChopShopState.d.ts +1 -1
- package/dist/importer/useChopShopState.js +35 -9
- package/dist/importer/useChopShopState.js.map +1 -1
- package/dist/importer/wheelCutterHelpers.d.ts +7 -4
- package/dist/importer/wheelCutterHelpers.js +58 -28
- package/dist/importer/wheelCutterHelpers.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -7
- package/dist/junk/DestructibleTarget.js +9 -3
- package/dist/junk/DestructibleTarget.js.map +1 -1
- package/dist/junk/ShardPieces.js +10 -2
- package/dist/junk/ShardPieces.js.map +1 -1
- package/dist/junk/index.d.ts +1 -0
- package/dist/junk/index.js +2 -1
- package/dist/junk/junkProceduralScenes.d.ts +12 -0
- package/dist/junk/junkProceduralScenes.js +220 -0
- package/dist/junk/junkProceduralScenes.js.map +1 -0
- package/dist/sand3d/KolmoSand3D.d.ts +19 -0
- package/dist/sand3d/KolmoSand3D.js +92 -0
- package/dist/sand3d/KolmoSand3D.js.map +1 -0
- package/dist/sand3d/Sand3dWorkshopSection.d.ts +8 -0
- package/dist/sand3d/Sand3dWorkshopSection.js +117 -0
- package/dist/sand3d/Sand3dWorkshopSection.js.map +1 -0
- package/dist/sand3d/gateBakeHelpers.d.ts +21 -0
- package/dist/sand3d/gateBakeHelpers.js +225 -0
- package/dist/sand3d/gateBakeHelpers.js.map +1 -0
- package/dist/sand3d/gateDoorwayBake.d.ts +12 -0
- package/dist/sand3d/gateDoorwayBake.js +203 -0
- package/dist/sand3d/gateDoorwayBake.js.map +1 -0
- package/dist/sand3d/index.d.ts +3 -0
- package/dist/sand3d/index.js +4 -0
- package/dist/sand3d/index.js.map +1 -0
- package/dist/sand3d/sand3dAssetLoader.d.ts +28 -0
- package/dist/sand3d/sand3dAssetLoader.js +177 -0
- package/dist/sand3d/sand3dAssetLoader.js.map +1 -0
- package/dist/suika/KolmoSuikaOrb.d.ts +33 -0
- package/dist/suika/KolmoSuikaOrb.js +375 -0
- package/dist/suika/KolmoSuikaOrb.js.map +1 -0
- package/dist/suika/index.d.ts +4 -0
- package/dist/suika/index.js +5 -0
- package/dist/suika/index.js.map +1 -0
- package/dist/suika/suikaArbiter.d.ts +60 -0
- package/dist/suika/suikaArbiter.js +265 -0
- package/dist/suika/suikaArbiter.js.map +1 -0
- package/dist/suika/suikaGeometry.d.ts +10 -0
- package/dist/suika/suikaGeometry.js +251 -0
- package/dist/suika/suikaGeometry.js.map +1 -0
- package/dist/suika/suikaTypes.d.ts +74 -0
- package/dist/suika/suikaTypes.js +196 -0
- package/dist/suika/suikaTypes.js.map +1 -0
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +2 -2
- package/dist/world/worldTypes.d.ts +4 -0
- package/dist/world/worldTypes.js +21 -1
- package/dist/world/worldTypes.js.map +1 -1
- package/docs/api-reference.md +82 -125
- package/package.json +22 -11
- package/skills/kolmo-engine/SKILL.md +111 -0
package/bin/kolmo.mjs
CHANGED
|
@@ -18,7 +18,7 @@ const template = rawTpl === "dust" || rawTpl === "garage" || rawTpl === "longlin
|
|
|
18
18
|
const targetDir = path.resolve(process.cwd(), dirArg);
|
|
19
19
|
|
|
20
20
|
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
21
|
-
console.error(`Error: Target directory "${targetDir}" already
|
|
21
|
+
console.error(`Error: Target directory "${targetDir}" already contains files. Choose a fresh directory path.`);
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -39,11 +39,6 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
39
39
|
},
|
|
40
40
|
dependencies: {
|
|
41
41
|
"@dimforge/rapier3d-compat": "0.19.2",
|
|
42
|
-
"@khr3/assets": kolmoPkg.dependencies["@khr3/assets"],
|
|
43
|
-
"@khr3/c12": kolmoPkg.dependencies["@khr3/c12"],
|
|
44
|
-
"@khr3/core": kolmoPkg.dependencies["@khr3/core"],
|
|
45
|
-
"@khr3/launchers": kolmoPkg.dependencies["@khr3/launchers"],
|
|
46
|
-
"@khr3/vehicles": kolmoPkg.dependencies["@khr3/vehicles"],
|
|
47
42
|
"@pinkaphant/ecctrl": kolmoPkg.peerDependencies["@pinkaphant/ecctrl"],
|
|
48
43
|
"@pinkaphant/kolmo": `^${kolmoPkg.version}`,
|
|
49
44
|
"@react-three/drei": "^10.7.7",
|
|
@@ -57,7 +52,7 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
57
52
|
},
|
|
58
53
|
overrides: {
|
|
59
54
|
"@dimforge/rapier3d-compat": "0.19.2",
|
|
60
|
-
"@pinkaphant/ecctrl": "2.0.4-beta.
|
|
55
|
+
"@pinkaphant/ecctrl": "2.0.4-beta.4",
|
|
61
56
|
},
|
|
62
57
|
devDependencies: {
|
|
63
58
|
"@types/node": "^22.20.5",
|
|
@@ -103,17 +98,462 @@ fs.writeFileSync(path.join(targetDir, "wrangler.jsonc"), JSON.stringify({
|
|
|
103
98
|
assets: { directory: "./dist", not_found_handling: "single-page-application" },
|
|
104
99
|
}, null, 2));
|
|
105
100
|
|
|
106
|
-
fs.writeFileSync(path.join(targetDir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:
|
|
101
|
+
fs.writeFileSync(path.join(targetDir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:100dvh;overflow:hidden;background:#05070e;touch-action:none;user-select:none;-webkit-user-select:none}canvas{touch-action:none;display:block}</style></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>\n`);
|
|
107
102
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
const DUST_WORLD_SRC = `import { useEffect, useMemo, useRef, useState } from "react";
|
|
104
|
+
import * as THREE from "three";
|
|
105
|
+
import { useFrame, useThree } from "@react-three/fiber";
|
|
106
|
+
import { CuboidCollider, RigidBody } from "@react-three/rapier";
|
|
107
|
+
import { Junk, computeIslandSpawnPose, getCachedIslandPlan } from "@pinkaphant/kolmo";
|
|
108
|
+
|
|
109
|
+
export interface BuiltWall { id: number; pos: [number, number, number]; yaw: number; tier: "wood" | "stone"; }
|
|
110
|
+
|
|
111
|
+
const _fwd = new THREE.Vector3();
|
|
112
|
+
|
|
113
|
+
export function DustGameplay({
|
|
114
|
+
tool, yawStep, tier, onHarvest, walls, onPlaceWall,
|
|
115
|
+
}: {
|
|
116
|
+
tool: "harvest" | "build";
|
|
117
|
+
yawStep: number;
|
|
118
|
+
tier: "wood" | "stone";
|
|
119
|
+
onHarvest: (kind: "wood" | "stone", amount: number) => void;
|
|
120
|
+
walls: readonly BuiltWall[];
|
|
121
|
+
onPlaceWall: (pos: [number, number, number], yaw: number) => void;
|
|
122
|
+
}) {
|
|
123
|
+
const camera = useThree((s) => s.camera);
|
|
124
|
+
const plan = useMemo(() => getCachedIslandPlan(77, 960), []);
|
|
125
|
+
const spawn = useMemo(() => computeIslandSpawnPose(77, 960), []);
|
|
126
|
+
const ghostRef = useRef<THREE.Mesh | null>(null);
|
|
127
|
+
const ghostPose = useRef<[number, number, number]>([spawn.actorPos[0], spawn.actorPos[1] + 1.5, spawn.actorPos[2] + 6]);
|
|
128
|
+
const [depleted, setDepleted] = useState<Record<number, number>>({});
|
|
129
|
+
|
|
130
|
+
const nodes = useMemo(() => {
|
|
131
|
+
const list: { id: number; kind: "wood" | "stone"; pos: [number, number, number] }[] = [];
|
|
132
|
+
for (let i = 0; i < 24; i++) {
|
|
133
|
+
const ang = (i / 24) * Math.PI * 2, r = 10 + (i % 4) * 6;
|
|
134
|
+
const x = spawn.actorPos[0] + Math.cos(ang) * r, z = spawn.actorPos[2] + Math.sin(ang) * r;
|
|
135
|
+
const y = plan.terrain.height(x, z);
|
|
136
|
+
list.push({ id: i + 1, kind: i % 3 === 0 ? "stone" : "wood", pos: [x, y, z] });
|
|
137
|
+
}
|
|
138
|
+
return list;
|
|
139
|
+
}, [plan, spawn]);
|
|
140
|
+
|
|
141
|
+
const yawRad = (yawStep * Math.PI) / 6;
|
|
142
|
+
|
|
143
|
+
useFrame(() => {
|
|
144
|
+
_fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
145
|
+
const gx = Math.round((camera.position.x + _fwd.x * 5.5) / 3) * 3;
|
|
146
|
+
const gz = Math.round((camera.position.z + _fwd.z * 5.5) / 3) * 3;
|
|
147
|
+
const gy = plan.terrain.height(gx, gz) + 1.5;
|
|
148
|
+
ghostPose.current[0] = gx;
|
|
149
|
+
ghostPose.current[1] = gy;
|
|
150
|
+
ghostPose.current[2] = gz;
|
|
151
|
+
if (ghostRef.current) {
|
|
152
|
+
ghostRef.current.position.set(gx, gy, gz);
|
|
153
|
+
ghostRef.current.rotation.set(0, yawRad, 0);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
const act = () => {
|
|
159
|
+
if (tool === "build") {
|
|
160
|
+
onPlaceWall([...ghostPose.current], yawRad);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const now = Date.now();
|
|
164
|
+
let best: (typeof nodes)[number] | null = null, bestD = 9.5;
|
|
165
|
+
for (const n of nodes) {
|
|
166
|
+
if ((depleted[n.id] ?? 0) > now) continue;
|
|
167
|
+
const d = Math.hypot(n.pos[0] - camera.position.x, n.pos[1] + 1 - camera.position.y, n.pos[2] - camera.position.z);
|
|
168
|
+
if (d < bestD) { bestD = d; best = n; }
|
|
169
|
+
}
|
|
170
|
+
if (best) {
|
|
171
|
+
onHarvest(best.kind, best.kind === "wood" ? 25 : 20);
|
|
172
|
+
setDepleted((prev) => ({ ...prev, [best!.id]: now + 8000 }));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const onClick = (e: MouseEvent) => { if ((e.target as HTMLElement)?.tagName === "CANVAS") act(); };
|
|
176
|
+
const onKey = (e: KeyboardEvent) => { if (e.code === "KeyE") act(); };
|
|
177
|
+
window.addEventListener("pointerdown", onClick);
|
|
178
|
+
window.addEventListener("keydown", onKey);
|
|
179
|
+
return () => { window.removeEventListener("pointerdown", onClick); window.removeEventListener("keydown", onKey); };
|
|
180
|
+
}, [tool, yawRad, nodes, depleted, camera, onHarvest, onPlaceWall]);
|
|
181
|
+
|
|
182
|
+
const now = Date.now();
|
|
183
|
+
return (
|
|
184
|
+
<group>
|
|
185
|
+
{nodes.map((n) => (depleted[n.id] ?? 0) > now ? null : (
|
|
186
|
+
<RigidBody key={n.id} type="fixed" position={n.pos}>
|
|
187
|
+
<CuboidCollider args={n.kind === "wood" ? [0.45, 1.8, 0.45] : [0.85, 0.65, 0.85]} position={[0, n.kind === "wood" ? 1.8 : 0.65, 0]} />
|
|
188
|
+
{n.kind === "wood" ? (
|
|
189
|
+
<group>
|
|
190
|
+
<mesh position={[0, 1.1, 0]}><cylinderGeometry args={[0.22, 0.3, 2.2, 7]} /><meshStandardMaterial color="#5c3a21" flatShading /></mesh>
|
|
191
|
+
<mesh position={[0, 2.9, 0]}><coneGeometry args={[1.35, 2.8, 7]} /><meshStandardMaterial color="#2d5a27" flatShading /></mesh>
|
|
192
|
+
</group>
|
|
193
|
+
) : (
|
|
194
|
+
<mesh position={[0, 0.65, 0]}><dodecahedronGeometry args={[0.95, 0]} /><meshStandardMaterial color="#64748b" flatShading /></mesh>
|
|
195
|
+
)}
|
|
196
|
+
</RigidBody>
|
|
197
|
+
))}
|
|
198
|
+
<Junk id="dust_salvage_1" position={[spawn.actorPos[0] + 3, spawn.actorPos[1] + 1.2, spawn.actorPos[2] - 4]} />
|
|
199
|
+
{tool === "build" && (
|
|
200
|
+
<mesh ref={ghostRef}>
|
|
201
|
+
<boxGeometry args={[3.0, 3.0, 0.28]} />
|
|
202
|
+
<meshStandardMaterial color={tier === "wood" ? "#f59e0b" : "#38bdf8"} transparent opacity={0.42} depthWrite={false} />
|
|
203
|
+
</mesh>
|
|
204
|
+
)}
|
|
205
|
+
{walls.map((w) => (
|
|
206
|
+
<RigidBody key={w.id} type="fixed" position={w.pos} rotation={[0, w.yaw, 0]}>
|
|
207
|
+
<CuboidCollider args={[1.5, 1.5, 0.14]} />
|
|
208
|
+
<mesh castShadow receiveShadow>
|
|
209
|
+
<boxGeometry args={[3.0, 3.0, 0.28]} />
|
|
210
|
+
<meshStandardMaterial color={w.tier === "wood" ? "#8b5a2b" : "#475569"} flatShading />
|
|
211
|
+
</mesh>
|
|
212
|
+
</RigidBody>
|
|
213
|
+
))}
|
|
214
|
+
</group>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
`;
|
|
218
|
+
|
|
219
|
+
const DUST_APP_SRC = `import { useCallback, useEffect, useState } from "react";
|
|
220
|
+
import { Actor, Game, Hud, Island, MobileTouchOverlay, RETRO_PS2_SHINOBI, Vehicle } from "@pinkaphant/kolmo";
|
|
221
|
+
import { DustGameplay, type BuiltWall } from "./DustGameplay.tsx";
|
|
222
|
+
|
|
223
|
+
export function App() {
|
|
224
|
+
const [wood, setWood] = useState(45);
|
|
225
|
+
const [stone, setStone] = useState(30);
|
|
226
|
+
const [tool, setTool] = useState<"harvest" | "build">("harvest");
|
|
227
|
+
const [tier, setTier] = useState<"wood" | "stone">("wood");
|
|
228
|
+
const [yawStep, setYawStep] = useState(0);
|
|
229
|
+
const [walls, setWalls] = useState<BuiltWall[]>([]);
|
|
230
|
+
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
const onKey = (e: KeyboardEvent) => {
|
|
233
|
+
if (e.code === "Digit1") setTool("harvest");
|
|
234
|
+
else if (e.code === "Digit2") setTool("build");
|
|
235
|
+
else if (e.code === "KeyQ") setYawStep((s) => (s + 11) % 12);
|
|
236
|
+
else if (e.code === "KeyT") setTier((t) => (t === "wood" ? "stone" : "wood"));
|
|
237
|
+
};
|
|
238
|
+
window.addEventListener("keydown", onKey);
|
|
239
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
240
|
+
}, []);
|
|
241
|
+
|
|
242
|
+
const handleHarvest = useCallback((kind: "wood" | "stone", amt: number) => {
|
|
243
|
+
if (kind === "wood") setWood((w) => w + amt);
|
|
244
|
+
else setStone((s) => s + amt);
|
|
245
|
+
}, []);
|
|
246
|
+
|
|
247
|
+
const handlePlaceWall = useCallback((pos: [number, number, number], yaw: number) => {
|
|
248
|
+
if (tier === "wood" && wood < 15) return;
|
|
249
|
+
if (tier === "stone" && stone < 15) return;
|
|
250
|
+
if (tier === "wood") setWood((w) => w - 15);
|
|
251
|
+
else setStone((s) => s - 15);
|
|
252
|
+
setWalls((prev) => [...prev, { id: prev.length + 1, pos, yaw, tier }]);
|
|
253
|
+
}, [tier, wood, stone]);
|
|
254
|
+
|
|
255
|
+
const tierLabel = tier === "wood" ? "Wood" : "Stone";
|
|
256
|
+
return (
|
|
257
|
+
<div style={{ position: "relative", width: "100vw", height: "100dvh", overflow: "hidden", touchAction: "none", userSelect: "none", WebkitUserSelect: "none" }}>
|
|
258
|
+
<Game retro={RETRO_PS2_SHINOBI}>
|
|
259
|
+
<Island seed={77} size={960} settlementTier="town" />
|
|
260
|
+
<Vehicle />
|
|
261
|
+
<Actor />
|
|
262
|
+
<DustGameplay tool={tool} yawStep={yawStep} tier={tier} onHarvest={handleHarvest} walls={walls} onPlaceWall={handlePlaceWall} />
|
|
263
|
+
<Hud />
|
|
264
|
+
<MobileTouchOverlay />
|
|
265
|
+
</Game>
|
|
266
|
+
<div style={{ position: "fixed", top: "max(12px, env(safe-area-inset-top))", right: "max(12px, env(safe-area-inset-right))", zIndex: 40, padding: "8px 12px", background: "rgba(9,13,22,0.86)", border: "1px solid #f59e0b", borderRadius: 6, color: "#f8fafc", fontFamily: "ui-monospace, monospace", fontSize: 12 }}>
|
|
267
|
+
<div style={{ fontWeight: 700, color: "#fbbf24", marginBottom: 4 }}>Kolmo Dust · C12 Survival</div>
|
|
268
|
+
<div>Wood <b>{wood}</b> · Stone <b>{stone}</b> · Walls <b>{walls.length}</b></div>
|
|
269
|
+
<div style={{ color: "#94a3b8", marginTop: 4 }}>[1] Harvest ({tool === "harvest" ? "active" : "idle"}) · [2] Build C12 ({tool === "build" ? tierLabel : "idle"}) · [Q] Rotate 30° · [T] Tier · [Click/E] Use</div>
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
`;
|
|
275
|
+
|
|
276
|
+
const LONGLINE_WORLD_SRC = `import { useEffect, useMemo, useRef, useState } from "react";
|
|
277
|
+
import * as THREE from "three";
|
|
278
|
+
import { useFrame, useThree } from "@react-three/fiber";
|
|
279
|
+
import { CuboidCollider, RigidBody } from "@react-three/rapier";
|
|
280
|
+
import {
|
|
281
|
+
Junk,
|
|
282
|
+
SuikaSystem,
|
|
283
|
+
computeLongDriveMainlandSpawn,
|
|
284
|
+
hashSeed,
|
|
285
|
+
kolmoTelemetry,
|
|
286
|
+
readFloatingOriginAnchorXZ,
|
|
287
|
+
spawnSuikaOrb,
|
|
288
|
+
useActiveKolmoWorld,
|
|
289
|
+
} from "@pinkaphant/kolmo";
|
|
290
|
+
|
|
291
|
+
export interface HighwayHudState { km: number; fuelL: number; targetKm: number; cash: number; stage: number; scrap: number; }
|
|
292
|
+
export type BuildTier = "wood" | "stone" | "metal";
|
|
293
|
+
export interface BuiltC12Wall { id: number; wx: number; y: number; wz: number; yaw: number; tier: BuildTier; }
|
|
294
|
+
interface FuelCanItem { id: number; wx: number; wz: number; y: number; }
|
|
295
|
+
|
|
296
|
+
const _mat4 = new THREE.Matrix4();
|
|
297
|
+
const _quat = new THREE.Quaternion();
|
|
298
|
+
const _pos = new THREE.Vector3();
|
|
299
|
+
const _scale = new THREE.Vector3(1, 1, 1);
|
|
300
|
+
const _up = new THREE.Vector3(0, 1, 0);
|
|
301
|
+
const _fwd = new THREE.Vector3();
|
|
302
|
+
|
|
303
|
+
function InstancedC12Walls({ walls, origin, tier, color }: {
|
|
304
|
+
walls: readonly BuiltC12Wall[];
|
|
305
|
+
origin: readonly [number, number];
|
|
306
|
+
tier: BuildTier;
|
|
307
|
+
color: string;
|
|
308
|
+
}) {
|
|
309
|
+
const ref = useRef<THREE.InstancedMesh>(null);
|
|
310
|
+
const filtered = useMemo(() => walls.filter((w) => w.tier === tier), [walls, tier]);
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
const mesh = ref.current;
|
|
313
|
+
if (!mesh) return;
|
|
314
|
+
filtered.forEach((w, i) => {
|
|
315
|
+
_pos.set(w.wx - origin[0], w.y, w.wz - origin[1]);
|
|
316
|
+
_quat.setFromAxisAngle(_up, w.yaw);
|
|
317
|
+
_mat4.compose(_pos, _quat, _scale);
|
|
318
|
+
mesh.setMatrixAt(i, _mat4);
|
|
319
|
+
});
|
|
320
|
+
mesh.count = filtered.length;
|
|
321
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
322
|
+
}, [filtered, origin]);
|
|
323
|
+
if (filtered.length === 0) return null;
|
|
324
|
+
return (
|
|
325
|
+
<>
|
|
326
|
+
<instancedMesh ref={ref} args={[undefined, undefined, Math.max(1, filtered.length)]} castShadow receiveShadow>
|
|
327
|
+
<boxGeometry args={[3, 3, 0.28]} />
|
|
328
|
+
<meshStandardMaterial color={color} flatShading />
|
|
329
|
+
</instancedMesh>
|
|
330
|
+
{filtered.map((w) => (
|
|
331
|
+
<RigidBody key={w.id} type="fixed" position={[w.wx - origin[0], w.y, w.wz - origin[1]]} rotation={[0, w.yaw, 0]}>
|
|
332
|
+
<CuboidCollider args={[1.5, 1.5, 0.14]} />
|
|
333
|
+
</RigidBody>
|
|
334
|
+
))}
|
|
335
|
+
</>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function LonglineGameplay({
|
|
340
|
+
seed, origin, tool, yawStep, tier, walls, onPlaceWall, onSyncHud,
|
|
341
|
+
}: {
|
|
342
|
+
seed: string;
|
|
343
|
+
origin: readonly [number, number];
|
|
344
|
+
tool: "drive" | "build";
|
|
345
|
+
yawStep: number;
|
|
346
|
+
tier: BuildTier;
|
|
347
|
+
walls: readonly BuiltC12Wall[];
|
|
348
|
+
onPlaceWall: (wx: number, y: number, wz: number, yaw: number) => void;
|
|
349
|
+
onSyncHud: (s: HighwayHudState) => void;
|
|
350
|
+
}) {
|
|
351
|
+
const world = useActiveKolmoWorld();
|
|
352
|
+
const camera = useThree((s) => s.camera);
|
|
353
|
+
const spawn = useMemo(() => computeLongDriveMainlandSpawn(hashSeed(seed), 1, 0), [seed]);
|
|
354
|
+
const anchorBuf = useRef<[number, number]>([0, 0]);
|
|
355
|
+
const prevWorld = useRef<[number, number] | null>(null);
|
|
356
|
+
const ghostRef = useRef<THREE.Mesh>(null);
|
|
357
|
+
const stats = useRef<HighwayHudState>({ km: 0, fuelL: 45, targetKm: 0.5, cash: 100, stage: 1, scrap: 60 });
|
|
358
|
+
const lastUiPush = useRef(0);
|
|
359
|
+
|
|
360
|
+
const initialCans = useMemo<FuelCanItem[]>(() =>
|
|
361
|
+
[1, 2, 3, 4].map((i) => ({
|
|
362
|
+
id: i,
|
|
363
|
+
wx: spawn.vehiclePos[0] + Math.sin(spawn.vehicleRot[1]) * i * 85 + 2.4,
|
|
364
|
+
wz: spawn.vehiclePos[2] + Math.cos(spawn.vehicleRot[1]) * i * 85,
|
|
365
|
+
y: spawn.vehiclePos[1] + 0.35,
|
|
366
|
+
})), [spawn]);
|
|
367
|
+
|
|
368
|
+
const cansRef = useRef<FuelCanItem[]>(initialCans);
|
|
369
|
+
const [cans, setCans] = useState<FuelCanItem[]>(initialCans);
|
|
370
|
+
const nextCanId = useRef(5);
|
|
371
|
+
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
const onDown = (e: MouseEvent) => {
|
|
374
|
+
if (e.button !== 0 || (e.target as HTMLElement)?.tagName !== "CANVAS") return;
|
|
375
|
+
const a = readFloatingOriginAnchorXZ(world, camera, anchorBuf.current);
|
|
376
|
+
_fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
377
|
+
if (tool === "build") {
|
|
378
|
+
const wx = Math.round((origin[0] + a[0] + _fwd.x * 6) / 3) * 3;
|
|
379
|
+
const wz = Math.round((origin[1] + a[1] + _fwd.z * 6) / 3) * 3;
|
|
380
|
+
onPlaceWall(wx, camera.position.y + 0.4, wz, (yawStep * Math.PI) / 6);
|
|
381
|
+
} else {
|
|
382
|
+
spawnSuikaOrb({
|
|
383
|
+
tier: 0,
|
|
384
|
+
position: [a[0] + _fwd.x * 2.2, camera.position.y + 0.5, a[1] + _fwd.z * 2.2],
|
|
385
|
+
velocity: [_fwd.x * 24, _fwd.y * 24 + 3, _fwd.z * 24],
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
window.addEventListener("mousedown", onDown);
|
|
390
|
+
return () => window.removeEventListener("mousedown", onDown);
|
|
391
|
+
}, [tool, yawStep, origin, world, camera, onPlaceWall]);
|
|
392
|
+
|
|
393
|
+
useFrame((_, delta) => {
|
|
394
|
+
const a = readFloatingOriginAnchorXZ(world, camera, anchorBuf.current);
|
|
395
|
+
const wx = origin[0] + a[0], wz = origin[1] + a[1];
|
|
396
|
+
if (ghostRef.current && tool === "build") {
|
|
397
|
+
_fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
398
|
+
const gx = Math.round((wx + _fwd.x * 6) / 3) * 3 - origin[0];
|
|
399
|
+
const gz = Math.round((wz + _fwd.z * 6) / 3) * 3 - origin[1];
|
|
400
|
+
ghostRef.current.position.set(gx, camera.position.y + 0.4, gz);
|
|
401
|
+
ghostRef.current.rotation.set(0, (yawStep * Math.PI) / 6, 0);
|
|
402
|
+
}
|
|
403
|
+
const prevX = prevWorld.current?.[0] ?? wx;
|
|
404
|
+
const prevZ = prevWorld.current?.[1] ?? wz - 1;
|
|
405
|
+
if (prevWorld.current) {
|
|
406
|
+
const stepM = Math.hypot(wx - prevX, wz - prevZ);
|
|
407
|
+
if (stepM > 0.01 && stepM < 60) {
|
|
408
|
+
stats.current.km += stepM / 1000;
|
|
409
|
+
stats.current.fuelL = Math.max(0, stats.current.fuelL - stepM * (kolmoTelemetry.boost > 0 ? 0.018 : 0.009));
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
prevWorld.current = [wx, wz];
|
|
413
|
+
|
|
414
|
+
if (stats.current.km >= stats.current.targetKm) {
|
|
415
|
+
stats.current.cash += 250 * stats.current.stage;
|
|
416
|
+
stats.current.scrap += 40;
|
|
417
|
+
stats.current.stage += 1;
|
|
418
|
+
stats.current.targetKm = +(stats.current.targetKm + 0.75).toFixed(2);
|
|
419
|
+
stats.current.fuelL = Math.min(60, stats.current.fuelL + 12);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
let picked = false;
|
|
423
|
+
for (let i = 0; i < cansRef.current.length; i++) {
|
|
424
|
+
if (Math.hypot(cansRef.current[i].wx - wx, cansRef.current[i].wz - wz) < 5.2) {
|
|
425
|
+
picked = true;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (picked) {
|
|
430
|
+
const fwdX = wx - prevX, fwdZ = wz - prevZ;
|
|
431
|
+
const len = Math.hypot(fwdX, fwdZ) || 1;
|
|
432
|
+
const next = cansRef.current.filter((c) => {
|
|
433
|
+
if (Math.hypot(c.wx - wx, c.wz - wz) < 5.2) {
|
|
434
|
+
stats.current.fuelL = Math.min(60, stats.current.fuelL + 18);
|
|
435
|
+
stats.current.cash += 50;
|
|
436
|
+
stats.current.scrap += 15;
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
});
|
|
441
|
+
next.push({ id: nextCanId.current++, wx: wx + (fwdX / len) * 220, wz: wz + (fwdZ / len) * 220, y: camera.position.y - 1.1 });
|
|
442
|
+
cansRef.current = next;
|
|
443
|
+
setCans(next);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
lastUiPush.current += delta;
|
|
447
|
+
if (lastUiPush.current >= 0.12) {
|
|
448
|
+
lastUiPush.current = 0;
|
|
449
|
+
onSyncHud({ ...stats.current });
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<group>
|
|
455
|
+
<SuikaSystem />
|
|
456
|
+
<Junk id="salvage_1" kind="tin-can" position={[spawn.vehiclePos[0] - origin[0] + 4, spawn.vehiclePos[1] + 0.5, spawn.vehiclePos[2] - origin[1] + 18]} />
|
|
457
|
+
<Junk id="salvage_2" kind="glass-bottle" position={[spawn.vehiclePos[0] - origin[0] - 4, spawn.vehiclePos[1] + 0.5, spawn.vehiclePos[2] - origin[1] + 24]} />
|
|
458
|
+
{tool === "build" && (
|
|
459
|
+
<mesh ref={ghostRef}>
|
|
460
|
+
<boxGeometry args={[3, 3, 0.28]} />
|
|
461
|
+
<meshStandardMaterial color={tier === "wood" ? "#f59e0b" : tier === "stone" ? "#94a3b8" : "#38bdf8"} transparent opacity={0.42} depthWrite={false} />
|
|
462
|
+
</mesh>
|
|
463
|
+
)}
|
|
464
|
+
<InstancedC12Walls walls={walls} origin={origin} tier="wood" color="#9a6324" />
|
|
465
|
+
<InstancedC12Walls walls={walls} origin={origin} tier="stone" color="#64748b" />
|
|
466
|
+
<InstancedC12Walls walls={walls} origin={origin} tier="metal" color="#334155" />
|
|
467
|
+
{cans.map((c) => (
|
|
468
|
+
<group key={c.id} position={[c.wx - origin[0], c.y, c.wz - origin[1]]}>
|
|
469
|
+
<mesh castShadow>
|
|
470
|
+
<boxGeometry args={[0.55, 0.75, 0.36]} />
|
|
471
|
+
<meshStandardMaterial color="#ef4444" emissive="#7f1d1d" flatShading />
|
|
472
|
+
</mesh>
|
|
473
|
+
<mesh position={[0, 1.6, 0]}>
|
|
474
|
+
<octahedronGeometry args={[0.35, 0]} />
|
|
475
|
+
<meshStandardMaterial color="#fbbf24" emissive="#f59e0b" flatShading />
|
|
476
|
+
</mesh>
|
|
477
|
+
</group>
|
|
478
|
+
))}
|
|
479
|
+
</group>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
`;
|
|
483
|
+
|
|
484
|
+
const LONGLINE_APP_SRC = `import { useCallback, useEffect, useState } from "react";
|
|
485
|
+
import { Actor, Game, Hud, LongDrive, MobileTouchOverlay, PAPER_SHELL_PRESETS, RETRO_DREAMCAST, Vehicle, generateSeed8, normalizeSeed8 } from "@pinkaphant/kolmo";
|
|
486
|
+
import { LonglineGameplay, type BuildTier, type BuiltC12Wall, type HighwayHudState } from "./LonglineGameplay.tsx";
|
|
487
|
+
|
|
488
|
+
export function App() {
|
|
489
|
+
const [seed, setSeed] = useState<string>(() => generateSeed8());
|
|
490
|
+
const [seedInput, setSeedInput] = useState<string>(seed);
|
|
491
|
+
const [origin, setOrigin] = useState<[number, number]>([0, 0]);
|
|
492
|
+
const [tool, setTool] = useState<"drive" | "build">("drive");
|
|
493
|
+
const [tier, setTier] = useState<BuildTier>("wood");
|
|
494
|
+
const [yawStep, setYawStep] = useState(0);
|
|
495
|
+
const [walls, setWalls] = useState<BuiltC12Wall[]>([]);
|
|
496
|
+
const [hud, setHud] = useState<HighwayHudState>({ km: 0, fuelL: 45, targetKm: 0.5, cash: 100, stage: 1, scrap: 60 });
|
|
497
|
+
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
const onKey = (e: KeyboardEvent) => {
|
|
500
|
+
if ((e.target as HTMLElement)?.tagName === "INPUT") return;
|
|
501
|
+
if (e.code === "Digit1") setTool("drive");
|
|
502
|
+
else if (e.code === "Digit2") setTool("build");
|
|
503
|
+
else if (e.code === "KeyQ") setYawStep((s) => (s + 11) % 12);
|
|
504
|
+
else if (e.code === "KeyT") setTier((t) => (t === "wood" ? "stone" : t === "stone" ? "metal" : "wood"));
|
|
505
|
+
};
|
|
506
|
+
window.addEventListener("keydown", onKey);
|
|
507
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
508
|
+
}, []);
|
|
509
|
+
|
|
510
|
+
const handlePlaceWall = useCallback((wx: number, y: number, wz: number, yaw: number) => {
|
|
511
|
+
setWalls((prev) => [...prev, { id: prev.length + 1, wx, y, wz, yaw, tier }]);
|
|
512
|
+
}, [tier]);
|
|
513
|
+
|
|
514
|
+
const tierLabel = tier === "wood" ? "Wood" : tier === "stone" ? "Stone" : "Metal";
|
|
515
|
+
return (
|
|
516
|
+
<div style={{ position: "relative", width: "100vw", height: "100dvh", overflow: "hidden", touchAction: "none", userSelect: "none", WebkitUserSelect: "none" }}>
|
|
517
|
+
<Game key={seed} retro={RETRO_DREAMCAST}>
|
|
518
|
+
<LongDrive seed={seed} pureMainland onOriginRebase={(ox, oz) => setOrigin([ox, oz])} />
|
|
519
|
+
<Vehicle preset={PAPER_SHELL_PRESETS.sedan_92} piloted />
|
|
520
|
+
<Actor />
|
|
521
|
+
<LonglineGameplay seed={seed} origin={origin} tool={tool} yawStep={yawStep} tier={tier} walls={walls} onPlaceWall={handlePlaceWall} onSyncHud={setHud} />
|
|
522
|
+
<Hud />
|
|
523
|
+
<MobileTouchOverlay />
|
|
524
|
+
</Game>
|
|
525
|
+
<div style={{ position: "fixed", top: "max(12px, env(safe-area-inset-top))", right: "max(12px, env(safe-area-inset-right))", zIndex: 40, padding: "8px 12px", background: "rgba(9,13,22,0.88)", border: "1px solid #38bdf8", borderRadius: 6, color: "#f8fafc", fontFamily: "ui-monospace, monospace", fontSize: 12 }}>
|
|
526
|
+
<div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 4 }}>
|
|
527
|
+
<b style={{ color: "#38bdf8" }}>Kolmo Longline · Stage {hud.stage} · Blind</b>
|
|
528
|
+
<input
|
|
529
|
+
value={seedInput}
|
|
530
|
+
maxLength={8}
|
|
531
|
+
onChange={(e) => setSeedInput(e.target.value.toUpperCase().replace(/0/g, "O").replace(/[^1-9A-Z]/g, ""))}
|
|
532
|
+
style={{ width: 82, background: "#0f172a", color: "#38bdf8", border: "1px solid #334155", borderRadius: 4, padding: "2px 6px", fontFamily: "inherit", fontWeight: 700 }}
|
|
533
|
+
/>
|
|
534
|
+
<button type="button" onClick={() => { const s = normalizeSeed8(seedInput); setSeedInput(s); setSeed(s); setWalls([]); }} style={{ cursor: "pointer", background: "#1e293b", color: "#e2e8f0", border: "1px solid #475569", borderRadius: 4, padding: "2px 6px" }}>Load</button>
|
|
535
|
+
<button type="button" onClick={() => { const s = generateSeed8(); setSeedInput(s); setSeed(s); setWalls([]); }} style={{ cursor: "pointer", background: "#0369a1", color: "#fff", border: "1px solid #0284c7", borderRadius: 4, padding: "2px 6px" }}>New seed</button>
|
|
536
|
+
</div>
|
|
537
|
+
<div>Odometer <b>{hud.km.toFixed(2)}/{hud.targetKm.toFixed(2)} km</b> · Fuel <b style={{ color: hud.fuelL < 10 ? "#f87171" : "#34d399" }}>{hud.fuelL.toFixed(1)} L</b> · Scrap <b>{hud.scrap}</b> · C12 walls <b>{walls.length}</b></div>
|
|
538
|
+
<div style={{ color: "#94a3b8", marginTop: 4 }}>[1] Drive/Orb ({tool === "drive" ? "active" : "idle"}) · [2] C12 build ({tool === "build" ? tierLabel : "idle"}) · [Q] 30° snap · [T] Tier · Click to place/launch</div>
|
|
539
|
+
</div>
|
|
540
|
+
</div>
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
`;
|
|
544
|
+
|
|
545
|
+
if (template === "dust") {
|
|
546
|
+
fs.writeFileSync(path.join(targetDir, "src/DustGameplay.tsx"), DUST_WORLD_SRC);
|
|
547
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), DUST_APP_SRC);
|
|
548
|
+
} else if (template === "longline") {
|
|
549
|
+
fs.writeFileSync(path.join(targetDir, "src/LonglineGameplay.tsx"), LONGLINE_WORLD_SRC);
|
|
550
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), LONGLINE_APP_SRC);
|
|
551
|
+
} else if (template === "garage") {
|
|
552
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), `import { GlbImportGate } from "@pinkaphant/kolmo/importer";\nexport function App() {\n return <GlbImportGate />;\n}\n`);
|
|
553
|
+
} else {
|
|
554
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), `import { Actor, Game, Hud, Island, MobileTouchOverlay, Vehicle } from "@pinkaphant/kolmo";\nexport function App() {\n return (\n <Game>\n <Island />\n <Vehicle piloted />\n <Actor />\n <Hud />\n <MobileTouchOverlay />\n </Game>\n );\n}\n`);
|
|
555
|
+
}
|
|
115
556
|
|
|
116
|
-
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), appSrc);
|
|
117
557
|
fs.writeFileSync(path.join(targetDir, "src/main.tsx"), `import { createRoot } from "react-dom/client";\nimport { App } from "./App.tsx";\ncreateRoot(document.getElementById("root")!).render(<App />);\n`);
|
|
118
558
|
fs.writeFileSync(path.join(targetDir, "src/App.test.ts"), `import assert from "node:assert/strict";\nimport { describe, it } from "node:test";\nimport { App } from "./App.tsx";\n\ndescribe("${pkgName} smoke test", () => {\n it("exports App component", () => {\n assert.equal(typeof App, "function");\n });\n});\n`);
|
|
119
559
|
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { ActorTrait, FloatingBodyTrait, InteractableTrait, PilotLink, PilotedTag
|
|
|
9
9
|
export { buildProceduralCarGlb, type ProceduralCarOptions } from "./kolmoProcedural.js";
|
|
10
10
|
export { loadOrAutoCompileVehicleGlb, type AutoCompileVehicleOptions } from "./kolmoVehicleAutoCompile.js";
|
|
11
11
|
export { KolmoGame, KolmoHud, KolmoOverlayContext, useKolmoGame, type KolmoGameHookState, type KolmoGameProps, type KolmoHudProps, } from "./kolmoGame.js";
|
|
12
|
+
export { KOLMO_STICK_DEADZONE, applyKolmoTouchLook, computeVirtualStick, defaultTouchActionsForMode, detectTouchDevice, kolmoTouchInput, resetKolmoTouchInput, resetKolmoTouchStick, snapshotKolmoTouchInput, writeKolmoTouchAction, type KolmoLookControls, type KolmoTouchActionButton, type KolmoTouchInputState, type VirtualStickSample, } from "./kolmoTouchState.js";
|
|
13
|
+
export { MobileTouchOverlay, type MobileTouchOverlayProps } from "./kolmoTouchOverlay.js";
|
package/dist/engine/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { KolmoCanvas, KolmoInCanvasContext, KolmoWorld } from "./kolmoWorld.js";
|
|
2
2
|
import { KolmoGravityContext, KolmoPhysics, useIsKolmoCustomGravity, useOptionalKootaWorld } from "../physics/index.js";
|
|
3
|
+
import { KolmoVehicle } from "./kolmoVehicle.js";
|
|
3
4
|
import { EMPTY_KOLMO_INPUT, KOLMO_KEY_MAP, useKolmoInput } from "./kolmoInput.js";
|
|
4
5
|
import { RetroViewportSync, RoomEnvRig, ShadowSnapRig } from "./kolmoRigs.js";
|
|
5
|
-
import { KolmoVehicle } from "./kolmoVehicle.js";
|
|
6
6
|
import { KolmoActor } from "./kolmoActor.js";
|
|
7
7
|
import { KolmoProp, KolmoSurface, togglePropJoint } from "./kolmoSurface.js";
|
|
8
8
|
import { KolmoIsland } from "./kolmoIsland.js";
|
|
@@ -11,10 +11,12 @@ import { ShiftedFixedBody } from "./shiftedFixedBody.js";
|
|
|
11
11
|
import { ActorTrait, FloatingBodyTrait, InteractableTrait, PilotLink, PilotedTag, TransformTrait, VehicleTelemetryTrait, VehicleTrait, VelocityTrait, WorldSessionTrait, WorldSpawnTrait, ensureWorldSession, kolmoWorld, pilotedVehicleQuery, publishWorldSpawn, useActiveKolmoWorld, vehicleSimQuery, writeEntityKinematics, writeVehicleTelemetry } from "./kolmoTraits.js";
|
|
12
12
|
import { flipVehicleBodyUpright, kolmoActions, kolmoTelemetry } from "./kolmoActions.js";
|
|
13
13
|
import { readFloatingOriginAnchorXZ, shiftFloatingOriginEntities } from "./kolmoFloatingOrigin.js";
|
|
14
|
-
import { computeIslandSpawnPose, getCachedIslandPlan } from "./islandSettlementMesh.js";
|
|
15
14
|
import { buildProceduralCarGlb } from "./kolmoProcedural.js";
|
|
16
|
-
import {
|
|
15
|
+
import { computeIslandSpawnPose, getCachedIslandPlan } from "./islandSettlementMesh.js";
|
|
17
16
|
import { loadOrAutoCompileVehicleGlb } from "./kolmoVehicleAutoCompile.js";
|
|
18
|
-
import {
|
|
17
|
+
import { computeLongDriveBridgeheadSpawn, computeLongDriveMainlandSpawn } from "./causewayBridge.js";
|
|
19
18
|
import { KolmoGame } from "./kolmoGame.js";
|
|
20
|
-
|
|
19
|
+
import { KolmoHud, KolmoOverlayContext, useKolmoGame } from "./kolmoHud.js";
|
|
20
|
+
import { KOLMO_STICK_DEADZONE, applyKolmoTouchLook, computeVirtualStick, defaultTouchActionsForMode, detectTouchDevice, kolmoTouchInput, resetKolmoTouchInput, resetKolmoTouchStick, snapshotKolmoTouchInput, writeKolmoTouchAction } from "./kolmoTouchState.js";
|
|
21
|
+
import { MobileTouchOverlay } from "./kolmoTouchOverlay.js";
|
|
22
|
+
export { ActorTrait, EMPTY_KOLMO_INPUT, FloatingBodyTrait, InteractableTrait, KOLMO_KEY_MAP, KOLMO_STICK_DEADZONE, KolmoActor, KolmoCanvas, KolmoGame, KolmoGravityContext, KolmoHud, KolmoInCanvasContext, KolmoIsland, KolmoLongDrive, KolmoOverlayContext, KolmoPhysics, KolmoProp, KolmoSurface, KolmoVehicle, KolmoWorld, MobileTouchOverlay, PilotLink, PilotedTag, RetroViewportSync, RoomEnvRig, ShadowSnapRig, ShiftedFixedBody, TransformTrait, VehicleTelemetryTrait, VehicleTrait, VelocityTrait, WorldSessionTrait, WorldSpawnTrait, applyKolmoTouchLook, buildProceduralCarGlb, computeIslandSpawnPose, computeLongDriveBridgeheadSpawn, computeLongDriveMainlandSpawn, computeVirtualStick, defaultTouchActionsForMode, detectTouchDevice, ensureWorldSession, flipVehicleBodyUpright, getCachedIslandPlan, kolmoActions, kolmoTelemetry, kolmoTouchInput, kolmoWorld, loadOrAutoCompileVehicleGlb, pilotedVehicleQuery, publishWorldSpawn, readFloatingOriginAnchorXZ, resetKolmoTouchInput, resetKolmoTouchStick, shiftFloatingOriginEntities, snapshotKolmoTouchInput, togglePropJoint, useActiveKolmoWorld, useIsKolmoCustomGravity, useKolmoGame, useKolmoInput, useOptionalKootaWorld, vehicleSimQuery, writeEntityKinematics, writeKolmoTouchAction, writeVehicleTelemetry };
|
|
@@ -16,22 +16,37 @@ var kolmoTelemetry = {
|
|
|
16
16
|
};
|
|
17
17
|
var _exitPos = new THREE.Vector3();
|
|
18
18
|
var _exitFwd = new THREE.Vector3();
|
|
19
|
+
var _flipUp = new THREE.Vector3();
|
|
20
|
+
var _flipFwd = new THREE.Vector3();
|
|
21
|
+
var _flipRight = new THREE.Vector3();
|
|
22
|
+
var _flipMat = new THREE.Matrix4();
|
|
23
|
+
var _flipQuat = new THREE.Quaternion();
|
|
19
24
|
function flipVehicleBodyUpright(veh) {
|
|
20
25
|
const body = veh.body;
|
|
21
26
|
if (!body) return;
|
|
22
27
|
const pos = body.translation();
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
_flipUp.copy(veh.upAxis);
|
|
29
|
+
if (_flipUp.lengthSq() < 1e-6) _flipUp.set(0, 1, 0);
|
|
30
|
+
else _flipUp.normalize();
|
|
31
|
+
_flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);
|
|
32
|
+
if (_flipFwd.lengthSq() < 1e-6) {
|
|
33
|
+
if (Math.abs(_flipUp.y) < .9) _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);
|
|
34
|
+
else _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);
|
|
35
|
+
}
|
|
36
|
+
_flipFwd.normalize();
|
|
37
|
+
_flipRight.crossVectors(_flipUp, _flipFwd).normalize();
|
|
38
|
+
_flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);
|
|
39
|
+
_flipQuat.setFromRotationMatrix(_flipMat);
|
|
25
40
|
body.setTranslation({
|
|
26
|
-
x: pos.x,
|
|
27
|
-
y: pos.y + 1.35,
|
|
28
|
-
z: pos.z
|
|
41
|
+
x: pos.x + _flipUp.x * 1.35,
|
|
42
|
+
y: pos.y + _flipUp.y * 1.35,
|
|
43
|
+
z: pos.z + _flipUp.z * 1.35
|
|
29
44
|
}, true);
|
|
30
45
|
body.setRotation({
|
|
31
|
-
x:
|
|
32
|
-
y:
|
|
33
|
-
z:
|
|
34
|
-
w:
|
|
46
|
+
x: _flipQuat.x,
|
|
47
|
+
y: _flipQuat.y,
|
|
48
|
+
z: _flipQuat.z,
|
|
49
|
+
w: _flipQuat.w
|
|
35
50
|
}, true);
|
|
36
51
|
body.setLinvel({
|
|
37
52
|
x: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kolmoActions.js","names":[],"sources":["../../src/engine/kolmoActions.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { createActions, type Entity } from \"koota\";\nimport type { EcctrlVehicleHandle } from \"@pinkaphant/ecctrl/vehicle\";\nimport { syncRetroUniforms, type RetroPreset, type RetroPresetId } from \"../shaders/retroShader.js\";\nimport {\n ActorTrait,\n PilotLink,\n PilotedTag,\n VehicleTrait,\n WorldSessionTrait,\n ensureWorldSession,\n pilotedVehicleQuery,\n publishWorldSpawn,\n type KolmoControlMode,\n type VehicleTraitData,\n type WorldSpawnData,\n} from \"./kolmoTraits.js\";\n\nexport interface KolmoTelemetryState {\n speedKmh: number;\n rpm: number;\n gear: number;\n throttle: number;\n boost: number;\n mode: KolmoControlMode;\n activeVehicleId: string | null;\n activeRetroPreset: RetroPresetId;\n nearVehicleId: string | null;\n}\n\nexport const kolmoTelemetry: KolmoTelemetryState = {\n speedKmh: 0, rpm: 0, gear: 1, throttle: 0, boost: 0,\n mode: \"foot\", activeVehicleId: null, activeRetroPreset: \"dreamcast\", nearVehicleId: null,\n};\n\nconst _exitPos = new THREE.Vector3();\nconst _exitFwd = new THREE.Vector3();\n\nexport function flipVehicleBodyUpright(veh: EcctrlVehicleHandle): void {\n const body = veh.body;\n if (!body) return;\n const pos = body.translation();\n _exitFwd.copy(veh.bodyZAxis).projectOnPlane(veh.upAxis).normalize();\n const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;\n const halfYaw = yaw * 0.5;\n body.setTranslation({ x: pos.x, y: pos.y + 1.35, z: pos.z }, true);\n body.setRotation({ x: 0, y: Math.sin(halfYaw), z: 0, w: Math.cos(halfYaw) }, true);\n body.setLinvel({ x: 0, y: 0, z: 0 }, true);\n body.setAngvel({ x: 0, y: 0, z: 0 }, true);\n}\n\nexport const kolmoActions = createActions((world) => ({\n boardVehicle: (vehicleId: string) => {\n ensureWorldSession(world);\n let targetEnt: Entity | undefined;\n let targetData: VehicleTraitData | undefined;\n for (const vehEnt of world.query(VehicleTrait)) {\n const v = vehEnt.get(VehicleTrait);\n if (!v) continue;\n if (!vehicleId || v.id === vehicleId) {\n targetEnt = vehEnt;\n targetData = v;\n break;\n }\n }\n if (!targetEnt || !targetData) return;\n\n for (const prev of world.query(pilotedVehicleQuery)) {\n if (prev !== targetEnt && prev.has(PilotedTag)) prev.remove(PilotedTag);\n }\n if (!targetEnt.has(PilotedTag)) targetEnt.add(PilotedTag);\n\n const pilot = world.queryFirst(ActorTrait);\n if (pilot) pilot.add(PilotLink(targetEnt));\n\n const session = world.get(WorldSessionTrait);\n if (session?.nearVehicleId) {\n world.set(WorldSessionTrait, { activeRetroPreset: session.activeRetroPreset, nearVehicleId: \"\" });\n }\n kolmoTelemetry.activeVehicleId = targetData.id;\n kolmoTelemetry.nearVehicleId = null;\n kolmoTelemetry.mode = targetData.isFlight ? \"flight\" : \"car\";\n },\n exitVehicle: () => {\n ensureWorldSession(world);\n const pilot = world.queryFirst(ActorTrait);\n const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n if (linked) {\n const v = linked.get(VehicleTrait);\n if (pilot) {\n if (pilot.has(PilotLink(linked))) pilot.remove(PilotLink(linked));\n if (v?.handle) {\n _exitPos\n .set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2])\n .applyQuaternion(v.handle.currQuat)\n .add(v.handle.currPos);\n _exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();\n const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;\n const lv = v.handle.currLinVel, curActor = pilot.get(ActorTrait);\n pilot.set(ActorTrait, {\n id: curActor?.id ?? \"pilot\",\n handle: null,\n exitSpawnPos: [_exitPos.x, _exitPos.y, _exitPos.z],\n exitSpawnYaw: yaw,\n exitLinVel: [lv.x, lv.y, lv.z],\n onOriginShift: curActor?.onOriginShift,\n });\n }\n }\n if (linked.has(PilotedTag)) linked.remove(PilotedTag);\n v?.handle?.setMovement({ forward: false, backward: false, steerLeft: false, steerRight: false, brake: !v.isFlight });\n }\n for (const extra of world.query(pilotedVehicleQuery)) {\n if (extra.has(PilotedTag)) extra.remove(PilotedTag);\n }\n Object.assign(kolmoTelemetry, {\n activeVehicleId: null,\n mode: \"foot\" as KolmoControlMode,\n speedKmh: 0,\n rpm: 0,\n throttle: 0,\n boost: 0,\n });\n },\n setRetroPreset: (preset: RetroPreset | RetroPresetId) => {\n ensureWorldSession(world);\n const applied = syncRetroUniforms(preset);\n const session = world.get(WorldSessionTrait);\n world.set(WorldSessionTrait, {\n activeRetroPreset: applied.id,\n nearVehicleId: session?.nearVehicleId ?? \"\",\n });\n kolmoTelemetry.activeRetroPreset = applied.id;\n },\n setSpawn: (spawn: WorldSpawnData) => {\n publishWorldSpawn(world, spawn);\n },\n resetVehicle: (vehicleId?: string) => {\n ensureWorldSession(world);\n let target: VehicleTraitData | undefined;\n if (vehicleId) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.id === vehicleId && v.handle?.body) { target = v; break; }\n }\n }\n if (!target) {\n const piloted = world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n const pv = piloted?.get(VehicleTrait);\n if (pv?.handle?.body) target = pv;\n }\n if (!target) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.handle?.body) { target = v; break; }\n }\n }\n if (target?.handle) flipVehicleBodyUpright(target.handle);\n },\n}));\n"],"mappings":";;;;;AA8BA,IAAa,iBAAsC;CAC/C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AAM,IAAI,IAAI,IAAI,YAAY;GAC9B,IAAI,GAAG,QAAQ,MAAM;IAAE,SAAS;IAAG;GAAO;EAC9C;EAEJ,IAAI,QAAQ,QAAQ,uBAAuB,OAAO,MAAM;CAC5D;AACJ,EAAE"}
|
|
1
|
+
{"version":3,"file":"kolmoActions.js","names":[],"sources":["../../src/engine/kolmoActions.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { createActions, type Entity } from \"koota\";\nimport type { EcctrlVehicleHandle } from \"@pinkaphant/ecctrl/vehicle\";\nimport { syncRetroUniforms, type RetroPreset, type RetroPresetId } from \"../shaders/retroShader.js\";\nimport {\n ActorTrait,\n PilotLink,\n PilotedTag,\n VehicleTrait,\n WorldSessionTrait,\n ensureWorldSession,\n pilotedVehicleQuery,\n publishWorldSpawn,\n type KolmoControlMode,\n type VehicleTraitData,\n type WorldSpawnData,\n} from \"./kolmoTraits.js\";\n\nexport interface KolmoTelemetryState {\n speedKmh: number;\n rpm: number;\n gear: number;\n throttle: number;\n boost: number;\n mode: KolmoControlMode;\n activeVehicleId: string | null;\n activeRetroPreset: RetroPresetId;\n nearVehicleId: string | null;\n}\n\nexport const kolmoTelemetry: KolmoTelemetryState = {\n speedKmh: 0, rpm: 0, gear: 1, throttle: 0, boost: 0,\n mode: \"foot\", activeVehicleId: null, activeRetroPreset: \"dreamcast\", nearVehicleId: null,\n};\n\nconst _exitPos = new THREE.Vector3();\nconst _exitFwd = new THREE.Vector3();\nconst _flipUp = new THREE.Vector3();\nconst _flipFwd = new THREE.Vector3();\nconst _flipRight = new THREE.Vector3();\nconst _flipMat = new THREE.Matrix4();\nconst _flipQuat = new THREE.Quaternion();\n\nexport function flipVehicleBodyUpright(veh: EcctrlVehicleHandle): void {\n const body = veh.body;\n if (!body) return;\n const pos = body.translation();\n _flipUp.copy(veh.upAxis);\n if (_flipUp.lengthSq() < 1e-6) _flipUp.set(0, 1, 0);\n else _flipUp.normalize();\n\n _flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);\n if (_flipFwd.lengthSq() < 1e-6) {\n if (Math.abs(_flipUp.y) < 0.9) _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);\n else _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);\n }\n _flipFwd.normalize();\n _flipRight.crossVectors(_flipUp, _flipFwd).normalize();\n _flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);\n _flipQuat.setFromRotationMatrix(_flipMat);\n\n body.setTranslation({ x: pos.x + _flipUp.x * 1.35, y: pos.y + _flipUp.y * 1.35, z: pos.z + _flipUp.z * 1.35 }, true);\n body.setRotation({ x: _flipQuat.x, y: _flipQuat.y, z: _flipQuat.z, w: _flipQuat.w }, true);\n body.setLinvel({ x: 0, y: 0, z: 0 }, true);\n body.setAngvel({ x: 0, y: 0, z: 0 }, true);\n}\n\nexport const kolmoActions = createActions((world) => ({\n boardVehicle: (vehicleId: string) => {\n ensureWorldSession(world);\n let targetEnt: Entity | undefined;\n let targetData: VehicleTraitData | undefined;\n for (const vehEnt of world.query(VehicleTrait)) {\n const v = vehEnt.get(VehicleTrait);\n if (!v) continue;\n if (!vehicleId || v.id === vehicleId) {\n targetEnt = vehEnt;\n targetData = v;\n break;\n }\n }\n if (!targetEnt || !targetData) return;\n\n for (const prev of world.query(pilotedVehicleQuery)) {\n if (prev !== targetEnt && prev.has(PilotedTag)) prev.remove(PilotedTag);\n }\n if (!targetEnt.has(PilotedTag)) targetEnt.add(PilotedTag);\n\n const pilot = world.queryFirst(ActorTrait);\n if (pilot) pilot.add(PilotLink(targetEnt));\n\n const session = world.get(WorldSessionTrait);\n if (session?.nearVehicleId) {\n world.set(WorldSessionTrait, { activeRetroPreset: session.activeRetroPreset, nearVehicleId: \"\" });\n }\n kolmoTelemetry.activeVehicleId = targetData.id;\n kolmoTelemetry.nearVehicleId = null;\n kolmoTelemetry.mode = targetData.isFlight ? \"flight\" : \"car\";\n },\n exitVehicle: () => {\n ensureWorldSession(world);\n const pilot = world.queryFirst(ActorTrait);\n const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n if (linked) {\n const v = linked.get(VehicleTrait);\n if (pilot) {\n if (pilot.has(PilotLink(linked))) pilot.remove(PilotLink(linked));\n if (v?.handle) {\n _exitPos\n .set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2])\n .applyQuaternion(v.handle.currQuat)\n .add(v.handle.currPos);\n _exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();\n const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;\n const lv = v.handle.currLinVel, curActor = pilot.get(ActorTrait);\n pilot.set(ActorTrait, {\n id: curActor?.id ?? \"pilot\",\n handle: null,\n exitSpawnPos: [_exitPos.x, _exitPos.y, _exitPos.z],\n exitSpawnYaw: yaw,\n exitLinVel: [lv.x, lv.y, lv.z],\n onOriginShift: curActor?.onOriginShift,\n });\n }\n }\n if (linked.has(PilotedTag)) linked.remove(PilotedTag);\n v?.handle?.setMovement({ forward: false, backward: false, steerLeft: false, steerRight: false, brake: !v.isFlight });\n }\n for (const extra of world.query(pilotedVehicleQuery)) {\n if (extra.has(PilotedTag)) extra.remove(PilotedTag);\n }\n Object.assign(kolmoTelemetry, {\n activeVehicleId: null,\n mode: \"foot\" as KolmoControlMode,\n speedKmh: 0,\n rpm: 0,\n throttle: 0,\n boost: 0,\n });\n },\n setRetroPreset: (preset: RetroPreset | RetroPresetId) => {\n ensureWorldSession(world);\n const applied = syncRetroUniforms(preset);\n const session = world.get(WorldSessionTrait);\n world.set(WorldSessionTrait, {\n activeRetroPreset: applied.id,\n nearVehicleId: session?.nearVehicleId ?? \"\",\n });\n kolmoTelemetry.activeRetroPreset = applied.id;\n },\n setSpawn: (spawn: WorldSpawnData) => {\n publishWorldSpawn(world, spawn);\n },\n resetVehicle: (vehicleId?: string) => {\n ensureWorldSession(world);\n let target: VehicleTraitData | undefined;\n if (vehicleId) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.id === vehicleId && v.handle?.body) { target = v; break; }\n }\n }\n if (!target) {\n const piloted = world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n const pv = piloted?.get(VehicleTrait);\n if (pv?.handle?.body) target = pv;\n }\n if (!target) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.handle?.body) { target = v; break; }\n }\n }\n if (target?.handle) flipVehicleBodyUpright(target.handle);\n },\n}));\n"],"mappings":";;;;;AA8BA,IAAa,iBAAsC;CAC/C,UAAU;CAAG,KAAK;CAAG,MAAM;CAAG,UAAU;CAAG,OAAO;CAClD,MAAM;CAAQ,iBAAiB;CAAM,mBAAmB;CAAa,eAAe;AACxF;AAEA,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,UAAU,IAAI,MAAM,QAAQ;AAClC,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,aAAa,IAAI,MAAM,QAAQ;AACrC,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,YAAY,IAAI,MAAM,WAAW;AAEvC,SAAgB,uBAAuB,KAAgC;CACnE,MAAM,OAAO,IAAI;CACjB,IAAI,CAAC,MAAM;CACX,MAAM,MAAM,KAAK,YAAY;CAC7B,QAAQ,KAAK,IAAI,MAAM;CACvB,IAAI,QAAQ,SAAS,IAAI,MAAM,QAAQ,IAAI,GAAG,GAAG,CAAC;MAC7C,QAAQ,UAAU;CAEvB,SAAS,KAAK,IAAI,SAAS,CAAC,CAAC,eAAe,OAAO;CACnD,IAAI,SAAS,SAAS,IAAI,MAAM;EAC5B,IAAI,KAAK,IAAI,QAAQ,CAAC,IAAI,IAAK,SAAS,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,eAAe,OAAO;OACtE,SAAS,IAAI,GAAG,GAAG,CAAC,CA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