@korial29/tiny-fps 0.200.1 → 0.202.0
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/index.js +7 -273
- package/dist/local.js +1 -1
- package/dist/server.js +31 -5
- package/dist/targeting-CxDFEq9x.js +1 -0
- package/dist/types/client/audio.d.ts +1 -1
- package/dist/types/client/balls.d.ts +1 -1
- package/dist/types/client/hud.d.ts +2 -0
- package/dist/types/client/hunter.d.ts +1 -0
- package/dist/types/client/katana.d.ts +1 -1
- package/dist/types/client/pacing.d.ts +4 -0
- package/dist/types/client/predict.d.ts +4 -2
- package/dist/types/client/render.d.ts +7 -1
- package/dist/types/client/sfx.d.ts +13 -0
- package/dist/types/shared/constants.d.ts +5 -1
- package/dist/types/shared/kit.d.ts +1 -1
- package/dist/types/shared/room.d.ts +5 -1
- package/package.json +1 -1
- package/dist/targeting-Dia_z4Fw.js +0 -1
package/dist/server.js
CHANGED
|
@@ -9540,6 +9540,8 @@ var Room = class {
|
|
|
9540
9540
|
balls = [];
|
|
9541
9541
|
/** Last tick a Hunter's shoulder laser hit, by player id. */
|
|
9542
9542
|
hunterLasers = /* @__PURE__ */ new Map();
|
|
9543
|
+
/** Target and start tick of each Hunter's uninterrupted shoulder-laser lock. */
|
|
9544
|
+
hunterLocks = /* @__PURE__ */ new Map();
|
|
9543
9545
|
/** The map's rovers, in the order of WorldDef.rovers, then its ships (ship.ts). */
|
|
9544
9546
|
rovers = [];
|
|
9545
9547
|
/** Collision geometry reused while a vehicle's pose is unchanged. */
|
|
@@ -9769,6 +9771,19 @@ var Room = class {
|
|
|
9769
9771
|
const now = ++this.ticks;
|
|
9770
9772
|
for (const p of players) p.bank = Math.min(10, p.bank + 1);
|
|
9771
9773
|
this.think(players);
|
|
9774
|
+
for (const p of players) {
|
|
9775
|
+
if (!this.kit(p).hunter || p.state.down || !p.state.railed) {
|
|
9776
|
+
this.hunterLocks.delete(p.info.id);
|
|
9777
|
+
continue;
|
|
9778
|
+
}
|
|
9779
|
+
const target = this.shoulderTarget(p, void 0);
|
|
9780
|
+
const lock = this.hunterLocks.get(p.info.id);
|
|
9781
|
+
if (!target) this.hunterLocks.delete(p.info.id);
|
|
9782
|
+
else if (lock?.target !== target.id) this.hunterLocks.set(p.info.id, {
|
|
9783
|
+
target: target.id,
|
|
9784
|
+
since: now
|
|
9785
|
+
});
|
|
9786
|
+
}
|
|
9772
9787
|
for (const b of this.balls) if (!b.burst && b.left > 0) this.fly(b, stepOf(b));
|
|
9773
9788
|
this.heal(players);
|
|
9774
9789
|
if (this.world.def.station && !this.ctf.over && this.station.tick() === "strike") this.strike(players);
|
|
@@ -10158,7 +10173,7 @@ var Room = class {
|
|
|
10158
10173
|
if (by) by.state.hits = by.state.hits + 1 & 255;
|
|
10159
10174
|
if (b.power === 6) this.shot(foe, BOLT_HP, by, b.dx, b.dz);
|
|
10160
10175
|
else if (b.power === 8) this.shot(foe, 2, by, b.dx, b.dz, FRAG.GUN, b.back);
|
|
10161
|
-
else if (b.power === 9) this.shot(foe,
|
|
10176
|
+
else if (b.power === 9) this.shot(foe, 3, by, b.dx, b.dz, FRAG.GUN, b.back);
|
|
10162
10177
|
else if (b.power === 0) {
|
|
10163
10178
|
foe.graze = ((foe.graze ?? 0) + 1) % 2;
|
|
10164
10179
|
if (!foe.graze) this.shot(foe, 1, by, b.dx, b.dz, FRAG.GUN, b.back);
|
|
@@ -10344,8 +10359,8 @@ var Room = class {
|
|
|
10344
10359
|
}
|
|
10345
10360
|
}
|
|
10346
10361
|
}
|
|
10347
|
-
/**
|
|
10348
|
-
|
|
10362
|
+
/** The shoulder laser's assisted target, kept inside a narrow forward cone and clear line of sight. */
|
|
10363
|
+
shoulderTarget(p, view) {
|
|
10349
10364
|
const foes = this.enemies(p, view);
|
|
10350
10365
|
const origin = [
|
|
10351
10366
|
p.state.x,
|
|
@@ -10374,7 +10389,18 @@ var Room = class {
|
|
|
10374
10389
|
target = foe;
|
|
10375
10390
|
}
|
|
10376
10391
|
}
|
|
10377
|
-
|
|
10392
|
+
return target;
|
|
10393
|
+
}
|
|
10394
|
+
/** Fires only after an uninterrupted three-second target lock; damage is three HP. */
|
|
10395
|
+
shoulder(p, view) {
|
|
10396
|
+
const target = this.shoulderTarget(p, view);
|
|
10397
|
+
const lock = this.hunterLocks.get(p.info.id);
|
|
10398
|
+
if (!target || lock?.target !== target.id || this.ticks - lock.since < 180 || this.ticks - (this.hunterLasers.get(p.info.id) ?? -Infinity) < 18) return;
|
|
10399
|
+
const origin = [
|
|
10400
|
+
p.state.x,
|
|
10401
|
+
p.state.y + eyeHeight(p.state),
|
|
10402
|
+
p.state.z
|
|
10403
|
+
];
|
|
10378
10404
|
const delta = [
|
|
10379
10405
|
target.x,
|
|
10380
10406
|
target.y + eyeHeight(target) * .65,
|
|
@@ -10392,7 +10418,7 @@ var Room = class {
|
|
|
10392
10418
|
this.hunterLasers.set(p.info.id, this.ticks);
|
|
10393
10419
|
p.state.hits = p.state.hits + 1 & 255;
|
|
10394
10420
|
const foe = this.players().find((q) => q.info.id === target.id);
|
|
10395
|
-
if (foe) this.shot(foe,
|
|
10421
|
+
if (foe) this.shot(foe, 3, p, aimed.d[0], aimed.d[2]);
|
|
10396
10422
|
}
|
|
10397
10423
|
/** 1 hp of the bolt's drain to `foe`, as his railer deals it; if it puts him down he is disintegrated (`fried`). */
|
|
10398
10424
|
fry(foe) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=e=>!!e&&e[0]>=0&&e[0]<=1&&e[1]>=0&&e[1]<=1,t=(t,n,r)=>{let{PLAYER_R:i,MODE:a,NOBODY:o,aimOf:s,cylinder:c,heightOf:l,homeOf:u,ray:d,struck:f}=r;t.insertAdjacentHTML(`beforeend`,`<style>q{width:26px;height:26px;margin:-13px 0 0 -13px;border:2px solid #5f8;border-radius:50%;box-shadow:0 0 6px #3f6,inset 0 0 4px #3f6;background:radial-gradient(#afc 0 1.5px,#0000 2px)}q::before,q::after{content:none}.targets{position:absolute;inset:0;pointer-events:none}.target,.lead{position:absolute;transform:translate(-50%,-50%);box-sizing:border-box;border:2px solid #ff514d;box-shadow:0 0 3px #000}.target{min-width:26px;min-height:26px;max-width:90%;max-height:90%}.lead{width:18px;height:18px;border-radius:50%;border-style:dashed;background:radial-gradient(#ff514d 0 1px,transparent 2px)}</style><span class="targets" aria-hidden="true" hidden><span class="lead" hidden></span></span>`);let p=t.querySelector(`.targets`),m=p.querySelector(`.lead`),h=[],g=(e,[t,n])=>{e.style.left=100*t+`%`,e.style.top=100*n+`%`};return{frame(t,{yaw:_,pitch:v},y,b,x,S,C,w,T){if(p.hidden=!t?.ship,!t)return;let E=e=>{let t=T(e);return t!==void 0&&t!==w},D=S.filter((e,r)=>{let i=e.driver===o?e.rider:e.driver;return!(e===t||e.wreck||t.ship&&(T(i)??u(n,r))===w)}),O=C.filter(e=>!e.down&&e.mode!==a.RIDE&&(!t.ship||E(e.id))),k=s(t,_,v,(e,t,r)=>Math.min(d(n,e,t,r),...D.map(n=>f(n,e,t,r)),...O.map(n=>c(e,t,n,i,l(n)))));if(!t.ship)return x(...k);let{boxes:A,aim:j,lead:M}=(({world:t,camera:n,yaw:r,aspect:i,project:a,hostile:o},s,c,l,u,{BOLT_SPEED:d,PLAYER_R:f,range:p,MODE:m,NOBODY:h,hidden:g,heightOf:_,muzzleOf:v})=>{let y=a(...c),b={boxes:[],aim:y},x=v(s),[S,C,w]=c.map((e,t)=>e-x[t]),T=S*S+C*C+w*w,[E,D]=[Math.cos(r),-Math.sin(r)],O=t.def.seam,k=1/0,A=(r,o,s,c)=>{let l=[r.x,o,r.z],u=a(...l);if(!e(u)||g(t,n,l))return;let f=a(l[0]+E,o,l[2]+D)??u,m=2*Math.hypot((f[0]-u[0])*i,f[1]-u[1]);b.boxes.push({at:u,width:m*s/i,height:m*c});let h=y?Math.hypot((u[0]-y[0])*i,u[1]-y[1]):1/0;if(h>=k)return;let _=((e,t,{vx:n,vy:r,vz:i},a,o)=>{let[s,c,l]=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],u=s*s+c*c+l*l,d=a**2-(n*n+r*r+i*i),f=s*n+c*r+l*i,p=u/(Math.sqrt(f*f+d*u)-f);if(p>0&&p<=o/a)return[t[0]+n*p,t[1]+r*p,t[2]+i*p]})(x,l,r,d,p);if(!_||O!==void 0&&_[1]>O!=x[1]>O)return;let v=a(..._);if(!e(v)||g(t,x,_))return;let A=((_[0]-x[0])*S+(_[1]-x[1])*C+(_[2]-x[2])*w)/T;A>0&&(k=h,b.lead=v,b.aim=a(x[0]+A*S,x[1]+A*C,x[2]+A*w))};for(let e of l){let t=e.driver===h?e.rider:e.driver;e!==s&&!e.wreck&&o(t)&&A(e,e.y,e.ship?7:2.8,e.ship?4:1.4)}for(let e of u)if(!e.down&&e.mode!==m.RIDE&&o(e.id)){let t=_(e)/2;A(e,e.y+t,f,t)}return b})({world:n,camera:y,yaw:_,aspect:b,project:x,hostile:E},t,k,D,O,r);for(let e=0;e<A.length;e++){let{at:t,width:n,height:r}=A[e],i=h[e];i||(i=h[e]=document.createElement(`span`),i.className=`target`,p.prepend(i)),i.hidden=!1,g(i,t),i.style.width=100*n+`%`,i.style.height=100*r+`%`}for(let e=A.length;e<h.length;e++)h[e].hidden=!0;return m.hidden=!M,M&&g(m,M),j}}};export{t as createTargeting};
|
|
@@ -51,7 +51,7 @@ export declare const db: (g: number) => number;
|
|
|
51
51
|
*/
|
|
52
52
|
export declare const LEVELS: number[];
|
|
53
53
|
export declare const LOUD: Record<number, number>;
|
|
54
|
-
export declare const GROUP
|
|
54
|
+
export declare const GROUP: string;
|
|
55
55
|
/** Sets bus `i` to `db` live, and keeps the mix for the next visit; none, the mix as made. */
|
|
56
56
|
export declare const mix: (i?: number, db?: number) => void;
|
|
57
57
|
/**
|
|
@@ -20,7 +20,7 @@ export interface Balls {
|
|
|
20
20
|
* The balls to draw at `now` (ms) and the places where one burst since the last frame. `muzzle`
|
|
21
21
|
* gives the muzzle of a player's gun, where a new ball is first drawn.
|
|
22
22
|
*/
|
|
23
|
-
frame(now: number, muzzle: (id: number) => Vec3 | undefined): {
|
|
23
|
+
frame(now: number, muzzle: (id: number) => Vec3 | undefined, discSound?: (kind: 'return' | 'catch', at: Vec3) => void): {
|
|
24
24
|
orbs: Orb[];
|
|
25
25
|
bursts: [Vec3, number, number?][];
|
|
26
26
|
};
|
|
@@ -80,6 +80,8 @@ export interface Hud {
|
|
|
80
80
|
mission(text?: string, hot?: boolean): void;
|
|
81
81
|
/** The Hunter's current local vision mode. */
|
|
82
82
|
hunterVision(text?: string): void;
|
|
83
|
+
/** The Predator-style shoulder-laser sight, at a screen point and progressing to a lock. */
|
|
84
|
+
hunterAim(at?: [number, number], progress?: number): void;
|
|
83
85
|
/** The dark rim of a space helmet's visor around the screen: on while the own player wears one, off otherwise. */
|
|
84
86
|
visor(on: boolean): void;
|
|
85
87
|
/** The red vignette of a tackle, 0 (none) to 1 (full). */
|
|
@@ -15,7 +15,7 @@ export declare const S: number, C: number;
|
|
|
15
15
|
* rounded-square guard, a grip wrapped in a violet check and a pommel with a glowing bead.
|
|
16
16
|
*/
|
|
17
17
|
export declare const katana: (lod: number) => number[];
|
|
18
|
-
/** The Hunter's twin wrist blades and
|
|
18
|
+
/** The Hunter's twin inward-curving wrist blades and forearm bracelet, in the hand's local space. */
|
|
19
19
|
export declare const wristBlade: (lod: number) => number[];
|
|
20
20
|
/** Places the wrist blade at the Hunter's right wrist. */
|
|
21
21
|
export declare const heldWrist: (out: Out, pos: Vec3, q: Quat, lod: number, k?: number, list?: Pieces) => void;
|
|
@@ -11,9 +11,9 @@ export interface Predictor {
|
|
|
11
11
|
* own player with it, keeps it for replay, and returns it for the caller to send (the very
|
|
12
12
|
* values predicted with, which the host reads back). Until the own player is known (no snapshot
|
|
13
13
|
* shows it yet) it only numbers and keeps the input: the first snapshot replays it.
|
|
14
|
-
* With `now` (ms, performance.now()) the input carries the view tick
|
|
14
|
+
* With `now` (ms, performance.now()) the input carries the view tick, unless a displayed tick is supplied.
|
|
15
15
|
*/
|
|
16
|
-
step(i: Omit<Input, 'seq' | 'view'>, now?: number): Input;
|
|
16
|
+
step(i: Omit<Input, 'seq' | 'view'>, now?: number, displayed?: number): Input;
|
|
17
17
|
/** A decoded snapshot, received at `now` (ms, performance.now()). */
|
|
18
18
|
snapshot(s: Snapshot, now: number): void;
|
|
19
19
|
/**
|
|
@@ -37,6 +37,8 @@ export interface Predictor {
|
|
|
37
37
|
view(alpha: number, input: Omit<Input, 'seq' | 'view'>): PlayerState | undefined;
|
|
38
38
|
/** The other players at now - INTERP_DELAY; a player missing from the latest snapshot is gone. */
|
|
39
39
|
others(now: number): PlayerState[];
|
|
40
|
+
viewTick(now: number): number | undefined;
|
|
41
|
+
piloting(): boolean;
|
|
40
42
|
/**
|
|
41
43
|
* The map's rovers, in the order of WorldDef.rovers: the one the own player drives predicted and
|
|
42
44
|
* eased by alpha like me(), the others at now - INTERP_DELAY. Empty on a map without rovers.
|
|
@@ -148,6 +148,11 @@ export declare const fogRef: ({ brushes }: WorldDef) => number;
|
|
|
148
148
|
export declare const fogDepth: (density: number, ref: number, eye: Vec3, p: Vec3) => number;
|
|
149
149
|
/** The shader's fog uniform: the world's fog colour pulled toward its horizon by HAZE, and its density; none when the world has no fog. */
|
|
150
150
|
export declare const fogOf: ({ fog, sky }: WorldDef) => [number, number, number, number];
|
|
151
|
+
interface FrameView {
|
|
152
|
+
width: number;
|
|
153
|
+
height: number;
|
|
154
|
+
now: number;
|
|
155
|
+
}
|
|
151
156
|
export interface Renderer {
|
|
152
157
|
/**
|
|
153
158
|
* Draws one frame: the sky, the brushes and the others as seen from eye, then the own `body` over
|
|
@@ -165,7 +170,7 @@ export interface Renderer {
|
|
|
165
170
|
/** The own player when the camera is not in his head (seated in a rover): drawn whole, like the others. */
|
|
166
171
|
self?: PlayerState,
|
|
167
172
|
/** Adds what else moves in the map (the doors): drawn lit, casting shadows, with the other players. */
|
|
168
|
-
more?: (v: Out) => void):
|
|
173
|
+
more?: (v: Out) => void, view?: FrameView): boolean;
|
|
169
174
|
/** A world point on screen as of the last frame, in [0, 1] from the top left. */
|
|
170
175
|
project(x: number, y: number, z: number): [number, number] | undefined;
|
|
171
176
|
/** The footsteps of the player `id`'s runner so far (Gait.steps), undefined before it is drawn. */
|
|
@@ -224,3 +229,4 @@ export declare const MAX_PIXELS: number;
|
|
|
224
229
|
export declare const backing: (cw: number, ch: number, dpr: number) => [number, number];
|
|
225
230
|
/** Throws when the browser has no WebGL2. */
|
|
226
231
|
export declare const createRenderer: (canvas: HTMLCanvasElement, world: World) => Renderer;
|
|
232
|
+
export {};
|
|
@@ -151,6 +151,19 @@ export declare const SOUND: {
|
|
|
151
151
|
readonly HUNTER_PAIN: 75;
|
|
152
152
|
readonly HUNTER_DEATH: 76;
|
|
153
153
|
readonly HUNTER_TAUNT: 77;
|
|
154
|
+
/** Original wrist-blade mechanisms: an upward deployment and a lower, locking retraction. */
|
|
155
|
+
readonly HUNTER_BLADE_DRAW: 78;
|
|
156
|
+
readonly HUNTER_BLADE_SHEATHE: 79;
|
|
157
|
+
/** The Hunter's paired blades: a rasping sweep and a bright metal impact. */
|
|
158
|
+
readonly HUNTER_BLADE_SWISH: 80;
|
|
159
|
+
readonly HUNTER_BLADE_HIT: 81;
|
|
160
|
+
/** A spinning disc launch, its return whistle, and the catch against the wrist bracer. */
|
|
161
|
+
readonly HUNTER_DISC_THROW: 82;
|
|
162
|
+
readonly HUNTER_DISC_RETURN: 83;
|
|
163
|
+
readonly HUNTER_DISC_CATCH: 84;
|
|
164
|
+
/** A rising three-step target lock and a heavy shoulder-mounted laser discharge. */
|
|
165
|
+
readonly HUNTER_LOCK: 85;
|
|
166
|
+
readonly HUNTER_LASER: 86;
|
|
154
167
|
};
|
|
155
168
|
/**
|
|
156
169
|
* The sounds of the game: one entry per sound, its voices layered, in SOUND order. A low-passed
|
|
@@ -371,8 +371,12 @@ export declare const DISK_RETURN = 10;
|
|
|
371
371
|
export declare const DISK_SPEED = 52;
|
|
372
372
|
export declare const DISK_RANGE = 28;
|
|
373
373
|
export declare const DISK_R = 0.16;
|
|
374
|
-
export declare const DISK_HP =
|
|
374
|
+
export declare const DISK_HP = 3;
|
|
375
375
|
export declare const DISK_COOL = 75;
|
|
376
|
+
/** Ticks a Hunter must keep a target in the shoulder laser's sight to lock on. */
|
|
377
|
+
export declare const HUNTER_LASER_LOCK: number;
|
|
378
|
+
/** Damage dealt by a locked Hunter shoulder laser. */
|
|
379
|
+
export declare const HUNTER_LASER_HP = 3;
|
|
376
380
|
/** Ticks between assisted shoulder-laser hits. */
|
|
377
381
|
export declare const HUNTER_LASER_COOL = 18;
|
|
378
382
|
/** Plasma balls in flight in a room at most: past it the oldest bursts. They go on the wire. */
|
|
@@ -49,7 +49,7 @@ export interface Kit {
|
|
|
49
49
|
* walls (MODE.CLING), a dash's burst that pins an enemy it reaches, acid for blood (room.ts).
|
|
50
50
|
*/
|
|
51
51
|
xeno: boolean;
|
|
52
|
-
/** The Hunter's class identity
|
|
52
|
+
/** The Hunter's class identity, used for its weapons and alternate vision modes. */
|
|
53
53
|
hunter?: boolean;
|
|
54
54
|
}
|
|
55
55
|
/** By ROLE. The astronaut moves and fights as the marine: the moon's gravity is the map's. */
|
|
@@ -23,6 +23,8 @@ export declare class Room {
|
|
|
23
23
|
private balls;
|
|
24
24
|
/** Last tick a Hunter's shoulder laser hit, by player id. */
|
|
25
25
|
private hunterLasers;
|
|
26
|
+
/** Target and start tick of each Hunter's uninterrupted shoulder-laser lock. */
|
|
27
|
+
private hunterLocks;
|
|
26
28
|
/** The map's rovers, in the order of WorldDef.rovers, then its ships (ship.ts). */
|
|
27
29
|
private rovers;
|
|
28
30
|
/** Collision geometry reused while a vehicle's pose is unchanged. */
|
|
@@ -192,7 +194,9 @@ export declare class Room {
|
|
|
192
194
|
* and counts a hit. An enemy vehicle's hull is drained the same way, and shields who is behind it.
|
|
193
195
|
*/
|
|
194
196
|
private rail;
|
|
195
|
-
/**
|
|
197
|
+
/** The shoulder laser's assisted target, kept inside a narrow forward cone and clear line of sight. */
|
|
198
|
+
private shoulderTarget;
|
|
199
|
+
/** Fires only after an uninterrupted three-second target lock; damage is three HP. */
|
|
196
200
|
private shoulder;
|
|
197
201
|
/** 1 hp of the bolt's drain to `foe`, as his railer deals it; if it puts him down he is disintegrated (`fried`). */
|
|
198
202
|
private fry;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.202.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=(e,t,{vx:n,vy:r,vz:i},a,o)=>{let[s,c,l]=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],u=s*s+c*c+l*l,d=a**2-(n*n+r*r+i*i),f=s*n+c*r+l*i,p=u/(Math.sqrt(f*f+d*u)-f);if(p>0&&p<=o/a)return[t[0]+n*p,t[1]+r*p,t[2]+i*p]},t=e=>!!e&&e[0]>=0&&e[0]<=1&&e[1]>=0&&e[1]<=1,n=({world:n,camera:r,yaw:i,aspect:a,project:o,hostile:s},c,l,u,d,{BOLT_SPEED:f,PLAYER_R:p,range:m,MODE:h,NOBODY:g,hidden:_,heightOf:v,muzzleOf:y})=>{let b=o(...l),x={boxes:[],aim:b},S=y(c),[C,w,T]=l.map((e,t)=>e-S[t]),E=C*C+w*w+T*T,[D,O]=[Math.cos(i),-Math.sin(i)],k=n.def.seam,A=1/0,j=(i,s,c,l)=>{let u=[i.x,s,i.z],d=o(...u);if(!t(d)||_(n,r,u))return;let p=o(u[0]+D,s,u[2]+O)??d,h=2*Math.hypot((p[0]-d[0])*a,p[1]-d[1]);x.boxes.push({at:d,width:h*c/a,height:h*l});let g=b?Math.hypot((d[0]-b[0])*a,d[1]-b[1]):1/0;if(g>=A)return;let v=e(S,u,i,f,m);if(!v||k!==void 0&&v[1]>k!=S[1]>k)return;let y=o(...v);if(!t(y)||_(n,S,v))return;let j=((v[0]-S[0])*C+(v[1]-S[1])*w+(v[2]-S[2])*T)/E;j>0&&(A=g,x.lead=y,x.aim=o(S[0]+j*C,S[1]+j*w,S[2]+j*T))};for(let e of u){let t=e.driver===g?e.rider:e.driver;e!==c&&!e.wreck&&s(t)&&j(e,e.y,e.ship?7:2.8,e.ship?4:1.4)}for(let e of d)if(!e.down&&e.mode!==h.RIDE&&s(e.id)){let t=v(e)/2;j(e,e.y+t,p,t)}return x},r=(e,t,r)=>{let{PLAYER_R:i,MODE:a,NOBODY:o,aimOf:s,cylinder:c,heightOf:l,homeOf:u,ray:d,struck:f}=r;e.insertAdjacentHTML(`beforeend`,`<style>q{width:26px;height:26px;margin:-13px 0 0 -13px;border:2px solid #5f8;border-radius:50%;box-shadow:0 0 6px #3f6,inset 0 0 4px #3f6;background:radial-gradient(#afc 0 1.5px,#0000 2px)}q::before,q::after{content:none}.targets{position:absolute;inset:0;pointer-events:none}.target,.lead{position:absolute;transform:translate(-50%,-50%);box-sizing:border-box;border:2px solid #ff514d;box-shadow:0 0 3px #000}.target{min-width:26px;min-height:26px;max-width:90%;max-height:90%}.lead{width:18px;height:18px;border-radius:50%;border-style:dashed;background:radial-gradient(#ff514d 0 1px,transparent 2px)}</style><span class="targets" aria-hidden="true" hidden><span class="lead" hidden></span></span>`);let p=e.querySelector(`.targets`),m=p.querySelector(`.lead`),h=[],g=(e,[t,n])=>{e.style.left=`${t*100}%`,e.style.top=`${n*100}%`};return{frame(e,{yaw:_,pitch:v},y,b,x,S,C,w,T){if(p.hidden=!e?.ship,!e)return;let E=e=>{let t=T(e);return t!==void 0&&t!==w},D=S.filter((n,r)=>{let i=n.driver===o?n.rider:n.driver;return n!==e&&!n.wreck&&(!e.ship||(T(i)??u(t,r))!==w)}),O=C.filter(t=>!t.down&&t.mode!==a.RIDE&&(!e.ship||E(t.id))),k=s(e,_,v,(e,n,r)=>Math.min(d(t,e,n,r),...D.map(t=>f(t,e,n,r)),...O.map(t=>c(e,n,t,i,l(t)))));if(!e.ship)return x(...k);let{boxes:A,aim:j,lead:M}=n({world:t,camera:y,yaw:_,aspect:b,project:x,hostile:E},e,k,D,O,r);for(let e=0;e<A.length;e++){let{at:t,width:n,height:r}=A[e],i=h[e];i||(i=h[e]=document.createElement(`span`),i.className=`target`,p.prepend(i)),i.hidden=!1,g(i,t),i.style.width=`${n*100}%`,i.style.height=`${r*100}%`}for(let e=A.length;e<h.length;e++)h[e].hidden=!0;return m.hidden=!M,M&&g(m,M),j}}};export{r as createTargeting};
|