@korial29/tiny-fps 0.130.2 → 0.132.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.
@@ -14,7 +14,8 @@ export interface TinyFpsOptions {
14
14
  /** The character to play (BODY): the man (0, the default) or the woman (1). The look only. */
15
15
  body?: number;
16
16
  }
17
- export type TinyFpsEvent = 'roster' | 'open' | 'close';
17
+ /** quit: the player left from the pause menu (Escape, then Quit); the page decides where he goes. */
18
+ export type TinyFpsEvent = 'roster' | 'open' | 'close' | 'quit';
18
19
  export interface TinyFps {
19
20
  on(ev: TinyFpsEvent, cb: () => void): void;
20
21
  /** Everyone in the room, the own player included. */
@@ -0,0 +1,14 @@
1
+ import type { Quat } from './rig';
2
+ import type { Vec3 } from './mesh';
3
+ import type { Skin } from './skin';
4
+ /** The suit's and the hood's black, a touch of blue in it; the guard's rim, a shade lighter; the disc's ink. */
5
+ export declare const CLOTH: number[];
6
+ /**
7
+ * Dresses the head of the skin `s` just drawn into `out` from `from` (skin(), in the order of its
8
+ * triangles' corners), on the head joint at `at` turned by `q`: the hood painted on it (the head,
9
+ * the neck and the skin at the neck's foot, but the opening round the eyes, soft at its edge), and
10
+ * the face under the guard pressed in behind it.
11
+ */
12
+ export declare const dress: (out: number[], from: number, s: Skin, at: Vec3, q: Quat, build?: number) => void;
13
+ /** Appends the guard and the ideograms on the head joint at `at` turned by `q` (see solve()), on the woman's smaller head with `build`, in the team's `color`. */
14
+ export declare const mask: (out: number[], at: Vec3, q: Quat, build?: number, color?: number[]) => void;
@@ -0,0 +1,25 @@
1
+ import type { Vec3 } from './mesh';
2
+ import type { Quat } from './rig';
3
+ /**
4
+ * A lame, from the arm's joint at rest (metres, +x out): where it starts and ends across, its half
5
+ * width fore and aft, and its height at its start.
6
+ */
7
+ export declare const LAMES: number[][];
8
+ /**
9
+ * His collar, standing round the back of the neck and open in front: how far round from the back it
10
+ * goes each side (rad), its radius at its foot and how much wider at its top, its foot under the
11
+ * neck's joint, and its height at the back and at its ends.
12
+ */
13
+ export declare const COLLAR: {
14
+ a: number;
15
+ r: number;
16
+ flare: number;
17
+ foot: number;
18
+ back: number;
19
+ end: number;
20
+ };
21
+ /** Appends the ninja's shoulder pads and his collar on the solved pose `s`, in the team's `color`; smaller on the woman (`build`). */
22
+ export declare const pads: (out: number[], s: {
23
+ pos: Vec3[];
24
+ rot: Quat[];
25
+ }, build?: number, color?: number[]) => void;
@@ -3,9 +3,9 @@ import type { World } from '../shared/world';
3
3
  export interface Predictor {
4
4
  /**
5
5
  * The own player id and team, from the roster. Snapshots before it are only used for the others.
6
- * The team picks the spawn a fall puts the player back at.
6
+ * The team picks the spawn a fall puts the player back at, the role (ROLE) the kit of the steps.
7
7
  */
8
- you(id: number, team?: number): void;
8
+ you(id: number, team?: number, role?: number): void;
9
9
  /**
10
10
  * One local step: gives the input the next seq, rounds its yaw and pitch to the wire, moves the
11
11
  * own player with it, keeps it for replay, and returns it for the caller to send (the very
@@ -1,4 +1,4 @@
1
- import type { PlayerState, Rover } from '../shared/types';
1
+ import type { Choice, PlayerState, Rover } from '../shared/types';
2
2
  import type { World, WorldDef } from '../shared/world';
3
3
  import type { Body } from './body';
4
4
  import type { Tracer } from './beams';
@@ -139,17 +139,17 @@ export interface Renderer {
139
139
  muzzle(id: number): Vec3 | undefined;
140
140
  /** The runners of the players `ids` grin for a moment: their team has captured. */
141
141
  cheer(ids: number[]): void;
142
- /** The body of each player (PlayerInfo.body, BODY), from the roster: the man's for one not in it. */
143
- wear(builds: ReadonlyMap<number, number>): void;
142
+ /** The body of each player (PlayerInfo.body, BODY), from the roster: the man's for one not in it; and the skin and haircut he picked, his id's for one not in `looks`. */
143
+ wear(builds: ReadonlyMap<number, number>, looks?: ReadonlyMap<number, Choice>): void;
144
144
  /**
145
- * A picture of the player `p` as the character `build` in `color`, into the 2D canvas `into`:
146
- * a frame of him alone in the map's sky, which the next frame() replaces on the screen. False
147
- * when nothing could be drawn yet.
145
+ * A picture of the player `p` as the character `build` in `color`, with the skin and haircut
146
+ * `look`, framed by `shot` (PORTRAIT, or HEAD for the head alone), into the 2D canvas `into`: a frame of him alone in the map's sky, which the next
147
+ * frame() replaces on the screen. False when nothing could be drawn yet.
148
148
  */
149
- portrait(into: HTMLCanvasElement, p: PlayerState, build: number, color: string): boolean;
149
+ portrait(into: HTMLCanvasElement, p: PlayerState, build: number, color: string, look?: Choice, shot?: typeof PORTRAIT): boolean;
150
150
  destroy(): void;
151
151
  }
152
- /** A character card's picture: how high over the map he stands (m), the camera's height over his feet and its distance (m), its angle off his front and his own off the sun (rad), and its field of view (degrees). */
152
+ /** A character card's picture: how high over the map he stands (m), the camera's height over his feet and its distance (m), its angle off his front and his own off the sun (rad), its field of view (degrees), and how far it steps to its right (m). */
153
153
  export declare const PORTRAIT: {
154
154
  y: number;
155
155
  eye: number;
@@ -157,6 +157,17 @@ export declare const PORTRAIT: {
157
157
  turn: number;
158
158
  sun: number;
159
159
  fov: number;
160
+ side: number;
161
+ };
162
+ /** A haircut's picture: the head alone, seen three quarters from behind so a tail or a bun shows. */
163
+ export declare const HEAD: {
164
+ eye: number;
165
+ away: number;
166
+ turn: number;
167
+ fov: number;
168
+ side: number;
169
+ y: number;
170
+ sun: number;
160
171
  };
161
172
  /** Pixels drawn at most (1080p): every one is lit per light and shadow map, so a 4K screen at a pixel ratio of 2 would pay for 8 million. */
162
173
  export declare const MAX_PIXELS: number;
@@ -1,15 +1,26 @@
1
+ import type { Choice } from '../shared/types';
1
2
  import type { Quat } from './rig';
2
3
  import type { Vec3 } from './mesh';
3
- /** A hair colour for the runner `id`, picked at random from HAIRS but the same for everyone who sees him. */
4
- export declare const hairOf: (id: number) => number[];
4
+ /** The regions a runner's outfit is recoloured or covered by: the skin, the trousers, the boots, the gloves, the stripes and the belt. */
5
+ export declare const REGION: {
6
+ FLESH: number;
7
+ PANTS: number;
8
+ UPPER: number;
9
+ GLOVE: number;
10
+ STRIPE: number;
11
+ STRIPE_LOW: number;
12
+ BELT: number;
13
+ };
14
+ /** A hair colour for the runner `id`, picked at random from HAIRS but the same for everyone who sees him; his haircut (`c.hair`, look.ts) says whether he is shaved. */
15
+ export declare const hairOf: (id: number, c?: Choice) => number[];
5
16
  /** The hair colour of the woman `id`: as hairOf(), never the shaved head's (her hair is a style of hair.ts). */
6
- export declare const tressOf: (id: number) => number[];
17
+ export declare const tressOf: (id: number, c?: Choice) => number[];
7
18
  /** How dark the shaved beard of the runner `id` is, 0 (none) to 1. */
8
19
  export declare const beardOf: (id: number) => number;
9
20
  /** Whether the runner `id` has a shaved head (the last of HAIRS): no hair to give a length to. */
10
- export declare const shaved: (id: number) => boolean;
21
+ export declare const shaved: (id: number, c?: Choice) => boolean;
11
22
  /** An iris colour for the runner `id`, as hairOf(). */
12
- export declare const eyesOf: (id: number) => number[];
23
+ export declare const eyesOf: (id: number, c?: Choice) => number[];
13
24
  /** Jacket, its darker trim, trousers (the suit's legs, darker), skin, hair, boots, sole, gloves, the whites of the eyes and their irises, the lips, the skin in its folds (nostrils, the mouth, the ears' hollows), the brows, between the hair and the skin, the shaved beard's shadow and its edge, the line between the lips (as the folds), the side stripe on the jacket and on the trousers and the belt (the jacket's and the trousers' own colours but on a space suit), the light caught in the eyes, which glows, and the cut's cauterized face, which glows too. */
14
25
  /**
15
26
  * With `suit` (the moon's, the user 2026-11-10), a dark grey space suit under white armour: the
@@ -1,4 +1,4 @@
1
- import type { PlayerState, Rover } from '../shared/types';
1
+ import type { Choice, PlayerState, Rover } from '../shared/types';
2
2
  import type { World } from '../shared/world';
3
3
  import type { Gait, Seat } from './gait';
4
4
  import type { Tracer } from './beams';
@@ -42,7 +42,11 @@ export interface Runner {
42
42
  tip?: Vec3;
43
43
  /** The BUILD of the body (rig.ts, PlayerInfo.body): the man's when absent. */
44
44
  build?: number;
45
+ /** The skin and haircut the player picked (PlayerInfo.tone and hair): his id's when absent. */
46
+ look?: Choice;
45
47
  }
48
+ /** A man's haircuts (look.ts's HAIR_NAMES[0]): how long the hair stands off the scalp, the first one shaved. */
49
+ export declare const LENGTHS: number[];
46
50
  /**
47
51
  * The seat of a player who rides: the rover whose `driver` or `rider` he is. Nothing for one on
48
52
  * foot, or whose rover is not among `rovers`.
@@ -56,7 +60,8 @@ export declare const HURT: number, GRIN: number;
56
60
  */
57
61
  export declare const femme: (w: Float32Array) => void;
58
62
  /** A runner as first seen: in the pose its state asks for, no ease. */
59
- export declare const createRunner: (p: PlayerState, seat?: Seat, build?: number) => Runner;
63
+ /** `calm`: at ease, not in a fighter's guard (the menu's picture, the user 2026-11-12). */
64
+ export declare const createRunner: (p: PlayerState, seat?: Seat, build?: number, look?: Choice, calm?: boolean) => Runner;
60
65
  /**
61
66
  * Moves each runner of `book` to its player in `others` after dt seconds: a new player gets a
62
67
  * runner already in pose, one that left loses it. With a `world` the feet stand on the brushes
@@ -75,7 +80,7 @@ export declare const WATCH: {
75
80
  };
76
81
  /** Where the head of the runner `p` looks at is, among `crowd`: nothing when he looks at no one, or is down. */
77
82
  export declare const watched: (p: PlayerState, crowd: PlayerState[]) => Vec3 | undefined;
78
- export declare const animate: (book: Map<number, Runner>, others: PlayerState[], dt: number, world?: World, tracer?: Pick<Tracer, "shock" | "spit">, rovers?: Rover[], builds?: ReadonlyMap<number, number>) => void;
83
+ export declare const animate: (book: Map<number, Runner>, others: PlayerState[], dt: number, world?: World, tracer?: Pick<Tracer, "shock" | "spit">, rovers?: Rover[], builds?: ReadonlyMap<number, number>, looks?: ReadonlyMap<number, Choice>) => void;
79
84
  /**
80
85
  * A long gun's butt plate in the hollow of the right shoulder: from the shoulder joint, in the
81
86
  * chest's frame (to its right, up, back). The gun goes from there along the look, so it is
@@ -1,3 +1,4 @@
1
+ import type { Kit } from './kit';
1
2
  import type { Body } from './physics';
2
3
  import type { Input, PlayerState } from './types';
3
4
  import type { World } from './world';
@@ -27,7 +28,7 @@ export type Strike = (typeof STRIKE)[keyof typeof STRIKE];
27
28
  * stays in hand for the length of a swing. `wield` is the katana in hand, `railed` the rail gun.
28
29
  * - The gun fires from its battery (`mag`), the rail gun from its capsule (`cap`). An empty one, or
29
30
  * KEY.RELOAD with room in it, swaps it for a full one from what he carries: `reload` ticks
30
- * without firing, then it holds GUN_MAG (RAIL_CAP) or what is left. A switch of weapon drops it.
31
+ * without firing, then it holds the kit's `mag` (`cap`, `clip`) or what is left. A switch of weapon drops it.
31
32
  * The racks fill both.
32
33
  * - The rail gun throws its bolt on every step FIRE is held, spending a tick of it (`zapping`),
33
34
  * unless it is `hot`: its `heat` rises while it fires and falls when it does not (HEAT_MAX).
@@ -44,7 +45,7 @@ export type Strike = (typeof STRIKE)[keyof typeof STRIKE];
44
45
  * its swing. The look is the input's, so both go where the player sees.
45
46
  * `armed` is false while the match is over: no weapon, no rack. `bodies` are move()'s.
46
47
  */
47
- export declare const step: (p: PlayerState, i: Input, w: World, team: number, armed?: boolean, bodies?: readonly Body[]) => Strike;
48
+ export declare const step: (p: PlayerState, i: Input, w: World, team: number, armed?: boolean, bodies?: readonly Body[], kit?: Kit) => Strike;
48
49
  /** The strength a charge of `ticks` gives, 1 to CHARGE_MAX: 1 under CHARGE_TAP, CHARGE_MAX at CHARGE_TICKS. */
49
50
  export declare const powerOf: (ticks: number) => number;
50
51
  export {};
@@ -0,0 +1,42 @@
1
+ import type { WorldDef } from './world';
2
+ export declare const ROLE: {
3
+ readonly MARINE: 0;
4
+ readonly NINJA: 1;
5
+ readonly ASTRONAUT: 2;
6
+ };
7
+ export interface Kit {
8
+ run: number;
9
+ sprint: number;
10
+ jump: number;
11
+ double: number;
12
+ /** Ticks a wall-run lasts at most. */
13
+ wallrun: number;
14
+ /** Dashes in a row before the full DASH_COOLDOWN; 1 is the old rule: one in the air, any on the ground. */
15
+ dashes: number;
16
+ /** Swing ticks the katana runs down per step. */
17
+ haste: number;
18
+ /** What the racks fill and the packs top up to: the gun's shots, the rail gun's lightning, the rifle's rounds. */
19
+ ammo: number;
20
+ rail: number;
21
+ rifle: number;
22
+ /** Ticks between two shots of the gun and of the rifle. */
23
+ cool: number;
24
+ rifleCool: number;
25
+ /** What the gun's battery, the rail gun's capsule and the rifle's cell hold. */
26
+ mag: number;
27
+ cap: number;
28
+ clip: number;
29
+ /** What a hit of his guns takes, of their damage (the host's: room.ts). */
30
+ damage: number;
31
+ /** His running speeds with a gun in hand, of his own. */
32
+ slow: number;
33
+ }
34
+ /** By ROLE. The astronaut moves and fights as the marine: the moon's gravity is the map's. */
35
+ export declare const KITS: readonly Kit[];
36
+ /** Ticks after a dash's start before the next of a chain: the burst and a breath. */
37
+ export declare const DASH_GAP = 16;
38
+ /** The classes a map offers, the first one the default: the astronaut alone on a map with space helmets. */
39
+ export declare const rolesOf: (def: Pick<WorldDef, "helmets">) => number[];
40
+ /** The class a player plays on the map: his `role` when the map offers it, else the map's default. */
41
+ export declare const roleOf: (role: number | undefined, def: Pick<WorldDef, "helmets">) => number;
42
+ export declare const kitOf: (role: number | undefined, def: Pick<WorldDef, "helmets">) => Kit;
@@ -1,4 +1,5 @@
1
1
  import type { Input, PlayerState } from './types';
2
+ import type { Kit } from './kit';
2
3
  import type { World } from './world';
3
4
  type Pos = Pick<PlayerState, 'x' | 'y' | 'z'>;
4
5
  export declare const TAU: number;
@@ -105,5 +106,5 @@ export declare const stumble: (p: PlayerState, dx: number, dz: number, ticks?: n
105
106
  * kill floor put the player back at a spawn of his `team` (EV.RESPAWN). `bodies` are the rovers'
106
107
  * (hull(), rover.ts) as they stand when the step runs: walls and floors for this step alone.
107
108
  */
108
- export declare const move: (p: PlayerState, i: Input, w: World, team?: number, bodies?: readonly Body[]) => void;
109
+ export declare const move: (p: PlayerState, i: Input, w: World, team?: number, bodies?: readonly Body[], kit?: Kit) => void;
109
110
  export {};
@@ -1,16 +1,19 @@
1
- import type { Input, PlayerInfo, Snapshot } from './types';
2
- /** join: the first frame of a peer, `body` the character he picked (BODY, the man without it). map: the host picks the map of the next match (MAPS key). body: a joined player changes character (BODY), at once. */
3
- export type ClientText = {
1
+ import type { Choice, Input, PlayerInfo, Snapshot } from './types';
2
+ /**
3
+ * join: the first frame of a peer, with what he picked on the title screen (Choice: the body, BODY,
4
+ * the man without it; the skin, the haircut, the class). map: the host picks the map of the next
5
+ * match (MAPS key). body: a joined player changes his choice, at once.
6
+ */
7
+ export type ClientText = ({
4
8
  t: 'join';
5
9
  name: string;
6
- body?: number;
7
- } | {
10
+ } & Choice) | {
8
11
  t: 'map';
9
12
  map: string;
10
- } | {
13
+ } | ({
11
14
  t: 'body';
12
15
  body: number;
13
- };
16
+ } & Choice);
14
17
  /** What a player did in a match, for the end screen: it carries the name and the team, which a leaver takes out of the roster. */
15
18
  export interface Result {
16
19
  id: number;
@@ -1,5 +1,10 @@
1
- import type { Conn, Every, PlayerState, Rules } from './types';
1
+ import type { Choice, Conn, Every, PlayerState, Rules } from './types';
2
2
  import type { WorldDef } from './world';
3
+ /**
4
+ * What a player picked, only what the game knows: the woman's body (the man's is no field, so an old
5
+ * roster is unchanged), a skin, a haircut of that body and a class (ROLE: the map says which it offers).
6
+ */
7
+ export declare const chosen: (m: Record<string, unknown>) => Choice;
3
8
  export declare class Room {
4
9
  /** Every connected peer; null until it joins. */
5
10
  private peers;
@@ -91,6 +96,11 @@ export declare class Room {
91
96
  * lies down now or did then.
92
97
  */
93
98
  private enemies;
99
+ /**
100
+ * `hp` of a gun's damage to `foe` from `by`: as his class deals it (Kit.damage, a ninja's half), the
101
+ * half points kept on `foe` toward the next. True when he went down.
102
+ */
103
+ private shot;
94
104
  /**
95
105
  * `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
96
106
  * the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
@@ -136,7 +146,7 @@ export declare class Room {
136
146
  * and counts a hit. An enemy vehicle's hull is drained the same way, and shields who is behind it.
137
147
  */
138
148
  private rail;
139
- /** 1 hp of the bolt's drain to `foe`; if it puts him down he is disintegrated (`fried`). */
149
+ /** 1 hp of the bolt's drain to `foe`, as his railer deals it; if it puts him down he is disintegrated (`fried`). */
140
150
  private fry;
141
151
  /**
142
152
  * A saber lock of `p`, after his input: it ends when a side leads by LOCK_WIN presses (the other
@@ -18,12 +18,23 @@ export interface PlayerInfo {
18
18
  color: string;
19
19
  /** BODY: the character he plays. Absent for the man, as before there was a choice. */
20
20
  body?: number;
21
+ /** The skin tone he picked (an index of TONES, features.ts); absent, his id picks one. */
22
+ tone?: number;
23
+ /** The haircut he picked (look.ts); absent, his id picks one. */
24
+ hair?: number;
25
+ /** ROLE (kit.ts) on the maps that offer it; absent, the map's default (the marine, the astronaut on the moon). */
26
+ role?: number;
21
27
  }
28
+ /** What a player picks on the title screen: his body, his skin, his haircut and his class (PlayerInfo's). */
29
+ export type Choice = Pick<PlayerInfo, 'body' | 'tone' | 'hair' | 'role'>;
22
30
  /** The characters a player can be (PlayerInfo.body, the join's `body`): the look only, the game is the same for both. */
23
31
  export declare const BODY: {
24
32
  readonly MALE: 0;
25
33
  readonly FEMALE: 1;
26
34
  };
35
+ /** How many skin tones there are, and haircuts for each BODY (the client's TONES and look.ts). */
36
+ export declare const TONES_N = 6;
37
+ export declare const HAIRS_N: number[];
27
38
  /** Bits of Input.keys. Keys are read by KeyboardEvent.code, so WASD is ZQSD on AZERTY. */
28
39
  export declare const KEY: {
29
40
  readonly FORWARD: 1;
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.130.2",
5
+ "version": "0.132.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"