@johnmorrisdotca/wakusei-planets 0.57.0 → 0.59.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/CHANGELOG.md +9 -0
- package/README.md +5 -3
- package/dist/element.d.ts +7 -0
- package/dist/element.js +16 -4
- package/dist/landing-sites.d.ts +120 -0
- package/dist/landing-sites.js +339 -0
- package/dist/scene/place-layer.d.ts +7 -3
- package/dist/scene/place-layer.js +93 -6
- package/dist/space/covered.d.ts +23 -0
- package/dist/space/covered.js +33 -11
- package/dist/space/element.d.ts +34 -4
- package/dist/space/element.js +55 -14
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +19 -2
- package/package.json +7 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { findLandingSite, flagCodeOf } from "../landing-sites.js";
|
|
1
2
|
const STYLE = `.wk-places{position:absolute;inset:0;pointer-events:none;overflow:hidden}
|
|
2
3
|
.wk-place{position:absolute;left:0;top:0;width:20px;height:20px;margin:-10px 0 0 -10px;padding:0;border:0;background:none;cursor:pointer;pointer-events:auto;will-change:transform;-webkit-tap-highlight-color:transparent}
|
|
3
4
|
.wk-place::before{content:"";position:absolute;left:50%;top:50%;width:6px;height:6px;margin:-3px 0 0 -3px;border-radius:50%;box-sizing:border-box;background:var(--wakusei-place-landing,#fff);box-shadow:0 0 0 1px rgba(0,0,0,.55);opacity:.85}
|
|
@@ -11,7 +12,14 @@ const STYLE = `.wk-places{position:absolute;inset:0;pointer-events:none;overflow
|
|
|
11
12
|
.wk-place[data-name]{width:auto;height:auto;margin:0;padding:0 3px;color:#fff;font:600 12px/1.2 var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;text-shadow:0 1px 2px #000,0 0 3px #000;pointer-events:auto}
|
|
12
13
|
.wk-place[data-pure]{pointer-events:none}
|
|
13
14
|
.wk-place[data-name]::before{display:none}
|
|
14
|
-
.wk-place-tip[data-on]{visibility:visible}
|
|
15
|
+
.wk-place-tip[data-on]{visibility:visible}
|
|
16
|
+
.wk-place-tip .wk-place-head{display:flex;align-items:center;gap:5px}
|
|
17
|
+
.wk-place-flag{flex:none;height:11px;pointer-events:none}
|
|
18
|
+
.wk-place-flag:not(:defined){display:none}
|
|
19
|
+
.wk-place-site{position:absolute;top:50%;left:13px;display:flex;align-items:center;gap:4px;margin-top:-8px;color:#fff;font:600 11px/16px var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;text-shadow:0 1px 2px #000,0 0 3px #000;pointer-events:none}
|
|
20
|
+
.wk-place-site[data-side=left]{left:auto;right:13px;flex-direction:row-reverse}`;
|
|
21
|
+
/** A body's radius on the screen, in CSS pixels, from which the landing sites' names are written beside their dots (when the `site-flags` attribute is on). */
|
|
22
|
+
export const SITE_LABEL_FROM_PX = 110;
|
|
15
23
|
const KIND_WORD = {
|
|
16
24
|
crewed: { en: "crewed landing", ja: "有人着陸" },
|
|
17
25
|
landing: { en: "lander", ja: "着陸機" },
|
|
@@ -52,6 +60,18 @@ export function placeLine(place, lang) {
|
|
|
52
60
|
const year = place.date?.slice(0, 4);
|
|
53
61
|
return year === undefined ? word : ja ? `${word}、${year}年` : `${word}, ${year}`;
|
|
54
62
|
}
|
|
63
|
+
/** A flag for a country, as `<hata-flag>` (from `@johnmorrisdotca/hata`, which the page imports; where it is not defined the element draws nothing and the name stands alone). */
|
|
64
|
+
function flagFor(place) {
|
|
65
|
+
const code = flagCodeOf(place.country);
|
|
66
|
+
if (code === undefined)
|
|
67
|
+
return undefined;
|
|
68
|
+
const flag = document.createElement("hata-flag");
|
|
69
|
+
flag.className = "wk-place-flag";
|
|
70
|
+
flag.setAttribute("code", code);
|
|
71
|
+
flag.setAttribute("border", "");
|
|
72
|
+
flag.setAttribute("aria-hidden", "true");
|
|
73
|
+
return flag;
|
|
74
|
+
}
|
|
55
75
|
// on globalThis, so the separate copies a CDN can load share the one loader
|
|
56
76
|
const SLOT = Symbol.for("@johnmorrisdotca/wakusei-planets/places-loader");
|
|
57
77
|
const slot = (globalThis[SLOT] ??= { heard: new Set() });
|
|
@@ -113,7 +133,15 @@ export function createPlaceLayer(root, options) {
|
|
|
113
133
|
name.textContent = entry.mark.place.name[lang];
|
|
114
134
|
const line = document.createElement("small");
|
|
115
135
|
line.textContent = placeLine(entry.mark.place, lang);
|
|
116
|
-
|
|
136
|
+
const flag = options.flags?.() === true ? flagFor(entry.mark.place) : undefined;
|
|
137
|
+
if (flag === undefined)
|
|
138
|
+
tip.replaceChildren(name, line);
|
|
139
|
+
else {
|
|
140
|
+
const head = document.createElement("div");
|
|
141
|
+
head.className = "wk-place-head";
|
|
142
|
+
head.append(flag, name);
|
|
143
|
+
tip.replaceChildren(head, line);
|
|
144
|
+
}
|
|
117
145
|
tip.setAttribute("data-on", "");
|
|
118
146
|
tipFor = id;
|
|
119
147
|
placeTip();
|
|
@@ -157,7 +185,7 @@ export function createPlaceLayer(root, options) {
|
|
|
157
185
|
event.stopPropagation();
|
|
158
186
|
const entry = held.get(id);
|
|
159
187
|
if (entry !== undefined)
|
|
160
|
-
options.pick(entry.mark.place, { x: entry.x, y: entry.y });
|
|
188
|
+
options.pick(entry.mark.place, entry.site, { x: entry.x, y: entry.y });
|
|
161
189
|
});
|
|
162
190
|
return button;
|
|
163
191
|
};
|
|
@@ -189,7 +217,7 @@ export function createPlaceLayer(root, options) {
|
|
|
189
217
|
best = { entry, away };
|
|
190
218
|
}
|
|
191
219
|
if (best !== undefined)
|
|
192
|
-
options.pick(best.entry.mark.place, { x: best.entry.x, y: best.entry.y });
|
|
220
|
+
options.pick(best.entry.mark.place, best.entry.site, { x: best.entry.x, y: best.entry.y });
|
|
193
221
|
};
|
|
194
222
|
const nameCancel = () => {
|
|
195
223
|
pressed = null;
|
|
@@ -197,8 +225,66 @@ export function createPlaceLayer(root, options) {
|
|
|
197
225
|
window.addEventListener("pointerdown", nameDown, true);
|
|
198
226
|
window.addEventListener("pointerup", nameUp, true);
|
|
199
227
|
window.addEventListener("pointercancel", nameCancel, true);
|
|
228
|
+
// The landing sites' names beside their dots, with the country's flag: only with flags on, only on a body close enough to leave the room, and each in the first of the right or the left side that clears the dots and the names
|
|
229
|
+
// already written (marks come in the order they matter). A label belongs to its dot's button, so a press on it is the dot's.
|
|
230
|
+
const labelSites = (marks, radiusPx) => {
|
|
231
|
+
const lang = options.lang();
|
|
232
|
+
const width = box.clientWidth;
|
|
233
|
+
const on = options.flags?.() === true && radiusPx >= SITE_LABEL_FROM_PX;
|
|
234
|
+
// the names of the surface (Mare Imbrium, Plato) are written first and keep their place: a site's label goes round them
|
|
235
|
+
const taken = marks
|
|
236
|
+
.filter((mark) => mark.label === true && (mark.fade ?? 1) > 0.2)
|
|
237
|
+
.map((mark) => {
|
|
238
|
+
const halfWidth = Math.ceil(mark.place.name[lang].length * 3.7) + 5;
|
|
239
|
+
return { x0: mark.x - halfWidth, x1: mark.x + halfWidth, y0: mark.y - 9, y1: mark.y + 9 };
|
|
240
|
+
});
|
|
241
|
+
const dots = marks.filter((mark) => mark.label !== true).map((mark) => ({ mark, x0: mark.x - 8, x1: mark.x + 8, y0: mark.y - 8, y1: mark.y + 8 }));
|
|
242
|
+
const clear = (r, self) => (width <= 0 || (r.x0 >= 0 && r.x1 <= width)) && !taken.some((o) => r.x0 < o.x1 && r.x1 > o.x0 && r.y0 < o.y1 && r.y1 > o.y0) &&
|
|
243
|
+
!dots.some((d) => d.mark !== self && r.x0 < d.x1 && r.x1 > d.x0 && r.y0 < d.y1 && r.y1 > d.y0);
|
|
244
|
+
for (const mark of marks) {
|
|
245
|
+
const entry = held.get(mark.place.id);
|
|
246
|
+
if (entry === undefined)
|
|
247
|
+
continue;
|
|
248
|
+
let side;
|
|
249
|
+
if (on && mark.label !== true && entry.site !== undefined) {
|
|
250
|
+
const text = entry.site.name[lang];
|
|
251
|
+
const w = 13 + text.length * 6.4 + (flagCodeOf(entry.site.country) === undefined ? 0 : 19);
|
|
252
|
+
const right = { x0: mark.x + 10, x1: mark.x + 10 + w, y0: mark.y - 8, y1: mark.y + 8 };
|
|
253
|
+
const left = { x0: mark.x - 10 - w, x1: mark.x - 10, y0: mark.y - 8, y1: mark.y + 8 };
|
|
254
|
+
const spot = clear(right, mark) ? right : clear(left, mark) ? left : undefined;
|
|
255
|
+
if (spot !== undefined) {
|
|
256
|
+
taken.push(spot);
|
|
257
|
+
side = spot === right ? "right" : "left";
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (side === undefined) {
|
|
261
|
+
entry.label?.remove();
|
|
262
|
+
entry.label = undefined;
|
|
263
|
+
entry.labelKey = undefined;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const key = `${lang}|${side}`;
|
|
267
|
+
if (entry.label === undefined || !entry.label.isConnected || entry.labelKey !== key) {
|
|
268
|
+
entry.label?.remove();
|
|
269
|
+
const label = document.createElement("span");
|
|
270
|
+
label.className = "wk-place-site";
|
|
271
|
+
label.setAttribute("part", "place-site");
|
|
272
|
+
label.setAttribute("aria-hidden", "true");
|
|
273
|
+
label.dataset.side = side;
|
|
274
|
+
const flag = flagFor(mark.place);
|
|
275
|
+
const name = document.createElement("span");
|
|
276
|
+
name.textContent = entry.site.name[lang];
|
|
277
|
+
if (flag !== undefined)
|
|
278
|
+
label.append(flag);
|
|
279
|
+
label.append(name);
|
|
280
|
+
entry.button.append(label);
|
|
281
|
+
entry.label = label;
|
|
282
|
+
entry.labelKey = key;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
200
286
|
return {
|
|
201
|
-
set(marks) {
|
|
287
|
+
set(marks, radiusPx = 0) {
|
|
202
288
|
const lang = options.lang();
|
|
203
289
|
const next = new Set();
|
|
204
290
|
for (const mark of marks) {
|
|
@@ -207,7 +293,7 @@ export function createPlaceLayer(root, options) {
|
|
|
207
293
|
let entry = held.get(id);
|
|
208
294
|
if (entry === undefined) {
|
|
209
295
|
const button = make(mark);
|
|
210
|
-
entry = { button, mark, x: Number.NaN, y: Number.NaN, lang: "" };
|
|
296
|
+
entry = { button, mark, x: Number.NaN, y: Number.NaN, lang: "", site: findLandingSite(id) };
|
|
211
297
|
held.set(id, entry);
|
|
212
298
|
box.insertBefore(button, tip);
|
|
213
299
|
}
|
|
@@ -249,6 +335,7 @@ export function createPlaceLayer(root, options) {
|
|
|
249
335
|
entry.button.style.transform = `translate(${mark.x.toFixed(1)}px,${mark.y.toFixed(1)}px)${shift}`;
|
|
250
336
|
}
|
|
251
337
|
}
|
|
338
|
+
labelSites(marks, radiusPx);
|
|
252
339
|
for (const [id, entry] of held) {
|
|
253
340
|
if (next.has(id))
|
|
254
341
|
continue;
|
package/dist/space/covered.d.ts
CHANGED
|
@@ -48,6 +48,29 @@ export declare const COVER_MIN_PX = 6;
|
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
export declare function coveredBy(entries: readonly CoverEntry[]): Map<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* Which body, if any, hides a point of a label: the nearest body whose drawn disc holds the point on the screen and which is nearer the camera than the point is. For a name, a ring or a pin whose place is a point
|
|
53
|
+
* (a belt's name at its anchor, the Oort cloud's note, a mark on a surface), not a body. A disc narrower than `COVER_MIN_PX` hides nothing, and `self` (the point's own body) never hides it. A disc test
|
|
54
|
+
* for each of the few discs big enough to matter; nothing is read back from the picture.
|
|
55
|
+
*
|
|
56
|
+
* @param point - The point's place on the screen in CSS pixels and its distance from the camera (any unit, the same as the discs').
|
|
57
|
+
* @param discs - The drawn discs: their places and radii on the screen (the radius `placeOf(id).r` gives, rounded at the edge of the picture) and their distances.
|
|
58
|
+
* @param self - The id of the body the point belongs to, if it belongs to one.
|
|
59
|
+
* @returns The id of the covering body, or `null` when the point is in the open.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { coverOf } from "@johnmorrisdotca/wakusei-planets/space";
|
|
64
|
+
*
|
|
65
|
+
* const discs = [{ id: "pholus", x: 300, y: 300, r: 200, distance: 4 }];
|
|
66
|
+
* console.log(coverOf({ x: 340, y: 280, distance: 5_000 }, discs), coverOf({ x: 640, y: 280, distance: 5_000 }, discs));
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function coverOf(point: {
|
|
70
|
+
x: number;
|
|
71
|
+
y: number;
|
|
72
|
+
distance: number;
|
|
73
|
+
}, discs: readonly CoverEntry[], self?: string): string | null;
|
|
51
74
|
/**
|
|
52
75
|
* One quiet arrow: outside the covering body's disc, on the side nearest the bodies behind it, pointing in behind it, with the surest of them named and the rest counted.
|
|
53
76
|
*
|
package/dist/space/covered.js
CHANGED
|
@@ -31,20 +31,42 @@ export const COVER_MIN_PX = 6;
|
|
|
31
31
|
export function coveredBy(entries) {
|
|
32
32
|
const behind = new Map();
|
|
33
33
|
for (const body of entries) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
continue;
|
|
38
|
-
if (Math.hypot(body.x - other.x, body.y - other.y) >= other.r)
|
|
39
|
-
continue;
|
|
40
|
-
if (cover === undefined || other.distance < cover.distance)
|
|
41
|
-
cover = other;
|
|
42
|
-
}
|
|
43
|
-
if (cover !== undefined)
|
|
44
|
-
behind.set(body.id, cover.id);
|
|
34
|
+
const cover = coverOf(body, entries, body.id);
|
|
35
|
+
if (cover !== null)
|
|
36
|
+
behind.set(body.id, cover);
|
|
45
37
|
}
|
|
46
38
|
return behind;
|
|
47
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Which body, if any, hides a point of a label: the nearest body whose drawn disc holds the point on the screen and which is nearer the camera than the point is. For a name, a ring or a pin whose place is a point
|
|
42
|
+
* (a belt's name at its anchor, the Oort cloud's note, a mark on a surface), not a body. A disc narrower than `COVER_MIN_PX` hides nothing, and `self` (the point's own body) never hides it. A disc test
|
|
43
|
+
* for each of the few discs big enough to matter; nothing is read back from the picture.
|
|
44
|
+
*
|
|
45
|
+
* @param point - The point's place on the screen in CSS pixels and its distance from the camera (any unit, the same as the discs').
|
|
46
|
+
* @param discs - The drawn discs: their places and radii on the screen (the radius `placeOf(id).r` gives, rounded at the edge of the picture) and their distances.
|
|
47
|
+
* @param self - The id of the body the point belongs to, if it belongs to one.
|
|
48
|
+
* @returns The id of the covering body, or `null` when the point is in the open.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { coverOf } from "@johnmorrisdotca/wakusei-planets/space";
|
|
53
|
+
*
|
|
54
|
+
* const discs = [{ id: "pholus", x: 300, y: 300, r: 200, distance: 4 }];
|
|
55
|
+
* console.log(coverOf({ x: 340, y: 280, distance: 5_000 }, discs), coverOf({ x: 640, y: 280, distance: 5_000 }, discs));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function coverOf(point, discs, self) {
|
|
59
|
+
let cover;
|
|
60
|
+
for (const other of discs) {
|
|
61
|
+
if (other.id === self || other.r < COVER_MIN_PX || other.distance >= point.distance)
|
|
62
|
+
continue;
|
|
63
|
+
if (Math.hypot(point.x - other.x, point.y - other.y) >= other.r)
|
|
64
|
+
continue;
|
|
65
|
+
if (cover === undefined || other.distance < cover.distance)
|
|
66
|
+
cover = other;
|
|
67
|
+
}
|
|
68
|
+
return cover === undefined ? null : cover.id;
|
|
69
|
+
}
|
|
48
70
|
/**
|
|
49
71
|
* How far outside the disc's edge the arrow's tip sits, in CSS pixels.
|
|
50
72
|
*
|
package/dist/space/element.d.ts
CHANGED
|
@@ -26,6 +26,18 @@ export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS, type EarthPlace, type EarthPlaceK
|
|
|
26
26
|
export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type Sight, type SightEdge, type SpaceBody, type SpaceLight };
|
|
27
27
|
/** Where a body is on the screen, in CSS pixels in the element: its centre and its radius. */
|
|
28
28
|
export type { BodyPlace };
|
|
29
|
+
/**
|
|
30
|
+
* What a body behind another gets: `hide` (fade its name and ring out), `arrow` (a quiet arrow on the disc's edge) or `name` (draw it over the disc).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import type { Covered } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
35
|
+
*
|
|
36
|
+
* const how: Covered = "hide";
|
|
37
|
+
* console.log(how);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type Covered = "hide" | "arrow" | "name";
|
|
29
41
|
/**
|
|
30
42
|
* What a page can tell a reader about a body now.
|
|
31
43
|
*
|
|
@@ -197,6 +209,13 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
197
209
|
*/
|
|
198
210
|
get places(): PlaceLayer[];
|
|
199
211
|
set places(layers: readonly PlaceLayer[] | null);
|
|
212
|
+
/**
|
|
213
|
+
* Whether the places carry their country's flag (the attribute `site-flags`): the tip of a place with a country shows its flag, and on a body close enough on the screen (110 pixels of radius) the landing sites (`LANDING_SITES` from
|
|
214
|
+
* `/landing-sites`) are named beside their dots, each with its flag. The flag is `<hata-flag>` from `@johnmorrisdotca/hata`, which the page imports itself (`import "@johnmorrisdotca/hata/element/define"`); until it is defined the name stands alone. Needs `places`.
|
|
215
|
+
* The `wakusei-place` event's detail carries the landing site as `site` where the place is one. Setting it writes the attribute.
|
|
216
|
+
*/
|
|
217
|
+
get siteFlags(): boolean;
|
|
218
|
+
set siteFlags(on: boolean);
|
|
200
219
|
/** The marks laid on the body looked at now: each place's id, its layer and where its mark is, in CSS pixels from the view's top left. */
|
|
201
220
|
get placesShown(): readonly {
|
|
202
221
|
id: string;
|
|
@@ -396,11 +415,13 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
396
415
|
get orbiterTrack(): boolean;
|
|
397
416
|
set orbiterTrack(value: boolean);
|
|
398
417
|
/**
|
|
399
|
-
* What a body behind another gets (the attribute `covered`): `
|
|
400
|
-
* disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted
|
|
418
|
+
* What a body behind another gets (the attribute `covered`): `hide` (the default) fades its floating name and ring out while its place is inside a nearer body's drawn disc, and back when it comes out, as if the disc hid
|
|
419
|
+
* them; `arrow` draws instead one small quiet arrow just outside the disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted
|
|
420
|
+
* (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out; `name` draws the name and ring over the nearer body's disc as 0.57 and earlier did. The same discs hide the Oort cloud's note, the
|
|
421
|
+
* marks of the places on a body that is behind another, and, through `coveredAt`, any label a page draws over the view.
|
|
401
422
|
*/
|
|
402
|
-
get covered():
|
|
403
|
-
set covered(value:
|
|
423
|
+
get covered(): Covered;
|
|
424
|
+
set covered(value: Covered);
|
|
404
425
|
/**
|
|
405
426
|
* Keep a body's floating name and dot while its name is drawn on its globe (the attribute `labels-always`; off by default). Off, a body that carries its drawn name (`body-label` on, and the body at least 24 CSS pixels in
|
|
406
427
|
* radius) fades its floating name and dot out, and they fade back when it shrinks below that; bodies with no drawn name keep their floating names.
|
|
@@ -783,6 +804,15 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
783
804
|
};
|
|
784
805
|
/** Where a body is on the screen now: its centre and radius in CSS pixels in the element, or `null` when it is behind the camera or not drawn. */
|
|
785
806
|
placeOf(id: BodyId): BodyPlace | null;
|
|
807
|
+
/**
|
|
808
|
+
* Which body's drawn disc hides a point of the scene at the last draw, or `null`: for a page that draws its own label over the view (a belt's name at its anchor, a pin) and wants it to go where a nearer body is in
|
|
809
|
+
* front of it, the way the view's own names do. The point is in the scene's places (`stats.camera` is in the same ones); the discs are the bodies and moons placed on the screen, at the radius `placeOf(id).r`
|
|
810
|
+
* gives. Always `null` while `labels` is off, since the discs are worked out with the names.
|
|
811
|
+
*
|
|
812
|
+
* @param point - A place in the scene.
|
|
813
|
+
* @returns The id of the covering body, or `null` when the point is in the open or off the view.
|
|
814
|
+
*/
|
|
815
|
+
coveredAt(point: readonly [number, number, number]): string | null;
|
|
786
816
|
/** True for the full-screen mode (the `immersive` attribute): the element fills its box in any shape, a plain wheel zooms instead of scrolling the page, and a touch drag turns the view instead of scrolling it. */
|
|
787
817
|
get immersive(): boolean;
|
|
788
818
|
set immersive(value: boolean);
|
package/dist/space/element.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createGameClock } from "./clock.js";
|
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
|
|
8
8
|
import { sightChanged, sightOf, withinMargin } from "./sight.js";
|
|
9
9
|
import { chooseLabels, nameSpot } from "./labels.js";
|
|
10
|
-
import { coverArrows } from "./covered.js";
|
|
10
|
+
import { coverArrows, coverOf } from "./covered.js";
|
|
11
11
|
import { createPainter, picturesPending } from "../scene/painter.js";
|
|
12
12
|
import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
|
|
13
13
|
import { createDoorHost } from "../door/host.js";
|
|
@@ -41,6 +41,7 @@ const SCALE_WORDS = {
|
|
|
41
41
|
};
|
|
42
42
|
/** A body whose disc is smaller than this many CSS pixels across its radius is marked with a ring as well as its name. */
|
|
43
43
|
const RING_BELOW_PX = 4;
|
|
44
|
+
const readCovered = (value) => (value === "arrow" ? "arrow" : value === "name" ? "name" : "hide");
|
|
44
45
|
/** The id of the package's own source of the belts: it is in every view, but is not one of `sources`. */
|
|
45
46
|
const BELTS_SOURCE_ID = "wakusei-belts";
|
|
46
47
|
/** The belts the attribute `belts` names: all of them where it is left out or says `all`, none for `off`, else a list of names separated by commas or spaces. */
|
|
@@ -107,7 +108,7 @@ const readBody = (value) => {
|
|
|
107
108
|
* 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.9 nothing moves; 3.6 is where the finest map tiles of the Earth, Mars and the Moon (16384 pixels round) run out of detail too, so it is the same ceiling for both.
|
|
108
109
|
*/
|
|
109
110
|
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
|
|
110
|
-
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
111
|
+
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none;transition:opacity .35s ease}.sp-oort[data-covered]{opacity:0}@media (prefers-reduced-motion:reduce){.sp-oort{transition:none}}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
|
|
111
112
|
const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
|
|
112
113
|
/**
|
|
113
114
|
* The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
|
|
@@ -142,7 +143,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
|
|
|
142
143
|
* ```
|
|
143
144
|
*/
|
|
144
145
|
export class WakuseiSpace extends HTMLElement {
|
|
145
|
-
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
|
|
146
|
+
static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
|
|
146
147
|
#model = newSpaceModel();
|
|
147
148
|
#allMoons = false;
|
|
148
149
|
#catalogue;
|
|
@@ -209,7 +210,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
209
210
|
this.#model.moonSize = readMoonSize(this.getAttribute("moon-size") ?? 2);
|
|
210
211
|
this.#model.labels = this.getAttribute("labels") !== "off";
|
|
211
212
|
this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
|
|
212
|
-
this.#covered = this.getAttribute("covered")
|
|
213
|
+
this.#covered = readCovered(this.getAttribute("covered"));
|
|
213
214
|
this.roadster = this.hasAttribute("roadster") && this.getAttribute("roadster") !== "off";
|
|
214
215
|
const craft = this.getAttribute("spacecraft");
|
|
215
216
|
if (craft !== null && craft !== "off")
|
|
@@ -368,7 +369,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
368
369
|
else if (name === "labels-always")
|
|
369
370
|
this.labelsAlways = value !== null && value !== "off";
|
|
370
371
|
else if (name === "covered")
|
|
371
|
-
this.covered = value
|
|
372
|
+
this.covered = readCovered(value);
|
|
372
373
|
else if (name === "roadster")
|
|
373
374
|
this.roadster = value !== null && value !== "off";
|
|
374
375
|
else if (name === "spacecraft")
|
|
@@ -421,7 +422,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
421
422
|
}
|
|
422
423
|
else if (NAME_LABEL_ATTRIBUTES.includes(name))
|
|
423
424
|
this.#relabel();
|
|
424
|
-
if (name === "places" || name === "lang" || name === "surface-names")
|
|
425
|
+
if (name === "places" || name === "site-flags" || name === "lang" || name === "surface-names")
|
|
425
426
|
this.#markSurface();
|
|
426
427
|
if (name === "earth-places" || name === "earth-places-look")
|
|
427
428
|
this.#askEarthPlaces();
|
|
@@ -439,6 +440,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
439
440
|
else
|
|
440
441
|
this.setAttribute("places", layers.join(" "));
|
|
441
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* Whether the places carry their country's flag (the attribute `site-flags`): the tip of a place with a country shows its flag, and on a body close enough on the screen (110 pixels of radius) the landing sites (`LANDING_SITES` from
|
|
445
|
+
* `/landing-sites`) are named beside their dots, each with its flag. The flag is `<hata-flag>` from `@johnmorrisdotca/hata`, which the page imports itself (`import "@johnmorrisdotca/hata/element/define"`); until it is defined the name stands alone. Needs `places`.
|
|
446
|
+
* The `wakusei-place` event's detail carries the landing site as `site` where the place is one. Setting it writes the attribute.
|
|
447
|
+
*/
|
|
448
|
+
get siteFlags() {
|
|
449
|
+
return this.hasAttribute("site-flags");
|
|
450
|
+
}
|
|
451
|
+
set siteFlags(on) {
|
|
452
|
+
this.toggleAttribute("site-flags", on);
|
|
453
|
+
}
|
|
442
454
|
/** The marks laid on the body looked at now: each place's id, its layer and where its mark is, in CSS pixels from the view's top left. */
|
|
443
455
|
get placesShown() {
|
|
444
456
|
return this.#markLayer?.shown ?? [];
|
|
@@ -701,6 +713,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
701
713
|
this.#earthLayer?.clear();
|
|
702
714
|
this.#earthOmitted = 0;
|
|
703
715
|
};
|
|
716
|
+
if (surface !== null && this.#covered !== "name" && this.#places?.["earth"]?.behind !== undefined)
|
|
717
|
+
return clear();
|
|
704
718
|
if (surface === null || root === null || using === undefined || !this.hasAttribute("earth-places") || !(surface.radiusPx >= EARTH_PLACES_FROM_PX))
|
|
705
719
|
return clear();
|
|
706
720
|
const places = this.#readEarthPlaces();
|
|
@@ -740,6 +754,11 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
740
754
|
const names = readSurfaceNames(this.getAttribute("surface-names"));
|
|
741
755
|
const surface = this.#surface;
|
|
742
756
|
const root = this.shadowRoot;
|
|
757
|
+
// the marks lie on the body looked at: not drawn while a nearer body's disc is over it
|
|
758
|
+
if (surface !== null && this.#covered !== "name" && this.#places?.[surface.id]?.behind !== undefined) {
|
|
759
|
+
this.#markLayer?.clear();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
743
762
|
if ((!names.on && layers.length === 0) || surface === null || root === null || !PLACE_BODIES.includes(surface.id)) {
|
|
744
763
|
if (!names.on && layers.length === 0 && this.#markLayer !== undefined) {
|
|
745
764
|
this.#markLayer.dispose();
|
|
@@ -769,7 +788,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
769
788
|
if (this.#markLayer === undefined) {
|
|
770
789
|
this.#markLayer = createPlaceLayer(root, {
|
|
771
790
|
lang: () => (this.getAttribute("lang") === "ja" ? "ja" : "en"),
|
|
772
|
-
|
|
791
|
+
flags: () => this.hasAttribute("site-flags"),
|
|
792
|
+
pick: (place, site, at) => this.dispatchEvent(new CustomEvent("wakusei-place", { detail: { body: id, place, site, x: at.x, y: at.y }, bubbles: true, composed: true })),
|
|
773
793
|
});
|
|
774
794
|
if (this.getAttribute("role") === "img")
|
|
775
795
|
this.setAttribute("role", "group");
|
|
@@ -782,7 +802,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
782
802
|
for (const [other, at] of Object.entries(this.#places ?? {}))
|
|
783
803
|
if (at !== null && other !== id)
|
|
784
804
|
keepClear.push({ x: at.x, y: at.y, halfWidth: 8, halfHeight: 8 });
|
|
785
|
-
this.#markLayer.set(marksToShow(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm, names, keepClear, this.getAttribute("lang") === "ja" ? "ja" : "en"));
|
|
805
|
+
this.#markLayer.set(marksToShow(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm, names, keepClear, this.getAttribute("lang") === "ja" ? "ja" : "en"), surface.radiusPx);
|
|
786
806
|
}
|
|
787
807
|
#bodyLabel;
|
|
788
808
|
/**
|
|
@@ -1073,11 +1093,13 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1073
1093
|
this.#model.orbiterTrack = value;
|
|
1074
1094
|
this.#gate?.request();
|
|
1075
1095
|
}
|
|
1076
|
-
#covered = "
|
|
1096
|
+
#covered = "hide";
|
|
1077
1097
|
#arrows = new Map();
|
|
1078
1098
|
/**
|
|
1079
|
-
* What a body behind another gets (the attribute `covered`): `
|
|
1080
|
-
* disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted
|
|
1099
|
+
* What a body behind another gets (the attribute `covered`): `hide` (the default) fades its floating name and ring out while its place is inside a nearer body's drawn disc, and back when it comes out, as if the disc hid
|
|
1100
|
+
* them; `arrow` draws instead one small quiet arrow just outside the disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted
|
|
1101
|
+
* (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out; `name` draws the name and ring over the nearer body's disc as 0.57 and earlier did. The same discs hide the Oort cloud's note, the
|
|
1102
|
+
* marks of the places on a body that is behind another, and, through `coveredAt`, any label a page draws over the view.
|
|
1081
1103
|
*/
|
|
1082
1104
|
get covered() {
|
|
1083
1105
|
return this.#covered;
|
|
@@ -1086,6 +1108,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1086
1108
|
this.#covered = value;
|
|
1087
1109
|
if (this.#places)
|
|
1088
1110
|
this.#placeLabels(this.#places);
|
|
1111
|
+
this.#placeOort();
|
|
1089
1112
|
}
|
|
1090
1113
|
#labelsAlways = false;
|
|
1091
1114
|
/**
|
|
@@ -1629,12 +1652,14 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1629
1652
|
return out;
|
|
1630
1653
|
}
|
|
1631
1654
|
/**
|
|
1632
|
-
* The controls' yaw and tilt that look at a body from the side the camera comes from, swung so a companion is in the picture and the body stays at least half lit; null
|
|
1655
|
+
* The controls' yaw and tilt that look at a body from the side the camera comes from, swung so a companion is in the picture and the body stays at least half lit; null for the Earth before the camera has drawn.
|
|
1633
1656
|
* The reader's own later turn is not touched: this runs for an arrival and for a double click, not for a drag.
|
|
1634
1657
|
*/
|
|
1635
1658
|
#faceApproach(id, swing = true) {
|
|
1636
1659
|
const model = this.#model;
|
|
1637
|
-
|
|
1660
|
+
// a move asked for before the first draw (an address that opens at a body, `goTo` on a page that has just loaded) comes from where the view opens, the Earth: its camera is not drawn yet, and with no side
|
|
1661
|
+
// chosen the body is looked at from whichever side the default aim falls on, which for a body beyond the Earth is the night side half the day
|
|
1662
|
+
if (!model.pose.valid && id === "earth")
|
|
1638
1663
|
return null;
|
|
1639
1664
|
const body = this.#site(id);
|
|
1640
1665
|
const sun = id === "sun" ? undefined : this.#site("sun").at;
|
|
@@ -1979,6 +2004,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1979
2004
|
this.#showNote();
|
|
1980
2005
|
if (this.#oortLabel.hidden)
|
|
1981
2006
|
this.#oortLabel.hidden = false;
|
|
2007
|
+
// the note fades out while a nearer body's disc is over its place
|
|
2008
|
+
const behind = this.#covered !== "name" && coverOf(at, this.#model.discs) !== null;
|
|
2009
|
+
if (this.#oortLabel.hasAttribute("data-covered") !== behind)
|
|
2010
|
+
this.#oortLabel.toggleAttribute("data-covered", behind);
|
|
1982
2011
|
this.#oortLabel.style.transform = `translate(${Math.round(at.x) + 6}px,${Math.round(at.y) - 8}px)`;
|
|
1983
2012
|
}
|
|
1984
2013
|
/** What the camera is riding along with now, or null. */
|
|
@@ -2178,7 +2207,8 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2178
2207
|
// beside the dot, on the side that stays inside the view
|
|
2179
2208
|
const { x, y, flipped } = nameSpot(at, { width, height: 16 }, frame);
|
|
2180
2209
|
// a body that carries its drawn name gives its floating name up (it fades, and leaves its place to the others) unless the page keeps both; a body behind another gives it up for the arrow
|
|
2181
|
-
const
|
|
2210
|
+
const hidden = at.behind !== undefined && this.#covered === "hide";
|
|
2211
|
+
const carried = hidden || (at.named === true && !this.#labelsAlways);
|
|
2182
2212
|
const covered = at.behind !== undefined && this.#covered === "arrow";
|
|
2183
2213
|
if (covered)
|
|
2184
2214
|
continue;
|
|
@@ -2439,6 +2469,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2439
2469
|
const at = this.#places?.[id];
|
|
2440
2470
|
return at ? { ...at } : null;
|
|
2441
2471
|
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Which body's drawn disc hides a point of the scene at the last draw, or `null`: for a page that draws its own label over the view (a belt's name at its anchor, a pin) and wants it to go where a nearer body is in
|
|
2474
|
+
* front of it, the way the view's own names do. The point is in the scene's places (`stats.camera` is in the same ones); the discs are the bodies and moons placed on the screen, at the radius `placeOf(id).r`
|
|
2475
|
+
* gives. Always `null` while `labels` is off, since the discs are worked out with the names.
|
|
2476
|
+
*
|
|
2477
|
+
* @param point - A place in the scene.
|
|
2478
|
+
* @returns The id of the covering body, or `null` when the point is in the open or off the view.
|
|
2479
|
+
*/
|
|
2480
|
+
coveredAt(point) {
|
|
2481
|
+
return this.#model.coverAt([point[0], point[1], point[2]]);
|
|
2482
|
+
}
|
|
2442
2483
|
#nameLabel(button, id) {
|
|
2443
2484
|
const text = this.#nameOf(id);
|
|
2444
2485
|
button.textContent = text;
|
package/dist/space/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf, type SpaceK
|
|
|
7
7
|
export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
|
|
8
8
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, helpSpin, readHelpPlace, spinArrow, type HelpPlace, type OrbitArrow } from "./arrows.ts";
|
|
9
9
|
export { spinAxis, type SpinAxis } from "./spin.ts";
|
|
10
|
-
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
|
|
10
|
+
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, coverOf, type CoverArrow, type CoverEntry } from "./covered.ts";
|
|
11
11
|
export { TRAVEL_BUDGET_MS, TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
|
|
12
12
|
export { bodyBasis, carry, controlsFor, directionBetween, FRAMES, hasRotation, holdSite, keepClear, pairAxis, pairBasis, readFrame, type FrameKind, type HoldBasis } from "./hold.ts";
|
|
13
13
|
export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf } from "./bo
|
|
|
8
8
|
export { besideMoon, BESIDE_RADII } from "./beside.js";
|
|
9
9
|
export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, helpSpin, readHelpPlace, spinArrow } from "./arrows.js";
|
|
10
10
|
export { spinAxis } from "./spin.js";
|
|
11
|
-
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
|
|
11
|
+
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, coverOf } from "./covered.js";
|
|
12
12
|
export { TRAVEL_BUDGET_MS, TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
13
13
|
export { bodyBasis, carry, controlsFor, directionBetween, FRAMES, hasRotation, holdSite, keepClear, pairAxis, pairBasis, readFrame } from "./hold.js";
|
|
14
14
|
export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { type PaintLabel, type WakuseiPainter } from "../scene/painter.ts";
|
|
|
9
9
|
import "../bodies/all.ts";
|
|
10
10
|
import { type Vec3 } from "../vec.ts";
|
|
11
11
|
import { type HelpPlace, type OrbitArrow } from "./arrows.ts";
|
|
12
|
+
import { type CoverEntry } from "./covered.ts";
|
|
12
13
|
import type { SightInput } from "./sight.ts";
|
|
13
14
|
import { type SpaceDwarf, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
14
15
|
import { type PaintSpec, type PaintTrail } from "../paint/trail.ts";
|
|
@@ -319,7 +320,11 @@ export interface SpaceModel {
|
|
|
319
320
|
oort: {
|
|
320
321
|
x: number;
|
|
321
322
|
y: number;
|
|
323
|
+
distance: number;
|
|
322
324
|
} | null;
|
|
325
|
+
/** The drawn discs at the last draw (the bodies and moons placed on the screen, with their distances from the camera), and which of them hides a point of the scene (in the scene's absolute places), or null when none does. */
|
|
326
|
+
discs: readonly CoverEntry[];
|
|
327
|
+
coverAt: (point: Vec3) => string | null;
|
|
323
328
|
/** How many frames the ephemeris has worked out. */
|
|
324
329
|
lookups: number;
|
|
325
330
|
/** Pixels a game-second moves things on the screen (the fastest turning body in sight): the draw rate follows it. */
|
package/dist/space/scene.js
CHANGED
|
@@ -12,7 +12,7 @@ import { groundDirection } from "./aim.js";
|
|
|
12
12
|
import { hostOf } from "./bodies.js";
|
|
13
13
|
import { arrowSites, ARROWS_PER_ORBIT, chevron, helpSpin, MAX_ARROWS_PER_ORBIT } from "./arrows.js";
|
|
14
14
|
import { besideMoon } from "./beside.js";
|
|
15
|
-
import { coveredBy } from "./covered.js";
|
|
15
|
+
import { coveredBy, coverOf } from "./covered.js";
|
|
16
16
|
import { spinAxis } from "./spin.js";
|
|
17
17
|
import { createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
18
18
|
import { createPaintOverlay } from "./paint-overlay.js";
|
|
@@ -170,6 +170,8 @@ export const newSpaceModel = () => ({
|
|
|
170
170
|
door: { points: 0, belts: 0, draws: 0, used: {} },
|
|
171
171
|
belts: BELT_IDS,
|
|
172
172
|
oort: null,
|
|
173
|
+
discs: [],
|
|
174
|
+
coverAt: () => null,
|
|
173
175
|
lookups: 0,
|
|
174
176
|
motion: 0,
|
|
175
177
|
drawnView: null,
|
|
@@ -852,7 +854,7 @@ export function createSpaceItem(model, deps) {
|
|
|
852
854
|
const off = projected.x * projected.x + projected.y * projected.y;
|
|
853
855
|
if (off < best) {
|
|
854
856
|
best = off;
|
|
855
|
-
model.oort = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height };
|
|
857
|
+
model.oort = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, distance: Math.hypot(oortPositions[i * 3] - camera.position.x, oortPositions[i * 3 + 1] - camera.position.y, oortPositions[i * 3 + 2] - camera.position.z) };
|
|
856
858
|
}
|
|
857
859
|
}
|
|
858
860
|
}
|
|
@@ -1314,8 +1316,23 @@ export function createSpaceItem(model, deps) {
|
|
|
1314
1316
|
}
|
|
1315
1317
|
for (const [id, cover] of coveredBy(entries))
|
|
1316
1318
|
places[id].behind = cover;
|
|
1319
|
+
// a point of the scene that a page labels (a belt's name at its anchor) is hidden by the same discs
|
|
1320
|
+
model.discs = entries;
|
|
1321
|
+
model.coverAt = (point) => {
|
|
1322
|
+
// in front of the camera, whatever the far plane cuts: a belt's name is labelled far beyond what is drawn
|
|
1323
|
+
projected.set(point[0] - origin[0], point[1] - origin[1], point[2] - origin[2]).applyMatrix4(camera.matrixWorldInverse);
|
|
1324
|
+
if (!(projected.z < 0))
|
|
1325
|
+
return null;
|
|
1326
|
+
const distance = Math.hypot(projected.x, projected.y, projected.z);
|
|
1327
|
+
projected.applyMatrix4(camera.projectionMatrix);
|
|
1328
|
+
return coverOf({ x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, distance }, entries);
|
|
1329
|
+
};
|
|
1317
1330
|
deps.onLabels(places);
|
|
1318
1331
|
}
|
|
1332
|
+
else {
|
|
1333
|
+
model.discs = [];
|
|
1334
|
+
model.coverAt = () => null;
|
|
1335
|
+
}
|
|
1319
1336
|
// after the names: the places on the Earth keep clear of them
|
|
1320
1337
|
if (deps.onEarth && (deps.wantEarth?.() ?? false)) {
|
|
1321
1338
|
const earth = rideFrom ? undefined : slots.get("earth")?.drawing;
|