@unson/brainbase-mcp 0.50.12 → 0.50.14
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/judgment-frame-evidence.d.ts +63 -0
- package/dist/judgment-frame-evidence.js +161 -0
- package/package.json +6 -2
- package/ui/world/world-district.js +326 -66
- package/ui/world/world-placement.js +262 -45
- package/ui/world/world-view.css +341 -0
- package/ui/world/world-view.js +204 -21
- package/ui/world/world-work-rail.js +270 -0
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { THREE, MapControls } from './world-vendor.js';
|
|
23
|
-
import { DISTRICT_STREETS,
|
|
23
|
+
import { DISTRICT_STREETS, districtPulse, districtRingLots, districtRingPlan, districtStage, siteActors, skyAt } from './world-placement.js';
|
|
24
24
|
import { canvasTexture, drawFacade, FACADE_SIZES, FACADE_UNITS, gableRoof, hashUnit, paintVertices, roundedPlate, valueNoise } from './world-scenery.js';
|
|
25
25
|
import { makeWorkspaceElement as el } from '../../workspace-kit.js';
|
|
26
26
|
import { attentionSignText } from './world-exits.js';
|
|
@@ -46,14 +46,15 @@ export const DISTRICT_LEGEND = Object.freeze([
|
|
|
46
46
|
['is-stakes', '杭と縄の空き地=未着手(記録上)'],
|
|
47
47
|
['is-house', '明かりのついた家=完了して、出典・成果の記録がある(本設の建物)'],
|
|
48
48
|
['is-prefab', 'プレハブ=完了したが、出典・成果の記録が無い'],
|
|
49
|
-
['is-worker', '
|
|
49
|
+
['is-worker', 'ヘルメットの人=記録された担当(人)'],
|
|
50
|
+
['is-agent', '頭に明かりのついた丸い人形=AI担当。色はAIごとに決まる。明かりが緑でゆれるのは、進行中Taskと5分以内の稼働の知らせが一致したときだけ。黄色=待ち、灰色=知らせが途絶えた・未確認'],
|
|
50
51
|
['is-empty', '誰もいない現場=担当の記録なし'],
|
|
51
52
|
['is-outside', '柵の外の人(破線の輪)=本文にだけ名前がある'],
|
|
52
53
|
['is-nopath', '通りへの道が無い=出典リンクなし'],
|
|
53
54
|
['is-blueprint', '図面の看板だけ=成果物の記録が未接続'],
|
|
54
55
|
['is-weeds', '雑草と色あせ=見直し予定を過ぎた'],
|
|
55
56
|
['is-stone', '庁舎前の石碑=方針の決定(枠だけ=題名からの推定)'],
|
|
56
|
-
['is-street', '
|
|
57
|
+
['is-street', '通りの看板=何のための仕事か(タスクの記録の言葉。言葉が無い仕事は門の近くの空き地)。押すと、その仕事の集まりに寄って、どのAIがどの仕事にいるかを見られる'],
|
|
57
58
|
['is-stage', '区画の段階(更地・村・町・街・都市)=本設の建物の数。石畳・街灯・噴水・時計塔が増える'],
|
|
58
59
|
['is-ambience', '通りを歩く人と煙=街の雰囲気(記録とは関係しません)'],
|
|
59
60
|
]);
|
|
@@ -312,10 +313,10 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
312
313
|
});
|
|
313
314
|
dashTexture.wrapT = THREE.RepeatWrapping;
|
|
314
315
|
/** A street along z (or along x when `across`): sidewalks, asphalt, and a dashed centre line if wide. */
|
|
315
|
-
function streetStrip(parent, { x = 0, z = 0, width, length, across = false, centreLine = false, dirt = false }) {
|
|
316
|
+
function streetStrip(parent, { x = 0, z = 0, width, length, across = false, angle = across ? Math.PI / 2 : 0, centreLine = false, dirt = false }) {
|
|
316
317
|
const strip = (stripWidth, mat, y) => {
|
|
317
318
|
const surface = mesh(new THREE.PlaneGeometry(stripWidth, length), mat, { x, y, z, shadow: false });
|
|
318
|
-
surface.rotation.set(-Math.PI / 2, 0,
|
|
319
|
+
surface.rotation.set(-Math.PI / 2, 0, angle);
|
|
319
320
|
parent.add(surface);
|
|
320
321
|
};
|
|
321
322
|
// A dirt track on vacant land; sidewalks and asphalt once the district has grown.
|
|
@@ -332,6 +333,28 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
332
333
|
strip(0.1, new THREE.MeshBasicMaterial({ map: dashes, transparent: true, opacity: 0.85, color: 0xf6f3e6 }), 0.055);
|
|
333
334
|
}
|
|
334
335
|
}
|
|
336
|
+
/** A road round the hall: the same surfaces as a street, as a ring. */
|
|
337
|
+
function ringRoad(parent, { radius, width, dirt = false }) {
|
|
338
|
+
const ring = (ringWidth, mat, y) => {
|
|
339
|
+
const surface = mesh(new THREE.RingGeometry(radius - ringWidth / 2, radius + ringWidth / 2, 96), mat, { y, shadow: false });
|
|
340
|
+
surface.rotation.x = -Math.PI / 2;
|
|
341
|
+
parent.add(surface);
|
|
342
|
+
};
|
|
343
|
+
if (dirt) {
|
|
344
|
+
ring(width, material(0xb59d7a, { roughness: 1 }), 0.03);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
ring(width + 0.7, material(0xe4dfd2, { roughness: 1 }), 0.025);
|
|
348
|
+
ring(width, material(0x8e938f, { roughness: 0.95 }), 0.04);
|
|
349
|
+
}
|
|
350
|
+
/** A round plate with the same soft edge as `roundedPlate`. */
|
|
351
|
+
function roundPlate(radius, height) {
|
|
352
|
+
const shape = new THREE.Shape();
|
|
353
|
+
shape.absarc(0, 0, radius, 0, Math.PI * 2, false);
|
|
354
|
+
const geometry = new THREE.ExtrudeGeometry(shape, { depth: height, bevelEnabled: true, bevelThickness: 0.12, bevelSize: 0.12, bevelSegments: 2, curveSegments: 64 });
|
|
355
|
+
geometry.rotateX(-Math.PI / 2);
|
|
356
|
+
return geometry;
|
|
357
|
+
}
|
|
335
358
|
// A tarp, folded: vertical bands of light and shade on the blue sheet (the colour is the meaning).
|
|
336
359
|
const tarpTexture = canvasTexture(doc, 64, 64, (ctx, w, h) => {
|
|
337
360
|
ctx.fillStyle = '#ffffff';
|
|
@@ -349,6 +372,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
349
372
|
let root = null;
|
|
350
373
|
let fountainJet = null;
|
|
351
374
|
let lots = new Map();
|
|
375
|
+
let siteLabels = new Map();
|
|
352
376
|
// The tools of the business (from the host), and their stations once the district is built.
|
|
353
377
|
let exitsData = [];
|
|
354
378
|
let stations = new Map();
|
|
@@ -367,6 +391,12 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
367
391
|
let flight = null;
|
|
368
392
|
let home = null;
|
|
369
393
|
let focusIds = null;
|
|
394
|
+
/** The street the viewer has come close to (its key; '' is the unlabelled lots), or null. */
|
|
395
|
+
let streetView = null;
|
|
396
|
+
let streetBlocks = new Map();
|
|
397
|
+
let districtRect = null;
|
|
398
|
+
/** Pixels of the stage's left edge a host panel covers; views are framed clear of it. */
|
|
399
|
+
let insetLeft = 0;
|
|
370
400
|
// What changed since the viewer was last here (AC-22, AC-23): a gold ring, a rising building, words.
|
|
371
401
|
let celebrations = [];
|
|
372
402
|
const RISING = new Set(['new', 'built', 'evidenced', 'started']);
|
|
@@ -406,6 +436,32 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
406
436
|
return group;
|
|
407
437
|
}
|
|
408
438
|
|
|
439
|
+
/*
|
|
440
|
+
* An agent on a work: a small round figure in the agent's own soft colour with a light on its head.
|
|
441
|
+
* The light says how it is there (see PRESENCE_LIGHT); it is set from `siteActors` and follows the clock.
|
|
442
|
+
*/
|
|
443
|
+
const ACTOR_Z = DISTRICT_STREETS.lot / 2 + 0.3;
|
|
444
|
+
const PRESENCE_LIGHT = Object.freeze({ running: 0x58d6a0, waiting: 0xf0b648, quiet: 0x9aa3a6, unconfirmed: 0xc3ccd0, queued: 0xa9cdea, done: 0xd9d4c6 });
|
|
445
|
+
function buddy(tone) {
|
|
446
|
+
const group = new THREE.Group();
|
|
447
|
+
group.add(mesh(new THREE.CapsuleGeometry(0.23, 0.3, 4, 12), material(tone, { roughness: 0.7 }), { y: 0.42 }));
|
|
448
|
+
group.add(mesh(new THREE.SphereGeometry(0.21, 14, 12), material(0xfbf7ee, { roughness: 0.6 }), { y: 0.93 }));
|
|
449
|
+
const eye = material(0x3a4450, { roughness: 0.4 });
|
|
450
|
+
for (const x of [-0.075, 0.075]) group.add(mesh(new THREE.SphereGeometry(0.028, 8, 6), eye, { x, y: 0.95, z: 0.19, shadow: false }));
|
|
451
|
+
group.add(mesh(new THREE.CylinderGeometry(0.012, 0.012, 0.16, 5), material(0x6f7a80), { y: 1.2, shadow: false }));
|
|
452
|
+
const bulb = material(0xffffff, { emissive: new THREE.Color(PRESENCE_LIGHT.unconfirmed), emissiveIntensity: 0.8, roughness: 0.3 });
|
|
453
|
+
group.add(mesh(new THREE.SphereGeometry(0.075, 12, 10), bulb, { y: 1.31, shadow: false }));
|
|
454
|
+
group.userData.bulb = bulb;
|
|
455
|
+
group.scale.setScalar(1.45);
|
|
456
|
+
return group;
|
|
457
|
+
}
|
|
458
|
+
function lightBuddy(worker, presence) {
|
|
459
|
+
const bulb = worker.userData.bulb;
|
|
460
|
+
bulb.color.set(PRESENCE_LIGHT[presence] ?? PRESENCE_LIGHT.unconfirmed);
|
|
461
|
+
bulb.emissive.set(PRESENCE_LIGHT[presence] ?? PRESENCE_LIGHT.unconfirmed);
|
|
462
|
+
bulb.emissiveIntensity = presence === 'running' ? 1.6 : presence === 'waiting' ? 1.1 : 0.35;
|
|
463
|
+
}
|
|
464
|
+
|
|
409
465
|
// --- a lot, in local space: its front (the street) toward +z -------------------------------------
|
|
410
466
|
function lotGroup(site) {
|
|
411
467
|
const group = new THREE.Group();
|
|
@@ -528,11 +584,18 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
528
584
|
worker.position.set(0.55, 0.06, 0.55);
|
|
529
585
|
group.add(worker);
|
|
530
586
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
587
|
+
// Agents stand on the work they are on; a finished house keeps none (the panel lists who finished it).
|
|
588
|
+
(status === 'completed' ? [] : siteActors(site)).forEach((actor, index) => {
|
|
589
|
+
// In front of the lot, on the kerb: seen from afar, never behind the scaffold or its net.
|
|
590
|
+
const worker = buddy(actor.tone);
|
|
591
|
+
worker.position.set(0.25 + index * 0.85, 0.02, ACTOR_Z);
|
|
592
|
+
lightBuddy(worker, actor.presence);
|
|
534
593
|
group.add(worker);
|
|
535
|
-
|
|
594
|
+
// The agent's own colour on the ground under it, so it is found before its figure is read.
|
|
595
|
+
const spot = mesh(new THREE.CircleGeometry(0.5, 24), new THREE.MeshBasicMaterial({ color: actor.tone, transparent: true, opacity: 0.5, depthWrite: false }), { x: worker.position.x, y: 0.035, z: ACTOR_Z, shadow: false });
|
|
596
|
+
spot.rotation.x = -Math.PI / 2;
|
|
597
|
+
group.add(spot);
|
|
598
|
+
taskActors.push({ worker, site, id: actor.id, x: worker.position.x, presence: actor.presence, phase: hash(actor.id + site.task_id) });
|
|
536
599
|
});
|
|
537
600
|
if (named && status !== 'completed') {
|
|
538
601
|
const outside = person(0x6b5b95);
|
|
@@ -635,6 +698,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
635
698
|
for (const label of labels) label.node.remove();
|
|
636
699
|
labels = [];
|
|
637
700
|
lots = new Map();
|
|
701
|
+
siteLabels = new Map();
|
|
638
702
|
stations = new Map();
|
|
639
703
|
civic = [];
|
|
640
704
|
stationLayer = null;
|
|
@@ -691,13 +755,17 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
691
755
|
const readable = work?.status === 'ok' && (work.reads.tasks.state === 'complete' || work.reads.tasks.state === 'partial');
|
|
692
756
|
taskActors.length = 0;
|
|
693
757
|
const shown = readable ? work.sites.filter((site) => site.work.status !== 'cancelled') : [];
|
|
694
|
-
const layout =
|
|
695
|
-
const
|
|
758
|
+
const layout = districtRingLots(shown.map((site) => ({ task_id: site.task_id, created_at: site.work.created_at, purpose_label: site.purpose_label })));
|
|
759
|
+
const pulse = new Map(districtPulse(shown).streets.map((street) => [street.key, street]));
|
|
760
|
+
streetBlocks = new Map(layout.streets.map((street) => [street.key, street]));
|
|
761
|
+
if (streetView !== null && !streetBlocks.has(streetView)) setStreetView(null);
|
|
762
|
+
const R = layout.radius;
|
|
696
763
|
// The stage of the district (AC-24): counted from permanent buildings, it sets how built-up it looks.
|
|
697
764
|
const stage = districtStage(shown);
|
|
698
765
|
const grown = stage.level;
|
|
699
|
-
const plan =
|
|
700
|
-
const { gateZ, hallZ,
|
|
766
|
+
const plan = districtRingPlan(layout);
|
|
767
|
+
const { gateZ, hallZ, courtZ, plazaRadius } = plan;
|
|
768
|
+
const plazaZ = courtZ;
|
|
701
769
|
gateAt = gateZ;
|
|
702
770
|
// Land as in the world: gentle, non-repeating shades of grass (scenery).
|
|
703
771
|
const grass = { low: new THREE.Color(0x9fbf8c), high: new THREE.Color(0xd3e4bd), warm: new THREE.Color(0xd9d6a6) };
|
|
@@ -708,49 +776,83 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
708
776
|
land.rotation.x = -Math.PI / 2;
|
|
709
777
|
land.receiveShadow = true;
|
|
710
778
|
root.add(land);
|
|
711
|
-
// The district's paving: a raised plate with a kerb
|
|
712
|
-
const pavingDepth = gateZ - hallZ + 14;
|
|
713
|
-
root.add(mesh(roundedPlate(28, pavingDepth, 0.04, 2.2), material(0xd4cec0, { roughness: 1 }), { z: (gateZ + hallZ) / 2, shadow: false }));
|
|
779
|
+
// The district's paving: a round raised plate with a kerb round the hall, and a forecourt out to the gate.
|
|
714
780
|
const pavingColor = [0xd8cdb2, 0xe2dac6, 0xebe6d8, 0xefeadc, 0xf2eee2][grown];
|
|
715
|
-
|
|
781
|
+
const court = stationsEnabled && exitsData.length ? { x: 7.5, width: 31 } : { x: 0, width: 13 };
|
|
782
|
+
const courtDepth = gateZ + 14 - (R - 4);
|
|
783
|
+
root.add(mesh(roundPlate(R + 1.9, 0.04), material(0xd4cec0, { roughness: 1 }), { shadow: false }));
|
|
784
|
+
root.add(mesh(roundedPlate(court.width + 1, courtDepth + 1, 0.04, 2.2), material(0xd4cec0, { roughness: 1 }), { x: court.x, z: R - 4 + courtDepth / 2, shadow: false }));
|
|
785
|
+
root.add(mesh(roundPlate(R + 1.4, 0.06), material(pavingColor, { roughness: 1 }), { shadow: false }));
|
|
786
|
+
root.add(mesh(roundedPlate(court.width, courtDepth, 0.06, 1.8), material(pavingColor, { roughness: 1 }), { x: court.x, z: R - 4 + courtDepth / 2, shadow: false }));
|
|
716
787
|
const lift = new THREE.Group();
|
|
717
788
|
lift.position.y = 0.17;
|
|
718
789
|
root.add(lift);
|
|
719
|
-
|
|
790
|
+
const at = (angle, radius) => [Math.sin(angle) * radius, Math.cos(angle) * radius];
|
|
791
|
+
// The avenue runs from beyond the gate to the plaza's rim; it never runs under the plaza (that overlap flickered).
|
|
720
792
|
streetStrip(lift, { x: 0, z: (plan.street.from + plan.street.to) / 2, width: DISTRICT_STREETS.main * 2, length: plan.street.to - plan.street.from, centreLine: grown >= 2, dirt: grown === 0 });
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
// A
|
|
724
|
-
const
|
|
725
|
-
layout.streets.forEach((block
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
793
|
+
// Ring roads round the hall: the town grows outward one ring at a time.
|
|
794
|
+
layout.roads.forEach((radius, index) => ringRoad(lift, { radius, width: DISTRICT_STREETS.road, dirt: index === 0 ? grown === 0 : grown < 2 }));
|
|
795
|
+
// A lane between two gatherings, from the plaza's road to the outermost ring road.
|
|
796
|
+
const lanes = { from: layout.roads[0], to: Math.max(layout.roads[layout.roads.length - 1], layout.roads[0] + 3.6) };
|
|
797
|
+
layout.streets.slice(1).forEach((block) => {
|
|
798
|
+
const [x, z] = at(block.from, (lanes.from + lanes.to) / 2);
|
|
799
|
+
streetStrip(lift, { x, z, width: DISTRICT_STREETS.spoke, length: lanes.to - lanes.from, angle: block.from, dirt: grown < 2 });
|
|
800
|
+
});
|
|
801
|
+
// On the plaza's rim, in front of each gathering, a sign saying what its work is for.
|
|
802
|
+
layout.streets.forEach((block) => {
|
|
803
|
+
const signX = block.sign.x;
|
|
804
|
+
const signZ = block.sign.z;
|
|
805
|
+
root.add(mesh(new THREE.CylinderGeometry(0.06, 0.08, 2.5, 8), material(0x3f4844, { roughness: 0.6, metalness: 0.4 }), { x: signX, y: 1.25, z: signZ }));
|
|
806
|
+
const board = mesh(new THREE.BoxGeometry(1.1, 0.34, 0.05), material(block.label ? 0x2f6e4f : 0xbfb8a8, { roughness: 0.6 }), { x: signX, y: 2.2, z: signZ });
|
|
807
|
+
board.rotation.y = Math.atan2(signX, signZ);
|
|
808
|
+
root.add(board);
|
|
732
809
|
const text = block.label ? `${block.label}(${block.count}件)` : `未分類の空き地:何のための仕事か未記録(${block.count}件)`;
|
|
733
|
-
const sign = addLabel(
|
|
810
|
+
const sign = addLabel('', new THREE.Vector3(block.name.x, 3.6, block.name.z), `is-street${block.label ? '' : ' is-unlabelled'}`, { priority: 2 });
|
|
811
|
+
sign.node.append(el(doc, 'span', { className: 'bb-world-street-name', text }));
|
|
812
|
+
// How this gathering of work is going, in the record's words, and a dot for each agent on it.
|
|
813
|
+
const going = pulse.get(block.key);
|
|
814
|
+
if (going) {
|
|
815
|
+
for (const [key, word] of [['in_progress', '進行中'], ['waiting', '待ち']]) {
|
|
816
|
+
if (going.counts[key]) sign.node.append(el(doc, 'span', { className: `bb-world-street-chip is-${key}`, text: `${word} ${going.counts[key]}` }));
|
|
817
|
+
}
|
|
818
|
+
for (const actor of going.actors) {
|
|
819
|
+
const dot = el(doc, 'span', { className: `bb-world-street-actor is-${actor.presence}`, attrs: { title: `${actor.name}:${actor.label}` } });
|
|
820
|
+
dot.style.setProperty('--bb-world-actor-tone', actor.tone);
|
|
821
|
+
sign.node.append(dot);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
sign.streetSign = block.key;
|
|
734
825
|
// The count is a way down: pressing the sign lists the work of this street (AC-05).
|
|
735
|
-
if (onPickStreet) enterable(sign, `${block.label ?? '何のための仕事か未記録の空き地'}の仕事${block.count}
|
|
826
|
+
if (onPickStreet) enterable(sign, `${block.label ?? '何のための仕事か未記録の空き地'}の仕事${block.count}件と、そこにいるAIを見る`, () => onPickStreet({ key: block.key, label: block.label, count: block.count }), '寄って見る');
|
|
736
827
|
});
|
|
737
|
-
// Trees along the
|
|
828
|
+
// Trees and lamps along the avenue and round the plaza; a belt of trees round the district (scenery).
|
|
738
829
|
const trees = [];
|
|
739
830
|
const lamps = [];
|
|
740
|
-
for (let z =
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
for (const x of [-2.45, 2.45]) trees.push([x, at, 0.62]);
|
|
744
|
-
for (const x of [-2.45, 2.45]) lamps.push([x, at + DISTRICT_STREETS.row / 2]);
|
|
831
|
+
for (let z = plazaRadius + 2.6; z < gateZ - 1.5; z += 3.4) {
|
|
832
|
+
for (const x of [-2.45, 2.45]) trees.push([x, z, 0.62]);
|
|
833
|
+
for (const x of [-2.45, 2.45]) lamps.push([x, z + 1.7]);
|
|
745
834
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
const
|
|
749
|
-
const
|
|
750
|
-
|
|
835
|
+
const rimTrees = Math.max(10, Math.round((plazaRadius * Math.PI * 2) / 4.2));
|
|
836
|
+
for (let i = 0; i < rimTrees; i += 1) {
|
|
837
|
+
const angle = ((i + 0.5) / rimTrees) * Math.PI * 2;
|
|
838
|
+
const [x, z] = at(angle, plazaRadius - 0.75);
|
|
839
|
+
// Clear of the avenue's mouth, the hall's steps and the signs.
|
|
840
|
+
if (Math.abs(x) < 3.4 && z > 0) continue;
|
|
841
|
+
if (layout.streets.some((block) => Math.hypot(block.sign.x - x, block.sign.z - z) < 1.3)) continue;
|
|
842
|
+
(i % 2 ? lamps : trees).push(i % 2 ? [x, z] : [x, z, 0.55]);
|
|
843
|
+
}
|
|
844
|
+
// Places not built on yet, on the rings the town already reaches, are green: some have a tree.
|
|
845
|
+
for (const spot of layout.open) {
|
|
846
|
+
if (hashUnit(`open${spot.x},${spot.z}`) < 0.45) trees.push([spot.x + (hashUnit(`open${spot.x}x`) - 0.5) * 1.2, spot.z + (hashUnit(`open${spot.z}z`) - 0.5) * 1.2, 0.5 + hashUnit(`open${spot.x}s`) * 0.35]);
|
|
847
|
+
}
|
|
848
|
+
for (let i = 0; i < 110; i += 1) {
|
|
849
|
+
const angle = (i / 110) * Math.PI * 2 + hashUnit(`belt${i}a`) * 0.05;
|
|
850
|
+
const radius = R + 4.5 + hashUnit(`belt${i}r`) * 11;
|
|
851
|
+
trees.push([...at(angle, radius), 0.8 + hashUnit(`belt${i}s`) * 0.6]);
|
|
751
852
|
}
|
|
752
853
|
const inYard = (x, z) => stationsEnabled && x > STATION_YARD.xFrom && x < STATION_YARD.xTo && z > gateZ + STATION_YARD.zFrom && z < gateZ + STATION_YARD.zTo;
|
|
753
|
-
|
|
854
|
+
const inCourt = (x, z) => z > R - 4 && Math.abs(x - court.x) < court.width / 2 + 1.5;
|
|
855
|
+
plantTrees(root, trees.filter(([x, z]) => Math.abs(x) < 3 || (!inCourt(x, z) && !inYard(x, z))));
|
|
754
856
|
// Lamps come with the district's growth: none on vacant land, every other one in a village.
|
|
755
857
|
placeLamps(lift, grown === 0 ? [] : grown === 1 ? lamps.filter((_, i) => i % 4 === 0) : lamps);
|
|
756
858
|
// The gate: stone pillars on plinths, a lintel with a cornice, lamps on its pillars.
|
|
@@ -782,7 +884,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
782
884
|
const hallChimney = new THREE.Vector3(2.8, 5.2, hallZ - 1.2);
|
|
783
885
|
const purposeText = work?.status === 'ok' ? (work.purpose.text ?? '目的は未登録') : '目的を読めません';
|
|
784
886
|
const hallLabel = addLabel(`庁舎:${business.name}(${purposeText})`, new THREE.Vector3(0, 5.6, hallZ), 'is-plaza', { priority: 1 });
|
|
785
|
-
const plaza = mesh(new THREE.CircleGeometry(plazaRadius - 0.25,
|
|
887
|
+
const plaza = mesh(new THREE.CircleGeometry(plazaRadius - 0.25, 72), material(0xf1ece1, { roughness: 1 }), { y: 0.24, shadow: false });
|
|
786
888
|
plaza.rotation.x = -Math.PI / 2;
|
|
787
889
|
root.add(plaza);
|
|
788
890
|
if (onPickHall) {
|
|
@@ -792,7 +894,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
792
894
|
civic = [hall, plaza];
|
|
793
895
|
enterable(hallLabel, `${business.name}の目的と方針を見る`, () => onPickHall(), '目的と方針を見る');
|
|
794
896
|
}
|
|
795
|
-
const ring = mesh(new THREE.RingGeometry(plazaRadius - 0.25, plazaRadius,
|
|
897
|
+
const ring = mesh(new THREE.RingGeometry(plazaRadius - 0.25, plazaRadius, 72), material(0xcfc8b8, { roughness: 1 }), { y: 0.25, shadow: false });
|
|
796
898
|
ring.rotation.x = -Math.PI / 2;
|
|
797
899
|
root.add(ring);
|
|
798
900
|
if (grown >= 3) {
|
|
@@ -853,21 +955,38 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
853
955
|
const lot = layout.lots[site.task_id];
|
|
854
956
|
const group = lotGroup(site);
|
|
855
957
|
group.position.set(lot.x, 0.17, lot.z);
|
|
856
|
-
group.rotation.y = lot.
|
|
958
|
+
group.rotation.y = lot.yaw;
|
|
857
959
|
group.userData = { kind: 'site', site, chimney: group.userData.chimney ?? null };
|
|
858
960
|
root.add(group);
|
|
859
961
|
lots.set(site.task_id, group);
|
|
860
962
|
const title = site.title.length > 15 ? `${site.title.slice(0, 14)}…` : site.title;
|
|
861
|
-
const
|
|
862
|
-
|
|
963
|
+
const full = site.title.length > 26 ? `${site.title.slice(0, 25)}…` : site.title;
|
|
964
|
+
const siteLabel = addLabel('', new THREE.Vector3(lot.x, 2.6, lot.z), `is-site${site.gaps.length ? ' is-check' : ''}`, { owner: group, near: 15, priority: 6 });
|
|
965
|
+
siteLabel.node.append(el(doc, 'span', { className: 'bb-world-site-title is-short', text: title }), el(doc, 'span', { className: 'bb-world-site-title is-full', text: full }));
|
|
966
|
+
siteLabel.street = lot.street;
|
|
967
|
+
// Who is on it: named from afar, and with how each is there once the viewer has come close to the street.
|
|
968
|
+
const here = siteActors(site);
|
|
969
|
+
if (here.length) {
|
|
970
|
+
const who = el(doc, 'span', { className: 'bb-world-site-actors' });
|
|
971
|
+
for (const actor of here) {
|
|
972
|
+
const chip = el(doc, 'span', { className: `bb-world-site-actor is-${actor.presence}`, attrs: { 'data-actor': actor.id } });
|
|
973
|
+
chip.style.setProperty('--bb-world-actor-tone', actor.tone);
|
|
974
|
+
chip.append(el(doc, 'span', { className: 'bb-world-site-actor-name', text: actor.name }), el(doc, 'span', { className: 'bb-world-site-actor-state', text: actor.label }));
|
|
975
|
+
who.append(chip);
|
|
976
|
+
}
|
|
977
|
+
siteLabel.node.append(who);
|
|
978
|
+
}
|
|
979
|
+
siteLabels.set(site.task_id, siteLabel);
|
|
863
980
|
}
|
|
864
981
|
// Atmosphere: walkers on the sidewalks and back streets, smoke from chimneys (no record behind them).
|
|
865
|
-
const routes = [-1.55, 1.55, -DISTRICT_STREETS.backStreet + 0.6, DISTRICT_STREETS.backStreet - 0.6];
|
|
866
982
|
const palette = [0xc0504d, 0x4f81bd, 0x9bbb59, 0x8064a2, 0xf79646, 0x4bacc6, 0x7f7f7f, 0xd99694];
|
|
867
983
|
for (let i = 0; i < 10; i += 1) {
|
|
868
984
|
const walker = person(palette[i % palette.length]);
|
|
869
|
-
const
|
|
870
|
-
|
|
985
|
+
const speed = 0.6 + hash(`walk${i}s`) * 0.6;
|
|
986
|
+
const phase = hash(`walk${i}p`);
|
|
987
|
+
// Four walk the avenue's sidewalks; the others stroll round the ring roads.
|
|
988
|
+
if (i < 4) walker.userData = { x: i % 2 ? 1.55 : -1.55, from: plazaRadius + 1, to: gateZ + 5, speed, phase };
|
|
989
|
+
else walker.userData = { ring: layout.roads[i % layout.roads.length] + (i % 2 ? 1.05 : -1.05), turn: i % 3 ? 1 : -1, speed, phase };
|
|
871
990
|
root.add(walker);
|
|
872
991
|
walkers.push(walker);
|
|
873
992
|
}
|
|
@@ -889,26 +1008,84 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
889
1008
|
}
|
|
890
1009
|
// Fog when the work could not be read: the district cannot be seen, which is not empty.
|
|
891
1010
|
scene.fog.color.set(sky.fog);
|
|
892
|
-
|
|
893
|
-
|
|
1011
|
+
districtRect = { cx: 0, cz: (gateZ + 2 - R - 1) / 2, w: R * 2 + 3, d: gateZ + 2 + R + 1 };
|
|
1012
|
+
home = viewOf(districtRect, { yaw: 0.6, pitch: 0.8, height: 3.5, margin: 0.95 });
|
|
1013
|
+
// A wider town is seen from further away: the reach of the camera, the fog and the shadows follow it.
|
|
1014
|
+
const reach = home.position.distanceTo(home.target);
|
|
1015
|
+
controls.maxDistance = Math.max(95, reach * 1.6);
|
|
1016
|
+
scene.fog.near = readable ? Math.max(70, reach * 1.1) : 6;
|
|
1017
|
+
scene.fog.far = readable ? Math.max(170, reach * 2.4 + R) : 34;
|
|
1018
|
+
const shade = Math.max(48, R + 10);
|
|
1019
|
+
Object.assign(sun.shadow.camera, { left: -shade, right: shade, top: shade, bottom: -shade });
|
|
1020
|
+
sun.shadow.camera.updateProjectionMatrix();
|
|
894
1021
|
noticeVisible = !readable;
|
|
895
1022
|
notice.hidden = !showChrome || !open || !noticeVisible;
|
|
896
1023
|
if (!readable) {
|
|
897
1024
|
const reason = work?.status === 'ok' ? work.reads.tasks.reason ?? work.reads.tasks.state : work?.reason ?? work?.status ?? '理由不明';
|
|
898
1025
|
notice.textContent = `仕事の記録を読めないため、区画の中は霧で見えません(${reason})。仕事の件数は未確認です。0件とは確認できません。`;
|
|
899
1026
|
}
|
|
900
|
-
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/*
|
|
1030
|
+
* A view that holds a rectangle of the ground (and what stands on it) in the part of the stage a host
|
|
1031
|
+
* panel does not cover: the direction is given, the distance and the target are found by projecting the
|
|
1032
|
+
* rectangle's corners.
|
|
1033
|
+
*/
|
|
1034
|
+
function viewOf(rect, { yaw, pitch, height = 4.5, margin = 0.9 }) {
|
|
1035
|
+
const size = stage.getBoundingClientRect();
|
|
1036
|
+
const aspect = size.width && size.height ? size.width / size.height : camera.aspect || 1.6;
|
|
1037
|
+
const inset = size.width > 760 ? Math.min(insetLeft / size.width, 0.45) : 0;
|
|
1038
|
+
const probe = new THREE.PerspectiveCamera(camera.fov, aspect, camera.near, camera.far);
|
|
1039
|
+
const direction = new THREE.Vector3(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), Math.cos(yaw) * Math.cos(pitch));
|
|
1040
|
+
const corners = [];
|
|
1041
|
+
for (const x of [rect.cx - rect.w / 2, rect.cx + rect.w / 2]) for (const z of [rect.cz - rect.d / 2, rect.cz + rect.d / 2]) for (const y of [0, height]) corners.push(new THREE.Vector3(x, y, z));
|
|
1042
|
+
const target = new THREE.Vector3(rect.cx, 0, rect.cz);
|
|
1043
|
+
const bounds = (distance) => {
|
|
1044
|
+
probe.position.copy(target).addScaledVector(direction, distance);
|
|
1045
|
+
probe.lookAt(target);
|
|
1046
|
+
probe.updateMatrixWorld(true);
|
|
1047
|
+
let minX = Infinity; let maxX = -Infinity; let minY = Infinity; let maxY = -Infinity;
|
|
1048
|
+
for (const corner of corners) {
|
|
1049
|
+
const point = corner.clone().project(probe);
|
|
1050
|
+
minX = Math.min(minX, point.x); maxX = Math.max(maxX, point.x); minY = Math.min(minY, point.y); maxY = Math.max(maxY, point.y);
|
|
1051
|
+
}
|
|
1052
|
+
return { minX, maxX, minY, maxY };
|
|
1053
|
+
};
|
|
1054
|
+
const fits = (box) => (box.maxX - box.minX) / 2 <= margin * (1 - inset) && (box.maxY - box.minY) / 2 <= margin * 0.86;
|
|
1055
|
+
let distance = 60;
|
|
1056
|
+
for (let pass = 0; pass < 3; pass += 1) {
|
|
1057
|
+
let near = 6; let far = 420;
|
|
1058
|
+
for (let i = 0; i < 18; i += 1) {
|
|
1059
|
+
const middle = (near + far) / 2;
|
|
1060
|
+
if (fits(bounds(middle))) far = middle; else near = middle;
|
|
1061
|
+
}
|
|
1062
|
+
distance = far;
|
|
1063
|
+
// Slide the target along the ground so the rectangle sits in the middle of the uncovered part.
|
|
1064
|
+
const box = bounds(distance);
|
|
1065
|
+
const halfHeight = Math.tan((camera.fov * Math.PI) / 360) * distance;
|
|
1066
|
+
const right = new THREE.Vector3(Math.cos(yaw), 0, -Math.sin(yaw));
|
|
1067
|
+
const ahead = new THREE.Vector3(-Math.sin(yaw), 0, -Math.cos(yaw));
|
|
1068
|
+
target.addScaledVector(right, ((box.minX + box.maxX) / 2 - inset) * halfHeight * aspect);
|
|
1069
|
+
target.addScaledVector(ahead, (((box.minY + box.maxY) / 2 + 0.06) * halfHeight) / Math.max(Math.sin(pitch), 0.3));
|
|
1070
|
+
}
|
|
1071
|
+
return { target, position: target.clone().addScaledVector(direction, distance) };
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
function setStreetView(key) {
|
|
1075
|
+
streetView = key;
|
|
1076
|
+
labelsLayer.classList.toggle('is-street-mode', key !== null);
|
|
1077
|
+
for (const label of labels) label.size = null;
|
|
901
1078
|
}
|
|
902
1079
|
|
|
903
1080
|
// --- camera, picking, frame loop ------------------------------------------------------------------
|
|
904
|
-
function fly(target, position, duration = 900) {
|
|
1081
|
+
function fly(target, position, duration = 900, { level = false } = {}) {
|
|
905
1082
|
if (reducedMotion) {
|
|
906
1083
|
controls.target.copy(target);
|
|
907
1084
|
camera.position.copy(position);
|
|
908
1085
|
return;
|
|
909
1086
|
}
|
|
910
1087
|
controls.enabled = false;
|
|
911
|
-
flight = { from: { target: controls.target.clone(), position: camera.position.clone() }, to: { target, position }, started: null, duration };
|
|
1088
|
+
flight = { from: { target: controls.target.clone(), position: camera.position.clone() }, to: { target, position }, started: null, duration, level };
|
|
912
1089
|
}
|
|
913
1090
|
|
|
914
1091
|
function resize() {
|
|
@@ -1021,12 +1198,21 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1021
1198
|
const projected = new THREE.Vector3();
|
|
1022
1199
|
function placeLabels() {
|
|
1023
1200
|
const rect = stage.getBoundingClientRect();
|
|
1024
|
-
|
|
1201
|
+
// The host's own controls over the stage (the toolbar, the notices): a name never sits under them.
|
|
1202
|
+
const placed = [...(stage.ownerDocument?.querySelectorAll?.('.bb-world-canvas-toolbar, .bb-world-canvas-quests, .bb-world-pulse') ?? [])]
|
|
1203
|
+
.map((node) => node.getBoundingClientRect())
|
|
1204
|
+
.filter((r) => r.width > 0 && r.height > 0)
|
|
1205
|
+
.map((r) => ({ x: r.left - rect.left, y: r.top - rect.top, w: r.width, h: r.height }));
|
|
1025
1206
|
const visible = [];
|
|
1026
1207
|
for (const label of labels) {
|
|
1027
1208
|
const owner = label.owner;
|
|
1028
1209
|
const taskId = owner?.userData?.site?.task_id;
|
|
1029
1210
|
const emphasised = owner && (owner === selected || owner === hovered || (focusIds && focusIds.has(taskId)));
|
|
1211
|
+
// Close to a street, the signs of the other streets step back so this one's work can be read.
|
|
1212
|
+
if (streetView !== null && label.streetSign !== undefined && label.streetSign !== streetView) {
|
|
1213
|
+
label.node.hidden = true;
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1030
1216
|
const hiddenByFocus = owner && focusIds && !focusIds.has(taskId);
|
|
1031
1217
|
const distance = camera.position.distanceTo(label.position);
|
|
1032
1218
|
projected.copy(label.position).project(camera);
|
|
@@ -1036,26 +1222,50 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1036
1222
|
continue;
|
|
1037
1223
|
}
|
|
1038
1224
|
label.screen = { x: ((projected.x + 1) / 2) * rect.width, y: ((1 - projected.y) / 2) * rect.height };
|
|
1039
|
-
|
|
1225
|
+
// The selected or hovered name is always shown; the names of a focused gathering come first but give way to each other.
|
|
1226
|
+
label.rank = owner && (owner === selected || owner === hovered) ? 0 : emphasised ? 0.5 : label.priority;
|
|
1040
1227
|
visible.push(label);
|
|
1041
1228
|
}
|
|
1042
1229
|
visible.sort((a, b) => a.rank - b.rank);
|
|
1043
1230
|
for (const label of visible) {
|
|
1044
1231
|
label.node.hidden = false;
|
|
1045
1232
|
label.size ??= { w: label.node.offsetWidth, h: label.node.offsetHeight };
|
|
1046
|
-
|
|
1233
|
+
// A name whose anchor is near an edge slides inward instead of being cut off by it.
|
|
1234
|
+
const left = Math.min(Math.max(label.screen.x - label.size.w / 2, 6), Math.max(rect.width - label.size.w - 6, 6));
|
|
1235
|
+
const box2 = { x: left, y: Math.max(label.screen.y - label.size.h, 6), w: label.size.w, h: label.size.h };
|
|
1047
1236
|
if (label.rank > 0 && placed.some((other) => box2.x < other.x + other.w + 2 && box2.x + box2.w + 2 > other.x && box2.y < other.y + other.h + 2 && box2.y + box2.h + 2 > other.y)) {
|
|
1048
1237
|
label.node.hidden = true;
|
|
1049
1238
|
continue;
|
|
1050
1239
|
}
|
|
1051
1240
|
placed.push(box2);
|
|
1052
1241
|
label.node.style.transform = `translate(${Math.round(box2.x)}px, ${Math.round(box2.y)}px)`;
|
|
1053
|
-
label.node.classList.toggle('is-selected', label.rank
|
|
1242
|
+
label.node.classList.toggle('is-selected', label.rank <= 0.5);
|
|
1054
1243
|
}
|
|
1055
1244
|
}
|
|
1056
1245
|
|
|
1057
1246
|
let running = true;
|
|
1058
1247
|
let lastSkyMinute = -1;
|
|
1248
|
+
let lastPresenceCheck = 0;
|
|
1249
|
+
/** A heartbeat grows old while the district is open: the figures and their words follow the clock. */
|
|
1250
|
+
function refreshPresence(now) {
|
|
1251
|
+
for (const actor of taskActors) {
|
|
1252
|
+
const current = siteActors(actor.site, now).find((entry) => entry.id === actor.id);
|
|
1253
|
+
const presence = current?.presence ?? 'unconfirmed';
|
|
1254
|
+
if (presence === actor.presence) continue;
|
|
1255
|
+
actor.presence = presence;
|
|
1256
|
+
lightBuddy(actor.worker, presence);
|
|
1257
|
+
actor.worker.position.set(actor.x, 0.02, ACTOR_Z);
|
|
1258
|
+
actor.worker.rotation.y = 0;
|
|
1259
|
+
const label = siteLabels.get(actor.site.task_id);
|
|
1260
|
+
const chip = [...(label?.node.querySelectorAll('.bb-world-site-actor') ?? [])].find((node) => node.getAttribute('data-actor') === actor.id);
|
|
1261
|
+
if (chip && current) {
|
|
1262
|
+
chip.className = `bb-world-site-actor is-${presence}`;
|
|
1263
|
+
const state = chip.querySelector('.bb-world-site-actor-state');
|
|
1264
|
+
if (state) state.textContent = current.label;
|
|
1265
|
+
label.size = null;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1059
1269
|
function frame(time) {
|
|
1060
1270
|
if (!running) return;
|
|
1061
1271
|
requestAnimationFrame(frame);
|
|
@@ -1067,6 +1277,10 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1067
1277
|
if (skyAt(now.getHours(), 'auto').phase !== sky.phase) applySky();
|
|
1068
1278
|
lastSkyMinute = minute;
|
|
1069
1279
|
}
|
|
1280
|
+
if (time - lastPresenceCheck > 5000) {
|
|
1281
|
+
lastPresenceCheck = time;
|
|
1282
|
+
refreshPresence(now.getTime());
|
|
1283
|
+
}
|
|
1070
1284
|
if (flight) {
|
|
1071
1285
|
flight.started ??= time;
|
|
1072
1286
|
const t = Math.min((time - flight.started) / flight.duration, 1);
|
|
@@ -1084,12 +1298,25 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1084
1298
|
if (!reducedMotion) {
|
|
1085
1299
|
const seconds = time / 1000;
|
|
1086
1300
|
for (const actor of taskActors) {
|
|
1087
|
-
|
|
1088
|
-
if (
|
|
1089
|
-
|
|
1090
|
-
|
|
1301
|
+
// Only an agent whose work is in progress with a fresh heartbeat moves; a waiting one's light breathes.
|
|
1302
|
+
if (actor.presence === 'running') {
|
|
1303
|
+
actor.worker.position.set(actor.x + Math.sin(seconds * 1.4 + actor.phase * 6) * 0.14, 0.02 + Math.abs(Math.sin(seconds * 3 + actor.phase * 6)) * 0.07, ACTOR_Z);
|
|
1304
|
+
actor.worker.rotation.y = Math.sin(seconds * 1.4 + actor.phase * 6) * 0.4;
|
|
1305
|
+
actor.worker.userData.bulb.emissiveIntensity = 1.3 + 0.5 * Math.sin(seconds * 4 + actor.phase * 6);
|
|
1306
|
+
} else if (actor.presence === 'waiting') {
|
|
1307
|
+
actor.worker.userData.bulb.emissiveIntensity = 0.8 + 0.4 * Math.sin(seconds * 1.2 + actor.phase * 6);
|
|
1308
|
+
}
|
|
1091
1309
|
}
|
|
1092
1310
|
for (const walker of walkers) {
|
|
1311
|
+
// Close to a street the question is who is on which work: the passers-by (no record) step out.
|
|
1312
|
+
walker.visible = streetView === null;
|
|
1313
|
+
if (walker.userData.ring) {
|
|
1314
|
+
const { ring, turn, speed, phase } = walker.userData;
|
|
1315
|
+
const angle = turn * ((seconds * speed) / ring + phase * Math.PI * 2);
|
|
1316
|
+
walker.position.set(Math.sin(angle) * ring, 0.2 + Math.abs(Math.sin(seconds * 8 * speed)) * 0.04, Math.cos(angle) * ring);
|
|
1317
|
+
walker.rotation.y = angle + (turn > 0 ? Math.PI / 2 : -Math.PI / 2);
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1093
1320
|
const { x, from, to, speed, phase } = walker.userData;
|
|
1094
1321
|
const span = to - from;
|
|
1095
1322
|
const travel = ((seconds * speed) / span + phase) % 2;
|
|
@@ -1145,7 +1372,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1145
1372
|
setVisible(true);
|
|
1146
1373
|
resize();
|
|
1147
1374
|
// Entering: from high over the gate down to the street.
|
|
1148
|
-
camera.position.
|
|
1375
|
+
camera.position.copy(home.target).addScaledVector(home.position.clone().sub(home.target), 1.45);
|
|
1149
1376
|
controls.target.copy(home.target);
|
|
1150
1377
|
camera.lookAt(home.target);
|
|
1151
1378
|
fly(home.target.clone(), home.position.clone(), 1300);
|
|
@@ -1154,6 +1381,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1154
1381
|
renderer.domElement.focus({ preventScroll: true });
|
|
1155
1382
|
},
|
|
1156
1383
|
hide() {
|
|
1384
|
+
setStreetView(null);
|
|
1157
1385
|
setVisible(false);
|
|
1158
1386
|
},
|
|
1159
1387
|
/** The sky: the same modes as the world ('auto' follows the hour). */
|
|
@@ -1165,6 +1393,7 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1165
1393
|
/** Back to the view from the gate, keeping the district. */
|
|
1166
1394
|
home() {
|
|
1167
1395
|
select(null);
|
|
1396
|
+
setStreetView(null);
|
|
1168
1397
|
if (home) fly(home.target.clone(), home.position.clone());
|
|
1169
1398
|
},
|
|
1170
1399
|
select(taskId) {
|
|
@@ -1180,12 +1409,43 @@ export function createDistrictView({ doc, stage, reducedMotion = false, focusSel
|
|
|
1180
1409
|
focusIds = taskIds ? new Set(taskIds) : null;
|
|
1181
1410
|
applyFocus();
|
|
1182
1411
|
},
|
|
1412
|
+
/** Comes close to one street (its key; '' is the unlabelled lots); false when the district has no such street. */
|
|
1413
|
+
enterStreet(key) {
|
|
1414
|
+
const block = streetBlocks.get(key);
|
|
1415
|
+
if (!block) return false;
|
|
1416
|
+
select(null, { focus: false });
|
|
1417
|
+
setStreetView(key);
|
|
1418
|
+
// The gathering's lots, seen from the same side as the whole district.
|
|
1419
|
+
const minX = block.box.minX - 2.6;
|
|
1420
|
+
const maxX = block.box.maxX + 2.6;
|
|
1421
|
+
const minZ = block.box.minZ - 2.6;
|
|
1422
|
+
const maxZ = block.box.maxZ + 2.6;
|
|
1423
|
+
const view = viewOf({ cx: (minX + maxX) / 2, cz: (minZ + maxZ) / 2, w: Math.max(maxX - minX, 12), d: Math.max(maxZ - minZ, 9) }, { yaw: 0.5, pitch: 0.85, height: 3, margin: 0.82 });
|
|
1424
|
+
fly(view.target, view.position, 900, { level: true });
|
|
1425
|
+
if (reducedMotion) camera.lookAt(controls.target);
|
|
1426
|
+
return true;
|
|
1427
|
+
},
|
|
1428
|
+
/** Steps back from the street to the whole district. */
|
|
1429
|
+
leaveStreet() {
|
|
1430
|
+
if (streetView === null) return;
|
|
1431
|
+
setStreetView(null);
|
|
1432
|
+
if (home) fly(home.target.clone(), home.position.clone(), 900, { level: true });
|
|
1433
|
+
if (reducedMotion) camera.lookAt(controls.target);
|
|
1434
|
+
},
|
|
1435
|
+
street: () => streetView,
|
|
1436
|
+
/** How many pixels of the stage's left edge a host panel covers (views are framed clear of it). */
|
|
1437
|
+
setViewInset({ left = 0 } = {}) {
|
|
1438
|
+
insetLeft = Number.isFinite(left) && left > 0 ? left : 0;
|
|
1439
|
+
},
|
|
1183
1440
|
/** Shows what changed since the viewer's last visit (from `districtChanges`). */
|
|
1184
1441
|
celebrate,
|
|
1185
1442
|
/** Rebuilds the open district from fresh records, keeping the camera where it is. */
|
|
1186
1443
|
refresh(business, work, { neighbours = new Map(), exits } = {}) {
|
|
1187
1444
|
if (exits !== undefined) exitsData = exits;
|
|
1188
|
-
|
|
1445
|
+
// A level the camera is still flying to (into or out of a street) is where the viewer asked to be: the
|
|
1446
|
+
// rebuild lands there. Any other flight stops where it is.
|
|
1447
|
+
const landing = flight?.level ? flight.to : null;
|
|
1448
|
+
const keep = { target: (landing?.target ?? controls.target).clone(), position: (landing?.position ?? camera.position).clone(), taskId: selected?.userData?.site?.task_id };
|
|
1189
1449
|
flight = null;
|
|
1190
1450
|
controls.enabled = true;
|
|
1191
1451
|
build(business, work, neighbours);
|