castle-web-sdk 0.4.10 → 0.4.11
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/castle.d.ts +1 -0
- package/dist/castle.js +1 -0
- package/dist/files.d.ts +15 -0
- package/dist/files.js +52 -0
- package/package.json +1 -1
package/dist/castle.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { isEdit } from "./context";
|
|
2
2
|
export { CastleError } from "./errors";
|
|
3
|
+
export { deckPrefixOf, IMPORTS_DIR, IMPORTS_PREFIX, isImportedFile, resolveDeckFile, } from "./files";
|
|
3
4
|
export { Haptics } from "./haptics";
|
|
4
5
|
export type { CastleHapticsApi, HapticsResult, HapticsStatus, HapticStyle } from "./haptics";
|
|
5
6
|
export { Leaderboard } from "./leaderboard";
|
package/dist/castle.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Castle Web SDK
|
|
2
2
|
export { isEdit } from "./context";
|
|
3
3
|
export { CastleError } from "./errors";
|
|
4
|
+
export { deckPrefixOf, IMPORTS_DIR, IMPORTS_PREFIX, isImportedFile, resolveDeckFile, } from "./files";
|
|
4
5
|
export { Haptics } from "./haptics";
|
|
5
6
|
export { Leaderboard } from "./leaderboard";
|
|
6
7
|
export { Lifecycle } from "./lifecycle";
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const IMPORTS_PREFIX = "@imports/";
|
|
2
|
+
export declare const IMPORTS_DIR = "imports";
|
|
3
|
+
export declare function deckPrefixOf(filePath: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a reference to the key it names in the deck's file map.
|
|
6
|
+
*
|
|
7
|
+
* @param ref the reference as written -- `drawings/rock.pxart` or
|
|
8
|
+
* `@imports/someone.pack/drawings/rock.pxart`
|
|
9
|
+
* @param from the path of the file the reference was written in; a reference in
|
|
10
|
+
* a deck's own file resolves against the deck root, one in an
|
|
11
|
+
* import's file against that import.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveDeckFile(ref: string, from?: string): string;
|
|
14
|
+
/** Whether a path names a file some import owns (rather than the deck's own). */
|
|
15
|
+
export declare function isImportedFile(filePath: string): boolean;
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// How a deck names a file -- one rule, everywhere a path appears: in JS module
|
|
2
|
+
// specifiers, in a scene's `blueprint`, in a Sprite's `file`, in anything a kit
|
|
3
|
+
// invents later.
|
|
4
|
+
//
|
|
5
|
+
// drawings/rock.pxart a file of the deck the REFERENCE lives in
|
|
6
|
+
// @imports/<alias>/drawings/rock.pxart a file of that import
|
|
7
|
+
//
|
|
8
|
+
// The unprefixed form is deck-relative, and "the deck" means whichever deck the
|
|
9
|
+
// referencing file belongs to. So a kit's blueprint saying `drawings/cauldron.pxart`
|
|
10
|
+
// means the kit's own drawing whether the kit is the deck being played or an
|
|
11
|
+
// import of it -- the same text keeps meaning the same file after the kit is
|
|
12
|
+
// imported by somebody else. That is what makes a deck publishable as a
|
|
13
|
+
// dependency without rewriting its insides.
|
|
14
|
+
//
|
|
15
|
+
// `@imports/` is the only way to name someone else's file, so a cross-deck
|
|
16
|
+
// reference is visible as one at a glance, and it means the same thing from any
|
|
17
|
+
// depth: imports are flattened into one `imports/` at the deck root, so the
|
|
18
|
+
// prefix is positional in nothing.
|
|
19
|
+
export const IMPORTS_PREFIX = '@imports/';
|
|
20
|
+
// Where imports live on disk, relative to the deck root. `@imports/x/y` is
|
|
21
|
+
// exactly `imports/x/y` -- the alias exists so the reference reads as a
|
|
22
|
+
// cross-deck one and does not depend on where the referencing file sits.
|
|
23
|
+
export const IMPORTS_DIR = 'imports';
|
|
24
|
+
function stripDotSlash(path) {
|
|
25
|
+
return path.replace(/^\.\//, '');
|
|
26
|
+
}
|
|
27
|
+
// The deck a file belongs to, as a path prefix: `imports/<alias>/` for a file of
|
|
28
|
+
// an import, `''` for one of the deck's own.
|
|
29
|
+
export function deckPrefixOf(filePath) {
|
|
30
|
+
const match = new RegExp(`^(${IMPORTS_DIR}/[^/]+/)`).exec(filePath ?? '');
|
|
31
|
+
return match ? match[1] : '';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolve a reference to the key it names in the deck's file map.
|
|
35
|
+
*
|
|
36
|
+
* @param ref the reference as written -- `drawings/rock.pxart` or
|
|
37
|
+
* `@imports/someone.pack/drawings/rock.pxart`
|
|
38
|
+
* @param from the path of the file the reference was written in; a reference in
|
|
39
|
+
* a deck's own file resolves against the deck root, one in an
|
|
40
|
+
* import's file against that import.
|
|
41
|
+
*/
|
|
42
|
+
export function resolveDeckFile(ref, from = '') {
|
|
43
|
+
const path = stripDotSlash(String(ref ?? ''));
|
|
44
|
+
if (path.startsWith(IMPORTS_PREFIX)) {
|
|
45
|
+
return `${IMPORTS_DIR}/${path.slice(IMPORTS_PREFIX.length)}`;
|
|
46
|
+
}
|
|
47
|
+
return deckPrefixOf(stripDotSlash(from)) + path;
|
|
48
|
+
}
|
|
49
|
+
/** Whether a path names a file some import owns (rather than the deck's own). */
|
|
50
|
+
export function isImportedFile(filePath) {
|
|
51
|
+
return deckPrefixOf(filePath) !== '';
|
|
52
|
+
}
|