@korial29/tiny-fps 0.130.1 → 0.131.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.
@@ -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';
@@ -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,34 @@
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
+ }
26
+ /** By ROLE. The astronaut moves and fights as the marine: the moon's gravity is the map's. */
27
+ export declare const KITS: readonly Kit[];
28
+ /** Ticks after a dash's start before the next of a chain: the burst and a breath. */
29
+ export declare const DASH_GAP = 16;
30
+ /** The classes a map offers, the first one the default: the astronaut alone on a map with space helmets. */
31
+ export declare const rolesOf: (def: Pick<WorldDef, "helmets">) => number[];
32
+ /** The class a player plays on the map: his `role` when the map offers it, else the map's default. */
33
+ export declare const roleOf: (role: number | undefined, def: Pick<WorldDef, "helmets">) => number;
34
+ 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;
@@ -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.1",
5
+ "version": "0.131.0",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "dist"