@arcadible/sdk 1.5.0-next.1 → 1.5.0-next.2
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/client.d.ts +8 -0
- package/dist/client.js +6 -0
- package/dist/context/client.d.ts +12 -0
- package/dist/context/client.js +31 -0
- package/dist/context/rules.d.ts +12 -0
- package/dist/context/rules.js +29 -0
- package/dist/context/server.d.ts +3 -0
- package/dist/context/server.js +13 -0
- package/dist/host.d.ts +4 -1
- package/dist/host.js +10 -1
- package/dist/index.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Build } from "./bus/protocol.js";
|
|
2
|
+
import { type Context } from "./context/client.js";
|
|
2
3
|
import { type System } from "./system/client.js";
|
|
3
4
|
import type { Backend } from "./saves/backend/types.js";
|
|
4
5
|
import { type Saves } from "./saves/client.js";
|
|
@@ -31,6 +32,13 @@ export interface Arcadible {
|
|
|
31
32
|
* `undefined` before.
|
|
32
33
|
*/
|
|
33
34
|
readonly system: System | null | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* How this run started, fixed for the run: `launch.at`, Arcadible's time
|
|
37
|
+
* at launch, so a daily puzzle doesn't trust the device's clock. Set by
|
|
38
|
+
* the time `ready` settles; `null` where no page says, such as standing
|
|
39
|
+
* alone, and `undefined` before.
|
|
40
|
+
*/
|
|
41
|
+
readonly context: Context | null | undefined;
|
|
34
42
|
/**
|
|
35
43
|
* Starts the game's initialization: call it as your code starts, before
|
|
36
44
|
* anything it awaits, and Arcadible shows the game's loading screen until
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,7 @@ import { openBus } from "./bus/client.js";
|
|
|
6
6
|
import { buildOf, REQUEST_TIMEOUT } from "./bus/protocol.js";
|
|
7
7
|
import { createLifecycle } from "./lifecycle/client.js";
|
|
8
8
|
import { createPause } from "./lifecycle/pause.js";
|
|
9
|
+
import { createContextClient } from "./context/client.js";
|
|
9
10
|
import { createSystemClient } from "./system/client.js";
|
|
10
11
|
import { indexedDBBackend } from "./saves/backend/indexeddb.js";
|
|
11
12
|
import { createSaves } from "./saves/client.js";
|
|
@@ -37,9 +38,11 @@ export function createClient(options = {}) {
|
|
|
37
38
|
});
|
|
38
39
|
let settled = null;
|
|
39
40
|
const system = createSystemClient(bus);
|
|
41
|
+
const context = createContextClient(bus);
|
|
40
42
|
// ready once welcomed, and each module's first messages have arrived.
|
|
41
43
|
const ready = Promise.all([bus.welcomed, opened]).then(([welcome]) => {
|
|
42
44
|
system.settle();
|
|
45
|
+
context.settle();
|
|
43
46
|
settled = { build: buildOf(welcome.build) };
|
|
44
47
|
return settled;
|
|
45
48
|
});
|
|
@@ -55,6 +58,9 @@ export function createClient(options = {}) {
|
|
|
55
58
|
get system() {
|
|
56
59
|
return system.value;
|
|
57
60
|
},
|
|
61
|
+
get context() {
|
|
62
|
+
return context.value;
|
|
63
|
+
},
|
|
58
64
|
initStart() {
|
|
59
65
|
lifecycle.start();
|
|
60
66
|
return ready;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Bus } from "../bus/client.js";
|
|
2
|
+
/** How this run started, fixed for the run. */
|
|
3
|
+
export interface Context {
|
|
4
|
+
readonly launch: {
|
|
5
|
+
/** This launch, by Arcadible's clock, as an ISO string. */
|
|
6
|
+
readonly at: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function createContextClient(bus: Bus): {
|
|
10
|
+
settle(): void;
|
|
11
|
+
readonly value: Context | null | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// The game's side of `context`: `arcadible.context`, how this run started,
|
|
2
|
+
// fixed for the run. `undefined` before `ready`, and `null` where no page
|
|
3
|
+
// says (standing alone, or an older page).
|
|
4
|
+
import { isObject, log } from "../bus/protocol.js";
|
|
5
|
+
import { contextOf, Names } from "./rules.js";
|
|
6
|
+
// [function]
|
|
7
|
+
export function createContextClient(bus) {
|
|
8
|
+
let context = null;
|
|
9
|
+
let settled = false;
|
|
10
|
+
bus.on(Names.State, isObject, (data) => {
|
|
11
|
+
// fixed for the run: the first one stands.
|
|
12
|
+
if (context)
|
|
13
|
+
return;
|
|
14
|
+
const next = contextOf(data);
|
|
15
|
+
if (!next) {
|
|
16
|
+
log("warn", "ignored a malformed context from the play page.");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
context = Object.freeze({ launch: Object.freeze({ ...next.launch }) });
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
settle() {
|
|
23
|
+
settled = true;
|
|
24
|
+
},
|
|
25
|
+
get value() {
|
|
26
|
+
if (!settled)
|
|
27
|
+
return undefined;
|
|
28
|
+
return context;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const Names: {
|
|
2
|
+
readonly State: "context.state";
|
|
3
|
+
};
|
|
4
|
+
export type ContextState = {
|
|
5
|
+
launch: {
|
|
6
|
+
at: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/** A time the page may send: an ISO string in UTC that reads as a date. */
|
|
10
|
+
export declare function isTime(value: unknown): value is string;
|
|
11
|
+
/** The context as the game keeps it: only fields it knows, each checked. */
|
|
12
|
+
export declare function contextOf(value: unknown): ContextState | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// `context` on the bus, shared by both ends: how this run started, fixed
|
|
2
|
+
// for the run.
|
|
3
|
+
// [import]
|
|
4
|
+
import { isObject } from "../bus/protocol.js";
|
|
5
|
+
// [declare]
|
|
6
|
+
export const Names = {
|
|
7
|
+
// the context, `{ launch: { at } }`: an event, sent once, as the module
|
|
8
|
+
// opens.
|
|
9
|
+
State: "context.state",
|
|
10
|
+
};
|
|
11
|
+
// a time as JavaScript's toISOString() writes it, in UTC.
|
|
12
|
+
const ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/u;
|
|
13
|
+
// [function]
|
|
14
|
+
/** A time the page may send: an ISO string in UTC that reads as a date. */
|
|
15
|
+
export function isTime(value) {
|
|
16
|
+
return (typeof value === "string" &&
|
|
17
|
+
ISO.test(value) &&
|
|
18
|
+
!Number.isNaN(Date.parse(value)));
|
|
19
|
+
}
|
|
20
|
+
// [function]
|
|
21
|
+
/** The context as the game keeps it: only fields it knows, each checked. */
|
|
22
|
+
export function contextOf(value) {
|
|
23
|
+
if (!isObject(value))
|
|
24
|
+
return null;
|
|
25
|
+
const launch = value["launch"];
|
|
26
|
+
if (!isObject(launch) || !isTime(launch["at"]))
|
|
27
|
+
return null;
|
|
28
|
+
return { launch: { at: launch["at"] } };
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The page's side of `context`: how this run started, sent once as the game
|
|
2
|
+
// connects. It never changes during the run.
|
|
3
|
+
import { Names } from "./rules.js";
|
|
4
|
+
// [function]
|
|
5
|
+
export function contextServer(context) {
|
|
6
|
+
return () => ({
|
|
7
|
+
handlers: {},
|
|
8
|
+
// first on each channel, so the game has it by `ready`.
|
|
9
|
+
async open(send) {
|
|
10
|
+
send(Names.State, context);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Hello } from "./bus/protocol.js";
|
|
2
2
|
import { type Server } from "./bus/server.js";
|
|
3
|
+
import type { ContextState } from "./context/rules.js";
|
|
3
4
|
import { type Holds } from "./lifecycle/holds.js";
|
|
4
5
|
import { type SystemState } from "./system/rules.js";
|
|
5
6
|
import { type System } from "./system/server.js";
|
|
@@ -16,6 +17,7 @@ export type ServeOptions = {
|
|
|
16
17
|
lifecycle?: LifecycleHost;
|
|
17
18
|
holds?: Holds;
|
|
18
19
|
system?: System;
|
|
20
|
+
context?: ContextState;
|
|
19
21
|
};
|
|
20
22
|
export type Host = {
|
|
21
23
|
close(): void;
|
|
@@ -23,8 +25,9 @@ export type Host = {
|
|
|
23
25
|
leave(timeout?: number): Promise<void>;
|
|
24
26
|
setSystem(state: Partial<SystemState>): void;
|
|
25
27
|
};
|
|
26
|
-
type HostOptions = Omit<ServeOptions, "holds" | "system"> & {
|
|
28
|
+
type HostOptions = Omit<ServeOptions, "holds" | "system" | "context"> & {
|
|
27
29
|
language?: string;
|
|
30
|
+
launchedAt?: string;
|
|
28
31
|
frame: HTMLIFrameElement;
|
|
29
32
|
origin: string;
|
|
30
33
|
window?: Window;
|
package/dist/host.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The page's side of the bus. The play page uses `createHost`;
|
|
2
2
|
// a game standing alone runs `serve` in its own page.
|
|
3
3
|
import { answerHellos, createServer } from "./bus/server.js";
|
|
4
|
+
import { contextServer } from "./context/server.js";
|
|
4
5
|
import { createHolds } from "./lifecycle/holds.js";
|
|
5
6
|
import { shortLanguage } from "./system/rules.js";
|
|
6
7
|
import { createSystem } from "./system/server.js";
|
|
@@ -17,6 +18,7 @@ export function serve(options) {
|
|
|
17
18
|
// state, by `ready`.
|
|
18
19
|
...(options.holds ? [options.holds.module] : []),
|
|
19
20
|
...(options.system ? [options.system.module] : []),
|
|
21
|
+
...(options.context ? [contextServer(options.context)] : []),
|
|
20
22
|
savesServer({
|
|
21
23
|
backend,
|
|
22
24
|
now: options.now ?? (() => new Date()),
|
|
@@ -43,7 +45,14 @@ export function createHost(options) {
|
|
|
43
45
|
const answering = answerHellos({
|
|
44
46
|
frame: options.frame,
|
|
45
47
|
origin: options.origin,
|
|
46
|
-
server: serve({
|
|
48
|
+
server: serve({
|
|
49
|
+
...options,
|
|
50
|
+
holds,
|
|
51
|
+
system,
|
|
52
|
+
context: {
|
|
53
|
+
launch: { at: options.launchedAt ?? new Date().toISOString() },
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
47
56
|
window: win,
|
|
48
57
|
onHello: options.onHello,
|
|
49
58
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export type { Build, Code } from "./bus/protocol.js";
|
|
|
5
5
|
export type { Arcadible, Ready } from "./client.js";
|
|
6
6
|
export type { Saves } from "./saves/client.js";
|
|
7
7
|
export type { System } from "./system/client.js";
|
|
8
|
+
export type { Context } from "./context/client.js";
|
|
8
9
|
export type { SaveInfo } from "./saves/rules.js";
|
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.2";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED