@patterkit/compiler 0.10.0 → 0.12.0

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/index.cjs CHANGED
@@ -618,11 +618,21 @@ function claimIssues(input, nodes, claims) {
618
618
  }
619
619
 
620
620
  // src/export.ts
621
- function compileBeat(beat, ctx) {
621
+ function compileBeat(beat, ctx, asAction = false) {
622
622
  const values = ctx.extensions.get(beat.id);
623
- if (values === void 0 && !Object.prototype.hasOwnProperty.call(beat, "extensions")) return beat;
624
- const { extensions: _source, ...rest } = beat;
625
- return values !== void 0 ? { ...rest, extensions: values } : rest;
623
+ const action = asAction && beat.kind === "text";
624
+ const has = (k) => Object.prototype.hasOwnProperty.call(beat, k);
625
+ if (values === void 0 && !action && !has("extensions") && !has("action")) return beat;
626
+ const { extensions: _source, action: _action, ...rest } = beat;
627
+ return { ...rest, ...values !== void 0 ? { extensions: values } : {}, ...action ? { action: true } : {} };
628
+ }
629
+ function collectActionIds(scene, out) {
630
+ for (const block of scene.blocks) {
631
+ (0, import_model3.walkNodes)(block.children, (node) => {
632
+ if (node.type !== "snippet") return;
633
+ for (const beat of node.beats ?? []) if (beat.kind === "text" && beat.action) out.push(beat.id);
634
+ });
635
+ }
626
636
  }
627
637
  function compileEffect(e, foreign) {
628
638
  return { kind: "set", target: e.target, value: compileExpression(e.value, foreign) };
@@ -656,7 +666,7 @@ function compileNode(node, ctx) {
656
666
  id: node.id,
657
667
  type: "snippet",
658
668
  condition: node.condition !== void 0 ? compileExpression(node.condition, foreign) : void 0,
659
- beats: node.beats && node.beats.map((b) => compileBeat(b, ctx)),
669
+ beats: node.beats && node.beats.map((b) => compileBeat(b, ctx, ctx.action)),
660
670
  onEnter: node.onEnter?.map((e) => compileEffect(e, foreign)),
661
671
  onExit: node.onExit?.map((e) => compileEffect(e, foreign)),
662
672
  padAfterDefault: node.padAfterDefault,
@@ -742,7 +752,12 @@ function exportBundle(input) {
742
752
  const extensionSection = compiledExt !== void 0 && Object.keys(compiledExt.bundle).length > 0 ? compiledExt.bundle : void 0;
743
753
  const ctx = { foreign: compileScopes, extensions: compiledExt?.nodes ?? /* @__PURE__ */ new Map() };
744
754
  const scenesOut = {};
745
- for (const scene of scenes) scenesOut[scene.id] = compileScene(scene, ctx);
755
+ const actionIds = [];
756
+ for (const scene of scenes) {
757
+ const action = (0, import_model3.textIsAction)(project, scene);
758
+ scenesOut[scene.id] = compileScene(scene, action ? { ...ctx, action } : ctx);
759
+ if (action) collectActionIds(scenesOut[scene.id], actionIds);
760
+ }
746
761
  const externalScopes = externalScopesIn(scenesOut, /* @__PURE__ */ new Set([...import_dialect3.EXTERNAL_SCOPES, ...gameExternal.map((s) => s.token)]));
747
762
  const qualifiers = (0, import_model3.usedQualifiers)(project, scenes).map((q) => ({ gameId: q.gameId, name: q.name }));
748
763
  const usedPairs = new Set((0, import_model3.usedSpeakerPairs)(scenes).map((p) => `${p.character}\0${p.qualifier}`));
@@ -758,6 +773,17 @@ function exportBundle(input) {
758
773
  table[key] = text;
759
774
  }
760
775
  }
776
+ if (actionIds.length > 0) {
777
+ const source = {};
778
+ for (const loc of locales) if (loc.locale === project.locales.default) Object.assign(source, loc.strings);
779
+ for (const [locale, table] of Object.entries(strings)) {
780
+ if (locale === project.locales.default) continue;
781
+ for (const id of actionIds) {
782
+ if (id in source) table[id] = source[id];
783
+ else delete table[id];
784
+ }
785
+ }
786
+ }
761
787
  return {
762
788
  schema: "patter/bundle@0",
763
789
  content: {
@@ -810,9 +836,10 @@ function exportBundle(input) {
810
836
  // The project's own line-padding default, only when it sets one: absent, every runtime uses the built-in one.
811
837
  ...typeof project.padAfterDefault === "number" ? { padAfterDefault: project.padAfterDefault } : {},
812
838
  properties: resolved(project.properties),
813
- // A host scope's declarations ship as written: there, "no default" is the game's to supply, and saying
814
- // so is what an integrator reads the bundle for.
815
- scopeRegistry: hostScopes,
839
+ scopeRegistry: hostScopes && {
840
+ ...hostScopes,
841
+ scopes: hostScopes.scopes.map((s) => s.declarations ? { ...s, declarations: resolved(s.declarations) } : s)
842
+ },
816
843
  gameDataFields: project.gameDataFields && Object.fromEntries(
817
844
  Object.entries(project.gameDataFields).map(([kind, fields]) => [kind, resolved(fields)])
818
845
  ),
package/dist/index.js CHANGED
@@ -315,7 +315,7 @@ import { hostScopesToSpec as hostScopesToSpec4, EXTERNAL_SCOPES as EXTERNAL_SCOP
315
315
  import { defaultFor } from "@wildwinter/scoperegistry";
316
316
  import { canonicalStringify, hash32 } from "@patterkit/core";
317
317
  import { hostScopesToSpec as hostScopesToSpec3, withEngineScopes as withEngineScopes2, EXTERNAL_SCOPES } from "@patterkit/dialect";
318
- import { usedQualifiers, usedSpeakerPairs, DEFAULT_SPEAKER_PATTERN } from "@patterkit/model";
318
+ import { textIsAction, usedQualifiers, usedSpeakerPairs, walkNodes as walkNodes2, DEFAULT_SPEAKER_PATTERN } from "@patterkit/model";
319
319
 
320
320
  // src/extensions.ts
321
321
  import { EXTENSIONS_DIR, MANIFEST_EXTENSION, PROJECT_LOCALE_SCENE } from "@patterkit/model";
@@ -595,11 +595,21 @@ function claimIssues(input, nodes, claims) {
595
595
  }
596
596
 
597
597
  // src/export.ts
598
- function compileBeat(beat, ctx) {
598
+ function compileBeat(beat, ctx, asAction = false) {
599
599
  const values = ctx.extensions.get(beat.id);
600
- if (values === void 0 && !Object.prototype.hasOwnProperty.call(beat, "extensions")) return beat;
601
- const { extensions: _source, ...rest } = beat;
602
- return values !== void 0 ? { ...rest, extensions: values } : rest;
600
+ const action = asAction && beat.kind === "text";
601
+ const has = (k) => Object.prototype.hasOwnProperty.call(beat, k);
602
+ if (values === void 0 && !action && !has("extensions") && !has("action")) return beat;
603
+ const { extensions: _source, action: _action, ...rest } = beat;
604
+ return { ...rest, ...values !== void 0 ? { extensions: values } : {}, ...action ? { action: true } : {} };
605
+ }
606
+ function collectActionIds(scene, out) {
607
+ for (const block of scene.blocks) {
608
+ walkNodes2(block.children, (node) => {
609
+ if (node.type !== "snippet") return;
610
+ for (const beat of node.beats ?? []) if (beat.kind === "text" && beat.action) out.push(beat.id);
611
+ });
612
+ }
603
613
  }
604
614
  function compileEffect(e, foreign) {
605
615
  return { kind: "set", target: e.target, value: compileExpression(e.value, foreign) };
@@ -633,7 +643,7 @@ function compileNode(node, ctx) {
633
643
  id: node.id,
634
644
  type: "snippet",
635
645
  condition: node.condition !== void 0 ? compileExpression(node.condition, foreign) : void 0,
636
- beats: node.beats && node.beats.map((b) => compileBeat(b, ctx)),
646
+ beats: node.beats && node.beats.map((b) => compileBeat(b, ctx, ctx.action)),
637
647
  onEnter: node.onEnter?.map((e) => compileEffect(e, foreign)),
638
648
  onExit: node.onExit?.map((e) => compileEffect(e, foreign)),
639
649
  padAfterDefault: node.padAfterDefault,
@@ -719,7 +729,12 @@ function exportBundle(input) {
719
729
  const extensionSection = compiledExt !== void 0 && Object.keys(compiledExt.bundle).length > 0 ? compiledExt.bundle : void 0;
720
730
  const ctx = { foreign: compileScopes, extensions: compiledExt?.nodes ?? /* @__PURE__ */ new Map() };
721
731
  const scenesOut = {};
722
- for (const scene of scenes) scenesOut[scene.id] = compileScene(scene, ctx);
732
+ const actionIds = [];
733
+ for (const scene of scenes) {
734
+ const action = textIsAction(project, scene);
735
+ scenesOut[scene.id] = compileScene(scene, action ? { ...ctx, action } : ctx);
736
+ if (action) collectActionIds(scenesOut[scene.id], actionIds);
737
+ }
723
738
  const externalScopes = externalScopesIn(scenesOut, /* @__PURE__ */ new Set([...EXTERNAL_SCOPES, ...gameExternal.map((s) => s.token)]));
724
739
  const qualifiers = usedQualifiers(project, scenes).map((q) => ({ gameId: q.gameId, name: q.name }));
725
740
  const usedPairs = new Set(usedSpeakerPairs(scenes).map((p) => `${p.character}\0${p.qualifier}`));
@@ -735,6 +750,17 @@ function exportBundle(input) {
735
750
  table[key] = text;
736
751
  }
737
752
  }
753
+ if (actionIds.length > 0) {
754
+ const source = {};
755
+ for (const loc of locales) if (loc.locale === project.locales.default) Object.assign(source, loc.strings);
756
+ for (const [locale, table] of Object.entries(strings)) {
757
+ if (locale === project.locales.default) continue;
758
+ for (const id of actionIds) {
759
+ if (id in source) table[id] = source[id];
760
+ else delete table[id];
761
+ }
762
+ }
763
+ }
738
764
  return {
739
765
  schema: "patter/bundle@0",
740
766
  content: {
@@ -787,9 +813,10 @@ function exportBundle(input) {
787
813
  // The project's own line-padding default, only when it sets one: absent, every runtime uses the built-in one.
788
814
  ...typeof project.padAfterDefault === "number" ? { padAfterDefault: project.padAfterDefault } : {},
789
815
  properties: resolved(project.properties),
790
- // A host scope's declarations ship as written: there, "no default" is the game's to supply, and saying
791
- // so is what an integrator reads the bundle for.
792
- scopeRegistry: hostScopes,
816
+ scopeRegistry: hostScopes && {
817
+ ...hostScopes,
818
+ scopes: hostScopes.scopes.map((s) => s.declarations ? { ...s, declarations: resolved(s.declarations) } : s)
819
+ },
793
820
  gameDataFields: project.gameDataFields && Object.fromEntries(
794
821
  Object.entries(project.gameDataFields).map(([kind, fields]) => [kind, resolved(fields)])
795
822
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/compiler",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Patter compiler: compile condition/effect expressions, validate them, and export source to the runtime bundle.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,11 +34,11 @@
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts --clean"
35
35
  },
36
36
  "dependencies": {
37
- "@patterkit/model": "0.17.0",
38
- "@patterkit/core": "0.9.1",
39
- "@patterkit/dialect": "0.2.14",
37
+ "@patterkit/model": "0.19.0",
38
+ "@patterkit/core": "0.9.3",
39
+ "@patterkit/dialect": "0.2.16",
40
40
  "@wildwinter/expr": "^0.6.0",
41
- "@wildwinter/toolkit": "^0.2.1"
41
+ "@wildwinter/toolkit": "^0.2.2"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@wildwinter/scoperegistry": ">=0.9.0 <1.0.0"