@adatechnology/game-urban 0.3.13 → 0.4.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/README.md +87 -1
- package/dist/index.d.ts +28 -995
- package/dist/index.global.js +359 -151
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +86 -18
- package/dist/index.js.map +1 -1
- package/dist/networks/index.d.ts +488 -0
- package/dist/networks/index.js +1882 -0
- package/dist/networks/index.js.map +1 -0
- package/dist/types-CYeqw_58.d.ts +1027 -0
- package/package.json +11 -7
package/dist/index.js
CHANGED
|
@@ -10,6 +10,34 @@ function createLightAllowance(count) {
|
|
|
10
10
|
}
|
|
11
11
|
var createLightBudget = createLightAllowance;
|
|
12
12
|
|
|
13
|
+
// src/lamps.ts
|
|
14
|
+
var UINT32 = 2 ** 32;
|
|
15
|
+
var PHASE_SALT = 1597463007;
|
|
16
|
+
var SEED_BITS = new DataView(new ArrayBuffer(8));
|
|
17
|
+
var hashLamp = (seed, x, z) => {
|
|
18
|
+
SEED_BITS.setFloat64(0, seed);
|
|
19
|
+
let h = 2166136261;
|
|
20
|
+
for (const value of [SEED_BITS.getUint32(0), SEED_BITS.getUint32(4), Math.round(x * 100), Math.round(z * 100)]) {
|
|
21
|
+
h ^= value & 65535;
|
|
22
|
+
h = Math.imul(h, 16777619);
|
|
23
|
+
h ^= value >>> 16 & 65535;
|
|
24
|
+
h = Math.imul(h, 16777619);
|
|
25
|
+
}
|
|
26
|
+
return (h >>> 0) / UINT32;
|
|
27
|
+
};
|
|
28
|
+
var flickerPhaseOf = (x, z) => hashLamp(PHASE_SALT, x, z) * 2 * Math.PI;
|
|
29
|
+
function assertLampShares(shares) {
|
|
30
|
+
const { lit, flicker } = shares;
|
|
31
|
+
if (!(lit >= 0 && lit <= 1)) throw new RangeError(`lamp shares: lit must be in [0, 1], got ${lit}`);
|
|
32
|
+
if (!(flicker >= 0 && flicker <= lit)) throw new RangeError(`lamp shares: flicker must be in [0, lit], got ${flicker}`);
|
|
33
|
+
}
|
|
34
|
+
function lampStateOf({ seed, x, z, shares }) {
|
|
35
|
+
assertLampShares(shares);
|
|
36
|
+
const roll = hashLamp(seed, x, z);
|
|
37
|
+
if (roll >= shares.lit) return { on: false, flicker: false };
|
|
38
|
+
return { on: true, flicker: roll >= shares.lit - shares.flicker };
|
|
39
|
+
}
|
|
40
|
+
|
|
13
41
|
// src/scene.ts
|
|
14
42
|
import { boxRadius } from "@adatechnology/game-floorplan";
|
|
15
43
|
var ROOT = -1;
|
|
@@ -28,6 +56,7 @@ function createUrbanBuilder(random, options = {}) {
|
|
|
28
56
|
const box = (x, y, z, width, height, depth, color, o = {}) => {
|
|
29
57
|
const part = { shape: "box", parent: o.parent ?? ROOT, x, y: y + height / 2, z, width, height, depth, color, emissive: o.emissive ?? false, ry: o.ry ?? 0, rz: o.rz ?? 0, radius: boxRadius(width, height, depth) };
|
|
30
58
|
if (o.style) part.style = o.style;
|
|
59
|
+
if (o.flickerPhase !== void 0) part.flickerPhase = o.flickerPhase;
|
|
31
60
|
parts.push(part);
|
|
32
61
|
};
|
|
33
62
|
const cylinder = (x, y, z, radiusTop, radiusBottom, height, color, parent = ROOT, segments = DEFAULT_CYLINDER_SEGMENTS, style) => {
|
|
@@ -92,52 +121,87 @@ function createUrbanBuilder(random, options = {}) {
|
|
|
92
121
|
return { random, pick, lights, parts, items, windows, group, box, cylinder, cone, prism, plane, vault, terrain, crown, line, label, light, spot, place, item, fence, add, scene };
|
|
93
122
|
}
|
|
94
123
|
|
|
124
|
+
// src/networks/slots.ts
|
|
125
|
+
var DEFAULT_POLE_SLOTS = {
|
|
126
|
+
height: 11,
|
|
127
|
+
embedment: 1.7,
|
|
128
|
+
bands: { mv: [9, 9.25], transformer: [7.7, 8.7], lv: [7.1, 7.4], lighting: [6.5, 6.8], telecom: [5.7, 6.1] }
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/pole-distribution.ts
|
|
132
|
+
var DISTRIBUTION = {
|
|
133
|
+
mast: { radiusTop: 0.12, radiusBottom: 0.22, height: 9.3, color: 9079428, segments: 4 },
|
|
134
|
+
arm: { reach: 1, y: 6.7, width: 2, height: 0.1, depth: 0.1, color: 6974054 },
|
|
135
|
+
lamp: { reach: 2, y: 6.55, width: 0.5, height: 0.16, depth: 0.3 },
|
|
136
|
+
lens: { lit: 16752704, unlit: 3815994 },
|
|
137
|
+
light: { color: 16751168, intensity: 1.3, distance: 20, y: 6.4 },
|
|
138
|
+
transformer: { offset: 0.45, y: 7.7, radius: 0.32, height: 1, color: 5922402, segments: 8 },
|
|
139
|
+
slots: DEFAULT_POLE_SLOTS
|
|
140
|
+
};
|
|
141
|
+
|
|
95
142
|
// src/poles.ts
|
|
96
143
|
var on = (o) => o.on ?? true;
|
|
144
|
+
var lensOf = (o, parent) => ({
|
|
145
|
+
emissive: on(o),
|
|
146
|
+
...parent === void 0 ? {} : { parent },
|
|
147
|
+
...on(o) && o.flicker ? { flickerPhase: flickerPhaseOf(o.x, o.z) } : {}
|
|
148
|
+
});
|
|
149
|
+
var along = (o, reach) => ({ x: o.x + reach * Math.cos(o.ry ?? 0), z: o.z - reach * Math.sin(o.ry ?? 0) });
|
|
97
150
|
function drawMast(b, mast, x, z, parent = -1) {
|
|
98
151
|
b.cylinder(x, 0, z, mast.radiusTop, mast.radiusBottom, mast.height, mast.color, parent, mast.segments, mast.style);
|
|
99
152
|
}
|
|
100
153
|
function spendLight(b, light, x, z, o) {
|
|
101
|
-
|
|
154
|
+
const ry = o.ry ?? 0;
|
|
155
|
+
const [reach, side] = [light.reach ?? 0, light.z ?? 0];
|
|
156
|
+
if (on(o) && b.lights.take()) b.light({ x: x + reach * Math.cos(ry) + side * Math.sin(ry), y: light.y, z: z - reach * Math.sin(ry) + side * Math.cos(ry), color: light.color, intensity: light.intensity, distance: light.distance, flicker: o.flicker ?? false, ...o.flicker ? { flickerPhase: flickerPhaseOf(o.x, o.z) } : {} });
|
|
102
157
|
}
|
|
103
158
|
var doubleArm = (b, spec, o) => {
|
|
104
159
|
const group = b.group(o.x, 0, o.z, o.ry ?? 0);
|
|
105
160
|
drawMast(b, spec.mast, 0, 0, group);
|
|
106
161
|
for (const side of [-1, 1]) {
|
|
107
162
|
b.box(side * spec.arm.reach, spec.arm.y, 0, spec.arm.width, spec.arm.height, spec.arm.depth, spec.arm.color, { parent: group });
|
|
108
|
-
b.box(side * spec.lamp.reach, spec.lamp.y, 0, spec.lamp.width, spec.lamp.height, spec.lamp.depth, on(o) ? spec.lens.lit : spec.lens.unlit,
|
|
163
|
+
b.box(side * spec.lamp.reach, spec.lamp.y, 0, spec.lamp.width, spec.lamp.height, spec.lamp.depth, on(o) ? spec.lens.lit : spec.lens.unlit, lensOf(o, group));
|
|
109
164
|
}
|
|
110
|
-
spendLight(b, spec.light, o.x, o.z, o);
|
|
165
|
+
spendLight(b, spec.light, o.x, o.z, { ...o, ry: 0 });
|
|
111
166
|
};
|
|
112
167
|
var singleArm = (b, spec, o) => {
|
|
113
168
|
const dir = o.dir ?? 1;
|
|
169
|
+
const ry = o.ry ?? 0;
|
|
170
|
+
const arm = along(o, dir * spec.arm.reach);
|
|
171
|
+
const lamp = along(o, dir * spec.lamp.reach);
|
|
172
|
+
const drum = along(o, -dir * spec.transformer.offset);
|
|
114
173
|
drawMast(b, spec.mast, o.x, o.z);
|
|
115
|
-
b.box(
|
|
116
|
-
b.box(
|
|
117
|
-
if (o.transformer) b.cylinder(
|
|
174
|
+
b.box(arm.x, spec.arm.y, arm.z, spec.arm.width, spec.arm.height, spec.arm.depth, spec.arm.color, { ry });
|
|
175
|
+
b.box(lamp.x, spec.lamp.y, lamp.z, spec.lamp.width, spec.lamp.height, spec.lamp.depth, on(o) ? spec.lens.lit : spec.lens.unlit, { ...lensOf(o), ry });
|
|
176
|
+
if (o.transformer) b.cylinder(drum.x, spec.transformer.y, drum.z, spec.transformer.radius, spec.transformer.radius, spec.transformer.height, spec.transformer.color, -1, spec.transformer.segments);
|
|
118
177
|
spendLight(b, { ...spec.light, reach: dir * (spec.light.reach ?? spec.lamp.reach) }, o.x, o.z, o);
|
|
119
178
|
};
|
|
120
179
|
var lantern = (b, spec, o) => {
|
|
180
|
+
const lamp = along(o, spec.lamp.reach);
|
|
121
181
|
drawMast(b, spec.mast, o.x, o.z);
|
|
122
|
-
b.box(
|
|
182
|
+
b.box(lamp.x, spec.lamp.y, lamp.z, spec.lamp.width, spec.lamp.height, spec.lamp.depth, on(o) ? spec.lens.lit : spec.lens.unlit, { ...lensOf(o), ry: o.ry ?? 0 });
|
|
123
183
|
b.cone(o.x, spec.cap.y, o.z, spec.cap.radius, spec.cap.height, spec.cap.color, -1, spec.cap.segments);
|
|
124
184
|
spendLight(b, spec.light, o.x, o.z, o);
|
|
125
185
|
};
|
|
126
186
|
var crossarm = (b, spec, o) => {
|
|
187
|
+
const ry = o.ry ?? 0;
|
|
188
|
+
const arm = along(o, spec.arm.reach);
|
|
189
|
+
const lamp = along(o, spec.lamp.reach);
|
|
127
190
|
drawMast(b, spec.mast, o.x, o.z);
|
|
128
|
-
b.box(
|
|
129
|
-
b.box(
|
|
191
|
+
b.box(arm.x, spec.arm.y, arm.z, spec.arm.width, spec.arm.height, spec.arm.depth, spec.arm.color, { ry });
|
|
192
|
+
b.box(lamp.x, spec.lamp.y, lamp.z, spec.lamp.width, spec.lamp.height, spec.lamp.depth, on(o) ? spec.lens.lit : spec.lens.unlit, { ...lensOf(o), ry });
|
|
130
193
|
spendLight(b, { ...spec.light, reach: spec.light.reach ?? spec.lamp.reach }, o.x, o.z, o);
|
|
131
194
|
};
|
|
132
195
|
var floodTower = (b, spec, o) => {
|
|
133
196
|
for (const a of [-1, 1]) for (const c of [-1, 1]) b.box(o.x + a * spec.legs.offset, 0, o.z + c * spec.legs.offset, spec.legs.size, spec.legs.height, spec.legs.size, spec.legs.color);
|
|
134
197
|
b.box(o.x + spec.deck.reach, spec.deck.y, o.z, spec.deck.width, spec.deck.height, spec.deck.depth, spec.deck.color);
|
|
135
198
|
for (let index = 0; index < spec.heads.count; index++) {
|
|
136
|
-
b.box(o.x + spec.heads.start + index * spec.heads.spacing, spec.heads.y, o.z + spec.heads.z, spec.heads.width, spec.heads.height, spec.heads.depth, on(o) ? spec.lens.lit : spec.lens.unlit,
|
|
199
|
+
b.box(o.x + spec.heads.start + index * spec.heads.spacing, spec.heads.y, o.z + spec.heads.z, spec.heads.width, spec.heads.height, spec.heads.depth, on(o) ? spec.lens.lit : spec.lens.unlit, lensOf(o));
|
|
137
200
|
}
|
|
138
201
|
spendLight(b, spec.light, o.x, o.z, o);
|
|
139
202
|
};
|
|
140
|
-
var
|
|
203
|
+
var distribution = (b, spec, o) => singleArm(b, spec, o);
|
|
204
|
+
var POLE_SHAPES = { double_arm: doubleArm, single_arm: singleArm, lantern, crossarm, flood_tower: floodTower, distribution };
|
|
141
205
|
var LED = {
|
|
142
206
|
mast: { radiusTop: 0.1, radiusBottom: 0.14, height: 9, color: 5593438, style: { metalness: 0.6, roughness: 0.5 } },
|
|
143
207
|
arm: { reach: 0.8, y: 8.8, width: 1.6, height: 0.1, depth: 0.12, color: 5593438 },
|
|
@@ -179,7 +243,8 @@ var DEFAULT_POLES = [
|
|
|
179
243
|
{ id: "concrete_arm", shape: "single_arm", spec: CONCRETE },
|
|
180
244
|
{ id: "cast_iron", shape: "lantern", spec: IRON },
|
|
181
245
|
{ id: "wood_crossarm", shape: "crossarm", spec: WOOD },
|
|
182
|
-
{ id: "flood_tower", shape: "flood_tower", spec: FLOOD }
|
|
246
|
+
{ id: "flood_tower", shape: "flood_tower", spec: FLOOD },
|
|
247
|
+
{ id: "concrete_distribution", shape: "distribution", spec: DISTRIBUTION }
|
|
183
248
|
];
|
|
184
249
|
|
|
185
250
|
// src/streets.ts
|
|
@@ -190,9 +255,9 @@ var DEFAULT_GROUND_COLOR = 1382426;
|
|
|
190
255
|
var DEFAULT_GROUND_SIZE = 600;
|
|
191
256
|
var roadStyle = (o) => ({ ...DEFAULT_ROAD_STYLE, ...o?.road, dash: { ...DEFAULT_ROAD_STYLE.dash, ...o?.road?.dash } });
|
|
192
257
|
var walkStyle = (o) => ({ ...DEFAULT_WALK_STYLE, ...o?.walk });
|
|
193
|
-
function drawRoad(b, x, z, w, l,
|
|
258
|
+
function drawRoad(b, x, z, w, l, along2, options) {
|
|
194
259
|
const style = roadStyle(options);
|
|
195
|
-
const alongX =
|
|
260
|
+
const alongX = along2 === "x";
|
|
196
261
|
b.plane(x, ROAD_LEVEL, z, alongX ? l : w, alongX ? w : l, style.color);
|
|
197
262
|
const { dash } = style;
|
|
198
263
|
for (let u = -l / 2 + dash.first; u < l / 2; u += dash.every) {
|
|
@@ -406,12 +471,12 @@ function drawWatchtower(b, x, z, searchlight = false, c) {
|
|
|
406
471
|
for (const side of [-1.5, 1.5]) b.box(x + side, 8.2, z, 0.15, 1.6, 0.15, palette.deck);
|
|
407
472
|
if (searchlight) b.spot({ x, y: 9, z, color: 15134463, intensity: 2.4, distance: 70, decay: 1.2, angle: 0.35, penumbra: 0.5, target: { x: x + 20, y: 0, z: z + 20 }, sweep: { speed: 0.5, radius: 25 } });
|
|
408
473
|
}
|
|
409
|
-
function drawSandbags(b, x, z, length,
|
|
474
|
+
function drawSandbags(b, x, z, length, along2, rows = 3, c) {
|
|
410
475
|
const color = colors(c).sandbags;
|
|
411
476
|
for (let r = 0; r < rows; r++) {
|
|
412
477
|
for (let i = 0; i < length / SANDBAG_LENGTH; i++) {
|
|
413
478
|
const u = -length / 2 + 0.28 + i * SANDBAG_LENGTH + r % 2 * 0.28;
|
|
414
|
-
b.item(
|
|
479
|
+
b.item(along2 === "x" ? x + u : x, r * 0.21, along2 === "x" ? z : z + u, along2 === "x" ? 0.55 : 0.32, 0.22, along2 === "x" ? 0.32 : 0.55, color);
|
|
415
480
|
}
|
|
416
481
|
}
|
|
417
482
|
}
|
|
@@ -1424,7 +1489,7 @@ function createUrban(options = {}) {
|
|
|
1424
1489
|
const core = {
|
|
1425
1490
|
poles,
|
|
1426
1491
|
streets: {
|
|
1427
|
-
road: (b, x, z, w, l,
|
|
1492
|
+
road: (b, x, z, w, l, along2) => drawRoad(b, x, z, w, l, along2, options.streets),
|
|
1428
1493
|
walk: (b, x, z, w, d) => drawWalk(b, x, z, w, d, options.streets),
|
|
1429
1494
|
ground: drawGround,
|
|
1430
1495
|
grid: (b, g) => drawStreetGrid(b, g.block, g.count, g.width, options.streets)
|
|
@@ -1441,7 +1506,7 @@ function createUrban(options = {}) {
|
|
|
1441
1506
|
tree: (b, x, z, scale) => drawTree(b, x, z, scale, propColors),
|
|
1442
1507
|
container: drawContainer,
|
|
1443
1508
|
watchtower: (b, x, z, searchlight) => drawWatchtower(b, x, z, searchlight, propColors),
|
|
1444
|
-
sandbags: (b, x, z, length,
|
|
1509
|
+
sandbags: (b, x, z, length, along2, rows) => drawSandbags(b, x, z, length, along2, rows, propColors),
|
|
1445
1510
|
label: (b, x, z, title, subtitle) => drawStripLabel(b, x, z, title, subtitle, propColors),
|
|
1446
1511
|
wires: (b, points, y, color) => drawWires(b, points, y, color, propColors)
|
|
1447
1512
|
}
|
|
@@ -1575,6 +1640,7 @@ export {
|
|
|
1575
1640
|
TOWER_DEFAULTS,
|
|
1576
1641
|
TOWER_PATTERNS,
|
|
1577
1642
|
TOWER_SAMPLE_CELLS,
|
|
1643
|
+
assertLampShares,
|
|
1578
1644
|
clamp,
|
|
1579
1645
|
composePattern,
|
|
1580
1646
|
createCities,
|
|
@@ -1605,9 +1671,11 @@ export {
|
|
|
1605
1671
|
drawWatchtower,
|
|
1606
1672
|
drawWires,
|
|
1607
1673
|
fillBlock,
|
|
1674
|
+
flickerPhaseOf,
|
|
1608
1675
|
hash2,
|
|
1609
1676
|
insideEllipse,
|
|
1610
1677
|
insideRect,
|
|
1678
|
+
lampStateOf,
|
|
1611
1679
|
lerp2 as lerp,
|
|
1612
1680
|
patternMarker,
|
|
1613
1681
|
pickTowerPreset,
|