@datamoc/mw_games 0.9.0-alpha → 0.9.1

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 (77) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +4 -0
  3. package/dist/core/ActionJournal.d.ts +2 -0
  4. package/dist/core/ActionJournal.d.ts.map +1 -1
  5. package/dist/core/ActionJournal.js +6 -0
  6. package/dist/core/ActionJournal.js.map +1 -1
  7. package/dist/core/Multiplayer.d.ts +21 -4
  8. package/dist/core/Multiplayer.d.ts.map +1 -1
  9. package/dist/core/Multiplayer.js +31 -4
  10. package/dist/core/Multiplayer.js.map +1 -1
  11. package/dist/core/State.d.ts +38 -0
  12. package/dist/core/State.d.ts.map +1 -1
  13. package/dist/core/State.js +76 -0
  14. package/dist/core/State.js.map +1 -1
  15. package/dist/core/index.d.ts +3 -3
  16. package/dist/core/index.d.ts.map +1 -1
  17. package/dist/core/index.js +1 -1
  18. package/dist/core/index.js.map +1 -1
  19. package/dist/mw_games.global.js +113 -113
  20. package/dist/mwl/catalog.d.ts +7 -0
  21. package/dist/mwl/catalog.d.ts.map +1 -1
  22. package/dist/mwl/catalog.js +0 -0
  23. package/dist/mwl/catalog.js.map +1 -1
  24. package/dist/mwl/compiler.d.ts +3 -0
  25. package/dist/mwl/compiler.d.ts.map +1 -1
  26. package/dist/mwl/compiler.js +10 -3
  27. package/dist/mwl/compiler.js.map +1 -1
  28. package/dist/mwl/grammar.d.ts +8 -1
  29. package/dist/mwl/grammar.d.ts.map +1 -1
  30. package/dist/mwl/grammar.js +207 -39
  31. package/dist/mwl/grammar.js.map +1 -1
  32. package/dist/mwl/hooks.d.ts +35 -2
  33. package/dist/mwl/hooks.d.ts.map +1 -1
  34. package/dist/mwl/hooks.js +8 -6
  35. package/dist/mwl/hooks.js.map +1 -1
  36. package/dist/mwl/index.d.ts +6 -6
  37. package/dist/mwl/index.d.ts.map +1 -1
  38. package/dist/mwl/index.js +3 -3
  39. package/dist/mwl/index.js.map +1 -1
  40. package/dist/mwl/persistence.d.ts +18 -1
  41. package/dist/mwl/persistence.d.ts.map +1 -1
  42. package/dist/mwl/persistence.js +59 -3
  43. package/dist/mwl/persistence.js.map +1 -1
  44. package/dist/mwl/readers.d.ts +37 -0
  45. package/dist/mwl/readers.d.ts.map +1 -1
  46. package/dist/mwl/readers.js +69 -0
  47. package/dist/mwl/readers.js.map +1 -1
  48. package/dist/mwl/runtime.d.ts +45 -1
  49. package/dist/mwl/runtime.d.ts.map +1 -1
  50. package/dist/mwl/runtime.js +72 -8
  51. package/dist/mwl/runtime.js.map +1 -1
  52. package/dist/mwl/schema.d.ts +31 -0
  53. package/dist/mwl/schema.d.ts.map +1 -1
  54. package/dist/mwl/schema.js +57 -2
  55. package/dist/mwl/schema.js.map +1 -1
  56. package/dist/simulation/Runtime.d.ts +66 -1
  57. package/dist/simulation/Runtime.d.ts.map +1 -1
  58. package/dist/simulation/Runtime.js +131 -3
  59. package/dist/simulation/Runtime.js.map +1 -1
  60. package/dist/simulation/index.d.ts +2 -2
  61. package/dist/simulation/index.d.ts.map +1 -1
  62. package/dist/simulation/index.js +1 -1
  63. package/dist/simulation/index.js.map +1 -1
  64. package/dist/two-d/render/RpgmAutotile.d.ts +65 -0
  65. package/dist/two-d/render/RpgmAutotile.d.ts.map +1 -0
  66. package/dist/two-d/render/RpgmAutotile.js +110 -0
  67. package/dist/two-d/render/RpgmAutotile.js.map +1 -0
  68. package/dist/two-d/render/index.d.ts +2 -0
  69. package/dist/two-d/render/index.d.ts.map +1 -1
  70. package/dist/two-d/render/index.js +1 -0
  71. package/dist/two-d/render/index.js.map +1 -1
  72. package/dist/version.d.ts +1 -1
  73. package/dist/version.d.ts.map +1 -1
  74. package/dist/version.js +1 -1
  75. package/dist/version.js.map +1 -1
  76. package/package.json +1 -1
  77. package/tools/mwl.mjs +85 -4
package/tools/mwl.mjs CHANGED
@@ -19,7 +19,8 @@ import {
19
19
  } from '../dist/mwl/index.js';
20
20
 
21
21
  /**
22
- * Command line for MWL: validate, compile, extract-i18n, assets, hooks, build.
22
+ * Command line for MWL: validate, compile, format, migrate, extract-i18n, assets, report,
23
+ * diagnostics, ci, hooks, build.
23
24
  *
24
25
  * Reading files happens here, not in the published module, so the library
25
26
  * itself stays free of node builtins. `hooks` needs esbuild and says so
@@ -40,7 +41,19 @@ import {
40
41
  */
41
42
 
42
43
  const args = process.argv.slice(2);
43
- const commands = ['validate', 'compile', 'extract-i18n', 'assets', 'report', 'hooks', 'build'];
44
+ const commands = [
45
+ 'validate',
46
+ 'compile',
47
+ 'format',
48
+ 'migrate',
49
+ 'extract-i18n',
50
+ 'assets',
51
+ 'report',
52
+ 'diagnostics',
53
+ 'ci',
54
+ 'hooks',
55
+ 'build',
56
+ ];
44
57
  const [command, input] = args;
45
58
  const outputFlag = args.indexOf('-o');
46
59
  const output = outputFlag === -1 ? undefined : args[outputFlag + 1];
@@ -48,17 +61,44 @@ const manifestFlag = args.indexOf('--manifest');
48
61
  const manifestPath = manifestFlag === -1 ? undefined : args[manifestFlag + 1];
49
62
  const assetRootFlag = args.indexOf('--asset-root');
50
63
  const assetRoot = assetRootFlag === -1 ? undefined : args[assetRootFlag + 1];
64
+ const targetFlag = args.indexOf('--to');
65
+ const target = targetFlag === -1 ? undefined : args[targetFlag + 1];
51
66
 
52
67
  if (!command || !input || !commands.includes(command)) {
53
68
  console.error(
54
- 'Usage: mwl <validate|compile|extract-i18n|assets|report|hooks|build> input.mwl [-o output] [--manifest hooks.json] [--asset-root directory]',
69
+ 'Usage: mwl <validate|compile|format|migrate|extract-i18n|assets|report|diagnostics|ci|hooks|build> input.mwl [-o output] [--to 1.0] [--manifest hooks.json] [--asset-root directory]',
55
70
  );
56
71
  process.exitCode = 2;
57
72
  } else {
58
73
  const files = fs.statSync(input).isDirectory()
59
74
  ? collectSources(input)
60
75
  : [{ file: sourceLabel(input), source: fs.readFileSync(input, 'utf8') }];
61
- if (command === 'validate') {
76
+ if (command === 'format' || command === 'migrate') {
77
+ if (command === 'migrate' && target !== '1.0') {
78
+ console.error('mwl migrate currently supports only --to 1.0');
79
+ process.exitCode = 2;
80
+ } else {
81
+ const nodes = files.flatMap((file) => parse(preprocess(file.source, { file: file.file }), file.file));
82
+ const text = `${JSON.stringify(
83
+ nodes.map((node) => formatNode(node, command === 'migrate' ? target : undefined)),
84
+ null,
85
+ '\t',
86
+ )}\n`;
87
+ if (output) {
88
+ fs.mkdirSync(path.dirname(path.resolve(output)), { recursive: true });
89
+ fs.writeFileSync(output, text);
90
+ } else process.stdout.write(text);
91
+ }
92
+ } else if (command === 'diagnostics' || command === 'ci') {
93
+ const diagnostics = diagnose(files);
94
+ const report = command === 'ci' ? { valid: diagnostics.length === 0, diagnostics } : diagnostics;
95
+ const text = `${JSON.stringify(report, null, '\t')}\n`;
96
+ if (output) {
97
+ fs.mkdirSync(path.dirname(path.resolve(output)), { recursive: true });
98
+ fs.writeFileSync(output, text);
99
+ } else process.stdout.write(text);
100
+ if (diagnostics.length) process.exitCode = 1;
101
+ } else if (command === 'validate') {
62
102
  const diagnostics = files.flatMap((file) =>
63
103
  validate(parse(preprocess(file.source, { file: file.file }), file.file)),
64
104
  );
@@ -123,6 +163,47 @@ function sourceLabel(file) {
123
163
  return (relative || path.basename(path.resolve(file))).split(path.sep).join('/');
124
164
  }
125
165
 
166
+ /** Parse and validate every input without throwing, for machine-readable CI diagnostics. */
167
+ function diagnose(files) {
168
+ const diagnostics = [];
169
+ for (const file of files) {
170
+ try {
171
+ diagnostics.push(...validate(parse(preprocess(file.source, { file: file.file }), file.file)));
172
+ } catch (error) {
173
+ if (error?.diagnostic) diagnostics.push(error.diagnostic);
174
+ else
175
+ diagnostics.push({
176
+ code: 'MWL_CLI',
177
+ message: error instanceof Error ? error.message : String(error),
178
+ location: { file: file.file, line: 1, column: 1 },
179
+ });
180
+ }
181
+ }
182
+ return diagnostics.sort(
183
+ (a, b) =>
184
+ a.location.file.localeCompare(b.location.file) ||
185
+ a.location.line - b.location.line ||
186
+ a.location.column - b.location.column ||
187
+ a.code.localeCompare(b.code),
188
+ );
189
+ }
190
+
191
+ /** Emit a stable, source-independent MWL document after preprocessing. */
192
+ function formatNode(node, target) {
193
+ const attributes = Object.fromEntries(
194
+ Object.entries(node.attributes).map(([name, value]) => [
195
+ name,
196
+ node.gettext?.includes(name) ? { $gettext: value } : value,
197
+ ]),
198
+ );
199
+ if (target === '1.0' && node.tag === 'game') attributes.schema = '1.0';
200
+ return {
201
+ tag: node.tag,
202
+ ...attributes,
203
+ ...(node.children.length ? { children: node.children.map((child) => formatNode(child, target)) } : {}),
204
+ };
205
+ }
206
+
126
207
  /** One deterministic build step for the three files every MWL game consumes. */
127
208
  function build(files) {
128
209
  const game = compileSources(files);