@arcadible/sdk 1.5.0-next.2 → 1.5.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/client.js +2 -2
- package/dist/host.d.ts +1 -1
- package/dist/host.js +8 -1
- package/dist/lifecycle/holds.js +4 -1
- package/dist/system/rules.d.ts +2 -0
- package/dist/system/rules.js +9 -2
- package/dist/system/server.js +5 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/context/client.js
CHANGED
|
@@ -8,8 +8,8 @@ export function createContextClient(bus) {
|
|
|
8
8
|
let context = null;
|
|
9
9
|
let settled = false;
|
|
10
10
|
bus.on(Names.State, isObject, (data) => {
|
|
11
|
-
// fixed for the run: the first one stands
|
|
12
|
-
if (context)
|
|
11
|
+
// fixed for the run: the first one stands, and none comes after `ready`.
|
|
12
|
+
if (context || settled)
|
|
13
13
|
return;
|
|
14
14
|
const next = contextOf(data);
|
|
15
15
|
if (!next) {
|
package/dist/host.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hello } from "./bus/protocol.js";
|
|
2
2
|
import { type Server } from "./bus/server.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type ContextState } from "./context/rules.js";
|
|
4
4
|
import { type Holds } from "./lifecycle/holds.js";
|
|
5
5
|
import { type SystemState } from "./system/rules.js";
|
|
6
6
|
import { type System } from "./system/server.js";
|
package/dist/host.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// a game standing alone runs `serve` in its own page.
|
|
3
3
|
import { answerHellos, createServer } from "./bus/server.js";
|
|
4
4
|
import { contextServer } from "./context/server.js";
|
|
5
|
+
import { isTime } from "./context/rules.js";
|
|
5
6
|
import { createHolds } from "./lifecycle/holds.js";
|
|
6
7
|
import { shortLanguage } from "./system/rules.js";
|
|
7
8
|
import { createSystem } from "./system/server.js";
|
|
@@ -50,7 +51,13 @@ export function createHost(options) {
|
|
|
50
51
|
holds,
|
|
51
52
|
system,
|
|
52
53
|
context: {
|
|
53
|
-
|
|
54
|
+
// Arcadible's time when given, else the device's: never a time the
|
|
55
|
+
// game would refuse.
|
|
56
|
+
launch: {
|
|
57
|
+
at: isTime(options.launchedAt)
|
|
58
|
+
? options.launchedAt
|
|
59
|
+
: new Date().toISOString(),
|
|
60
|
+
},
|
|
54
61
|
},
|
|
55
62
|
}),
|
|
56
63
|
window: win,
|
package/dist/lifecycle/holds.js
CHANGED
|
@@ -58,7 +58,10 @@ export function createHolds() {
|
|
|
58
58
|
},
|
|
59
59
|
[Names.Paused]: (data) => {
|
|
60
60
|
const value = isObject(data) ? data["n"] : undefined;
|
|
61
|
-
|
|
61
|
+
// a pause the page sent: a whole number, from 1 up to the last.
|
|
62
|
+
if (!Number.isInteger(value) || value < 1)
|
|
63
|
+
return;
|
|
64
|
+
if (value > n)
|
|
62
65
|
return;
|
|
63
66
|
settled = Math.max(settled, value);
|
|
64
67
|
if (settled < n)
|
package/dist/system/rules.d.ts
CHANGED
|
@@ -8,5 +8,7 @@ export type SystemState = {
|
|
|
8
8
|
export declare function isLanguage(value: unknown): value is string;
|
|
9
9
|
/** The state as the game keeps it: only fields it knows, each checked. */
|
|
10
10
|
export declare function stateOf(value: unknown): SystemState | null;
|
|
11
|
+
/** A language tag as a short one: `en-US` as `en`, or null if it isn't one. */
|
|
12
|
+
export declare function languageOf(tag: unknown): string | null;
|
|
11
13
|
/** A browser's language as a short tag: `en-US` as `en`, or `en`. */
|
|
12
14
|
export declare function shortLanguage(tag: string | undefined): string;
|
package/dist/system/rules.js
CHANGED
|
@@ -23,8 +23,15 @@ export function stateOf(value) {
|
|
|
23
23
|
return { language: value["language"] };
|
|
24
24
|
}
|
|
25
25
|
// [function]
|
|
26
|
+
/** A language tag as a short one: `en-US` as `en`, or null if it isn't one. */
|
|
27
|
+
export function languageOf(tag) {
|
|
28
|
+
if (typeof tag !== "string")
|
|
29
|
+
return null;
|
|
30
|
+
const short = tag.split("-")[0]?.toLowerCase() ?? "";
|
|
31
|
+
return isLanguage(short) ? short : null;
|
|
32
|
+
}
|
|
33
|
+
// [function]
|
|
26
34
|
/** A browser's language as a short tag: `en-US` as `en`, or `en`. */
|
|
27
35
|
export function shortLanguage(tag) {
|
|
28
|
-
|
|
29
|
-
return isLanguage(short) ? short : "en";
|
|
36
|
+
return languageOf(tag) ?? "en";
|
|
30
37
|
}
|
package/dist/system/server.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// The page's side of `system`: Arcadible's state for the player, sent as
|
|
2
2
|
// the game connects and again whenever it changes. Nothing waits on it.
|
|
3
|
-
import {
|
|
3
|
+
import { languageOf, Names, shortLanguage } from "./rules.js";
|
|
4
4
|
// [function]
|
|
5
5
|
export function createSystem(initial) {
|
|
6
|
-
|
|
6
|
+
// only a short tag goes to the game: `en-US` as `en`.
|
|
7
|
+
let state = { ...initial, language: shortLanguage(initial.language) };
|
|
7
8
|
let context = null;
|
|
8
9
|
return {
|
|
9
10
|
set(next) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
: state.language;
|
|
11
|
+
// a tag that isn't a language changes nothing.
|
|
12
|
+
const language = languageOf(next.language) ?? state.language;
|
|
13
13
|
if (language === state.language)
|
|
14
14
|
return;
|
|
15
15
|
state = { ...state, language };
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.5.0-next.
|
|
1
|
+
export declare const VERSION = "1.5.0-next.3";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED