@directivegames/genesys.sdk 3.2.2 → 3.2.5

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.
Files changed (125) hide show
  1. package/README.md +60 -60
  2. package/dist/src/asset-pack/eslint.config.js +4 -4
  3. package/dist/src/core/cli.js +22 -22
  4. package/dist/src/core/common.js +2 -2
  5. package/dist/src/core/tools/build-project.js +1 -1
  6. package/dist/src/core/tools/new-asset-pack.js +1 -1
  7. package/dist/src/core/tools/new-project.js +1 -1
  8. package/dist/src/dependencies.js +1 -1
  9. package/dist/src/electron/backend/tools/const.js +1 -1
  10. package/dist/src/electron/backend/tools/open-project.js +1 -1
  11. package/dist/src/templates/eslint.config.js +4 -4
  12. package/dist/src/templates/scripts/genesys/calc-bounding-box.js +2 -2
  13. package/dist/src/templates/scripts/genesys/dev/dump-default-scene.js +1 -1
  14. package/dist/src/templates/scripts/genesys/dev/generate-manifest.js +1 -1
  15. package/dist/src/templates/scripts/genesys/dev/launcher.js +1 -1
  16. package/dist/src/templates/scripts/genesys/dev/storage-provider.js +4 -4
  17. package/dist/src/templates/scripts/genesys/genesys-mcp.js +26 -26
  18. package/dist/src/templates/scripts/genesys/mcp/doc-tools.js +2 -2
  19. package/dist/src/templates/scripts/genesys/mcp/editor-functions.js +5 -5
  20. package/dist/src/templates/scripts/genesys/mcp/search-actors.js +1 -1
  21. package/dist/src/templates/scripts/genesys/mcp/search-assets.js +1 -1
  22. package/dist/src/templates/scripts/genesys/mcp/utils.js +1 -1
  23. package/dist/src/templates/scripts/genesys/misc.js +1 -1
  24. package/dist/src/templates/scripts/genesys/mock.js +1 -1
  25. package/dist/src/templates/scripts/genesys/place-actors.js +1 -1
  26. package/dist/src/templates/scripts/genesys/post-install.js +1 -1
  27. package/dist/src/templates/scripts/genesys/storageProvider.js +2 -2
  28. package/dist/src/templates/src/index.js +1 -1
  29. package/dist/src/templates/src/templates/firstPerson/src/game.js +1 -1
  30. package/dist/src/templates/src/templates/firstPerson/src/player.js +1 -1
  31. package/dist/src/templates/src/templates/fps/src/game.js +1 -1
  32. package/dist/src/templates/src/templates/fps/src/player.js +1 -1
  33. package/dist/src/templates/src/templates/fps/src/weapon.js +1 -1
  34. package/dist/src/templates/src/templates/freeCamera/src/game.js +1 -1
  35. package/dist/src/templates/src/templates/freeCamera/src/player.js +1 -1
  36. package/dist/src/templates/src/templates/sideScroller/src/game.js +1 -1
  37. package/dist/src/templates/src/templates/sideScroller/src/level-generator.js +1 -1
  38. package/dist/src/templates/src/templates/sideScroller/src/player.js +1 -1
  39. package/dist/src/templates/src/templates/thirdPerson/src/game.js +1 -1
  40. package/dist/src/templates/src/templates/thirdPerson/src/player.js +1 -1
  41. package/dist/src/templates/src/templates/vehicle/src/base-vehicle.js +1 -1
  42. package/dist/src/templates/src/templates/vehicle/src/game.js +1 -1
  43. package/dist/src/templates/src/templates/vehicle/src/mesh-vehicle.js +1 -1
  44. package/dist/src/templates/src/templates/vehicle/src/player.js +1 -1
  45. package/dist/src/templates/src/templates/vehicle/src/primitive-vehicle.js +1 -1
  46. package/dist/src/templates/src/templates/vehicle/src/ui-hints.js +31 -31
  47. package/dist/src/templates/src/templates/vr-game/src/game.js +1 -1
  48. package/dist/src/templates/src/templates/vr-game/src/sample-vr-actor.js +1 -1
  49. package/package.json +176 -176
  50. package/scripts/post-install.ts +143 -143
  51. package/src/asset-pack/.gitattributes +88 -88
  52. package/src/asset-pack/eslint.config.js +45 -45
  53. package/src/asset-pack/gitignore +11 -11
  54. package/src/asset-pack/scripts/postinstall.ts +81 -81
  55. package/src/asset-pack/tsconfig.json +33 -33
  56. package/src/templates/.cursor/mcp.json +20 -20
  57. package/src/templates/.cursorignore +2 -2
  58. package/src/templates/.gitattributes +88 -88
  59. package/src/templates/.vscode/settings.json +6 -6
  60. package/src/templates/AGENTS.md +86 -86
  61. package/src/templates/README.md +24 -24
  62. package/src/templates/eslint.config.js +45 -45
  63. package/src/templates/gitignore +11 -11
  64. package/src/templates/index.html +34 -34
  65. package/src/templates/pnpm-lock.yaml +3676 -3676
  66. package/src/templates/scripts/genesys/build-project.ts +51 -51
  67. package/src/templates/scripts/genesys/calc-bounding-box.ts +272 -272
  68. package/src/templates/scripts/genesys/common.ts +46 -46
  69. package/src/templates/scripts/genesys/const.ts +9 -9
  70. package/src/templates/scripts/genesys/dev/dump-default-scene.ts +11 -11
  71. package/src/templates/scripts/genesys/dev/generate-manifest.ts +146 -146
  72. package/src/templates/scripts/genesys/dev/launcher.ts +46 -46
  73. package/src/templates/scripts/genesys/dev/storage-provider.ts +229 -229
  74. package/src/templates/scripts/genesys/dev/update-template-scenes.ts +84 -84
  75. package/src/templates/scripts/genesys/doc-server.ts +16 -16
  76. package/src/templates/scripts/genesys/genesys-mcp.ts +526 -526
  77. package/src/templates/scripts/genesys/mcp/doc-tools.ts +86 -86
  78. package/src/templates/scripts/genesys/mcp/editor-functions.ts +151 -151
  79. package/src/templates/scripts/genesys/mcp/editor-tools.ts +73 -73
  80. package/src/templates/scripts/genesys/mcp/get-scene-state.ts +35 -35
  81. package/src/templates/scripts/genesys/mcp/run-subprocess.ts +30 -30
  82. package/src/templates/scripts/genesys/mcp/search-actors.ts +858 -858
  83. package/src/templates/scripts/genesys/mcp/search-assets.ts +380 -380
  84. package/src/templates/scripts/genesys/mcp/utils.ts +281 -281
  85. package/src/templates/scripts/genesys/misc.ts +42 -42
  86. package/src/templates/scripts/genesys/mock.ts +6 -6
  87. package/src/templates/scripts/genesys/place-actors.ts +179 -179
  88. package/src/templates/scripts/genesys/post-install.ts +30 -30
  89. package/src/templates/scripts/genesys/prefab.schema.json +84 -84
  90. package/src/templates/scripts/genesys/remove-engine-comments.ts +134 -134
  91. package/src/templates/scripts/genesys/run-mcp-inspector.bat +4 -4
  92. package/src/templates/scripts/genesys/storageProvider.ts +182 -182
  93. package/src/templates/scripts/genesys/validate-prefabs.ts +138 -138
  94. package/src/templates/src/index.ts +22 -22
  95. package/src/templates/src/templates/firstPerson/assets/default.genesys-scene +165 -165
  96. package/src/templates/src/templates/firstPerson/src/game.ts +39 -39
  97. package/src/templates/src/templates/firstPerson/src/player.ts +63 -63
  98. package/src/templates/src/templates/fps/assets/default.genesys-scene +9459 -9459
  99. package/src/templates/src/templates/fps/src/game.ts +39 -39
  100. package/src/templates/src/templates/fps/src/player.ts +69 -69
  101. package/src/templates/src/templates/fps/src/weapon.ts +54 -54
  102. package/src/templates/src/templates/freeCamera/assets/default.genesys-scene +165 -165
  103. package/src/templates/src/templates/freeCamera/src/game.ts +39 -39
  104. package/src/templates/src/templates/freeCamera/src/player.ts +45 -45
  105. package/src/templates/src/templates/sideScroller/assets/default.genesys-scene +121 -121
  106. package/src/templates/src/templates/sideScroller/src/const.ts +45 -45
  107. package/src/templates/src/templates/sideScroller/src/game.ts +122 -122
  108. package/src/templates/src/templates/sideScroller/src/level-generator.ts +361 -361
  109. package/src/templates/src/templates/sideScroller/src/player.ts +125 -125
  110. package/src/templates/src/templates/thirdPerson/assets/default.genesys-scene +165 -165
  111. package/src/templates/src/templates/thirdPerson/src/game.ts +39 -39
  112. package/src/templates/src/templates/thirdPerson/src/player.ts +61 -61
  113. package/src/templates/src/templates/vehicle/assets/default.genesys-scene +225 -225
  114. package/src/templates/src/templates/vehicle/src/base-vehicle.ts +145 -145
  115. package/src/templates/src/templates/vehicle/src/game.ts +43 -43
  116. package/src/templates/src/templates/vehicle/src/mesh-vehicle.ts +191 -191
  117. package/src/templates/src/templates/vehicle/src/player.ts +109 -109
  118. package/src/templates/src/templates/vehicle/src/primitive-vehicle.ts +266 -266
  119. package/src/templates/src/templates/vehicle/src/ui-hints.ts +101 -101
  120. package/src/templates/src/templates/vr-game/assets/default.genesys-scene +246 -246
  121. package/src/templates/src/templates/vr-game/src/auto-imports.ts +1 -1
  122. package/src/templates/src/templates/vr-game/src/game.ts +66 -66
  123. package/src/templates/src/templates/vr-game/src/sample-vr-actor.ts +26 -26
  124. package/src/templates/tsconfig.json +34 -34
  125. package/src/templates/vite.config.ts +52 -52
@@ -1,135 +1,135 @@
1
- #!/usr/bin/env tsx
2
-
3
- import { readdir, readFile, stat, writeFile } from 'fs/promises';
4
- import { join } from 'path';
5
-
6
- /**
7
- * Recursively finds all TypeScript files in a directory
8
- */
9
- async function findTsFiles(dir: string): Promise<string[]> {
10
- const files: string[] = [];
11
-
12
- try {
13
- const entries = await readdir(dir);
14
-
15
- for (const entry of entries) {
16
- const fullPath = join(dir, entry);
17
- const stats = await stat(fullPath);
18
-
19
- if (stats.isDirectory()) {
20
- const subFiles = await findTsFiles(fullPath);
21
- files.push(...subFiles);
22
- } else if (entry.endsWith('.ts') || entry.endsWith('.tsx')) {
23
- files.push(fullPath);
24
- }
25
- }
26
- } catch (error) {
27
- console.warn(`Warning: Could not read directory ${dir}:`, error);
28
- }
29
-
30
- return files;
31
- }
32
-
33
- /**
34
- * Removes comments from TypeScript code using regex
35
- */
36
- function removeComments(code: string): { cleaned: string; hadComments: boolean } {
37
- const originalLength = code.length;
38
-
39
- // Remove single-line comments (// comments)
40
- // This regex handles // comments but preserves URLs and string literals
41
- let cleaned = code.replace(/^(\s*)\/\/.*$/gm, '$1');
42
-
43
- // Remove multi-line comments (/* ... */ and /** ... */)
44
- // This regex handles nested quotes and preserves strings
45
- cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, '');
46
-
47
- // Clean up multiple consecutive empty lines (replace with single empty line)
48
- cleaned = cleaned.replace(/\n\s*\n\s*\n/g, '\n\n');
49
-
50
- // Trim trailing whitespace on each line
51
- cleaned = cleaned.replace(/[ \t]+$/gm, '');
52
-
53
- const hadComments = cleaned.length !== originalLength || cleaned !== code;
54
-
55
- return { cleaned, hadComments };
56
- }
57
-
58
- /**
59
- * Removes comments from a TypeScript file
60
- */
61
- async function removeCommentsFromFile(filePath: string): Promise<boolean> {
62
- try {
63
- const content = await readFile(filePath, 'utf8');
64
- const { cleaned, hadComments } = removeComments(content);
65
-
66
- if (!hadComments) {
67
- return false; // No comments to remove
68
- }
69
-
70
- await writeFile(filePath, cleaned, 'utf8');
71
- return true;
72
- } catch (error) {
73
- console.error(`Error processing file ${filePath}:`, error);
74
- return false;
75
- }
76
- }
77
-
78
- async function main() {
79
- const engineDir = '.engine';
80
-
81
- console.log(`Searching for TypeScript files in ${engineDir}...`);
82
- console.log(`Current working directory: ${process.cwd()}`);
83
-
84
- try {
85
- const tsFiles = await findTsFiles(engineDir);
86
-
87
- console.log(`Found ${tsFiles.length} TypeScript files.`);
88
- if (tsFiles.length > 0) {
89
- console.log('First few files:');
90
- tsFiles.slice(0, 5).forEach(file => console.log(` - ${file}`));
91
- }
92
-
93
- if (tsFiles.length === 0) {
94
- console.log('No TypeScript files found in .engine folder.');
95
- return;
96
- }
97
-
98
- let processedCount = 0;
99
- let modifiedCount = 0;
100
-
101
- for (const filePath of tsFiles) {
102
- console.log(`Processing: ${filePath}`);
103
-
104
- try {
105
- const wasModified = await removeCommentsFromFile(filePath);
106
- processedCount++;
107
-
108
- if (wasModified) {
109
- modifiedCount++;
110
- console.log(' ✓ Comments removed');
111
- } else {
112
- console.log(' - No comments found');
113
- }
114
- } catch (error) {
115
- console.error(` ✗ Error: ${error}`);
116
- }
117
- }
118
-
119
- console.log('\nCompleted:');
120
- console.log(`- Files processed: ${processedCount}`);
121
- console.log(`- Files modified: ${modifiedCount}`);
122
- console.log(`- Files skipped: ${processedCount - modifiedCount}`);
123
-
124
- } catch (error) {
125
- console.error('Error:', error);
126
- process.exit(1);
127
- }
128
- }
129
-
130
- // Always run main if this file is executed directly
131
- main().catch((error) => {
132
- console.error('Unexpected error:', error);
133
- console.error('Stack trace:', error.stack);
134
- process.exit(1);
1
+ #!/usr/bin/env tsx
2
+
3
+ import { readdir, readFile, stat, writeFile } from 'fs/promises';
4
+ import { join } from 'path';
5
+
6
+ /**
7
+ * Recursively finds all TypeScript files in a directory
8
+ */
9
+ async function findTsFiles(dir: string): Promise<string[]> {
10
+ const files: string[] = [];
11
+
12
+ try {
13
+ const entries = await readdir(dir);
14
+
15
+ for (const entry of entries) {
16
+ const fullPath = join(dir, entry);
17
+ const stats = await stat(fullPath);
18
+
19
+ if (stats.isDirectory()) {
20
+ const subFiles = await findTsFiles(fullPath);
21
+ files.push(...subFiles);
22
+ } else if (entry.endsWith('.ts') || entry.endsWith('.tsx')) {
23
+ files.push(fullPath);
24
+ }
25
+ }
26
+ } catch (error) {
27
+ console.warn(`Warning: Could not read directory ${dir}:`, error);
28
+ }
29
+
30
+ return files;
31
+ }
32
+
33
+ /**
34
+ * Removes comments from TypeScript code using regex
35
+ */
36
+ function removeComments(code: string): { cleaned: string; hadComments: boolean } {
37
+ const originalLength = code.length;
38
+
39
+ // Remove single-line comments (// comments)
40
+ // This regex handles // comments but preserves URLs and string literals
41
+ let cleaned = code.replace(/^(\s*)\/\/.*$/gm, '$1');
42
+
43
+ // Remove multi-line comments (/* ... */ and /** ... */)
44
+ // This regex handles nested quotes and preserves strings
45
+ cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, '');
46
+
47
+ // Clean up multiple consecutive empty lines (replace with single empty line)
48
+ cleaned = cleaned.replace(/\n\s*\n\s*\n/g, '\n\n');
49
+
50
+ // Trim trailing whitespace on each line
51
+ cleaned = cleaned.replace(/[ \t]+$/gm, '');
52
+
53
+ const hadComments = cleaned.length !== originalLength || cleaned !== code;
54
+
55
+ return { cleaned, hadComments };
56
+ }
57
+
58
+ /**
59
+ * Removes comments from a TypeScript file
60
+ */
61
+ async function removeCommentsFromFile(filePath: string): Promise<boolean> {
62
+ try {
63
+ const content = await readFile(filePath, 'utf8');
64
+ const { cleaned, hadComments } = removeComments(content);
65
+
66
+ if (!hadComments) {
67
+ return false; // No comments to remove
68
+ }
69
+
70
+ await writeFile(filePath, cleaned, 'utf8');
71
+ return true;
72
+ } catch (error) {
73
+ console.error(`Error processing file ${filePath}:`, error);
74
+ return false;
75
+ }
76
+ }
77
+
78
+ async function main() {
79
+ const engineDir = '.engine';
80
+
81
+ console.log(`Searching for TypeScript files in ${engineDir}...`);
82
+ console.log(`Current working directory: ${process.cwd()}`);
83
+
84
+ try {
85
+ const tsFiles = await findTsFiles(engineDir);
86
+
87
+ console.log(`Found ${tsFiles.length} TypeScript files.`);
88
+ if (tsFiles.length > 0) {
89
+ console.log('First few files:');
90
+ tsFiles.slice(0, 5).forEach(file => console.log(` - ${file}`));
91
+ }
92
+
93
+ if (tsFiles.length === 0) {
94
+ console.log('No TypeScript files found in .engine folder.');
95
+ return;
96
+ }
97
+
98
+ let processedCount = 0;
99
+ let modifiedCount = 0;
100
+
101
+ for (const filePath of tsFiles) {
102
+ console.log(`Processing: ${filePath}`);
103
+
104
+ try {
105
+ const wasModified = await removeCommentsFromFile(filePath);
106
+ processedCount++;
107
+
108
+ if (wasModified) {
109
+ modifiedCount++;
110
+ console.log(' ✓ Comments removed');
111
+ } else {
112
+ console.log(' - No comments found');
113
+ }
114
+ } catch (error) {
115
+ console.error(` ✗ Error: ${error}`);
116
+ }
117
+ }
118
+
119
+ console.log('\nCompleted:');
120
+ console.log(`- Files processed: ${processedCount}`);
121
+ console.log(`- Files modified: ${modifiedCount}`);
122
+ console.log(`- Files skipped: ${processedCount - modifiedCount}`);
123
+
124
+ } catch (error) {
125
+ console.error('Error:', error);
126
+ process.exit(1);
127
+ }
128
+ }
129
+
130
+ // Always run main if this file is executed directly
131
+ main().catch((error) => {
132
+ console.error('Unexpected error:', error);
133
+ console.error('Stack trace:', error.stack);
134
+ process.exit(1);
135
135
  });
@@ -1,5 +1,5 @@
1
- pushd %~dp0
2
- cd ..
3
- set DANGEROUSLY_OMIT_AUTH=1
4
- pnpm dlx @modelcontextprotocol/inspector pnpm dlx tsx ./scripts/genesys/genesys-mcp.ts
1
+ pushd %~dp0
2
+ cd ..
3
+ set DANGEROUSLY_OMIT_AUTH=1
4
+ pnpm dlx @modelcontextprotocol/inspector pnpm dlx tsx ./scripts/genesys/genesys-mcp.ts
5
5
  popd
@@ -1,182 +1,182 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- import * as ENGINE from 'genesys.js';
5
- import { AssetPath, AssetPathEncodeState } from 'genesys.js';
6
-
7
- import { getProjectRoot } from './common.js';
8
-
9
-
10
- export class StorageProvider implements ENGINE.IStorageProvider {
11
- public async resolvePath(assetPath: AssetPath, expiry?: number): Promise<AssetPath> {
12
- if (assetPath.isResolved()) {
13
- return assetPath;
14
- }
15
-
16
- assetPath.resolvePath(this.getFullPath(assetPath.initialPath), AssetPathEncodeState.Decoded);
17
- return assetPath;
18
- }
19
-
20
- public getFullPath(filePath: string): string {
21
- let fullPath = filePath;
22
- let rootPath = undefined;
23
-
24
- if (filePath.startsWith(ENGINE.PROJECT_PATH_PREFIX)) {
25
- filePath = filePath.slice(ENGINE.PROJECT_PATH_PREFIX.length);
26
- rootPath = getProjectRoot();
27
- }
28
- else if (filePath.startsWith(ENGINE.ENGINE_PATH_PREFIX)) {
29
- filePath = filePath.slice(ENGINE.ENGINE_PATH_PREFIX.length);
30
- rootPath = path.join(getProjectRoot(), 'node_modules', 'genesys.js');
31
- }
32
-
33
- if (rootPath !== undefined) {
34
- fullPath = AssetPath.join(rootPath, filePath);
35
- }
36
- return fullPath;
37
- }
38
-
39
- public async downloadFileAsBuffer(
40
- assetPath: AssetPath,
41
- ): Promise<ArrayBuffer> {
42
- assetPath = await this.resolvePath(assetPath);
43
- const fullPath = getResolvedPath(assetPath);
44
- if (!fs.existsSync(fullPath)) {
45
- return new ArrayBuffer(0);
46
- }
47
-
48
- const data = fs.readFileSync(fullPath);
49
- const arrayBuffer = data.buffer.slice(
50
- data.byteOffset,
51
- data.byteOffset + data.byteLength
52
- );
53
- return arrayBuffer;
54
- }
55
-
56
- public async downloadFileAsJson<T>(assetPath: AssetPath): Promise<T> {
57
- assetPath = await this.resolvePath(assetPath);
58
- const fullPath = getResolvedPath(assetPath);
59
- if (!fs.existsSync(fullPath)) {
60
- return {} as T;
61
- }
62
- return JSON.parse(fs.readFileSync(fullPath, 'utf8'));
63
- }
64
-
65
- public async downloadFileAsText(assetPath: AssetPath): Promise<string> {
66
- assetPath = await this.resolvePath(assetPath);
67
- const fullPath = getResolvedPath(assetPath);
68
- if (!fs.existsSync(fullPath)) {
69
- return '';
70
- }
71
- return fs.readFileSync(fullPath, 'utf8');
72
- }
73
-
74
- public async exists(assetPath: AssetPath): Promise<boolean> {
75
- assetPath = await this.resolvePath(assetPath);
76
- const fullPath = getResolvedPath(assetPath);
77
- return fs.existsSync(fullPath);
78
- }
79
-
80
- public async buildCurrentProject(runTsc: boolean): Promise<boolean> {
81
- throw new Error('Not implemented');
82
- }
83
-
84
- public async uploadFile(assetPath: AssetPath, content: Blob | File | string | ArrayBuffer, options?: ENGINE.FileUploadOptions): Promise<{
85
- path: string;
86
- name: string;
87
- }>
88
- {
89
- assetPath = await this.resolvePath(assetPath);
90
- const fullPath = getResolvedPath(assetPath);
91
- fs.mkdirSync(path.dirname(fullPath), { recursive: true });
92
-
93
- if (typeof content === 'string') {
94
- fs.writeFileSync(fullPath, content);
95
- } else {
96
- throw new Error(`Unsupported content type: ${typeof content}`);
97
- }
98
-
99
- return {
100
- path: fullPath,
101
- name: path.basename(fullPath)
102
- };
103
- }
104
-
105
- public async deleteFile(assetPath: AssetPath): Promise<void> {
106
- assetPath = await this.resolvePath(assetPath);
107
- const fullPath = getResolvedPath(assetPath);
108
- if (fs.existsSync(fullPath)) {
109
- fs.unlinkSync(fullPath);
110
- }
111
- }
112
-
113
- public async listFiles(assetPath: AssetPath, recursive?: boolean, includeHiddenFiles?: boolean): Promise<ENGINE.FileListResult> {
114
- assetPath = await this.resolvePath(assetPath);
115
- const fullPath = getResolvedPath(assetPath);
116
-
117
- if (!fs.existsSync(fullPath)) {
118
- return { files: [], directories: [] };
119
- }
120
-
121
- const files: ENGINE.FileItem[] = [];
122
- const directories: ENGINE.FileItem[] = [];
123
-
124
- const processDirectory = (dirPath: string, basePath: string = '') => {
125
- const entries = fs.readdirSync(dirPath, { withFileTypes: true });
126
-
127
- for (const entry of entries) {
128
- // Skip hidden files if not requested
129
- if (!includeHiddenFiles && entry.name.startsWith('.')) {
130
- continue;
131
- }
132
-
133
- const fullEntryPath = path.join(dirPath, entry.name);
134
- const relativePath = basePath ? path.join(basePath, entry.name) : entry.name;
135
- const stats = fs.statSync(fullEntryPath);
136
-
137
- const fileItem: ENGINE.FileItem = {
138
- name: entry.name,
139
- path: relativePath,
140
- absolutePath: fullEntryPath,
141
- size: stats.size,
142
- modifiedTime: stats.mtime,
143
- isDirectory: entry.isDirectory()
144
- };
145
-
146
- if (entry.isDirectory()) {
147
- directories.push(fileItem);
148
-
149
- // Recursively process subdirectories if requested
150
- if (recursive) {
151
- processDirectory(fullEntryPath, relativePath);
152
- }
153
- } else {
154
- files.push(fileItem);
155
- }
156
- }
157
- };
158
-
159
- // Check if the path is a directory
160
- const stats = fs.statSync(fullPath);
161
- if (stats.isDirectory()) {
162
- processDirectory(fullPath);
163
- } else {
164
- // If it's a file, return just that file
165
- const fileItem: ENGINE.FileItem = {
166
- name: path.basename(fullPath),
167
- path: path.basename(fullPath),
168
- absolutePath: fullPath,
169
- size: stats.size,
170
- modifiedTime: stats.mtime,
171
- isDirectory: false
172
- };
173
- files.push(fileItem);
174
- }
175
-
176
- return { files, directories };
177
- }
178
- }
179
-
180
- export function getResolvedPath(assetPath: ENGINE.AssetPath): string {
181
- return assetPath.getResolvedPath(false);
182
- }
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ import * as ENGINE from '@directivegames/genesys.js';
5
+ import { AssetPath, AssetPathEncodeState } from '@directivegames/genesys.js';
6
+
7
+ import { getProjectRoot } from './common.js';
8
+
9
+
10
+ export class StorageProvider implements ENGINE.IStorageProvider {
11
+ public async resolvePath(assetPath: AssetPath, expiry?: number): Promise<AssetPath> {
12
+ if (assetPath.isResolved()) {
13
+ return assetPath;
14
+ }
15
+
16
+ assetPath.resolvePath(this.getFullPath(assetPath.initialPath), AssetPathEncodeState.Decoded);
17
+ return assetPath;
18
+ }
19
+
20
+ public getFullPath(filePath: string): string {
21
+ let fullPath = filePath;
22
+ let rootPath = undefined;
23
+
24
+ if (filePath.startsWith(ENGINE.PROJECT_PATH_PREFIX)) {
25
+ filePath = filePath.slice(ENGINE.PROJECT_PATH_PREFIX.length);
26
+ rootPath = getProjectRoot();
27
+ }
28
+ else if (filePath.startsWith(ENGINE.ENGINE_PATH_PREFIX)) {
29
+ filePath = filePath.slice(ENGINE.ENGINE_PATH_PREFIX.length);
30
+ rootPath = path.join(getProjectRoot(), 'node_modules', 'genesys.js');
31
+ }
32
+
33
+ if (rootPath !== undefined) {
34
+ fullPath = AssetPath.join(rootPath, filePath);
35
+ }
36
+ return fullPath;
37
+ }
38
+
39
+ public async downloadFileAsBuffer(
40
+ assetPath: AssetPath,
41
+ ): Promise<ArrayBuffer> {
42
+ assetPath = await this.resolvePath(assetPath);
43
+ const fullPath = getResolvedPath(assetPath);
44
+ if (!fs.existsSync(fullPath)) {
45
+ return new ArrayBuffer(0);
46
+ }
47
+
48
+ const data = fs.readFileSync(fullPath);
49
+ const arrayBuffer = data.buffer.slice(
50
+ data.byteOffset,
51
+ data.byteOffset + data.byteLength
52
+ );
53
+ return arrayBuffer;
54
+ }
55
+
56
+ public async downloadFileAsJson<T>(assetPath: AssetPath): Promise<T> {
57
+ assetPath = await this.resolvePath(assetPath);
58
+ const fullPath = getResolvedPath(assetPath);
59
+ if (!fs.existsSync(fullPath)) {
60
+ return {} as T;
61
+ }
62
+ return JSON.parse(fs.readFileSync(fullPath, 'utf8'));
63
+ }
64
+
65
+ public async downloadFileAsText(assetPath: AssetPath): Promise<string> {
66
+ assetPath = await this.resolvePath(assetPath);
67
+ const fullPath = getResolvedPath(assetPath);
68
+ if (!fs.existsSync(fullPath)) {
69
+ return '';
70
+ }
71
+ return fs.readFileSync(fullPath, 'utf8');
72
+ }
73
+
74
+ public async exists(assetPath: AssetPath): Promise<boolean> {
75
+ assetPath = await this.resolvePath(assetPath);
76
+ const fullPath = getResolvedPath(assetPath);
77
+ return fs.existsSync(fullPath);
78
+ }
79
+
80
+ public async buildCurrentProject(runTsc: boolean): Promise<boolean> {
81
+ throw new Error('Not implemented');
82
+ }
83
+
84
+ public async uploadFile(assetPath: AssetPath, content: Blob | File | string | ArrayBuffer, options?: ENGINE.FileUploadOptions): Promise<{
85
+ path: string;
86
+ name: string;
87
+ }>
88
+ {
89
+ assetPath = await this.resolvePath(assetPath);
90
+ const fullPath = getResolvedPath(assetPath);
91
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
92
+
93
+ if (typeof content === 'string') {
94
+ fs.writeFileSync(fullPath, content);
95
+ } else {
96
+ throw new Error(`Unsupported content type: ${typeof content}`);
97
+ }
98
+
99
+ return {
100
+ path: fullPath,
101
+ name: path.basename(fullPath)
102
+ };
103
+ }
104
+
105
+ public async deleteFile(assetPath: AssetPath): Promise<void> {
106
+ assetPath = await this.resolvePath(assetPath);
107
+ const fullPath = getResolvedPath(assetPath);
108
+ if (fs.existsSync(fullPath)) {
109
+ fs.unlinkSync(fullPath);
110
+ }
111
+ }
112
+
113
+ public async listFiles(assetPath: AssetPath, recursive?: boolean, includeHiddenFiles?: boolean): Promise<ENGINE.FileListResult> {
114
+ assetPath = await this.resolvePath(assetPath);
115
+ const fullPath = getResolvedPath(assetPath);
116
+
117
+ if (!fs.existsSync(fullPath)) {
118
+ return { files: [], directories: [] };
119
+ }
120
+
121
+ const files: ENGINE.FileItem[] = [];
122
+ const directories: ENGINE.FileItem[] = [];
123
+
124
+ const processDirectory = (dirPath: string, basePath: string = '') => {
125
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
126
+
127
+ for (const entry of entries) {
128
+ // Skip hidden files if not requested
129
+ if (!includeHiddenFiles && entry.name.startsWith('.')) {
130
+ continue;
131
+ }
132
+
133
+ const fullEntryPath = path.join(dirPath, entry.name);
134
+ const relativePath = basePath ? path.join(basePath, entry.name) : entry.name;
135
+ const stats = fs.statSync(fullEntryPath);
136
+
137
+ const fileItem: ENGINE.FileItem = {
138
+ name: entry.name,
139
+ path: relativePath,
140
+ absolutePath: fullEntryPath,
141
+ size: stats.size,
142
+ modifiedTime: stats.mtime,
143
+ isDirectory: entry.isDirectory()
144
+ };
145
+
146
+ if (entry.isDirectory()) {
147
+ directories.push(fileItem);
148
+
149
+ // Recursively process subdirectories if requested
150
+ if (recursive) {
151
+ processDirectory(fullEntryPath, relativePath);
152
+ }
153
+ } else {
154
+ files.push(fileItem);
155
+ }
156
+ }
157
+ };
158
+
159
+ // Check if the path is a directory
160
+ const stats = fs.statSync(fullPath);
161
+ if (stats.isDirectory()) {
162
+ processDirectory(fullPath);
163
+ } else {
164
+ // If it's a file, return just that file
165
+ const fileItem: ENGINE.FileItem = {
166
+ name: path.basename(fullPath),
167
+ path: path.basename(fullPath),
168
+ absolutePath: fullPath,
169
+ size: stats.size,
170
+ modifiedTime: stats.mtime,
171
+ isDirectory: false
172
+ };
173
+ files.push(fileItem);
174
+ }
175
+
176
+ return { files, directories };
177
+ }
178
+ }
179
+
180
+ export function getResolvedPath(assetPath: ENGINE.AssetPath): string {
181
+ return assetPath.getResolvedPath(false);
182
+ }