@johnmorrisdotca/wakusei-planets 0.28.0 → 0.31.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 +30 -0
- package/NOTICE.md +20 -0
- package/README.md +61 -16
- package/dist/embed.d.ts +64 -0
- package/dist/embed.js +66 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/lineup/data.d.ts +160 -0
- package/dist/lineup/data.js +303 -0
- package/dist/lineup/element.d.ts +99 -0
- package/dist/lineup/element.js +782 -0
- package/dist/lineup/labels.d.ts +141 -0
- package/dist/lineup/labels.js +155 -0
- package/dist/lineup/layout.d.ts +174 -0
- package/dist/lineup/layout.js +162 -0
- package/dist/lineup/scene3d.d.ts +47 -0
- package/dist/lineup/scene3d.js +155 -0
- package/dist/portrait/element.d.ts +5 -2
- package/dist/portrait/element.js +57 -6
- package/dist/portrait/scene3d.d.ts +13 -0
- package/dist/portrait/scene3d.js +21 -2
- package/dist/scene/body.d.ts +3 -1
- package/dist/scene/body.js +2 -1
- package/dist/scene/detail.d.ts +8 -2
- package/dist/scene/detail.js +56 -28
- package/dist/scene/painter.d.ts +32 -0
- package/dist/scene/painter.js +94 -10
- package/dist/scene/textures.d.ts +4 -2
- package/dist/scene/textures.js +2 -0
- package/dist/scene/tiles.d.ts +46 -0
- package/dist/scene/tiles.js +165 -19
- package/dist/space/arrows.d.ts +87 -0
- package/dist/space/arrows.js +117 -0
- package/dist/space/beside.d.ts +74 -0
- package/dist/space/beside.js +76 -0
- package/dist/space/bodies.d.ts +83 -0
- package/dist/space/bodies.js +93 -0
- package/dist/space/clock.d.ts +31 -0
- package/dist/space/clock.js +45 -0
- package/dist/space/element.d.ts +98 -15
- package/dist/space/element.js +320 -63
- package/dist/space/frame.d.ts +45 -2
- package/dist/space/frame.js +56 -4
- package/dist/space/index.d.ts +6 -1
- package/dist/space/index.js +6 -1
- package/dist/space/labels.d.ts +52 -0
- package/dist/space/labels.js +40 -0
- package/dist/space/scale.d.ts +5 -5
- package/dist/space/scale.js +10 -4
- package/dist/space/scene.d.ts +50 -9
- package/dist/space/scene.js +313 -36
- package/dist/space/spin.d.ts +37 -0
- package/dist/space/spin.js +29 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -1
package/dist/space/element.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
2
2
|
import { BODIES, MOONS_OF } from "../facts.js";
|
|
3
3
|
import { createGate, frameCap } from "../gate.js";
|
|
4
|
+
import { createGameClock } from "./clock.js";
|
|
5
|
+
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER } from "./bodies.js";
|
|
6
|
+
import { chooseLabels } from "./labels.js";
|
|
4
7
|
import { createPainter } from "../scene/painter.js";
|
|
5
8
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
6
|
-
import { texturePaths } from "../scene/textures.js";
|
|
7
|
-
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_PLANETS } from "./frame.js";
|
|
9
|
+
import { texturePaths, tilesBase } from "../scene/textures.js";
|
|
10
|
+
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_DWARFS, SPACE_PLANETS } from "./frame.js";
|
|
11
|
+
import { moonOffset } from "../scene/orient.js";
|
|
8
12
|
import { moonDistance, placeBodies, radiusIn } from "./scale.js";
|
|
9
13
|
import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
10
14
|
export { setThreeLoader, SPACE_BODIES };
|
|
15
|
+
/** The words the view says on itself for the scale in use. A page in another language gives its own with `scaleNames`. */
|
|
16
|
+
const SCALE_WORDS = {
|
|
17
|
+
en: { true: "True distances", compressed: "Distances squeezed to fit" },
|
|
18
|
+
ja: { true: "本当の距離", compressed: "距離を縮めて表示" },
|
|
19
|
+
};
|
|
20
|
+
/** A body whose disc is smaller than this many CSS pixels across its radius is marked with a ring as well as its name. */
|
|
21
|
+
const RING_BELOW_PX = 4;
|
|
11
22
|
const readLight = (value) => (value === "lit" ? "lit" : "sun");
|
|
12
23
|
const RAD = Math.PI / 180;
|
|
13
24
|
const REAL_TIME_TICK_MS = 60_000;
|
|
25
|
+
/** The plain wheel in an immersive view is passed on as a pinch of this share, so a notch (100) zooms about 1.2 times, as the family's mouse wheel does with Alt. */
|
|
26
|
+
const WHEEL_AS_PINCH = 0.2;
|
|
14
27
|
/** The least time between two `wakusei-timechange` events while time runs: a few a second at most, however fast the picture is drawn. */
|
|
15
28
|
const TIME_EVENT_MS = 250;
|
|
16
29
|
const readCentre = (value) => {
|
|
@@ -27,22 +40,26 @@ const readTime = (value) => {
|
|
|
27
40
|
const ms = Date.parse(value);
|
|
28
41
|
return Number.isFinite(ms) ? ms : "now";
|
|
29
42
|
};
|
|
43
|
+
/** A body the view can put at its middle: the eleven of `SPACE_BODIES` and the moons of the planets in them. */
|
|
44
|
+
const canCentre = (id) => SPACE_BODIES.includes(id) || (BODIES[id].kind === "moon" && SPACE_BODIES.includes(hostOf(id) ?? ""));
|
|
30
45
|
const readBody = (value) => {
|
|
31
|
-
const id = value
|
|
32
|
-
return
|
|
46
|
+
const id = findBody(value);
|
|
47
|
+
return id !== undefined && canCentre(id) ? id : undefined;
|
|
33
48
|
};
|
|
34
49
|
/**
|
|
35
50
|
* The zoom range of the space view when it carries its own controls. The floor, a millionth, takes the camera out past Neptune in the true scale. The ceiling is where the camera reaches the body: it is held at
|
|
36
|
-
* 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.
|
|
51
|
+
* 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.
|
|
37
52
|
*/
|
|
38
|
-
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3, tiltMax: 90 };
|
|
39
|
-
const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}#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[hidden]{display:none}</style><div id="stage"></div><div id="labels"></div>`;
|
|
53
|
+
const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
|
|
54
|
+
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[hidden]{display: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}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p>`;
|
|
40
55
|
/**
|
|
41
56
|
* 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`
|
|
42
57
|
* (`"lon,lat"`), `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `look` (`realistic` or `painted`),
|
|
43
|
-
* `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base
|
|
58
|
+
* `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base`, `max-texture` and `tiles` (where the finer map tiles are, for a close zoom; `off` for none). Positions come from this package's own models. It draws
|
|
44
59
|
* only when something changes, and nothing while it is out of sight.
|
|
45
60
|
*
|
|
61
|
+
* `immersive` makes it a full-screen view: it fills the box it is in, whatever the shape (the body looked at is framed by the shorter side), the plain wheel zooms and a drag anywhere on it turns it. Without it Ctrl, Command or Alt with the wheel zooms and the plain wheel scrolls the page.
|
|
62
|
+
*
|
|
46
63
|
* It carries the shared view controls itself: a drag turns the camera round the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page), and the arrow keys, + and - and 0 work once it is
|
|
47
64
|
* focused. `controls="none"` turns them off; `zoom-min` and `zoom-max` set the range (a millionth to 3 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
|
|
48
65
|
*
|
|
@@ -64,10 +81,9 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
|
|
|
64
81
|
* ```
|
|
65
82
|
*/
|
|
66
83
|
export class WakuseiSpace extends HTMLElement {
|
|
67
|
-
static observedAttributes = ["center", "time", "speed", "scale", "labels", "orbits", "look", "light", "lang"];
|
|
84
|
+
static observedAttributes = ["center", "time", "speed", "scale", "labels", "orbits", "help", "look", "light", "lang"];
|
|
68
85
|
#model = newSpaceModel();
|
|
69
|
-
#
|
|
70
|
-
#speed = 1;
|
|
86
|
+
#clock = createGameClock("now", 1);
|
|
71
87
|
#view;
|
|
72
88
|
#gate;
|
|
73
89
|
#taken;
|
|
@@ -75,11 +91,14 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
75
91
|
#labelBox;
|
|
76
92
|
#state = "loading";
|
|
77
93
|
#timer;
|
|
78
|
-
#last = 0;
|
|
79
94
|
#announced = -Infinity;
|
|
80
95
|
#pool = new Map();
|
|
81
96
|
#places;
|
|
82
97
|
#names = {};
|
|
98
|
+
#selected = null;
|
|
99
|
+
#scaleNames = {};
|
|
100
|
+
#rings = new Map();
|
|
101
|
+
#scaleLine;
|
|
83
102
|
#hint = "choose to look at it";
|
|
84
103
|
#painter;
|
|
85
104
|
#focusBeforeRide = "earth";
|
|
@@ -91,15 +110,15 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
91
110
|
}
|
|
92
111
|
connectedCallback() {
|
|
93
112
|
this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
|
|
94
|
-
this.#
|
|
95
|
-
this.#model.time = this.#
|
|
96
|
-
this.#
|
|
97
|
-
this.#model.mode = this.getAttribute("scale") === "true" ? "true" : "compressed";
|
|
113
|
+
this.#clock = createGameClock(readTime(this.getAttribute("time")), this.#readSpeed());
|
|
114
|
+
this.#model.time = this.#clock.time;
|
|
115
|
+
this.#model.mode = this.getAttribute("scale") === "compressed" ? "compressed" : "true";
|
|
98
116
|
this.#model.labels = this.getAttribute("labels") !== "off";
|
|
99
117
|
this.#model.orbits = this.getAttribute("orbits") !== "off";
|
|
118
|
+
this.#model.help = this.hasAttribute("help") && this.getAttribute("help") !== "off";
|
|
100
119
|
this.#model.look = this.getAttribute("look") === "painted" ? "painted" : "realistic";
|
|
101
120
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
102
|
-
this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
|
|
121
|
+
this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
|
|
103
122
|
if (!this.hasAttribute("role"))
|
|
104
123
|
this.setAttribute("role", "img");
|
|
105
124
|
if (!this.hasAttribute("tabindex"))
|
|
@@ -110,7 +129,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
110
129
|
root.innerHTML = STYLE;
|
|
111
130
|
this.#stage = root.getElementById("stage");
|
|
112
131
|
this.#labelBox = root.getElementById("labels");
|
|
132
|
+
this.#scaleLine = root.querySelector(".sp-scale");
|
|
133
|
+
this.#nameScale();
|
|
113
134
|
this.#pool.clear();
|
|
135
|
+
this.#rings.clear();
|
|
114
136
|
const nav = navigator;
|
|
115
137
|
this.#gate = createGate(1000 / frameCap(30, { deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency }), () => this.#view?.invalidate());
|
|
116
138
|
this.#stage.addEventListener("webglcontextlost", this.#lost, true);
|
|
@@ -124,6 +146,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
124
146
|
painter: () => this.#painterNow(),
|
|
125
147
|
cap: () => this.#textureCap(),
|
|
126
148
|
invalidate: () => this.#gate?.request(),
|
|
149
|
+
advance: () => this.#advance(),
|
|
127
150
|
onLabels: (places) => this.#placeLabels(places),
|
|
128
151
|
onMoving: () => this.#gate?.request(),
|
|
129
152
|
onRideLost: () => this.#rideLost(),
|
|
@@ -139,9 +162,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
139
162
|
else if (this.#state === "loading")
|
|
140
163
|
this.#set("unavailable");
|
|
141
164
|
});
|
|
142
|
-
this.#last = performance.now();
|
|
143
165
|
this.#schedule();
|
|
144
166
|
this.addEventListener("pointerdown", this.#down);
|
|
167
|
+
// before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
|
|
168
|
+
this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
|
|
145
169
|
this.#hands = carryControls(this, { limits: CARRIED_LIMITS, onChange: (view, info) => this.setView(view, info.final) });
|
|
146
170
|
this.#labelBox.addEventListener("click", this.#labelClick);
|
|
147
171
|
this.#labelBox.addEventListener("focusin", this.#labelFocus);
|
|
@@ -150,6 +174,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
150
174
|
this.#hands?.unbind();
|
|
151
175
|
this.#hands = undefined;
|
|
152
176
|
this.removeEventListener("pointerdown", this.#down);
|
|
177
|
+
this.removeEventListener("wheel", this.#wheel, { capture: true });
|
|
153
178
|
window.removeEventListener("pointerup", this.#up, true);
|
|
154
179
|
clearTimeout(this.#timer);
|
|
155
180
|
this.#timer = undefined;
|
|
@@ -167,18 +192,22 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
167
192
|
else if (name === "speed")
|
|
168
193
|
this.speed = this.#readSpeed();
|
|
169
194
|
else if (name === "scale")
|
|
170
|
-
this.scale = value === "
|
|
195
|
+
this.scale = value === "compressed" ? "compressed" : "true";
|
|
171
196
|
else if (name === "labels")
|
|
172
197
|
this.labels = value !== "off";
|
|
173
198
|
else if (name === "orbits")
|
|
174
199
|
this.orbits = value !== "off";
|
|
200
|
+
else if (name === "help")
|
|
201
|
+
this.help = value !== null && value !== "off";
|
|
175
202
|
else if (name === "look")
|
|
176
203
|
this.look = value === "painted" ? "painted" : "realistic";
|
|
177
204
|
else if (name === "light")
|
|
178
205
|
this.light = readLight(value);
|
|
179
|
-
else if (name === "lang")
|
|
206
|
+
else if (name === "lang") {
|
|
180
207
|
for (const [id, button] of this.#pool)
|
|
181
208
|
this.#nameLabel(button, id);
|
|
209
|
+
this.#nameScale();
|
|
210
|
+
}
|
|
182
211
|
}
|
|
183
212
|
/** The home place the camera starts above, as longitude and latitude in degrees. */
|
|
184
213
|
get centre() {
|
|
@@ -190,48 +219,56 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
190
219
|
}
|
|
191
220
|
/** The moment shown: milliseconds since the epoch, or "now" to follow the clock. Setting it points the camera at the same place on the ground again. */
|
|
192
221
|
get time() {
|
|
222
|
+
this.#advance();
|
|
193
223
|
return this.#model.time;
|
|
194
224
|
}
|
|
195
225
|
set time(value) {
|
|
196
|
-
this.#
|
|
197
|
-
this.#model.time = this.#
|
|
226
|
+
this.#clock.set(value instanceof Date ? value.getTime() : value);
|
|
227
|
+
this.#model.time = this.#clock.time;
|
|
198
228
|
this.#model.anchor = null;
|
|
199
|
-
this.#last = performance.now();
|
|
200
229
|
this.#schedule();
|
|
201
230
|
this.#gate?.request();
|
|
202
231
|
}
|
|
203
232
|
/** Seconds of game time per second: 1 is real time, 0 holds still, negative runs backwards. */
|
|
204
233
|
get speed() {
|
|
205
|
-
return this.#speed;
|
|
234
|
+
return this.#clock.speed;
|
|
206
235
|
}
|
|
207
236
|
set speed(value) {
|
|
208
|
-
// time up to this moment is worked out at the old speed, so a hold keeps the moment the reader saw last
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
|
|
214
|
-
this.#last = performance.now();
|
|
237
|
+
// time up to this moment is worked out at the old speed (the clock does that), so a hold keeps the moment the reader saw last
|
|
238
|
+
const was = this.#clock.speed;
|
|
239
|
+
this.#clock.setSpeed(value);
|
|
240
|
+
if (this.isConnected)
|
|
241
|
+
this.#model.time = this.#clock.time;
|
|
242
|
+
this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
|
|
215
243
|
this.#schedule();
|
|
216
244
|
this.#gate?.request();
|
|
217
|
-
if (this.#speed === 0 && was !== 0)
|
|
245
|
+
if (this.#clock.speed === 0 && was !== 0)
|
|
218
246
|
this.#announce(false);
|
|
219
247
|
}
|
|
220
|
-
/** `
|
|
248
|
+
/** `true` (the default: real distances and sizes; a body too small to see is marked with a ring and its name) or `compressed` (every direction real, the distances squeezed). The scale in use is always named on the view. */
|
|
221
249
|
get scale() {
|
|
222
250
|
return this.#model.mode;
|
|
223
251
|
}
|
|
224
252
|
set scale(value) {
|
|
225
253
|
this.#model.mode = value;
|
|
254
|
+
this.#nameScale();
|
|
226
255
|
this.#gate?.request();
|
|
227
256
|
}
|
|
257
|
+
/** The words naming the scale on the view, for a page in another language (`{ true: "距離はそのまま" }`). A scale left out keeps its words in the element's `lang`. */
|
|
258
|
+
get scaleNames() {
|
|
259
|
+
return { ...this.#scaleNames };
|
|
260
|
+
}
|
|
261
|
+
set scaleNames(value) {
|
|
262
|
+
this.#scaleNames = { ...value };
|
|
263
|
+
this.#nameScale();
|
|
264
|
+
}
|
|
228
265
|
get labels() {
|
|
229
266
|
return this.#model.labels;
|
|
230
267
|
}
|
|
231
268
|
set labels(value) {
|
|
232
269
|
this.#model.labels = value;
|
|
233
270
|
if (!value)
|
|
234
|
-
for (const label of this.#pool.values())
|
|
271
|
+
for (const label of [...this.#pool.values(), ...this.#rings.values()])
|
|
235
272
|
label.hidden = true;
|
|
236
273
|
this.#gate?.request();
|
|
237
274
|
}
|
|
@@ -242,6 +279,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
242
279
|
this.#model.orbits = value;
|
|
243
280
|
this.#gate?.request();
|
|
244
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Help mode (the `help` attribute; off by default): on the body looked at, a line along its axis and a curved arrow round it showing which way it spins, by the right-hand rule about the axis it really turns about, so it is
|
|
284
|
+
* right for Venus and Uranus, which turn backwards, and for Uranus on its side. It is about learning, so the arrow is drawn over the body.
|
|
285
|
+
*/
|
|
286
|
+
get help() {
|
|
287
|
+
return this.#model.help;
|
|
288
|
+
}
|
|
289
|
+
set help(value) {
|
|
290
|
+
this.#model.help = value;
|
|
291
|
+
this.#gate?.request();
|
|
292
|
+
}
|
|
245
293
|
/** How the bodies are drawn: `realistic` (shaded from the body's real colours and features) or `painted` (public-domain surface maps). */
|
|
246
294
|
get look() {
|
|
247
295
|
return this.#model.look === "painted" ? "painted" : "realistic";
|
|
@@ -280,7 +328,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
280
328
|
}
|
|
281
329
|
this.#gate?.request();
|
|
282
330
|
}
|
|
283
|
-
/** The body the camera looks at (`earth`, `sun`, `moon`, `mercury` to `neptune`, `pluto`)
|
|
331
|
+
/** The body the camera looks at: any body the view places, by name in any case (`earth`, `sun`, `moon`, `mercury` to `neptune`, `pluto`, and the moons of the planets such as `titan`). At zoom 1 it fills the view; the yaw and tilt turn the camera round it. Setting it moves the camera there at once and keeps the zoom; `goTo` glides and brings the body into view. */
|
|
284
332
|
get body() {
|
|
285
333
|
return this.#model.focus;
|
|
286
334
|
}
|
|
@@ -288,8 +336,75 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
288
336
|
const id = readBody(name);
|
|
289
337
|
if (!id)
|
|
290
338
|
return;
|
|
339
|
+
this.#centre(id);
|
|
340
|
+
}
|
|
341
|
+
/** Move the camera to `id` (not yet drawn) and tell the page. */
|
|
342
|
+
#centre(id) {
|
|
343
|
+
const was = this.#model.focus;
|
|
344
|
+
this.#model.focus = id;
|
|
345
|
+
this.#gate?.request();
|
|
346
|
+
if (was !== id)
|
|
347
|
+
this.#announceHop();
|
|
348
|
+
}
|
|
349
|
+
/** What the hopper can do from where it is: the body at the middle, and the bodies the previous and next hop lead to. */
|
|
350
|
+
get hopper() {
|
|
351
|
+
const here = this.#model.focus;
|
|
352
|
+
return { current: this.bodyInfo(here), previous: this.bodyInfo(hopFrom(here, -1, canCentre)), next: this.bodyInfo(hopFrom(here, 1, canCentre)) };
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Go to a body: it becomes the middle of the view and the zoom brings it whole into view (`zoom`, 1 by default; a planet's `-moons` preset for its system), gliding there from where the camera is unless `smooth` is
|
|
356
|
+
* false or the reader asked for reduced motion. `wakusei-hop` tells the page where it went and where the next and previous hops lead. A name in any case, in English or Japanese, works.
|
|
357
|
+
*
|
|
358
|
+
* @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`).
|
|
359
|
+
* @param options - `smooth` (true by default) and `zoom` (1 by default).
|
|
360
|
+
* @returns Whether the view can go there.
|
|
361
|
+
*/
|
|
362
|
+
goTo(target, options = {}) {
|
|
363
|
+
const id = readBody(target);
|
|
364
|
+
if (!id)
|
|
365
|
+
return false;
|
|
366
|
+
const model = this.#model;
|
|
367
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
368
|
+
const pose = model.pose;
|
|
369
|
+
const glide = (options.smooth ?? true) && !reduced && pose.valid && model.ride === null;
|
|
370
|
+
if (model.ride !== null)
|
|
371
|
+
this.ride(null, { smooth: false });
|
|
372
|
+
model.transition = glide ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
|
|
373
|
+
this.#selected = id;
|
|
291
374
|
this.#model.focus = id;
|
|
375
|
+
const zoom = options.zoom ?? 1;
|
|
376
|
+
// a bar bound to the element holds the view's state: it applies the zoom the page hears in the event; without one the element's own hands do
|
|
377
|
+
if (!this.hasAttribute("data-kazoku-bar"))
|
|
378
|
+
this.#hands?.controller.set({ zoom }, true, "jump");
|
|
379
|
+
this.#schedule();
|
|
292
380
|
this.#gate?.request();
|
|
381
|
+
this.#announceHop(zoom);
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
/** Go to the next body in the order of `bodyList()` (the Sun, Mercury, Venus, the Earth, the Moon, Mars, Phobos, Deimos, Ceres, Jupiter, its moons, and on), round to the Sun after the last. */
|
|
385
|
+
next(options = {}) {
|
|
386
|
+
this.goTo(hopFrom(this.#model.focus, 1, canCentre), options);
|
|
387
|
+
return this.bodyInfo(this.#model.focus);
|
|
388
|
+
}
|
|
389
|
+
/** Go to the previous body in the same order. */
|
|
390
|
+
previous(options = {}) {
|
|
391
|
+
this.goTo(hopFrom(this.#model.focus, -1, canCentre), options);
|
|
392
|
+
return this.bodyInfo(this.#model.focus);
|
|
393
|
+
}
|
|
394
|
+
/** Every body the view can go to, in the hopper's order, with its kind and, for a moon, its planet: a page's jump list. */
|
|
395
|
+
bodyList() {
|
|
396
|
+
return HOP_ORDER.filter(canCentre).map((id) => this.bodyInfo(id));
|
|
397
|
+
}
|
|
398
|
+
/** The body a press has chosen and the page may be showing a card for, or null. A second press on it, or `goTo`, makes it the middle of the view. */
|
|
399
|
+
get selected() {
|
|
400
|
+
return this.#selected;
|
|
401
|
+
}
|
|
402
|
+
set selected(id) {
|
|
403
|
+
this.#selected = id;
|
|
404
|
+
}
|
|
405
|
+
/** `zoom` is the zoom the page should bring the view to: given by `goTo`, left out when the body was only set (the zoom stays). */
|
|
406
|
+
#announceHop(zoom) {
|
|
407
|
+
this.dispatchEvent(new CustomEvent("wakusei-hop", { detail: { ...this.hopper, zoom }, bubbles: true, composed: true }));
|
|
293
408
|
}
|
|
294
409
|
/** The words shown beside each body, for a page in another language (`{ mars: "火星" }`). A body left out keeps its name in the element's `lang`. */
|
|
295
410
|
get bodyNames() {
|
|
@@ -312,8 +427,30 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
312
427
|
/** The name, radius and distance from the Earth of a body now, for a page's own caption. */
|
|
313
428
|
bodyInfo(id) {
|
|
314
429
|
const frame = this.#model.drawn?.frame ?? frameAt(this.#model.time);
|
|
315
|
-
const
|
|
316
|
-
|
|
430
|
+
const km = AU_IN_EARTH_RADII * EARTH_RADIUS_KM;
|
|
431
|
+
let geo = [Number.NaN, Number.NaN, Number.NaN];
|
|
432
|
+
const host = hostOf(id);
|
|
433
|
+
if (id === "earth")
|
|
434
|
+
geo = [0, 0, 0];
|
|
435
|
+
else if (id === "sun")
|
|
436
|
+
geo = frame.sun;
|
|
437
|
+
else if (id === "moon")
|
|
438
|
+
geo = frame.moon;
|
|
439
|
+
else if (SPACE_PLANETS.includes(id))
|
|
440
|
+
geo = frame.planets[id];
|
|
441
|
+
else if (SPACE_DWARFS.includes(id))
|
|
442
|
+
geo = frame.dwarfs[id];
|
|
443
|
+
else if (host !== undefined && (SPACE_PLANETS.includes(host) || SPACE_DWARFS.includes(host))) {
|
|
444
|
+
// a moon: its planet's place and its offset in the planet's radii
|
|
445
|
+
const at = SPACE_DWARFS.includes(host) ? frame.dwarfs[host] : frame.planets[host];
|
|
446
|
+
const offset = moonOffset(id, this.#model.time);
|
|
447
|
+
const radius = BODIES[host].radiusKm / km;
|
|
448
|
+
geo = [at[0] + offset[0] * radius, at[1] + offset[1] * radius, at[2] + offset[2] * radius];
|
|
449
|
+
}
|
|
450
|
+
const info = { id, name: this.#nameOf(id), kind: bodyKindOf(id), radiusKm: BODIES[id].radiusKm, distanceKm: Math.hypot(geo[0], geo[1], geo[2]) * km };
|
|
451
|
+
if (host !== undefined)
|
|
452
|
+
info.host = host;
|
|
453
|
+
return info;
|
|
317
454
|
}
|
|
318
455
|
// --- riding along -------------------------------------------------------------------------------------------------------------------------------
|
|
319
456
|
/**
|
|
@@ -348,7 +485,6 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
348
485
|
this.#lostTold = false;
|
|
349
486
|
const pose = model.pose;
|
|
350
487
|
model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
|
|
351
|
-
this.#last = performance.now();
|
|
352
488
|
this.#schedule();
|
|
353
489
|
this.#gate?.request();
|
|
354
490
|
this.dispatchEvent(new CustomEvent("wakusei-ride", { detail: this.riding }));
|
|
@@ -358,11 +494,17 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
358
494
|
const distanceKm = Math.max(100, options.distanceKm ?? 3000);
|
|
359
495
|
if (typeof target !== "string") {
|
|
360
496
|
const around = options.around && SPACE_BODIES.includes(options.around) ? options.around : "earth";
|
|
497
|
+
if (options.view === "beside")
|
|
498
|
+
return undefined;
|
|
361
499
|
return { target, around, view: options.view ?? "from", look, distanceKm };
|
|
362
500
|
}
|
|
363
501
|
const id = target.toLowerCase();
|
|
364
|
-
if (SPACE_BODIES.includes(id))
|
|
502
|
+
if (SPACE_BODIES.includes(id)) {
|
|
503
|
+
// the view from beside a moon is for a moon: of the bodies of the view only the Moon is one
|
|
504
|
+
if (options.view === "beside" && id !== "moon")
|
|
505
|
+
return undefined;
|
|
365
506
|
return { target: id, around: "earth", view: id === "earth" ? "follow" : (options.view ?? "from"), look, distanceKm };
|
|
507
|
+
}
|
|
366
508
|
for (const [planet, moons] of Object.entries(MOONS_OF)) {
|
|
367
509
|
if (!moons.includes(id) || !SPACE_BODIES.includes(planet) || planet === "earth")
|
|
368
510
|
continue;
|
|
@@ -381,12 +523,19 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
381
523
|
this.dispatchEvent(new CustomEvent("wakusei-ride-lost", { detail: this.riding }));
|
|
382
524
|
}
|
|
383
525
|
/** The zoom that shows a part of the sky: the Earth alone, the Moon's orbit, the Sun, the planets out to Mars, all of them, or a planet's nearer moons, at this scale and moment. */
|
|
384
|
-
zoomFor(
|
|
526
|
+
zoomFor(named) {
|
|
385
527
|
const mode = this.#model.mode;
|
|
528
|
+
// a name in any case; one that is no preset gives 1, the zoom that fills the view with the body looked at, not NaN
|
|
529
|
+
const preset = String(named).toLowerCase();
|
|
530
|
+
if (!["earth", "moon", "sun", "inner", "solar-system"].includes(preset) && !(preset.endsWith("-moons") && findBody(preset.slice(0, -6)) !== undefined))
|
|
531
|
+
return 1;
|
|
386
532
|
if (preset.endsWith("-moons")) {
|
|
387
533
|
const id = preset.slice(0, -6);
|
|
388
534
|
const sites = this.#painterNow().moons(id, this.#model.time);
|
|
389
|
-
const
|
|
535
|
+
const distances = sites.map((site) => moonDistance(mode, id, Math.hypot(...site.offset)));
|
|
536
|
+
// the moons within 22 radii; a system whose moons are all farther (a dwarf planet's) is framed by them all
|
|
537
|
+
const near = distances.filter((r) => r <= 22);
|
|
538
|
+
const reach = Math.max(1, ...(near.length > 0 ? near : distances));
|
|
390
539
|
const radius = radiusIn(id, mode);
|
|
391
540
|
return Math.min(1, (FIT_DISTANCE * radius) / ((reach * radius * 1.15) / Math.tan(17.5 * RAD)));
|
|
392
541
|
}
|
|
@@ -400,7 +549,11 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
400
549
|
inner: Math.max(away("mercury"), away("venus"), away("mars"), away("sun")),
|
|
401
550
|
"solar-system": Math.max(...SPACE_PLANETS.map(away), away("sun")),
|
|
402
551
|
}[preset];
|
|
403
|
-
|
|
552
|
+
if (preset === "earth")
|
|
553
|
+
return 1;
|
|
554
|
+
const zoom = FIT_DISTANCE / Math.max(FIT_DISTANCE, reach * 3.4);
|
|
555
|
+
// the Moon's own picture is a quarter of the Earth's in the compressed scale (it was drawn as 0.9 of it): the view of its orbit is still the one that holds the Earth too, three Moon-distances out
|
|
556
|
+
return preset === "moon" && mode === "compressed" ? zoom * (radiusIn("moon", mode) / 0.9) : zoom;
|
|
404
557
|
}
|
|
405
558
|
/** What the element is doing, for a page or a test. */
|
|
406
559
|
get stats() {
|
|
@@ -412,11 +565,16 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
412
565
|
canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
|
|
413
566
|
distance: this.#model.drawn?.distance ?? 0,
|
|
414
567
|
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
415
|
-
time: this
|
|
568
|
+
time: this.time,
|
|
416
569
|
lookups: this.#model.lookups,
|
|
417
570
|
camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov },
|
|
418
571
|
bodies: { look: this.#model.look, painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held },
|
|
572
|
+
tiles: { ...this.#model.tiles },
|
|
419
573
|
ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
|
|
574
|
+
orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden] },
|
|
575
|
+
arrows: Object.fromEntries(Object.entries(this.#model.arrows).map(([id, list]) => [id, list.map((a) => ({ position: [...a.position], direction: [...a.direction] }))])),
|
|
576
|
+
arrowPx: this.#model.arrowPx,
|
|
577
|
+
help: this.#model.helpDrawn ? { body: this.#model.helpDrawn.body, axis: [...this.#model.helpDrawn.axis], pole: [...this.#model.helpDrawn.pole], retrograde: this.#model.helpDrawn.retrograde, arcTurn: [...this.#model.helpDrawn.arcTurn] } : null,
|
|
420
578
|
};
|
|
421
579
|
}
|
|
422
580
|
// --- the game clock ----------------------------------------------------------------------------------------------------------------------------
|
|
@@ -429,23 +587,20 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
429
587
|
#schedule() {
|
|
430
588
|
clearTimeout(this.#timer);
|
|
431
589
|
this.#timer = undefined;
|
|
432
|
-
if (!this.isConnected || this.#speed === 0)
|
|
590
|
+
if (!this.isConnected || this.#clock.speed === 0)
|
|
433
591
|
return;
|
|
434
592
|
const riding = this.#model.ride !== null;
|
|
435
|
-
const pixels = Math.max(this.#model.motion || 0.015, this.#model.rideMotion) * Math.abs(this.#speed);
|
|
593
|
+
const pixels = Math.max(this.#model.motion || 0.015, this.#model.rideMotion) * Math.abs(this.#clock.speed);
|
|
436
594
|
let perSecond = Math.min(30, Math.max(1, pixels));
|
|
437
595
|
if (riding && typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
438
596
|
perSecond = 1;
|
|
439
|
-
const wait = !riding && this.#speed === 1 ? REAL_TIME_TICK_MS : 1000 / perSecond;
|
|
597
|
+
const wait = !riding && this.#clock.speed === 1 ? REAL_TIME_TICK_MS : 1000 / perSecond;
|
|
440
598
|
this.#timer = setTimeout(this.#tick, wait);
|
|
441
599
|
}
|
|
442
|
-
/** Bring the moment shown up to
|
|
443
|
-
#advance(
|
|
444
|
-
if (this
|
|
445
|
-
this.#model.time =
|
|
446
|
-
else
|
|
447
|
-
this.#model.time += (now - this.#last) * this.#speed;
|
|
448
|
-
this.#last = now;
|
|
600
|
+
/** Bring the moment shown up to the page's clock, by the time that really passed at the speed it has run at, however few frames were drawn (`createGameClock`). */
|
|
601
|
+
#advance() {
|
|
602
|
+
if (this.isConnected)
|
|
603
|
+
this.#model.time = this.#clock.advance();
|
|
449
604
|
}
|
|
450
605
|
/** Tell the page the moment shown: at most four times a second while time runs (`running`), and once, at once, when it holds. */
|
|
451
606
|
#announce(running) {
|
|
@@ -456,11 +611,11 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
456
611
|
this.dispatchEvent(new CustomEvent("wakusei-timechange", { detail: { time: this.#model.time, running } }));
|
|
457
612
|
}
|
|
458
613
|
#tick = () => {
|
|
459
|
-
this.#advance(
|
|
614
|
+
this.#advance();
|
|
460
615
|
this.#gate?.request();
|
|
461
616
|
this.#schedule();
|
|
462
617
|
this.dispatchEvent(new CustomEvent("wakusei-time", { detail: { time: this.#model.time } }));
|
|
463
|
-
this.#announce(this.#speed !== 0);
|
|
618
|
+
this.#announce(this.#clock.speed !== 0);
|
|
464
619
|
};
|
|
465
620
|
// --- labels --------------------------------------------------------------------------------------------------------------------------------------
|
|
466
621
|
#nameOf(id) {
|
|
@@ -471,7 +626,10 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
471
626
|
const box = this.#labelBox;
|
|
472
627
|
if (!box)
|
|
473
628
|
return;
|
|
474
|
-
|
|
629
|
+
const wanted = [];
|
|
630
|
+
const spots = new Map();
|
|
631
|
+
const ids = [...new Set([...SPACE_BODIES, ...this.#pool.keys(), ...Object.keys(places)])];
|
|
632
|
+
for (const id of ids) {
|
|
475
633
|
let label = this.#pool.get(id);
|
|
476
634
|
const at = places[id];
|
|
477
635
|
if (!label) {
|
|
@@ -486,21 +644,107 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
486
644
|
this.#pool.set(id, button);
|
|
487
645
|
label = button;
|
|
488
646
|
}
|
|
489
|
-
|
|
647
|
+
let ring = this.#rings.get(id);
|
|
648
|
+
if (!ring) {
|
|
649
|
+
ring = box.ownerDocument.createElement("div");
|
|
650
|
+
ring.className = "sp-ring";
|
|
651
|
+
ring.dataset["ring"] = id;
|
|
652
|
+
ring.hidden = true;
|
|
653
|
+
box.append(ring);
|
|
654
|
+
this.#rings.set(id, ring);
|
|
655
|
+
}
|
|
656
|
+
if (!at)
|
|
657
|
+
continue;
|
|
658
|
+
const x = Math.round(at.x + Math.max(4, Math.min(at.r, 40)));
|
|
659
|
+
const y = Math.round(at.y - 8);
|
|
660
|
+
spots.set(id, { x, y, small: at.r < RING_BELOW_PX });
|
|
661
|
+
wanted.push({ id, x, y, width: this.#widthOf(label), height: 16, rank: this.#rank(id), size: at.r });
|
|
662
|
+
}
|
|
663
|
+
// no two names overlap: a moon gives way to its planet and a planet to the Sun
|
|
664
|
+
const shown = chooseLabels(wanted);
|
|
665
|
+
for (const id of ids) {
|
|
666
|
+
const label = this.#pool.get(id);
|
|
667
|
+
const ring = this.#rings.get(id);
|
|
668
|
+
if (!label || !ring)
|
|
669
|
+
continue;
|
|
670
|
+
const spot = spots.get(id);
|
|
671
|
+
if (!spot || !shown.has(id)) {
|
|
490
672
|
if (!label.hidden)
|
|
491
673
|
label.hidden = true;
|
|
674
|
+
if (!ring.hidden)
|
|
675
|
+
ring.hidden = true;
|
|
492
676
|
continue;
|
|
493
677
|
}
|
|
494
678
|
if (label.hidden)
|
|
495
679
|
label.hidden = false;
|
|
496
|
-
label.style.transform = `translate(${
|
|
680
|
+
label.style.transform = `translate(${spot.x}px,${spot.y}px)`;
|
|
681
|
+
// a body too small to see is marked: a ring round the place it is, as well as its name
|
|
682
|
+
if (ring.hidden === spot.small)
|
|
683
|
+
ring.hidden = !spot.small;
|
|
684
|
+
if (spot.small)
|
|
685
|
+
ring.style.transform = `translate(${Math.round(places[id].x)}px,${Math.round(places[id].y)}px)`;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/** How sure a body's name is of its place: the body looked at first, then the Sun, the planets, the dwarf planets and the moons. */
|
|
689
|
+
#rank(id) {
|
|
690
|
+
if (id === this.#model.focus)
|
|
691
|
+
return 0;
|
|
692
|
+
if (id === "sun")
|
|
693
|
+
return 1;
|
|
694
|
+
const kind = bodyKindOf(id);
|
|
695
|
+
return kind === "moon" ? 4 : kind === "dwarf-planet" ? 3 : 2;
|
|
696
|
+
}
|
|
697
|
+
#widths = new WeakMap();
|
|
698
|
+
/** The width of a name's box on the screen, measured when its words change and not at every frame. */
|
|
699
|
+
#widthOf(label) {
|
|
700
|
+
let width = this.#widths.get(label);
|
|
701
|
+
if (width === undefined) {
|
|
702
|
+
const hidden = label.hidden;
|
|
703
|
+
if (hidden)
|
|
704
|
+
label.hidden = false;
|
|
705
|
+
width = label.offsetWidth;
|
|
706
|
+
if (hidden)
|
|
707
|
+
label.hidden = true;
|
|
708
|
+
if (width > 0)
|
|
709
|
+
this.#widths.set(label, width);
|
|
497
710
|
}
|
|
711
|
+
return width;
|
|
712
|
+
}
|
|
713
|
+
/** Say which scale is on, on the view itself. */
|
|
714
|
+
#nameScale() {
|
|
715
|
+
if (!this.#scaleLine)
|
|
716
|
+
return;
|
|
717
|
+
const words = SCALE_WORDS[this.getAttribute("lang") === "ja" ? "ja" : "en"];
|
|
718
|
+
this.#scaleLine.textContent = this.#scaleNames[this.#model.mode] ?? words[this.#model.mode];
|
|
719
|
+
}
|
|
720
|
+
/** 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. */
|
|
721
|
+
placeOf(id) {
|
|
722
|
+
const at = this.#places?.[id];
|
|
723
|
+
return at ? { ...at } : null;
|
|
498
724
|
}
|
|
499
725
|
#nameLabel(button, id) {
|
|
500
726
|
const text = this.#nameOf(id);
|
|
501
727
|
button.textContent = text;
|
|
728
|
+
this.#widths.delete(button);
|
|
502
729
|
button.setAttribute("aria-label", `${text}: ${this.#hint}`);
|
|
503
730
|
}
|
|
731
|
+
/** 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. */
|
|
732
|
+
get immersive() {
|
|
733
|
+
return this.hasAttribute("immersive");
|
|
734
|
+
}
|
|
735
|
+
set immersive(value) {
|
|
736
|
+
this.toggleAttribute("immersive", value);
|
|
737
|
+
}
|
|
738
|
+
// In an immersive view a plain wheel zooms. It is passed on to the shared hands as the wheel's own pinch (Ctrl and a small step), so whichever hands hold the view (the element's, or a bar bound to it) apply it with their limits;
|
|
739
|
+
// Ctrl, Command, Alt and Shift with the wheel are the family's own and are left alone.
|
|
740
|
+
#wheel = (event) => {
|
|
741
|
+
if (!this.hasAttribute("immersive") || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey)
|
|
742
|
+
return;
|
|
743
|
+
event.preventDefault();
|
|
744
|
+
event.stopImmediatePropagation();
|
|
745
|
+
const pixels = event.deltaMode === 1 ? event.deltaY * 33 : event.deltaMode === 2 ? event.deltaY * 800 : event.deltaY;
|
|
746
|
+
this.dispatchEvent(new WheelEvent("wheel", { deltaY: Math.max(-250, Math.min(250, pixels)) * WHEEL_AS_PINCH, deltaMode: 0, clientX: event.clientX, clientY: event.clientY, ctrlKey: true, bubbles: true, cancelable: true, composed: true }));
|
|
747
|
+
};
|
|
504
748
|
// A body is chosen by pressing on it or on its name (and by Tab and Enter on the name); a drag that turns the view is not a choice.
|
|
505
749
|
#downX = 0;
|
|
506
750
|
#downY = 0;
|
|
@@ -521,8 +765,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
521
765
|
const y = event.clientY - rect.top;
|
|
522
766
|
let best;
|
|
523
767
|
let bestD = Infinity;
|
|
524
|
-
for (const id of
|
|
525
|
-
const at = this.#places[id];
|
|
768
|
+
for (const [id, at] of Object.entries(this.#places)) {
|
|
526
769
|
if (!at)
|
|
527
770
|
continue;
|
|
528
771
|
const d = Math.hypot(x - at.x, y - at.y);
|
|
@@ -532,13 +775,27 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
532
775
|
}
|
|
533
776
|
}
|
|
534
777
|
if (best)
|
|
535
|
-
this
|
|
778
|
+
this.#press(best);
|
|
536
779
|
};
|
|
537
780
|
#labelClick = (event) => {
|
|
538
781
|
const id = event.target?.dataset?.["body"];
|
|
539
782
|
if (id)
|
|
540
|
-
this
|
|
783
|
+
this.#press(id);
|
|
541
784
|
};
|
|
785
|
+
/**
|
|
786
|
+
* A press on a body or its name. `wakusei-body-click` tells the page every time. The first press on a body selects it (`wakusei-body-select`, for the page's card); a second press on the body that is selected makes it
|
|
787
|
+
* the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else.
|
|
788
|
+
*/
|
|
789
|
+
#press(id) {
|
|
790
|
+
this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
|
|
791
|
+
if (this.#selected === id) {
|
|
792
|
+
if (canCentre(id) && this.#model.focus !== id)
|
|
793
|
+
this.goTo(id);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
this.#selected = id;
|
|
797
|
+
this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
|
|
798
|
+
}
|
|
542
799
|
#labelFocus = (event) => {
|
|
543
800
|
const id = event.target?.dataset?.["body"];
|
|
544
801
|
if (id)
|
|
@@ -546,7 +803,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
546
803
|
};
|
|
547
804
|
// --- the rest --------------------------------------------------------------------------------------------------------------------------------------
|
|
548
805
|
#painterNow() {
|
|
549
|
-
return (this.#painter ??= createPainter({ textureBase: texturePaths(this).textureBase(), farBase: texturePaths(this).farBase() }));
|
|
806
|
+
return (this.#painter ??= createPainter({ textureBase: texturePaths(this).textureBase(), farBase: texturePaths(this).farBase(), tiles: tilesBase(this) ?? "off" }));
|
|
550
807
|
}
|
|
551
808
|
#textureCap() {
|
|
552
809
|
const given = Number(this.getAttribute("max-texture"));
|