{ const modURL = (id) => URL.createObjectURL(new Blob([document.getElementById(id).textContent], { type: 'text/javascript' })); const THREE = await import(modURL('three-src')); const E = await import(modURL('engine-src')); const $ = (s) => document.querySelector(s); // ---- 仕組みの項目 ---- const GROUPS = [ { k: 'dir', scene: true, label: 'バスの来る向き', opts: [['wl', '西から来て左折'], ['er', '東から来て右折(対向車線を横切る)'], ['nl', '脇道から出て左折'], ['nr', '脇道から出て右折(対向車線を横切る)']] }, { k: 'mode', label: '運行の形', opts: [['l2', 'レベル2・運転士(バスが走り、運転士が見張る。止まったあとの発進は運転士)'], ['l4in', 'レベル4・車内に主任者(バスが判断して走る。車内の主任者が見て、危ないときに止める)'], ['l4r1', 'レベル4・遠隔監視1台(車内は無人。遠隔監視者1人が1台を映像で見る)'], ['l4r3', 'レベル4・遠隔監視3台(車内は無人。遠隔監視者1人が3台を映像で見る)']] }, { k: 'sensor', label: 'センサー', opts: [['normal', 'ふつう'], ['wide', '死角の少ないもの']] }, { k: 'speed', label: '交差点での速さ', opts: [[6, '6 km/時'], [10, '10 km/時'], [15, '15 km/時']] }, { k: 'guide', label: '交差点に誘導員', opts: [[true, '置く'], [false, '置かない']] }, { k: 'route', label: '交差点の植え込み', opts: [['short', 'そのまま(見通しが悪い)'], ['long', '低く刈ってもらう(道の管理者に頼む)']] }, { k: 'rest', label: (c) => `${WATCHER(c)}の休憩`, opts: [[true, 'こまめに入れる(見落としが減る・費用が上がる)'], [false, 'なしで回す(費用が下がる・見落としが増える)']] }, { k: 'maint', label: '点検・保守', opts: [['often', 'こまめに(走る前に不具合を見つけやすい・費用が上がる)'], ['min', '最低限(費用が下がる・不具合が残りやすい)']] }, { k: 'update', label: 'ソフト更新の確かめ方', opts: [['test', '試走してから入れる(費用が上がる)'], ['direct', 'そのまま入れる(費用が下がる)']] }, { k: 'commLoss', label: '通信が切れたときのバス(遠隔のとき)', opts: [['stop', 'その場で止まる(メーカーの作り)'], ['go', '走り続ける(メーカーの作り)']] } ]; const NOUN = { dir: 'バスの向きを', mode: '運行の形を', sensor: 'センサーを', speed: '交差点の速さを', guide: '誘導員を', route: '植え込みを', rest: '休憩を', maint: '点検を', update: '更新の確かめ方を', commLoss: '通信が切れたときの作りを' }; // 仕組みを変えたことを、文で言う(「〜したら、事故は減った」) const changePhrase = (k, v) => ({ dir: `バスの来る向きを「${label('dir', v)}」にした`, mode: `運行の形を「${label('mode', v)}」にした`, sensor: `センサーを${v === 'wide' ? '死角の少ないもの' : 'ふつうのもの'}にした`, speed: `交差点の速さを時速${v}kmにした`, guide: v ? '誘導員を置いた' : '誘導員をなくした', route: v === 'long' ? '植え込みを低く刈ってもらった' : '植え込みをそのままにした', rest: v ? '休憩をこまめに入れた' : '休憩なしで回した', maint: v === 'often' ? '点検をこまめにした' : '点検を最低限にした', update: v === 'test' ? '更新を試走してから入れた' : '更新をそのまま入れた', commLoss: v === 'stop' ? '通信が切れたら止まる作りにした' : '通信が切れても走り続ける作りにした' })[k]; // 選択肢の言葉は「本文(注釈)」の形。ボタンには本文だけ、注釈はボタンの下に小さく出す // 設定のまとめ:見出しを上、選んだものを下に。2列に並べる。通信が切れたときの作りは、遠隔のときだけ出す const SHORT = { route: '植え込み', guide: '誘導員', speed: '交差点の速さ', commLoss: '通信が切れたとき', update: 'ソフト更新', dir: 'バスの向き' }; function cfgSummary(c, other) { return G().filter((g) => g.k !== 'commLoss' || c.mode === 'l4r1' || c.mode === 'l4r3').map((g) => `
${SHORT[g.k] || glabel(g)}${label(g.k, c[g.k])}
`).join(''); } const glabel = (g) => (typeof g.label === 'function' ? g.label(cfg) : g.label); // 見出しが、ほかの選択で変わるもの(休憩の対象など) const splitOpt = (t) => { const m = t.match(/^(.*?)((.*))$/); return m ? [m[1], m[2]] : [t, '']; }; const label = (k, v) => splitOpt(GROUPS.find((g) => g.k === k).opts.find((o) => o[0] === v)[1])[0]; let cfg = { ...E.DEFAULTS, dir: E.SCENES[0].route }; const G = () => GROUPS.filter((g) => !g.scene || playKind === 'scene'); // バスの向きは場面のときだけ選ぶ(1年回すときは毎回ばらばら) let locked = false; // 場面によっては、前提として決まっている設定がある(例:誘導員の合図の場面は、誘導員がいることが前提) const sceneReq = () => (playKind === 'scene' ? (E.SCENES.find((x) => x.id === sceneId) || {}).requires || {} : {}); // この場面で選べるバスの向き(場面のもとの向き+ずらし方を決めてある向き) const sceneDirs = () => { const sc = E.SCENES.find((x) => x.id === sceneId); return sc ? [sc.route, ...Object.keys(E.SCENE_DIRS[sc.id] || {})] : []; }; function drawPanel() { const req = sceneReq(); Object.assign(cfg, req); $('#groups').innerHTML = G().map((g) => { const fixed = g.k in req; return `
${glabel(g)}
${g.opts.map((o, i) => ``).join('')}
${fixed ? '

この場面の前提なので、変えられません

' : g.k === 'dir' && sceneDirs().length < 4 ? '

この場面の人は、脇道から出るバスとは交わりません

' : (() => { const n = splitOpt(g.opts.find((o) => o[0] === cfg[g.k])[1])[1]; return n ? `

${n}

` : ''; })()}
`; }).join(''); $('#panel').classList.toggle('locked', locked); $('#sCost').textContent = E.cost(cfg); } $('#groups').addEventListener('click', (e) => { const b = e.target.closest('button[data-k]'); if (!b || locked) return; const g = GROUPS.find((x) => x.k === b.dataset.k); cfg[g.k] = g.opts[+b.dataset.i][0]; drawPanel(); scene.setCfg({ ...cfg }); }); // ---- 3D ---- const scene = (() => { const host = $('#stage'); const r = new THREE.WebGLRenderer({ antialias: true }); r.setPixelRatio(Math.min(devicePixelRatio, 2)); r.shadowMap.enabled = true; r.shadowMap.type = THREE.PCFSoftShadowMap; host.prepend(r.domElement); const s = new THREE.Scene(); s.background = new THREE.Color('#eceef1'); const cam = new THREE.PerspectiveCamera(34, 1, 0.8, 400); const target = new THREE.Vector3(-1, 0, -4); const home = { az: Math.atan2(21, 32), el: Math.atan2(30, Math.hypot(21, 32)), dist: Math.hypot(21, 30, 32) }; let az = home.az, el = home.el, dist = home.dist, mode = 'orbit'; function placeCam() { if (mode === 'follow') return; cam.position.set(target.x + dist * Math.cos(el) * Math.sin(az), target.y + dist * Math.sin(el), target.z + dist * Math.cos(el) * Math.cos(az)); cam.lookAt(target); } placeCam(); s.add(new THREE.HemisphereLight('#ffffff', '#b9b4a8', 1.6)); const d = new THREE.DirectionalLight('#ffffff', 1.5); d.position.set(-20, 40, 25); d.castShadow = true; d.shadow.mapSize.set(2048, 2048); Object.assign(d.shadow.camera, { left: -40, right: 40, top: 40, bottom: -40, near: 1, far: 120 }); s.add(d); const M = (c) => new THREE.MeshLambertMaterial({ color: c }); const box = (w, h, dp, c, x, y, z, cast = false) => { const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, dp), M(c)); m.position.set(x, y + h / 2, z); m.castShadow = cast; m.receiveShadow = true; s.add(m); return m; }; box(260, 0.1, 260, '#e3e0d8', 0, -0.1, 0); box(200, 0.15, 14, '#efe7d4', 0, 0, 0); box(12, 0.15, 90, '#efe7d4', 0, 0, -51); box(200, 0.16, 7, '#7a7f87', 0, 0, 0); box(6, 0.16, 90, '#7a7f87', 0, 0, -48.5); for (let x = -96; x < 96; x += 4) if (Math.abs(x) > 5) box(2, 0.17, 0.15, '#f2f2f2', x, 0, 0); for (let x = -2.7; x <= 2.8; x += 0.9) box(0.45, 0.18, 2.8, '#ffffff', x, 0, -5.0); box(16, 2.6, 9, '#9aa0a8', -15, 0, -13, true); box(13, 2.2, 10, '#a3a8af', 15, 0, -14, true); box(16, 1.2, 6, '#b3b7bd', -15, 0, 12, true); box(16, 1.2, 6, '#b3b7bd', 15, 0, 12, true); const hedge = new THREE.Group(); for (const h of E.HEDGES) { const m = new THREE.Mesh(new THREE.BoxGeometry(h[1] - h[0], 1.3, h[3] - h[2]), M('#6f9a5a')); m.position.set((h[0] + h[1]) / 2, 0.8, (h[2] + h[3]) / 2); m.castShadow = true; hedge.add(m); } s.add(hedge); // バス const bus = new THREE.Group(); const add = (g, w, h, dp, c, x, y, z) => { const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, dp), M(c)); m.position.set(x, y, z); m.castShadow = true; g.add(m); return m; }; { // バスの形(アーチ屋根)。真横から見た輪郭を幅方向に押し出す。前後は同じ形で、端のガラスは屋根の上まで続く const Lb = 5.2, Wb = 2.2, yb = 0.06, yt = 2.62, Rt = 1.35, Rb = 0.18, bv = 0.14, white = '#f6f6f4', glass = '#1d242c'; const prof = (L2, y0, y1, rt, rbm) => { const x = L2 / 2, sh = new THREE.Shape(); sh.moveTo(-x + rbm, y0); sh.lineTo(x - rbm, y0); sh.quadraticCurveTo(x, y0, x, y0 + rbm); sh.lineTo(x, y1 - rt); sh.absarc(x - rt, y1 - rt, rt, 0, Math.PI / 2, false); sh.lineTo(-x + rt, y1); sh.absarc(-x + rt, y1 - rt, rt, Math.PI / 2, Math.PI, false); sh.lineTo(-x, y0 + rbm); sh.quadraticCurveTo(-x, y0, -x + rbm, y0); return sh; }; const ext = (sh, depth, bev, mat, seg = 24) => { const g = new THREE.ExtrudeGeometry(sh, { depth, curveSegments: seg, bevelEnabled: bev > 0, bevelSize: bev, bevelThickness: bev, bevelSegments: 5 }); g.translate(0, 0, -depth / 2); const m = new THREE.Mesh(g, mat); m.castShadow = true; bus.add(m); return m; }; ext(prof(Lb - 2 * bv, yb + bv, yt - bv, Rt - bv, Rb), Wb - 2 * bv, bv, M(white)); // 端のガラス:輪郭の端の部分だけを、車体の外へ少し出して作る。幅は車体より狭く、左右の面へは回り込まない const glassMat = new THREE.MeshPhongMaterial({ color: glass, specular: '#9aa6b2', shininess: 70 }); const xe = Lb / 2 + 0.008, cy = yt - Rt, rr2 = Rt + 0.008, xg = 1.45, yw = 0.62, cx = Lb / 2 - Rt; for (const sg of [1, -1]) { // 縦の面は細かく区切って点を置く(角を丸めるときに、輪郭がなめらかになるように) const sh = new THREE.Shape(); sh.moveTo(xg, yw); sh.lineTo(xe, yw); for (let i = 1; i <= 24; i++) sh.lineTo(xe, yw + (cy - yw) * i / 24); const aEnd = Math.acos((xg - cx) / rr2); sh.absarc(cx, cy, rr2, 0, aEnd, false); sh.lineTo(xg, yw); const gwid = Wb - 2 * bv - 0.02, m = ext(sh, gwid, 0, glassMat, 40); if (sg < 0) m.scale.x = -1; // 端から見たガラスの四隅を丸める:ガラスの面に沿った長さ u で、両端に近い点ほど幅を狭める const uMax = (cy - yw) + rr2 * aEnd, hw = gwid / 2, rc = 0.32, pos = m.geometry.attributes.position; for (let i = 0; i < pos.count; i++) { const x = pos.getX(i), y = pos.getY(i), z = pos.getZ(i); const u = y <= cy + 1e-6 ? y - yw : (cy - yw) + rr2 * Math.atan2(y - cy, x - cx); const dEnd = Math.max(0, Math.min(u, uMax - u)); if (dEnd >= rc) continue; const lim = hw - rc + Math.sqrt(Math.max(0, rc * rc - (rc - dEnd) ** 2)); if (Math.abs(z) > lim) pos.setZ(i, Math.sign(z) * lim); } pos.needsUpdate = true; add(bus, 0.02, 0.05, Wb * 0.62, '#e9f4ff', sg * (xe + 0.002), yw - 0.12, 0); for (const z of [0.5, -0.5]) add(bus, 0.02, 0.07, 0.22, sg > 0 ? '#ffffff' : '#d9534f', sg * (xe + 0.002), 0.34, z); } // 側面:外側の上の角を大きく丸めた窓、真ん中の2枚引き戸、足元のネイビーの帯 // 側面に貼る部品は、層ごとに外へ少しずつ離す(同じ面に重ねるとチラつくため)。layer 0=窓とドア枠、1=ドアの板 const flat = (sh, c, x, y, z, mx = 1, layer = 0) => { const g = new THREE.ExtrudeGeometry(sh, { depth: 0.02, bevelEnabled: false, curveSegments: 8 }); g.translate(0, 0, -0.01); const mat = M(c); mat.polygonOffset = true; mat.polygonOffsetFactor = -1 - layer * 2; mat.polygonOffsetUnits = -4 - layer * 4; const m = new THREE.Mesh(g, mat); m.position.set(x, y, z + Math.sign(z) * (0.012 + layer * 0.03)); m.scale.x = mx; bus.add(m); return m; }; const rect = (w, h, q) => { const sh = new THREE.Shape(); sh.moveTo(-w / 2 + q, -h / 2); sh.lineTo(w / 2 - q, -h / 2); sh.quadraticCurveTo(w / 2, -h / 2, w / 2, -h / 2 + q); sh.lineTo(w / 2, h / 2 - q); sh.quadraticCurveTo(w / 2, h / 2, w / 2 - q, h / 2); sh.lineTo(-w / 2 + q, h / 2); sh.quadraticCurveTo(-w / 2, h / 2, -w / 2, h / 2 - q); sh.lineTo(-w / 2, -h / 2 + q); sh.quadraticCurveTo(-w / 2, -h / 2, -w / 2 + q, -h / 2); return sh; }; const win = (() => { const w = 0.98, h = 1.5, q = 0.12, qo = 0.55, sh = new THREE.Shape(); sh.moveTo(0, 0); sh.lineTo(w - q, 0); sh.quadraticCurveTo(w, 0, w, q); sh.lineTo(w, h - qo); sh.quadraticCurveTo(w, h, w - qo, h); sh.lineTo(q, h); sh.quadraticCurveTo(0, h, 0, h - q); sh.lineTo(0, q); sh.quadraticCurveTo(0, 0, q, 0); return sh; })(); for (const z of [1, -1]) { const zz = z * (Wb / 2 + 0.004); flat(win, glass, 0.74, 0.82, zz); flat(win, glass, -0.74, 0.82, zz, -1); flat(rect(1.36, 2.1, 0.08), '#dfe2e6', 0, 1.29, zz); for (const x of [-0.335, 0.335]) flat(rect(0.62, 2.0, 0.05), '#1f252d', x, 1.3, zz, 1, 1); add(bus, Lb - 0.9, 0.16, 0.03, '#1f3a5f', 0, 0.2, z * (Wb / 2 + 0.02)); } for (const [x, z] of [[1.85, 1.0], [1.85, -1.0], [-1.85, 1.0], [-1.85, -1.0]]) { const w = new THREE.Mesh(new THREE.CylinderGeometry(0.32, 0.32, 0.28, 20), M('#262626')); w.rotation.x = Math.PI / 2; w.position.set(x, 0.32, z); bus.add(w); const hub = new THREE.Mesh(new THREE.CylinderGeometry(0.18, 0.18, 0.3, 16), M('#cfd2d6')); hub.rotation.x = Math.PI / 2; hub.position.set(x, 0.32, z); bus.add(hub); } // 屋根の LiDAR は真ん中に1つ、小さく add(bus, 0.12, 0.05, 0.12, '#8d939b', 0, yt + 0.02, 0); const ld = new THREE.Mesh(new THREE.CylinderGeometry(0.055, 0.06, 0.08, 16), M('#2b2f36')); ld.position.set(0, yt + 0.08, 0); bus.add(ld); } const blinkOn = new THREE.MeshBasicMaterial({ color: '#ffb020' }), blinkOff = new THREE.MeshLambertMaterial({ color: '#b08a40' }); // ウインカー:前後の端の角(低い位置)と、側面の前後。左右どちらにも付け、曲がる側だけ光らせる const blinkers = [-1, 1].flatMap((side) => [[2.611, 0.5, side * 0.8, 0.02, 0.1, 0.16], [-2.611, 0.5, side * 0.8, 0.02, 0.1, 0.16], [2.25, 0.62, side * 1.106, 0.22, 0.08, 0.012], [-2.25, 0.62, side * 1.106, 0.22, 0.08, 0.012]].map(([x, y, z, w, h, d]) => { const m = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), blinkOff); m.position.set(x, y, z); m.userData.left = side < 0; bus.add(m); return m; })); s.add(bus); const person = (c) => { const g = new THREE.Group(); const b = new THREE.Mesh(new THREE.CylinderGeometry(0.26, 0.28, 1.22, 14), M(c)); b.position.y = 0.61; b.castShadow = true; g.add(b); const h = new THREE.Mesh(new THREE.SphereGeometry(0.2, 14, 10), M(c)); h.position.y = 1.46; h.castShadow = true; g.add(h); return g; }; let vc = cfg; // 描いている回の設定(自動再生では回ごとに変わる) const setRoute = (rt) => { hedge.scale.y = rt === 'short' ? 1 : 0.35; hedge.position.y = rt === 'short' ? 0 : -0.25; }; const guide = person('#1f5fd6'); guide.position.set(-4.6, 0.15, -6.7); s.add(guide); const arm = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.12, 0.9), M('#1f5fd6')); arm.position.set(-4.6, 1.35, -6.2); s.add(arm); const pool = []; const ring = (c) => { const g = new THREE.Group(); const mat = new THREE.MeshBasicMaterial({ color: c }); const m = new THREE.Mesh(new THREE.TorusGeometry(1.4, 0.08, 8, 48), mat); m.rotation.x = -Math.PI / 2; g.add(m); const pin = new THREE.Mesh(new THREE.CylinderGeometry(0.06, 0.06, 2.2, 8), mat); pin.position.y = 2.6; g.add(pin); const head = new THREE.Mesh(new THREE.SphereGeometry(0.32, 16, 12), mat); head.position.y = 3.8; g.add(head); g.visible = false; s.add(g); return g; }; const red = ring('#d93a3a'), black = ring('#111111'); let cur = host; function resize() { const w = cur.clientWidth, h = cur.clientHeight; if (!w || !h) return; r.setSize(w, h, false); cam.aspect = w / h; cam.updateProjectionMatrix(); } const ro = new ResizeObserver(resize); ro.observe(host); resize(); function setFrame(f, opts = {}) { const jump = Math.hypot(bus.position.x - f.bus.x, bus.position.z - f.bus.z) > 6; bus.position.set(f.bus.x, 0.16, f.bus.z); bus.rotation.y = f.bus.h; if (jump && mode === 'follow') snapFollow = true; // 左折の合図:交差点の手前から曲がり終わるまで点滅 // 曲がる合図:曲がる側(左折なら左、右折なら右)だけを、交差点の手前から曲がり終わるまで点滅 const lit = !!f.bus.blink && (performance.now() % 700) < 380; blinkers.forEach((m) => { m.material = lit && (f.bus.blink === 'L') === m.userData.left ? blinkOn : blinkOff; }); // 人は id ごとに色と背の高さを少しずつ変える(誘導員の青は使わない)。通り過ぎるだけの人は淡い色 while (pool.length < f.peds.length) { const p = person('#e8b923'); s.add(p); pool.push(p); } pool.forEach((p, i) => { const q = f.peds[i]; p.visible = !!q; if (!q) return; p.position.set(q.x, 0.15, q.z); const c = q.type === 'ambient' ? '#c4c1ba' : '#e8b923'; // 渡る人は黄色、通り過ぎるだけの人は淡い灰色、誘導員は青 if (p.userData.c !== c) { p.userData.c = c; p.children.forEach((m) => m.material.color.set(c)); } const sc = 0.9 + ((q.id * 37) % 5) * 0.05; p.scale.set(1, sc, 1); }); arm.visible = !!f.guide && vc.guide; guide.visible = vc.guide; red.visible = !!opts.red; if (opts.red) red.position.set(opts.red.x, 0.3, opts.red.z); black.visible = !!opts.black; if (opts.black) black.position.set(opts.black.x, 0.3, opts.black.z); } function screenOf(x, z) { const v = new THREE.Vector3(x, 1.5, z).project(cam); return { x: (v.x + 1) / 2 * host.clientWidth, y: (1 - v.y) / 2 * host.clientHeight }; } let lastT = performance.now(), followH = 0, snapFollow = true; const lookAt = new THREE.Vector3(); function loop() { const now = performance.now(), dtR = Math.min(0.1, (now - lastT) / 1000); lastT = now; if (mode === 'follow') { // 向きをなめらかに追い、斜め後ろの少し上から見る let dh = bus.rotation.y - followH; dh = Math.atan2(Math.sin(dh), Math.cos(dh)); const k = snapFollow ? 1 : 1 - Math.exp(-dtR * 3); followH += dh * k; const dx = Math.cos(followH), dz = -Math.sin(followH); const want = new THREE.Vector3(bus.position.x - dx * 14, 8.5, bus.position.z - dz * 14); if (snapFollow) cam.position.copy(want); else cam.position.lerp(want, k); lookAt.lerp(new THREE.Vector3(bus.position.x + dx * 6, 0.5, bus.position.z + dz * 6), snapFollow ? 1 : k); cam.lookAt(lookAt); snapFollow = false; } r.render(s, cam); requestAnimationFrame(loop); } loop(); // 動かす:ドラッグで回す、ホイール・2本指で寄る const ptrs = new Map(); let pinch0 = 0; const cv = r.domElement; cv.addEventListener('pointerdown', (e) => { cv.setPointerCapture(e.pointerId); ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY }); if (ptrs.size === 2) { const [a, b] = [...ptrs.values()]; pinch0 = Math.hypot(a.x - b.x, a.y - b.y); } }); cv.addEventListener('pointermove', (e) => { const p = ptrs.get(e.pointerId); if (!p) return; if (ptrs.size === 1) { if (mode === 'follow') setView('custom'); az -= (e.clientX - p.x) * 0.006; el = Math.min(1.55, Math.max(0.12, el + (e.clientY - p.y) * 0.005)); placeCam(); } else if (ptrs.size === 2) { p.x = e.clientX; p.y = e.clientY; const [a, b] = [...ptrs.values()]; const d = Math.hypot(a.x - b.x, a.y - b.y); if (pinch0) { dist = Math.min(90, Math.max(8, dist * pinch0 / d)); pinch0 = d; placeCam(); } return; } p.x = e.clientX; p.y = e.clientY; }); const up = (e) => { ptrs.delete(e.pointerId); pinch0 = 0; }; cv.addEventListener('pointerup', up); cv.addEventListener('pointercancel', up); cv.addEventListener('wheel', (e) => { e.preventDefault(); if (mode === 'follow') setView('custom'); dist = Math.min(90, Math.max(8, dist * Math.exp(e.deltaY * 0.0012))); placeCam(); }, { passive: false }); function setView(v) { mode = v === 'follow' ? 'follow' : 'orbit'; if (mode === 'follow') { snapFollow = true; followH = bus.rotation.y; } if (v === 'iso') { az = home.az; el = home.el; dist = home.dist; } if (v === 'opp') { az = home.az + Math.PI; el = home.el; dist = home.dist; } if (v === 'top') { el = 1.55; dist = 52; } placeCam(); document.querySelectorAll('#viewBtns button').forEach((b) => b.classList.toggle('on', b.dataset.v === v)); } return { setView, setFrame, setRoute, setCfg: (c) => { vc = c; setRoute(c.route); }, screenOf, moveTo: (el) => { el.prepend(r.domElement); el.appendChild(document.getElementById('views')); ro.disconnect(); cur = el; ro.observe(el); requestAnimationFrame(resize); }, host }; })(); scene.setFrame({ bus: { ...E.busPose(49), v: 0 }, peds: [], guide: false }); $('#viewBtns').addEventListener('click', (e) => { const b = e.target.closest('button'); if (b) scene.setView(b.dataset.v); }); // ---- 1年を回す ---- const runs = []; let year = null, speed = 'day', timer = null, replay = null; const dateOf = (d) => { const t = new Date(2027, 3, 1 + Math.floor(d * 365 / E.PARAMS.daysPerYear)); return `${t.getMonth() + 1}月${t.getDate()}日`; }; const timeOf = (i) => { const m = 7 * 60 + i * 18; return `${Math.floor(m / 60)}:${String(m % 60).padStart(2, '0')}`; }; $('#speeds').addEventListener('click', (e) => { const b = e.target.closest('button'); if (!b) return; speed = b.dataset.s; [...$('#speeds').children].forEach((x) => x.classList.toggle('on', x === b)); if (speed === 'skip') finishFast(); }); $('#run').addEventListener('click', () => (playKind === 'scene' ? startScene() : startYear())); $('#autoRun').addEventListener('click', startAuto); $('#incLog').addEventListener('click', (e) => { const b = e.target.closest('.li'); if (!b) return; const open = b.getAttribute('aria-expanded') !== 'true'; b.setAttribute('aria-expanded', String(open)); if (incLog[+b.dataset.i]) incLog[+b.dataset.i].open = open; /* 新しいできごとが来ても、ひらいたものはひらいたまま */ }); $('#stopRun').addEventListener('click', () => { auto = null; stopTimers(); setPlayMode('setup'); }); function setPlayMode(m) { if (m !== 'scene') { const bb = document.getElementById('bubble'); if (bb) bb.style.display = 'none'; } const running = m === 'run' || m === 'scene'; if (m === 'setup') { stopTimers(); scene.setCfg({ ...cfg }); } locked = running; drawPanel(); $('#groups').style.display = running ? 'none' : ''; $('#runInfo').style.display = running ? '' : 'none'; $('#modeTabs').style.display = running ? 'none' : ''; $('#scenes').style.display = running ? 'none' : ''; if (running) { $('#cfgLine').innerHTML = cfgSummary(cfg); $('#incident').innerHTML = '

ひやりや事故が起きると、ここに「何が起きたか・原因・かかわる人」が出ます

'; $('#incLog').innerHTML = ''; incLog = []; } $('#sceneSpeeds').style.display = m === 'scene' ? 'flex' : 'none'; $('#intro').style.display = m === 'setup' ? '' : 'none'; $('#clock').style.display = m === 'run' ? 'block' : 'none'; $('#stats').style.display = m === 'run' ? 'grid' : 'none'; $('#callout').style.display = 'none'; $('#run').style.display = m === 'setup' ? '' : 'none'; $('#autoRun').style.display = m === 'setup' && playKind === 'scene' ? '' : 'none'; $('#stopRun').style.display = running ? '' : 'none'; $('#stopRun').textContent = m === 'scene' ? '設定に戻る' : '止めて仕組みを変える'; $('#incLog').style.display = m === 'scene' ? 'none' : ''; $('#panelTitle').textContent = running ? 'シミュレーション設定' : ''; $('#panelTitle').style.display = running ? '' : 'none'; // 決める画面では、左上の説明が同じことを言っているので出さない $('#panelNote').textContent = m === 'run' ? '数字は試作の仮の決まり。予測ではありません' : '数字は試作の仮の決まり。予測ではありません'; } function stopTimers() { clearTimeout(timer); timer = null; replay = null; } // ---- 場面を選んで確かめる ---- let playKind = 'scene', sceneId = E.SCENES[0].id, sceneRuns = [], runCounter = 0, sceneRate = 1; $('#sceneSpeeds').addEventListener('click', (e) => { const b = e.target.closest('button'); if (!b) return; sceneRate = +b.dataset.r; [...$('#sceneSpeeds').children].forEach((x) => x.classList.toggle('on', x === b)); if (replay && replay.scene) replay.rate = sceneRate; }); function drawScenes() { const btn = (sc) => ``; $('#scenes').innerHTML = playKind === 'scene' ? '
場面
まわりの人の動き
' + E.SCENES.filter((x) => !x.group).map(btn).join('') + '
バスの動作不良
' + E.SCENES.filter((x) => x.group === 'C').map(btn).join('') + '
' : ''; } function setPlayKind(k) { playKind = k; [...$('#modeTabs').children].forEach((b) => b.classList.toggle('on', b.dataset.m === k)); drawScenes(); drawPanel(); $('#autoRun').style.display = k === 'scene' ? '' : 'none'; $('#run').innerHTML = k === 'scene' ? 'この場面を見る ' : 'この仕組みで1年を回す '; $('#introText').textContent = k === 'scene' ? '右で場面と設定を選んで、その1回を見てください。設定を1つ変えてもう一度見ると、問題が誰に移るかを比べられます。' : '右で仕組みを決めて、1年を回してください。いろいろな場面が混ざって起きます。起きた事故で誰にどれだけ責任があるかを、最後にあなたが考えます。'; } $('#modeTabs').addEventListener('click', (e) => { const b = e.target.closest('button'); if (b) setPlayKind(b.dataset.m); }); $('#scenes').addEventListener('click', (e) => { const b = e.target.closest('.sc'); if (!b) return; sceneId = b.dataset.id; const sc = E.SCENES.find((x) => x.id === sceneId); cfg.dir = sc.route; // 動作不良の場面を選んだら、不具合が残る設定から始める(こまめな点検や試走のままだと、走る前に見つかって起きないため) if (sc.fault === 'brake' || sc.fault === 'steer') cfg.maint = 'min'; if (sc.fault === 'update') cfg.update = 'direct'; if (sc.fault === 'comm' && cfg.mode !== 'l4r1' && cfg.mode !== 'l4r3') cfg.mode = 'l4r1'; drawScenes(); drawPanel(); scene.setCfg({ ...cfg }); }); function startScene(imp) { auto = null; const sc = E.SCENES.find((x) => x.id === sceneId); show('play'); setPlayMode('scene'); if (imp) { $('#panelTitle').textContent = sc.title; const p = { seed: imp.seed, scene: imp.sceneDef, cfg: { ...imp.cfg }, kind: 'scene', runId: ++runCounter, rate: sceneRate, expect: imp.expect, ver: imp.ver }; playPass(p, 1, (r) => sceneDone(p, r), -1); return; } $('#panelTitle').textContent = sc.title; $('#incident').innerHTML = '

この場面を再生しています

'; const p = { seed: 42, scene: E.sceneFor(sc, cfg.dir, cfg), cfg: { ...cfg }, kind: 'scene', runId: ++runCounter, rate: sceneRate }; playPass(p, 1, (r) => sceneDone(p, r), -1); } // ---- 自動再生:選んだ場面を、設定を1つずつ変えながら次々に再生し、最後に一覧で並べる ---- let auto = null; function autoVariants() { const req = sceneReq(), list = [{ label: 'もとの設定のまま(下の設定)', cfg: { ...cfg }, k: null }]; for (const g of G()) { if (g.k in req) continue; for (const o of g.opts) if (o[0] !== cfg[g.k] && (g.k !== 'dir' || sceneDirs().includes(o[0]))) list.push({ label: `${SHORT[g.k] || glabel(g)}:${label(g.k, cfg[g.k])} → ${splitOpt(o[1])[0]}`, cfg: { ...cfg, [g.k]: o[0] }, k: g.k }); } return list; } function startAuto() { const sc = E.SCENES.find((x) => x.id === sceneId); auto = { sc, list: autoVariants(), i: 0, res: [] }; show('play'); setPlayMode('scene'); $('#panelTitle').textContent = `${sc.title}(自動再生)`; autoNext(); } function autoNext() { const a = auto; if (!a) return; if (a.i >= a.list.length) { const done = a; auto = null; openAutoSummary(done); return; } const v = a.list[a.i]; $('#cfgLine').innerHTML = cfgSummary(v.cfg, v.k || undefined); $('#incident').innerHTML = `

${a.i + 1} / ${a.list.length} ${v.label}

${autoHistory(a)}`; const p = { seed: 42, scene: E.sceneFor(a.sc, v.cfg.dir, v.cfg), cfg: v.cfg, kind: 'scene', runId: ++runCounter, rate: sceneRate }; playPass(p, 1, (r) => { if (auto !== a) return; const kind = runKind(r), ex = runEx(r, v.cfg, kind); a.res.push({ ...v, kind, ex, events: r.events, reasons: kind === 'safe' ? safeReasons(r, v.cfg) : null, seed: 42, scene: E.sceneFor(a.sc, v.cfg.dir, v.cfg) }); // いまの回の結果を出し、その下にこれまでの回の履歴を並べる const cur = kind === 'safe' ? `
何も起きなかった
` : incCard(kind, ex, v.label, ''); $('#incident').innerHTML = `

${a.i + 1} / ${a.list.length} ${v.label}

${cur}${autoHistory(a, true)}`; a.i++; timer = setTimeout(autoNext, 1500 / sceneRate); }, -1); } // 自動再生の履歴:これまでの回を新しい順に。押すと、その回の説明がひらく function autoHistory(a, skipLast) { const list = (skipLast ? a.res.slice(0, -1) : a.res).map((x, i) => ({ x, n: i + 1 })).reverse(); if (!list.length) return ''; const badge = (x) => `${KIND_LABEL[x.kind]}`; return `

これまでの回

${list.map(({ x, n }) => `
${n}${badge(x)}${x.label}${x.kind === 'safe' ? `
    ${x.reasons.map((t) => `
  • ${t}
  • `).join('')}
` : incCard(x.kind, x.ex, x.label, '')}
`).join('')}
`; } function openAutoSummary(a) { const res = (x) => `${KIND_LABEL[x.kind]}`; // 行を押すと、その回の詳しい説明(場面を1回見たときと同じカード)が下にひらく const detail = (x) => (x.kind === 'safe' ? `
何も起きなかった${x.label}

止まれた理由

` : incCard(x.kind, x.ex, x.label, '')); const rows = a.res.map((x, i) => `+${i === 0 ? 'もとの設定のまま' : x.label}${res(x)}${x.ex ? x.ex.who.map((w) => `${w}`).join('') : `${x.reasons[0]}`}${x.ex && x.ex.open ? `${x.ex.open}` : ''}${detail(x)}`).join(''); $('#sceneCmp').innerHTML = `

場面:${a.sc.title}(自動再生)

設定を1つずつ変えると、結果と問題はどう変わる?

下のもとの設定から1つだけ変えて、同じ場面を${a.res.length}回見た結果です。歩く人の動きは毎回同じです。行を押すと、その回の詳しい説明がひらきます

もとの設定

${cfgSummary(a.res[0].cfg)}
${rows}
変えたこと結果かかわる人(何も起きなければ止まれた理由)まだ決まっていないこと
${ctaPanel()}
`; scene.moveTo($('#stage')); show('sceneCmp'); $('#sceneCmp').querySelector('tbody').addEventListener('click', (e) => { const r = e.target.closest('.arow'); if (!r) return; const d = $('#sceneCmp').querySelector(`.adet[data-i="${r.dataset.i}"]`); d.hidden = !d.hidden; r.querySelector('.tg').textContent = d.hidden ? '+' : '-'; }); $('#autoRep').addEventListener('click', () => saveReport(`事故責任レポート_${a.sc.title}_設定を1つずつ変えた結果.html`, `${a.sc.title}:設定を1つずつ変えた結果`, `下のもとの設定から1つだけ変えて、同じ場面を${a.res.length}回見た結果です。歩く人の動きは毎回同じです。`, [`

もとの設定

${cfgSummary(a.res[0].cfg)}
`, summaryTable(a.res.map((x, i) => ({ ...x, label: i === 0 ? 'もとの設定のまま' : x.label }))), ...a.res.map((x, i) => runBlock(x, i === 0 ? 'もとの設定のまま' : x.label, i > 0))])); $('#autoCsv').addEventListener('click', () => downloadCsv(`事故責任_${a.sc.id}_自動再生.csv`, a.res.map((x, i) => sceneRow(a.sc, x, i === 0 ? 'もとの設定のまま' : x.label)))); $('#autoBack').addEventListener('click', () => { show('play'); setPlayMode('setup'); }); $('#autoAgain').addEventListener('click', () => { show('play'); setPlayMode('setup'); }); } function safeReasons(r, c) { const k = new Set(r.events.map((e) => e.k)), out = []; if (k.has('sensed')) out.push('バスのセンサーが人に気づき、自動ブレーキで止まった'); if (k.has('opbrake')) out.push(`${WATCHER(c)}が人に気づいて止めた`); if (k.has('remote')) out.push('遠隔監視者が映像で気づき、止める指示を出した'); if (k.has('steerfix')) out.push(`${WATCHER(c)}がハンドルで道へ戻した`); if (!out.length) out.push('人が渡り終えるまでバスが待ったか、人がバスに気づいて待った'); return out; } function sceneDone(p, r) { const sc = p.scene, c = p.cfg; const kind = runKind(r), ex = runEx(r, c, kind); if (kind === 'issue') $('#incident').innerHTML = incCard('issue', ex, sc.title, ''); maybeBubble(kind, ex); if (kind === 'safe') $('#incident').innerHTML = `
何も起きなかった${sc.title}

止まれた理由

`; const prev = sceneRuns.filter((x) => x.sceneId === sc.id).at(-1); sceneRuns.push({ sceneId: sc.id, cfg: c, kind, ex, events: r.events, reasons: kind === 'safe' ? safeReasons(r, c) : null, seed: p.seed, scene: sc }); const btns = `
${prev ? '' : ''}${p.expect ? `

${p.expect === kind ? `読み込んだ回:書き出したときと同じ結果(${KIND_LABEL[kind]})になった` : `読み込んだ回:書き出したときは「${KIND_LABEL[p.expect]}」、今は「${KIND_LABEL[kind]}」(決まりの版 ${p.ver || '不明'} → ${E.RULES_VERSION})`}

` : ''}
`; $('#incident').insertAdjacentHTML('beforeend', btns); $('#sAgain').addEventListener('click', () => { setPlayMode('setup'); }); $('#sReplay').addEventListener('click', () => startScene()); $('#sRep').addEventListener('click', () => saveReport(`事故責任レポート_${sc.title}.html`, sc.title, 'あなたが決めた設定で、この場面を1回見た結果です。', [runBlock(sceneRuns.at(-1), 'この回')])); $('#sJson').addEventListener('click', () => downloadText(`事故責任_${sc.id}_${Date.now()}.json`, JSON.stringify(passRecord(p, r, kind, ex), null, 1), 'application/json')); if (prev) $('#sCmp').addEventListener('click', () => openSceneCompare(prev, sceneRuns.at(-1))); } function openSceneCompare(a, b) { const sc = E.SCENES.find((x) => x.id === b.sceneId); const res = (x) => KIND_LABEL[x.kind]; const changed = G().filter((g) => a.cfg[g.k] !== b.cfg[g.k]); const col = (x, other, title) => `

${title}

${cfgSummary(x.cfg, other.cfg)}
${x.kind === 'safe' ? `
何も起きなかった

止まれた理由

` : incCard(x.kind, x.ex, sc.title, '')}
`; const csvRows = [sceneRow(sc, a, 'まえ'), sceneRow(sc, b, 'あと')]; const wa = new Set(a.ex ? a.ex.who : []), wb = new Set(b.ex ? b.ex.who : []); const gone = [...wa].filter((w) => !wb.has(w)), added = [...wb].filter((w) => !wa.has(w)); const sum = `変えたこと:${changed.length ? changed.map((g) => `${g.label instanceof Function ? g.label(b.cfg) : g.label}を「${label(g.k, b.cfg[g.k])}」に`).join('、') : 'なし'}。
結果:${res(a)} → ${res(b)}。` + (gone.length ? `
問題から外れた:${gone.join('・')}` : '') + (added.length ? `
新しく問題になった:${added.join('・')}` : '') + (!gone.length && !added.length ? '
かかわる人は変わらなかった' : ''); $('#sceneCmp').innerHTML = `

場面:${sc.title}

設定を変えると、問題はどこへ移る?

${sum}
${col(a, b, 'まえ')}${col(b, a, 'あと')}
${ctaPanel()}
`; scene.moveTo($('#stage')); show('sceneCmp'); $('#cmpRep').addEventListener('click', () => saveReport(`事故責任レポート_${sc.title}_比較.html`, `${sc.title}:設定を変えると、問題はどこへ移る?`, '', [`
${sum}
`, runBlock(a, 'まえ'), runBlock(b, 'あと')])); $('#cmpCsv').addEventListener('click', () => downloadCsv(`事故責任_${sc.id}_比較.csv`, csvRows)); $('#cmpBack').addEventListener('click', () => { show('play'); setPlayMode('setup'); }); $('#cmpAgain').addEventListener('click', () => { show('play'); setPlayMode('setup'); }); } // ---- 書き出し・読み込み ---- // 公開したページでは、ダウンロードは claude の downloads を通す(見る人が確かめてから保存される)。使えない所では、ふつうのダウンロード let dlNs; const dlReady = (async () => { try { dlNs = window.claude && window.claude.use ? await window.claude.use('downloads') : null; } catch { dlNs = null; } })(); async function downloadText(name, text, type) { await dlReady; if (dlNs) { try { await dlNs.save({ filename: name, data: new Blob([text], { type }) }); } catch (e) { if (e && e.code !== 'declined') alertNote(`書き出せませんでした(${e && e.code || 'unavailable'})`); } return; } const url = URL.createObjectURL(new Blob([text], { type: type + ';charset=utf-8' })); const a = document.createElement('a'); a.href = url; a.download = name; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(url), 2000); } function downloadCsv(name, rows) { if (!rows.length) return; const keys = [...new Set(rows.flatMap((r) => Object.keys(r)))]; const esc = (v) => { const t = v === undefined || v === null ? '' : String(v); return /[",\n]/.test(t) ? '"' + t.replace(/"/g, '""') + '"' : t; }; downloadText(name, '' + [keys.map(esc).join(','), ...rows.map((r) => keys.map((k) => esc(r[k])).join(','))].join('\r\n'), 'text/csv'); // 先頭の印は、Excel で文字化けしないため } const lines = (arr) => (arr || []).map((x) => `${x.who}:${x.text}`).join(' / '); const cfgCols = (c, groups) => Object.fromEntries(groups.map((g) => [g.k === 'rest' ? '見張る人の休憩' : g.label, label(g.k, c[g.k])])); function sceneRow(sc, x, changed) { return { 場面: sc.title, 変えたこと: changed, ...cfgCols(x.cfg, G()), 結果: KIND_LABEL[x.kind], 何が起きたか: x.ex ? x.ex.what : '', かかわる人: x.ex ? x.ex.who.join('・') : '', 人の問題: x.ex ? lines(x.ex.people) : '', 企業の問題: x.ex ? lines(x.ex.company) : '', '決まり・行政': x.ex ? lines(x.ex.rules) : '', まだ決まっていないこと: x.ex ? x.ex.open : '', 関連する課題: x.ex && x.ex.issues ? x.ex.issues.map((i) => '#' + i.no + ' ' + i.title).join(' / ') : '', 止まれた理由: x.reasons ? x.reasons.join(' / ') : '', 乱数の種: x.seed ?? 42, 決まりの版: E.RULES_VERSION }; } function yearRows(y) { const items = [...y.accidents.map((a) => ({ ...a, kind: 'hit' })), ...y.nears.map((a) => ({ ...a, kind: 'near' })), ...y.faults.filter((f) => f.kind === 'safe' || f.kind === 'issue').map((a) => ({ ...a, kind: 'fault' }))].sort((a, b) => a.day - b.day || a.pass - b.pass); const base = cfgCols(y.cfg, GROUPS.filter((g) => !g.scene)); return items.map((a) => { const ex = a.kind === 'fault' ? null : explain(a.facts, y.cfg, a.kind); return { 日付: dateOf(a.day), 時刻: timeOf(a.pass), 種類: a.kind === 'fault' ? '不具合(事故・ひやりなし)' : KIND_LABEL[a.kind], 不具合: a.fault ? E.FAULT_LABEL[a.fault] : '', 夕方の逆光: a.evening ? 'はい' : '', 何が起きたか: ex ? ex.what : '', かかわる人: ex ? ex.who.join('・') : '', 人の問題: ex ? lines(ex.people) : '', 企業の問題: ex ? lines(ex.company) : '', '決まり・行政': ex ? lines(ex.rules) : '', まだ決まっていないこと: ex ? ex.open : '', 乱数の種: a.seed, ...base, 決まりの版: E.RULES_VERSION }; }); } // 1回分の記録:条件・乱数の種・決まりの版・結果・出来事・0.5秒ごとの位置。読み込めば同じ1回を再生できる function passRecord(p, r, kind, ex) { const sc = E.SCENES.find((x) => x.id === sceneId) || {}; return { tool: '事故が起きたら誰の責任?(試作)', rulesVersion: E.RULES_VERSION, exportedAt: new Date().toISOString(), scene: { id: sc.id, title: sc.title, def: p.scene }, cfg: p.cfg, seed: p.seed, result: { kind, label: KIND_LABEL[kind], facts: r.facts || r.nearFacts || r.issueFacts || null, explanation: ex, waitSec: r.wait }, events: r.events, frames: r.frames, params: E.PARAMS }; } $('#scenes').addEventListener('click', (e) => { if (e.target.closest('#impBtn')) $('#impFile').click(); }); $('#scenes').addEventListener('change', async (e) => { const inp = e.target.closest('#impFile'); if (!inp || !inp.files[0]) return; let d; try { d = JSON.parse(await inp.files[0].text()); } catch { alertNote('読み込めませんでした(JSON の形ではありません)'); return; } if (!d || !d.scene || !d.scene.def || !d.cfg || d.seed === undefined) { alertNote('この画面で書き出した回の記録ではありません'); return; } if (E.SCENES.some((x) => x.id === d.scene.id)) sceneId = d.scene.id; cfg = { ...E.DEFAULTS, ...d.cfg }; drawScenes(); drawPanel(); scene.setCfg({ ...cfg }); startScene({ seed: d.seed, sceneDef: d.scene.def, cfg: cfg, expect: d.result && d.result.kind, ver: d.rulesVersion }); }); if (location.hash === '#dev') document.body.classList.add('devmode'); // 作る側の書き出し(JSON・CSV・読み込み)は #dev のときだけ出す function alertNote(t) { $('#panelNote').textContent = t; } // ---- 見る人が持ち帰るレポート(1つのHTMLファイル。ブラウザで開き、印刷すればPDFにもなる) ---- const escH = (t) => String(t ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]); function timeline(events) { const ev = (events || []).filter((e) => e.k !== 'route'); if (!ev.length) return ''; return `

できごとの記録(通過の始まりからの秒数)

${ev.map((e) => ``).join('')}
${e.t.toFixed(1)}秒${escH(e.text)}
`; } function runBlock(x, title, showChange) { const body = x.kind === 'safe' ? `
何も起きなかった

止まれた理由

` : incCard(x.kind, x.ex, '', ''); return `

${escH(title)}

選んだ設定

${cfgSummary(x.cfg, showChange ? x.k : undefined)}
${body}${timeline(x.events)}
`; } function summaryTable(list) { return `

結果の一覧

${list.map((x) => ``).join('')}
変えたこと結果かかわる人まだ決まっていないこと
${escH(x.label)}${KIND_LABEL[x.kind]}${x.ex ? escH(x.ex.who.join('・')) : escH((x.reasons || [])[0] || '')}${x.ex ? escH(x.ex.open) : ''}
`; } function yearBlocks(y, prev) { const num = (r) => `${r.accidents.length}件${r.near}回${r.delay.toFixed(2)}分${r.cost}${r.faults ? r.faults.length + '回' : ''}`; const out = [`

数字

${prev ? num(prev).replace('', '') : ''}${num(y)}
事故ひやり1便の遅れ(平均)運行の費用(いちばん安い仕組みを100)バスの不具合
${prev ? '

上の段が前の1年、下の段がこの1年

' : ''}

選んだ設定

${cfgSummary(y.cfg, prev ? prev.cfg : undefined)}
`]; y.accidents.slice(0, 20).forEach((a, i) => { const r = E.simulatePass(y.cfg, E.rng(a.seed), { evening: a.evening, record: false, fault: a.fault }); out.push(runBlock({ kind: 'hit', ex: explain(a.facts, y.cfg, 'hit'), cfg: y.cfg, events: r.events }, `事故 ${i + 1} ${dateOf(a.day)} ${timeOf(a.pass)}${a.evening ? '(夕方の逆光)' : ''}`)); }); if (y.accidents.length > 20) out.push(`

ほか ${y.accidents.length - 20}件の事故は省いています

`); return out; } const REPORT_CSS = `body{margin:0;background:#fff;color:#111;font:15px/1.7 'Hiragino Sans','Noto Sans JP',sans-serif}main{max-width:860px;margin:0 auto;padding:36px 24px 60px} h1{font-size:26px;line-height:1.35;margin:4px 0 8px}h2{font-size:18px;margin:0 0 10px;padding-top:10px;border-top:2px solid #111}section{margin:28px 0;break-inside:avoid-page} .eyebrow,.note{font-size:12.5px;color:#666}h4{margin:14px 0 6px;font-size:12px;color:#777;font-weight:600} .cfgs{background:#f5f5f3;border-radius:10px;padding:12px 14px;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px 16px}.cfgs div{display:flex;flex-direction:column}.cfgs span{font-size:11.5px;color:#777}.cfgs b{font-size:13.5px}.cfgs b.chg{background:#fff1b8;border-radius:4px;padding:0 4px;align-self:flex-start} .inc{border:1px solid #e3e3e0;border-radius:12px;padding:12px 16px;margin-top:12px}.inc.hit{border-color:#d93a3a}.inc.issue{border-color:#b7791f}.inc.safe{border-color:#2f7d4f} .inc .hd{display:flex;gap:8px;align-items:center;font-size:12px;color:#666}.tag,.rk{font-size:12px;font-weight:700;color:#fff;background:#111;border-radius:6px;padding:2px 8px;white-space:nowrap} .inc.hit .tag,.rk.hit{background:#d93a3a}.inc.issue .tag,.rk.issue{background:#b7791f}.inc.safe .tag,.rk.safe{background:#2f7d4f}.what{font-weight:700;margin:8px 0 0} ul.who3{list-style:none;padding:0;margin:0}ul.who3 li{margin:4px 0}ul.who3 b{display:inline-block;font-size:11px;background:#f0f0ee;border-radius:999px;padding:0 8px;margin-right:6px}ul.who3 b.me{background:#111;color:#fff} .open{background:#fff6e5;border-radius:8px;padding:8px 12px;margin-top:10px}.iss{margin-top:10px;display:flex;flex-wrap:wrap;gap:6px}.iss span{width:100%;font-size:11px;font-weight:700;color:#777}.iss a{font-size:12.5px;color:#097ac1;border:1px solid #d6d6d2;border-radius:999px;padding:2px 10px;text-decoration:none}.open span{display:block;font-size:11px;font-weight:700;color:#8a5a00} table{width:100%;border-collapse:collapse;font-size:13px}td,th{text-align:left;padding:7px 8px;border-bottom:1px solid #eee;vertical-align:top}th{font-size:11.5px;color:#777}.tl td:first-child{width:5.5em;color:#666;white-space:nowrap}tr.prev td{color:#888} .sum{background:#111;color:#fff;border-radius:12px;padding:14px 16px}.rcta{border:1px solid #111;border-radius:12px;padding:16px 20px}.rcta h2{border:0;padding:0}.rcta a{color:#097ac1;font-weight:700}footer{margin-top:40px;font-size:12px;color:#666;border-top:1px solid #ddd;padding-top:12px} @media(max-width:600px){.cfgs{grid-template-columns:repeat(2,minmax(0,1fr))}}.pbar{position:sticky;top:0;background:#111;color:#fff;padding:10px 24px;display:flex;gap:14px;align-items:center;font-size:12.5px}.pbar button{font-family:inherit;font-weight:700;font-size:14px;background:#fff;color:#111;border:0;border-radius:8px;padding:10px 16px;cursor:pointer}@media print{main{padding:0}.pbar{display:none}}`; function saveReport(name, title, lead, blocks) { const now = new Date(), d = `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`; const html = `${escH(title)}|事故が起きたら誰の責任?

事故が起きたら誰の責任?(試作)のレポート ${d}

${escH(title)}

${lead ? `

${escH(lead)}

` : ''} ${blocks.join('\n')}

あなたの現場で、同じことを確かめませんか

このレポートは、架空の交差点で設定を変えたときに、人・企業・決まりのどこに問題が出るかを確かめたものです。自動運転バスや移動ロボットの導入を進めている方は、あなたの現場の交差点や路線、運行の形、見張る人の体制に合わせて作り直し、導入の前に同じことを確かめられます。

相談する ${MSG_URL}

`; openReport(html); } // レポートは、まず画面の上で見せる。保存は見た人が「PDFで保存」を押したときだけ(ブラウザの保存の画面で、置き場所を選べる) function openReport(html) { let v = $('#repV'); if (!v) { v = document.createElement('div'); v.id = 'repV'; v.innerHTML = `
レポート保存の画面で、送り先を「PDFに保存」にしてください
`; document.body.appendChild(v); const close = () => { v.style.display = 'none'; document.body.style.overflow = ''; }; $('#rvClose').addEventListener('click', close); v.addEventListener('click', (e) => { if (e.target === v) close(); }); document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && v.style.display === 'flex') close(); }); // 枠の中からの印刷はブラウザによって動かないため、レポートを新しいタブで単独のページとして開き、そこで保存の画面を出す $('#rvPdf').addEventListener('click', () => { const page = v.dataset.html.replace('
', `
保存の画面で、送り先を「PDFに保存」にしてください。開かないときは、ブラウザのメニューの「印刷」から保存できます。
`).replace('', '