@datamoc/mw_games 0.7.1 → 0.7.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +964 -0
  2. package/README.md +27 -2
  3. package/dist/actors/Affix.d.ts +7 -1
  4. package/dist/actors/Affix.d.ts.map +1 -1
  5. package/dist/actors/Affix.js +4 -2
  6. package/dist/actors/Affix.js.map +1 -1
  7. package/dist/actors/StatBlock.d.ts +20 -0
  8. package/dist/actors/StatBlock.d.ts.map +1 -1
  9. package/dist/actors/StatBlock.js +14 -3
  10. package/dist/actors/StatBlock.js.map +1 -1
  11. package/dist/actors/index.d.ts +2 -2
  12. package/dist/actors/index.d.ts.map +1 -1
  13. package/dist/actors/index.js +1 -1
  14. package/dist/actors/index.js.map +1 -1
  15. package/dist/ai/index.d.ts +118 -0
  16. package/dist/ai/index.d.ts.map +1 -0
  17. package/dist/ai/index.js +203 -0
  18. package/dist/ai/index.js.map +1 -0
  19. package/dist/ai/lua.d.ts +47 -0
  20. package/dist/ai/lua.d.ts.map +1 -0
  21. package/dist/ai/lua.js +195 -0
  22. package/dist/ai/lua.js.map +1 -0
  23. package/dist/ai/search.d.ts +59 -0
  24. package/dist/ai/search.d.ts.map +1 -0
  25. package/dist/ai/search.js +100 -0
  26. package/dist/ai/search.js.map +1 -0
  27. package/dist/board/Engine.d.ts +14 -0
  28. package/dist/board/Engine.d.ts.map +1 -1
  29. package/dist/board/Engine.js +33 -45
  30. package/dist/board/Engine.js.map +1 -1
  31. package/dist/board/index.d.ts +1 -1
  32. package/dist/board/index.d.ts.map +1 -1
  33. package/dist/board/index.js +1 -1
  34. package/dist/board/index.js.map +1 -1
  35. package/dist/core/Csv.d.ts +10 -0
  36. package/dist/core/Csv.d.ts.map +1 -1
  37. package/dist/core/Csv.js +34 -3
  38. package/dist/core/Csv.js.map +1 -1
  39. package/dist/core/Entity.d.ts +2 -2
  40. package/dist/core/Entity.d.ts.map +1 -1
  41. package/dist/core/Entity.js +18 -4
  42. package/dist/core/Entity.js.map +1 -1
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -0
  46. package/dist/index.js.map +1 -1
  47. package/dist/mw_games.global.js +96 -96
  48. package/dist/mwl/actors.d.ts +3 -1
  49. package/dist/mwl/actors.d.ts.map +1 -1
  50. package/dist/mwl/actors.js +5 -0
  51. package/dist/mwl/actors.js.map +1 -1
  52. package/dist/mwl/catalog.d.ts.map +1 -1
  53. package/dist/mwl/catalog.js +2 -10
  54. package/dist/mwl/catalog.js.map +1 -1
  55. package/dist/mwl/compiler.d.ts +14 -0
  56. package/dist/mwl/compiler.d.ts.map +1 -1
  57. package/dist/mwl/compiler.js +23 -0
  58. package/dist/mwl/compiler.js.map +1 -1
  59. package/dist/mwl/conditions.d.ts +9 -0
  60. package/dist/mwl/conditions.d.ts.map +1 -0
  61. package/dist/mwl/conditions.js +162 -0
  62. package/dist/mwl/conditions.js.map +1 -0
  63. package/dist/mwl/content.d.ts +25 -0
  64. package/dist/mwl/content.d.ts.map +1 -1
  65. package/dist/mwl/content.js +46 -34
  66. package/dist/mwl/content.js.map +1 -1
  67. package/dist/mwl/fengari.d.ts +8 -0
  68. package/dist/mwl/fengari.d.ts.map +1 -0
  69. package/dist/mwl/fengari.js +136 -0
  70. package/dist/mwl/fengari.js.map +1 -0
  71. package/dist/mwl/hooks.d.ts +1 -1
  72. package/dist/mwl/index.d.ts +16 -7
  73. package/dist/mwl/index.d.ts.map +1 -1
  74. package/dist/mwl/index.js +7 -3
  75. package/dist/mwl/index.js.map +1 -1
  76. package/dist/mwl/readers.d.ts +18 -0
  77. package/dist/mwl/readers.d.ts.map +1 -0
  78. package/dist/mwl/readers.js +58 -0
  79. package/dist/mwl/readers.js.map +1 -0
  80. package/dist/mwl/report.d.ts +9 -0
  81. package/dist/mwl/report.d.ts.map +1 -0
  82. package/dist/mwl/report.js +36 -0
  83. package/dist/mwl/report.js.map +1 -0
  84. package/dist/mwl/runtime.d.ts +37 -1
  85. package/dist/mwl/runtime.d.ts.map +1 -1
  86. package/dist/mwl/runtime.js +170 -19
  87. package/dist/mwl/runtime.js.map +1 -1
  88. package/dist/mwl/schema.d.ts +13 -1
  89. package/dist/mwl/schema.d.ts.map +1 -1
  90. package/dist/mwl/schema.js +195 -8
  91. package/dist/mwl/schema.js.map +1 -1
  92. package/dist/mwl/scripts.d.ts +15 -0
  93. package/dist/mwl/scripts.d.ts.map +1 -0
  94. package/dist/mwl/scripts.js +23 -0
  95. package/dist/mwl/scripts.js.map +1 -0
  96. package/dist/mwl/utils.d.ts +8 -0
  97. package/dist/mwl/utils.d.ts.map +1 -0
  98. package/dist/mwl/utils.js +37 -0
  99. package/dist/mwl/utils.js.map +1 -0
  100. package/dist/two-d/render/Types2D.d.ts +19 -4
  101. package/dist/two-d/render/Types2D.d.ts.map +1 -1
  102. package/dist/two-d/render/Types2D.js +25 -0
  103. package/dist/two-d/render/Types2D.js.map +1 -1
  104. package/dist/two-d/render/index.d.ts +2 -2
  105. package/dist/two-d/render/index.d.ts.map +1 -1
  106. package/dist/two-d/render/index.js +1 -1
  107. package/dist/two-d/render/index.js.map +1 -1
  108. package/dist/version.d.ts +1 -1
  109. package/dist/version.js +1 -1
  110. package/package.json +19 -3
  111. package/tools/mwl.mjs +32 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datamoc/mw_games",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "A local-file game framework: renderer-free game logic, drawn through PixiJS in 2D or Babylon.js in 3D, with mobile and desktop packaging.",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {
@@ -45,6 +45,7 @@
45
45
  "tools/compress-dist.d.mts",
46
46
  "tools/mwl.mjs",
47
47
  "LICENSE",
48
+ "CHANGELOG.md",
48
49
  "README.md"
49
50
  ],
50
51
  "exports": {
@@ -112,6 +113,18 @@
112
113
  "types": "./dist/mwl/index.d.ts",
113
114
  "import": "./dist/mwl/index.js"
114
115
  },
116
+ "./mwl/fengari": {
117
+ "types": "./dist/mwl/fengari.d.ts",
118
+ "import": "./dist/mwl/fengari.js"
119
+ },
120
+ "./ai": {
121
+ "types": "./dist/ai/index.d.ts",
122
+ "import": "./dist/ai/index.js"
123
+ },
124
+ "./ai/lua": {
125
+ "types": "./dist/ai/lua.d.ts",
126
+ "import": "./dist/ai/lua.js"
127
+ },
115
128
  "./tools/compile-resources": "./tools/compile-resources.mjs",
116
129
  "./tools/compress-dist": "./tools/compress-dist.mjs",
117
130
  "./two-d": {
@@ -151,7 +164,7 @@
151
164
  "mwl": "npm run build:pkg && node tools/mwl.mjs",
152
165
  "size:check": "node tools/bundle-size.mjs",
153
166
  "size:update": "node tools/bundle-size.mjs --update",
154
- "audit": "npm audit --audit-level=high",
167
+ "audit": "node tools/npm-audit.mjs",
155
168
  "example": "vite --config examples/colour-transform/vite.config.ts",
156
169
  "example:build": "vite build --config examples/colour-transform/vite.config.ts && node tools/emit-page.mjs examples/colour-transform",
157
170
  "test": "node --test \"tests/**/*.test.ts\"",
@@ -267,5 +280,8 @@
267
280
  },
268
281
  "main": "./dist/index.js",
269
282
  "types": "./dist/index.d.ts",
270
- "unpkg": "./dist/mw_games.global.js"
283
+ "unpkg": "./dist/mw_games.global.js",
284
+ "optionalDependencies": {
285
+ "fengari": "^0.1.5"
286
+ }
271
287
  }
package/tools/mwl.mjs CHANGED
@@ -6,7 +6,9 @@ import { pathToFileURL } from 'node:url';
6
6
  import {
7
7
  collectHookReferences,
8
8
  compile,
9
+ compileAndEmitSources,
9
10
  compileSources,
11
+ contentReport,
10
12
  emitHooksDeclaration,
11
13
  emitModule,
12
14
  extractCatalog,
@@ -26,16 +28,18 @@ import {
26
28
  */
27
29
 
28
30
  const args = process.argv.slice(2);
29
- const commands = ['validate', 'compile', 'extract-i18n', 'assets', 'hooks', 'build'];
31
+ const commands = ['validate', 'compile', 'extract-i18n', 'assets', 'report', 'hooks', 'build'];
30
32
  const [command, input] = args;
31
33
  const outputFlag = args.indexOf('-o');
32
34
  const output = outputFlag === -1 ? undefined : args[outputFlag + 1];
33
35
  const manifestFlag = args.indexOf('--manifest');
34
36
  const manifestPath = manifestFlag === -1 ? undefined : args[manifestFlag + 1];
37
+ const assetRootFlag = args.indexOf('--asset-root');
38
+ const assetRoot = assetRootFlag === -1 ? undefined : args[assetRootFlag + 1];
35
39
 
36
40
  if (!command || !input || !commands.includes(command)) {
37
41
  console.error(
38
- 'Usage: mwl <validate|compile|extract-i18n|assets|hooks|build> input.mwl [-o output] [--manifest hooks.json]',
42
+ 'Usage: mwl <validate|compile|extract-i18n|assets|report|hooks|build> input.mwl [-o output] [--manifest hooks.json] [--asset-root directory]',
39
43
  );
40
44
  process.exitCode = 2;
41
45
  } else {
@@ -69,7 +73,8 @@ if (!command || !input || !commands.includes(command)) {
69
73
  const result = compileSources(files);
70
74
  const values =
71
75
  command === 'extract-i18n' ? extractCatalog(result) : command === 'assets' ? result.assets : result;
72
- const text = command === 'compile' ? emitModule(result) : `${JSON.stringify(values, null, '\t')}\n`;
76
+ const report = command === 'report' ? contentReport(result) : values;
77
+ const text = command === 'compile' ? emitModule(result) : `${JSON.stringify(report, null, '\t')}\n`;
73
78
  if (output) {
74
79
  fs.mkdirSync(path.dirname(path.resolve(output)), { recursive: true });
75
80
  fs.writeFileSync(output, text);
@@ -109,14 +114,35 @@ function sourceLabel(file) {
109
114
  /** One deterministic build step for the three files every MWL game consumes. */
110
115
  function build(files) {
111
116
  const game = compileSources(files);
117
+ if (assetRoot) validateAssets(game, path.resolve(assetRoot));
112
118
  const directory = path.resolve(output ?? 'generated');
113
119
  fs.mkdirSync(directory, { recursive: true });
114
- fs.writeFileSync(path.join(directory, 'game-data.ts'), emitModule(game));
115
- fs.writeFileSync(path.join(directory, 'i18n.json'), `${JSON.stringify(extractCatalog(game), null, '\t')}\n`);
116
- fs.writeFileSync(path.join(directory, 'assets.json'), `${JSON.stringify({ assets: game.assets }, null, '\t')}\n`);
120
+ const artifacts = compileAndEmitSources(files);
121
+ for (const artifact of artifacts) fs.writeFileSync(path.join(directory, artifact.name), artifact.content);
117
122
  console.log(`built MWL into ${directory}`);
118
123
  }
119
124
 
125
+ function validateAssets(game, root) {
126
+ const missing = game.assets.filter(
127
+ (asset) => !asset.startsWith('data:') && !fs.existsSync(path.resolve(root, asset)),
128
+ );
129
+ if (!missing.length) return;
130
+ const locations = new Map();
131
+ const visit = (node) => {
132
+ for (const value of Object.values(node.attributes))
133
+ for (const asset of missing)
134
+ if (value.includes(asset) && !locations.has(asset)) locations.set(asset, node.location);
135
+ node.children.forEach(visit);
136
+ };
137
+ game.roots.forEach(visit);
138
+ for (const asset of missing) {
139
+ const location = locations.get(asset);
140
+ const prefix = location ? `${location.file}:${location.line}:${location.column}: ` : '';
141
+ console.error(`${prefix}missing MWL asset "${asset}" under ${root}`);
142
+ }
143
+ throw new Error(`${missing.length} MWL asset(s) not found`);
144
+ }
145
+
120
146
  /**
121
147
  * `mwl hooks game.mwl` prints the hook references content needs.
122
148
  * `mwl hooks game.mwl --manifest hooks.json -o generated/hooks.mjs` resolves