feat: initialize sunrise with 100-player shared rooms
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { PerspectiveCamera, Vector3 } from 'three';
|
||||
import { createFpsCameraController } from '../src/controls/fpsCameraController.ts';
|
||||
import { directionFromAngles } from '../src/astronomy/direction.ts';
|
||||
import { SUMMIT_TERRAIN } from '../src/constants/summitTerrain.ts';
|
||||
|
||||
function withController(run: (camera: PerspectiveCamera, canvas: EventTarget, picks: number[][]) => void) {
|
||||
const oldWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
|
||||
const oldDocument = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
||||
const doc = Object.assign(new EventTarget(), { querySelector: () => ({ textContent: '' }) });
|
||||
const canvas = Object.assign(new EventTarget(), { ownerDocument: doc, focus() {}, blur() {}, tabIndex: 0,
|
||||
setPointerCapture() {}, releasePointerCapture() {}, hasPointerCapture() { return true; } });
|
||||
Object.defineProperty(globalThis, 'window', { value: new EventTarget(), configurable: true });
|
||||
Object.defineProperty(globalThis, 'document', { value: doc, configurable: true });
|
||||
const camera = new PerspectiveCamera();
|
||||
const picks: number[][] = [];
|
||||
const controller = createFpsCameraController(camera, canvas as unknown as HTMLCanvasElement,
|
||||
(x, y) => { picks.push([x, y]); return new Vector3(x, 0, y); });
|
||||
try { run(camera, canvas, picks); }
|
||||
finally {
|
||||
controller.dispose();
|
||||
for (const [key, value] of [['window', oldWindow], ['document', oldDocument]] as const) {
|
||||
if (value) Object.defineProperty(globalThis, key, value);
|
||||
else Reflect.deleteProperty(globalThis, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
function pointer(canvas: EventTarget, type: string, x: number, y: number, pointerType = 'touch', button = 0) {
|
||||
canvas.dispatchEvent(Object.assign(new Event(type, { cancelable: true }),
|
||||
{ pointerId: 1, isPrimary: true, pointerType, button, clientX: x, clientY: y }));
|
||||
}
|
||||
|
||||
test('touch tap and mouse right click select a destination, left click does not', () => {
|
||||
withController((_camera, canvas, picks) => {
|
||||
for (const [type, button] of [['touch', 0], ['mouse', 2], ['mouse', 0]] as const) {
|
||||
pointer(canvas, 'pointerdown', 100, 120, type, button);
|
||||
pointer(canvas, 'pointerup', 100, 120, type, button);
|
||||
}
|
||||
assert.deepEqual(picks, [[100, 120], [100, 120]]);
|
||||
});
|
||||
});
|
||||
|
||||
test('drag changes the view without selecting a destination, including when returning to its start', () => {
|
||||
withController((camera, canvas, picks) => {
|
||||
pointer(canvas, 'pointerdown', 100, 100);
|
||||
pointer(canvas, 'pointermove', 130, 110);
|
||||
assert.notEqual(camera.rotation.y, 0);
|
||||
pointer(canvas, 'pointerup', 100, 100);
|
||||
assert.deepEqual(picks, []);
|
||||
pointer(canvas, 'pointerdown', 100, 100);
|
||||
pointer(canvas, 'pointercancel', 100, 100);
|
||||
pointer(canvas, 'pointerup', 100, 100);
|
||||
assert.deepEqual(picks, []);
|
||||
});
|
||||
});
|
||||
|
||||
test('first horizontal drag after a southward reset preserves camera pitch', () => {
|
||||
withController((camera, canvas) => {
|
||||
camera.lookAt(new Vector3(...directionFromAngles(SUMMIT_TERRAIN.heading, SUMMIT_TERRAIN.pitch)));
|
||||
const before = camera.getWorldDirection(new Vector3());
|
||||
pointer(canvas, 'pointerdown', 100, 100, 'mouse');
|
||||
pointer(canvas, 'pointermove', 110, 100, 'mouse');
|
||||
const after = camera.getWorldDirection(new Vector3());
|
||||
assert.ok(Math.abs(after.y - before.y) < 1e-8);
|
||||
assert.ok(before.angleTo(after) > 0);
|
||||
assert.ok(before.angleTo(after) < 0.04);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user