@netforge/template-survivor 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/NOTICE +30 -0
- package/README.md +40 -2
- package/client/debris.ts +257 -0
- package/client/decor.ts +21 -0
- package/client/host.ts +96 -0
- package/client/hud.ts +575 -0
- package/client/icons.ts +42 -0
- package/client/index.html +277 -0
- package/client/input.ts +172 -0
- package/client/library.ts +250 -0
- package/client/main.ts +606 -0
- package/client/names.ts +57 -0
- package/client/scene.ts +1065 -0
- package/client/stake.ts +101 -0
- package/client/styled.ts +53 -0
- package/client/threats.ts +157 -0
- package/llms.txt +369 -0
- package/package.json +57 -3
- package/src/game.ts +354 -0
- package/src/manifest.ts +38 -0
- package/src/store.ts +107 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NetNet Capital Management
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
@netforge/template-survivor (EMBERWATCH)
|
|
2
|
+
Copyright (c) 2026 NetNet Capital Management
|
|
3
|
+
|
|
4
|
+
An original game. No names, characters, sprites, models, sounds or code
|
|
5
|
+
from any other game or franchise. Nothing from PokéSurvivor (its code and
|
|
6
|
+
sprites are non-commercial) or SpriteCollab was used or consulted for code.
|
|
7
|
+
|
|
8
|
+
Art and sound
|
|
9
|
+
- Models come from the per-style asset library
|
|
10
|
+
(@netforge/asset-library): CC0 1.0 models by Quaternius (keepers,
|
|
11
|
+
enemies) and Kenney (Nature Kit trees, rocks and stumps), each pack listed
|
|
12
|
+
with its source URL and licence verification in that package's NOTICE and
|
|
13
|
+
manifest/packs.json. The files are fetched and built, never committed
|
|
14
|
+
here; the build copies only the models this game uses.
|
|
15
|
+
- Fallback shapes (client/library.ts) are generated from three.js
|
|
16
|
+
primitives; textures are drawn on a canvas at load.
|
|
17
|
+
|
|
18
|
+
Dependencies (unmodified, via npm)
|
|
19
|
+
- three.js 0.186.1 (https://github.com/mrdoob/three.js), MIT.
|
|
20
|
+
- nipplejs 1.0.4 (https://github.com/yoannmoinet/nipplejs), MIT.
|
|
21
|
+
- @netforge/engine and @netforge/engine-sim (this repository);
|
|
22
|
+
see their NOTICE files (bitECS MPL-2.0, Rapier Apache-2.0, Colyseus MIT,
|
|
23
|
+
zod MIT).
|
|
24
|
+
|
|
25
|
+
Patterns (ideas only)
|
|
26
|
+
- The survivor-like genre's general mechanics (auto-firing weapons, XP
|
|
27
|
+
gems, pick-one-of-three level-ups, waves, a boss). Mechanics, not
|
|
28
|
+
expression; no level, item, enemy or text was copied from any game.
|
|
29
|
+
- Hit-stop, screen shake and damage numbers as described in common
|
|
30
|
+
game-feel talks and articles (e.g. "Juice it or lose it", GDC 2012).
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# EMBERWATCH (Template 1: survivor-like co-op)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Four keepers hold a field at night against a swarm that grows every wave,
|
|
4
|
+
up to 2,000 at once. Weapons fire by themselves, gems level you up, pick
|
|
5
|
+
one of three upgrades, stand by a downed teammate to revive them, survive
|
|
6
|
+
ten waves and break the Bell Warden.
|
|
7
|
+
|
|
8
|
+
| Path | What |
|
|
9
|
+
|---|---|
|
|
10
|
+
| `src/game.ts` | The game, as the model writes it (declarations only). |
|
|
11
|
+
| `src/manifest.ts` | Loads and compiles it; `survivorAdapter()` for the room server and client. |
|
|
12
|
+
| `src/store.ts` | Store hooks on the Kit's API names (`kit.coins.*`, `kit.store.*`): a revive (50 coins) and a cosmetic (300 coins), shown under the token's own symbol and logo; mock until the token is live. |
|
|
13
|
+
| `client/` | The browser client: three.js scene, HUD, input (keys, gamepad, touch), game feel. |
|
|
14
|
+
| `test/` | Playtest bots through `engine.test.run`. |
|
|
15
|
+
| `llms.txt` | How to change the game (for agents). |
|
|
16
|
+
|
|
17
|
+
## Why a package here
|
|
18
|
+
|
|
19
|
+
It is a game, not engine code: Net Forge copies it as the starting repo
|
|
20
|
+
for a generated game. The room server loads its game module and a browser
|
|
21
|
+
bundle is its client, so it is its own package, depending on
|
|
22
|
+
`@netforge/engine` and `-sim`.
|
|
23
|
+
|
|
24
|
+
## Run it
|
|
25
|
+
|
|
26
|
+
This template runs on your own computer with play money through
|
|
27
|
+
`kit play` (`@netforge/kit-play`). From the repository root:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pnpm install --frozen-lockfile && pnpm build
|
|
31
|
+
mkdir -p play-survivor/src && cp packages/template-survivor/src/game.ts play-survivor/src/
|
|
32
|
+
echo '{"template":"survivor"}' > play-survivor/netnet.json
|
|
33
|
+
node packages/kit-play/dist/cli.js play-survivor # opens http://127.0.0.1:4663
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Edit `play-survivor/src/game.ts` and run it again to try a change. Real-token
|
|
37
|
+
earning, stakes and claims run only on the hosted Net Forge server.
|
|
38
|
+
|
|
39
|
+
Open the Invite link in another tab or on a phone on the same network to
|
|
40
|
+
play together (`?room=<id>`). Keys: WASD or arrows, Space dash, 1 2 3 pick.
|
|
41
|
+
Touch: drag on the left half, DASH button, tap a card. ` shows stats.
|
package/client/debris.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side physics dressing on engine-sim's PhysicsWorld (Rapier, the
|
|
3
|
+
* same build the server runs): chunks that fly off killed enemies and
|
|
4
|
+
* bounce off the floor and pillars, and a scatter of rocks and stumps
|
|
5
|
+
* the keepers shove around and novas blast away.
|
|
6
|
+
*
|
|
7
|
+
* Presentation only. None of it feeds back into the authoritative sim, so
|
|
8
|
+
* it never needs to match the server or other players exactly; every
|
|
9
|
+
* client drives the props from the same interpolated keeper positions, so
|
|
10
|
+
* what they see agrees closely anyway.
|
|
11
|
+
*/
|
|
12
|
+
import { Color, InstancedMesh, Matrix4, MeshStandardMaterial, Quaternion, Vector3 } from "three/webgpu";
|
|
13
|
+
import type { BufferGeometry, Material, Scene } from "three/webgpu";
|
|
14
|
+
import { CylinderGeometry, DodecahedronGeometry } from "three/webgpu";
|
|
15
|
+
import { Layer, createPhysics } from "@netforge/engine-sim";
|
|
16
|
+
import type { BodyId, PhysicsWorld, ResolvedSimConfig } from "@netforge/engine-sim";
|
|
17
|
+
|
|
18
|
+
const HZ = 60;
|
|
19
|
+
const MAX_CHUNKS = 220;
|
|
20
|
+
const MAX_STEPS = 4;
|
|
21
|
+
const CHUNK_LIFE = 2.2;
|
|
22
|
+
|
|
23
|
+
interface Chunk {
|
|
24
|
+
id: BodyId;
|
|
25
|
+
life: number;
|
|
26
|
+
max: number;
|
|
27
|
+
size: number;
|
|
28
|
+
color: Color;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Prop {
|
|
32
|
+
id: BodyId;
|
|
33
|
+
barrel: boolean;
|
|
34
|
+
/** Last speed, for impact thuds. */
|
|
35
|
+
speed: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Seeded PRNG so every client scatters the props in the same places. */
|
|
39
|
+
function rng(seed: number): () => number {
|
|
40
|
+
let s = seed >>> 0;
|
|
41
|
+
return () => {
|
|
42
|
+
s = (s + 0x6d2b79f5) >>> 0;
|
|
43
|
+
let t = s;
|
|
44
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
45
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
46
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** An art style's own drawing of a debris shape (the voxel style's cube chunks, rocks and stumps); null keeps the primitive. */
|
|
51
|
+
export type DebrisShape = (name: "chunk" | "rock" | "stump") => { readonly geometry: BufferGeometry; readonly material: Material } | null;
|
|
52
|
+
|
|
53
|
+
function instanced(geometry: BufferGeometry, color: number, capacity: number, emissive = 0x000000, styled?: ReturnType<DebrisShape>): InstancedMesh {
|
|
54
|
+
const material = styled?.material ?? new MeshStandardMaterial({ color, roughness: 0.75, flatShading: true, emissive, emissiveIntensity: 0.6 });
|
|
55
|
+
const mesh = new InstancedMesh(styled?.geometry ?? geometry, material, capacity);
|
|
56
|
+
mesh.count = 0;
|
|
57
|
+
mesh.frustumCulled = false;
|
|
58
|
+
mesh.castShadow = true;
|
|
59
|
+
mesh.receiveShadow = true;
|
|
60
|
+
const white = new Color(1, 1, 1);
|
|
61
|
+
for (let i = 0; i < capacity; i++) mesh.setColorAt(i, white);
|
|
62
|
+
return mesh;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class PhysicsDressing {
|
|
66
|
+
readonly physics: PhysicsWorld;
|
|
67
|
+
private readonly chunks: Chunk[] = [];
|
|
68
|
+
private readonly props: Prop[] = [];
|
|
69
|
+
private readonly keepers = new Map<number, BodyId>();
|
|
70
|
+
private readonly chunkMesh: InstancedMesh;
|
|
71
|
+
private readonly crateMesh: InstancedMesh;
|
|
72
|
+
private readonly barrelMesh: InstancedMesh;
|
|
73
|
+
private acc = 0;
|
|
74
|
+
private readonly m = new Matrix4();
|
|
75
|
+
private readonly q = new Quaternion();
|
|
76
|
+
private readonly p = new Vector3();
|
|
77
|
+
private readonly s = new Vector3();
|
|
78
|
+
private readonly random = rng(0xe3b1);
|
|
79
|
+
/** Impacts this frame (world position and speed), for thud sounds. */
|
|
80
|
+
readonly impacts: { x: number; y: number; z: number; speed: number }[] = [];
|
|
81
|
+
/** Effects fired so far (playtest checks). */
|
|
82
|
+
readonly counts = { chunks: 0, blasts: 0 };
|
|
83
|
+
|
|
84
|
+
constructor(scene: Scene, config: ResolvedSimConfig, opts: { props?: boolean; shape?: DebrisShape } = {}) {
|
|
85
|
+
this.physics = createPhysics({ gravity: [0, -24, 0], tickRate: HZ });
|
|
86
|
+
const P = this.physics;
|
|
87
|
+
const h = config.arena.halfExtent;
|
|
88
|
+
const wall = config.arena.wallHeight;
|
|
89
|
+
P.addStaticBox([h + 1, 0.5, h + 1], [0, -0.5, 0], { friction: 0.8, layer: Layer.Level });
|
|
90
|
+
P.addStaticBox([h + 1, wall, 0.5], [0, wall, h + 0.5], { layer: Layer.Level });
|
|
91
|
+
P.addStaticBox([h + 1, wall, 0.5], [0, wall, -h - 0.5], { layer: Layer.Level });
|
|
92
|
+
P.addStaticBox([0.5, wall, h + 1], [h + 0.5, wall, 0], { layer: Layer.Level });
|
|
93
|
+
P.addStaticBox([0.5, wall, h + 1], [-h - 0.5, wall, 0], { layer: Layer.Level });
|
|
94
|
+
for (const pl of config.arena.pillars) {
|
|
95
|
+
P.addBody({ type: "static", shape: { cylinder: [pl.height / 2, pl.radius] }, position: [pl.x, pl.height / 2, pl.z], layer: Layer.Level, friction: 0.6 });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Props: crates and barrels around the pillars and in the open, the same scatter on every client.
|
|
99
|
+
const props = rng(0x51f7);
|
|
100
|
+
const spots: [number, number][] = [];
|
|
101
|
+
for (const pl of config.arena.pillars) {
|
|
102
|
+
for (let k = 0; k < 3; k++) {
|
|
103
|
+
const a = props() * Math.PI * 2;
|
|
104
|
+
const d = pl.radius + 1.2 + props() * 1.5;
|
|
105
|
+
spots.push([pl.x + Math.cos(a) * d, pl.z + Math.sin(a) * d]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (let k = 0; k < 14; k++) {
|
|
109
|
+
const a = props() * Math.PI * 2;
|
|
110
|
+
const d = 6 + props() * (h - 12);
|
|
111
|
+
spots.push([Math.cos(a) * d, Math.sin(a) * d]);
|
|
112
|
+
}
|
|
113
|
+
if (opts.props === false) spots.length = 0;
|
|
114
|
+
for (const [x, z] of spots) {
|
|
115
|
+
const barrel = props() < 0.4;
|
|
116
|
+
const yaw = props() * Math.PI;
|
|
117
|
+
const id = P.addBody({
|
|
118
|
+
type: "dynamic",
|
|
119
|
+
shape: barrel ? { cylinder: [0.45, 0.35] } : { box: [0.4, 0.4, 0.4] },
|
|
120
|
+
position: [x, barrel ? 0.45 : 0.4, z],
|
|
121
|
+
rotation: [0, Math.sin(yaw / 2), 0, Math.cos(yaw / 2)],
|
|
122
|
+
density: 40,
|
|
123
|
+
friction: 0.7,
|
|
124
|
+
restitution: 0.15,
|
|
125
|
+
linearDamping: 0.4,
|
|
126
|
+
angularDamping: 0.6,
|
|
127
|
+
layer: Layer.Prop,
|
|
128
|
+
mask: Layer.Level | Layer.Prop | Layer.Player | Layer.Debris,
|
|
129
|
+
});
|
|
130
|
+
this.props.push({ id, barrel, speed: 0 });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.chunkMesh = instanced(new DodecahedronGeometry(1, 0), 0xffffff, MAX_CHUNKS, 0, opts.shape?.("chunk"));
|
|
134
|
+
// One family with the field's stone and the Nature Kit stumps: loose rocks and cut stumps, not crates and barrels.
|
|
135
|
+
this.crateMesh = instanced(new DodecahedronGeometry(0.5), 0x5e5246, Math.max(1, this.props.length), 0, opts.shape?.("rock"));
|
|
136
|
+
this.barrelMesh = instanced(new CylinderGeometry(0.33, 0.38, 0.9, 7), 0x4e3a28, Math.max(1, this.props.length), 0, opts.shape?.("stump"));
|
|
137
|
+
scene.add(this.chunkMesh, this.crateMesh, this.barrelMesh);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Keepers push props: one kinematic capsule per player, moved to where it is drawn. */
|
|
141
|
+
keeper(owner: number, x: number, y: number, z: number, up: boolean): void {
|
|
142
|
+
let id = this.keepers.get(owner);
|
|
143
|
+
if (id === undefined) {
|
|
144
|
+
id = this.physics.addBody({ type: "kinematic", shape: { capsule: [0.5, 0.4] }, position: [x, y, z], layer: Layer.Player, mask: Layer.Prop | Layer.Debris });
|
|
145
|
+
this.keepers.set(owner, id);
|
|
146
|
+
}
|
|
147
|
+
this.physics.setKinematicTarget(id, [x, up ? y : -5, z]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Forget keepers not seen this frame. */
|
|
151
|
+
keepOnly(owners: ReadonlySet<number>): void {
|
|
152
|
+
for (const [owner, id] of this.keepers) {
|
|
153
|
+
if (owners.has(owner)) continue;
|
|
154
|
+
this.physics.removeBody(id);
|
|
155
|
+
this.keepers.delete(owner);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Chunks off a killed enemy, thrown along the push direction. */
|
|
160
|
+
shatter(x: number, z: number, radius: number, color: Color, count: number, dirX = 0, dirZ = 0): void {
|
|
161
|
+
const P = this.physics;
|
|
162
|
+
this.counts.chunks += count;
|
|
163
|
+
for (let i = 0; i < count; i++) {
|
|
164
|
+
if (this.chunks.length >= MAX_CHUNKS) this.retire(0);
|
|
165
|
+
const size = radius * (0.22 + this.random() * 0.25);
|
|
166
|
+
const a = this.random() * Math.PI * 2;
|
|
167
|
+
const sp = 2 + this.random() * 3.5;
|
|
168
|
+
const id = P.addBody({
|
|
169
|
+
type: "dynamic",
|
|
170
|
+
shape: { box: [size, size, size] },
|
|
171
|
+
position: [x + Math.cos(a) * radius * 0.5, radius + 0.2 + this.random() * radius, z + Math.sin(a) * radius * 0.5],
|
|
172
|
+
density: 8,
|
|
173
|
+
friction: 0.6,
|
|
174
|
+
restitution: 0.35,
|
|
175
|
+
angularDamping: 0.3,
|
|
176
|
+
linearVelocity: [Math.cos(a) * sp + dirX * 5, 3.5 + this.random() * 4, Math.sin(a) * sp + dirZ * 5],
|
|
177
|
+
angularVelocity: [(this.random() - 0.5) * 18, (this.random() - 0.5) * 18, (this.random() - 0.5) * 18],
|
|
178
|
+
layer: Layer.Debris,
|
|
179
|
+
mask: Layer.Level | Layer.Prop,
|
|
180
|
+
});
|
|
181
|
+
const life = CHUNK_LIFE * (0.7 + this.random() * 0.6);
|
|
182
|
+
this.chunks.push({ id, life, max: life, size, color });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** A blast (nova) shoves props and chunks out of `radius`. */
|
|
187
|
+
blast(x: number, z: number, radius: number, strength: number): void {
|
|
188
|
+
const P = this.physics;
|
|
189
|
+
this.counts.blasts++;
|
|
190
|
+
const hits = P.overlap({ cylinder: [1.5, radius] }, [x, 1.5, z], { mask: Layer.Prop | Layer.Debris });
|
|
191
|
+
for (const id of hits) P.applyKnockback(id, [x, 0, z], strength, { lift: strength * 0.35 });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private retire(i: number): void {
|
|
195
|
+
const c = this.chunks[i];
|
|
196
|
+
if (!c) return;
|
|
197
|
+
this.physics.removeBody(c.id);
|
|
198
|
+
this.chunks[i] = this.chunks[this.chunks.length - 1] as Chunk;
|
|
199
|
+
this.chunks.pop();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
update(dt: number): void {
|
|
203
|
+
this.impacts.length = 0;
|
|
204
|
+
this.acc = Math.min(this.acc + dt, MAX_STEPS / HZ);
|
|
205
|
+
while (this.acc >= 1 / HZ) {
|
|
206
|
+
this.acc -= 1 / HZ;
|
|
207
|
+
this.physics.step();
|
|
208
|
+
}
|
|
209
|
+
for (let i = this.chunks.length - 1; i >= 0; i--) {
|
|
210
|
+
const c = this.chunks[i] as Chunk;
|
|
211
|
+
c.life -= dt;
|
|
212
|
+
if (c.life <= 0) this.retire(i);
|
|
213
|
+
}
|
|
214
|
+
// Draw.
|
|
215
|
+
const P = this.physics;
|
|
216
|
+
let n = 0;
|
|
217
|
+
for (const c of this.chunks) {
|
|
218
|
+
const [x, y, z] = P.position(c.id);
|
|
219
|
+
const [qx, qy, qz, qw] = P.rotation(c.id);
|
|
220
|
+
const k = Math.min(1, c.life / (c.max * 0.35));
|
|
221
|
+
this.p.set(x, y, z);
|
|
222
|
+
this.q.set(qx, qy, qz, qw);
|
|
223
|
+
this.s.setScalar(c.size * 1.25 * k);
|
|
224
|
+
this.m.compose(this.p, this.q, this.s);
|
|
225
|
+
this.chunkMesh.setMatrixAt(n, this.m);
|
|
226
|
+
this.chunkMesh.setColorAt(n, c.color);
|
|
227
|
+
n++;
|
|
228
|
+
}
|
|
229
|
+
this.chunkMesh.count = n;
|
|
230
|
+
this.chunkMesh.instanceMatrix.needsUpdate = true;
|
|
231
|
+
if (this.chunkMesh.instanceColor) this.chunkMesh.instanceColor.needsUpdate = true;
|
|
232
|
+
let crates = 0;
|
|
233
|
+
let barrels = 0;
|
|
234
|
+
this.s.setScalar(1);
|
|
235
|
+
for (const prop of this.props) {
|
|
236
|
+
const [x, y, z] = P.position(prop.id);
|
|
237
|
+
const [vx, vy, vz] = P.velocity(prop.id);
|
|
238
|
+
const speed = Math.hypot(vx, vy, vz);
|
|
239
|
+
if (prop.speed - speed > 3) this.impacts.push({ x, y, z, speed: prop.speed - speed });
|
|
240
|
+
prop.speed = speed;
|
|
241
|
+
const [qx, qy, qz, qw] = P.rotation(prop.id);
|
|
242
|
+
this.p.set(x, y, z);
|
|
243
|
+
this.q.set(qx, qy, qz, qw);
|
|
244
|
+
this.m.compose(this.p, this.q, this.s);
|
|
245
|
+
if (prop.barrel) this.barrelMesh.setMatrixAt(barrels++, this.m);
|
|
246
|
+
else this.crateMesh.setMatrixAt(crates++, this.m);
|
|
247
|
+
}
|
|
248
|
+
this.crateMesh.count = crates;
|
|
249
|
+
this.barrelMesh.count = barrels;
|
|
250
|
+
this.crateMesh.instanceMatrix.needsUpdate = true;
|
|
251
|
+
this.barrelMesh.instanceMatrix.needsUpdate = true;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
get liveChunks(): number {
|
|
255
|
+
return this.chunks.length;
|
|
256
|
+
}
|
|
257
|
+
}
|
package/client/decor.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library models the EMBERWATCH scene draws on its own (template machinery,
|
|
3
|
+
* not game content): the forest past the wall.
|
|
4
|
+
* The build copies these with the models game.ts uses.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Enemy models are drawn about this many hit radii tall. */
|
|
8
|
+
export const ENEMY_HEIGHT_PER_RADIUS = 3.2;
|
|
9
|
+
/** Keepers are drawn this tall, m. */
|
|
10
|
+
export const KEEPER_HEIGHT = 1.8;
|
|
11
|
+
|
|
12
|
+
/** [library id, height m, how many] in a ring outside the wall. */
|
|
13
|
+
export const DECOR: readonly (readonly [string, number, number])[] = [
|
|
14
|
+
["style.lowpoly.tree_pine", 5.5, 26],
|
|
15
|
+
["style.lowpoly.tree_pine_tall", 7.5, 14],
|
|
16
|
+
["style.lowpoly.tree_dark", 5, 14],
|
|
17
|
+
["style.lowpoly.rock_large", 1.8, 12],
|
|
18
|
+
["style.lowpoly.stump", 0.7, 10],
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export const SCENE_MODELS: readonly string[] = DECOR.map(([id]) => id);
|
package/client/host.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Net Forge as host. Framed by Net Forge, the page URL carries
|
|
3
|
+
* the Kit flags and the host posts one message; played on its own, none of
|
|
4
|
+
* this applies and the game behaves exactly as before.
|
|
5
|
+
*
|
|
6
|
+
* ?host=netnet the host draws Invite and sign-in; the game hides its own
|
|
7
|
+
* ?coin=TICKER the coin the HUD names (2 to 6 capitals or digits)
|
|
8
|
+
* ?title=NAME the game's own name for the wordmark and the tab title
|
|
9
|
+
* ?player=guest no wallet is connected: play pays nothing, and the HUD
|
|
10
|
+
* says "not earning" instead of a balance
|
|
11
|
+
* ?player=play the token has not launched: coins are play money
|
|
12
|
+
*
|
|
13
|
+
* The player flag changes while the game runs (a wallet connects), so the
|
|
14
|
+
* host also posts { kind: "netnet-kit", type: "player", mode }. Only the
|
|
15
|
+
* parent window is listened to, and only when the URL says it is the host.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type PlayerMode = "earning" | "guest" | "play";
|
|
19
|
+
|
|
20
|
+
export interface HostFlags {
|
|
21
|
+
/** Framed by Net Forge. */
|
|
22
|
+
readonly framed: boolean;
|
|
23
|
+
/** The coin's ticker, when the host names one. */
|
|
24
|
+
readonly coin: string | null;
|
|
25
|
+
/** The game's own name, when the host names one. */
|
|
26
|
+
readonly title: string | null;
|
|
27
|
+
/** What play pays the person at the screen. Standalone play is "earning" (the game's own kit decides). */
|
|
28
|
+
readonly player: PlayerMode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const TICKER_RE = /^[A-Z0-9]{2,6}$/;
|
|
32
|
+
|
|
33
|
+
export function hostFlags(params: URLSearchParams): HostFlags {
|
|
34
|
+
const framed = params.get("host") === "netnet";
|
|
35
|
+
const coin = params.get("coin");
|
|
36
|
+
// eslint-disable-next-line no-control-regex
|
|
37
|
+
const title = (params.get("title") ?? "").replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim().slice(0, 40);
|
|
38
|
+
const player = params.get("player");
|
|
39
|
+
return {
|
|
40
|
+
framed,
|
|
41
|
+
coin: coin && TICKER_RE.test(coin) ? coin : null,
|
|
42
|
+
title: title || null,
|
|
43
|
+
player: framed && (player === "guest" || player === "play") ? player : "earning",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The player mode the host named on the URL, or null when it named none (a
|
|
49
|
+
* connected player on a live game gets no flag, only the posted message) or
|
|
50
|
+
* the page is not framed by Net Forge.
|
|
51
|
+
*/
|
|
52
|
+
export function namedPlayer(params: URLSearchParams): PlayerMode | null {
|
|
53
|
+
if (params.get("host") !== "netnet") return null;
|
|
54
|
+
const player = params.get("player");
|
|
55
|
+
return player === "earning" || player === "guest" || player === "play" ? player : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The store's note under its prices, from one source of truth. Once the host
|
|
60
|
+
* has named the player mode (on the URL or in a message), that mode decides,
|
|
61
|
+
* exactly as it does for the coin box: a live game never calls its coins play
|
|
62
|
+
* money. Standalone play, or a host that names no mode (the studio's drafts),
|
|
63
|
+
* keeps the room's own word (`welcome.earnLive`).
|
|
64
|
+
*/
|
|
65
|
+
export function storeNote(hostMode: PlayerMode | null, earnLive: boolean, symbol: string): string {
|
|
66
|
+
if (hostMode === "play") return "Play money until launch";
|
|
67
|
+
if (hostMode === "guest") return `Connect a wallet to earn ${symbol}`;
|
|
68
|
+
if (hostMode === "earning") return "";
|
|
69
|
+
return earnLive ? "" : "Play money until launch";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A host message, checked: anything else is ignored. */
|
|
73
|
+
export function playerFrom(data: unknown): PlayerMode | null {
|
|
74
|
+
if (typeof data !== "object" || data === null) return null;
|
|
75
|
+
const m = data as Record<string, unknown>;
|
|
76
|
+
if (m["kind"] !== "netnet-kit" || m["type"] !== "player") return null;
|
|
77
|
+
const mode = m["mode"];
|
|
78
|
+
return mode === "earning" || mode === "guest" || mode === "play" ? mode : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Calls `cb` with each player mode the host posts. Framed pages only. */
|
|
82
|
+
export function onHostPlayer(flags: HostFlags, cb: (mode: PlayerMode) => void): void {
|
|
83
|
+
if (!flags.framed || window.parent === window) return;
|
|
84
|
+
window.addEventListener("message", (e: MessageEvent<unknown>) => {
|
|
85
|
+
if (e.source !== window.parent) return;
|
|
86
|
+
const mode = playerFrom(e.data);
|
|
87
|
+
if (mode) cb(mode);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Tells the host the game is up, so it can post the current player mode. */
|
|
92
|
+
export function postReady(flags: HostFlags): void {
|
|
93
|
+
if (!flags.framed || window.parent === window) return;
|
|
94
|
+
// The host's origin is not known to an opaque-origin frame; the message is one public flag.
|
|
95
|
+
window.parent.postMessage({ kind: "netnet-kit", type: "ready" }, "*");
|
|
96
|
+
}
|