squiffy-runtime 6.0.0-alpha.13 → 6.0.0-alpha.15

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2024 Alex Warren, textadventures.co.uk and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -463,7 +463,7 @@ export const init = (options) => {
463
463
  else if (newSection.text && newSection.text != story.sections[existingSection].text) {
464
464
  // section has been updated
465
465
  for (const element of elements) {
466
- updateElementTextPreservingDisabledPassageLinks(element, newSection.text);
466
+ updateElementTextPreservingDisabledPassageLinks(element, ui.processText(newSection.text));
467
467
  }
468
468
  }
469
469
  }
@@ -484,7 +484,7 @@ export const init = (options) => {
484
484
  else if (newPassage.text && newPassage.text != story.sections[existingSection].passages[existingPassage].text) {
485
485
  // passage has been updated
486
486
  for (const element of elements) {
487
- updateElementTextPreservingDisabledPassageLinks(element, newPassage.text);
487
+ updateElementTextPreservingDisabledPassageLinks(element, ui.processText(newPassage.text));
488
488
  }
489
489
  }
490
490
  }
@@ -342,3 +342,53 @@ Text from a passage.
342
342
  let output = getSectionContent(element, 'section1');
343
343
  expect(output).toBe('Here is some text from a passage: Text from a passage.');
344
344
  });
345
+ test('Update section with embedded text', async () => {
346
+ const script = `
347
+ [[section1]]:
348
+ Here is some text from the next section: {section2}
349
+
350
+ [[section2]]:
351
+ Text from next section.
352
+ `;
353
+ const { squiffyApi, element } = await initScript(script);
354
+ let output = getSectionContent(element, 'section1');
355
+ expect(output).toBe('Here is some text from the next section: Text from next section.');
356
+ const script2 = `
357
+ [[section1]]:
358
+ Here is an updated script with text from the next section: {section2}
359
+
360
+ [[section2]]:
361
+ Updated text from next section.
362
+ `;
363
+ const updated = await compile(script2);
364
+ squiffyApi.update(updated.story);
365
+ output = getSectionContent(element, 'section1');
366
+ // NOTE: The embedded text does not currently get updated. We would need to track where the embedded
367
+ // text has been written.
368
+ expect(output).toBe('Here is an updated script with text from the next section: Text from next section.');
369
+ });
370
+ test('Update passage with embedded text', async () => {
371
+ const script = `
372
+ [[section1]]:
373
+ Here is some text from a passage: {passage}
374
+
375
+ [passage]:
376
+ Text from a passage.
377
+ `;
378
+ const { squiffyApi, element } = await initScript(script);
379
+ let output = getSectionContent(element, 'section1');
380
+ expect(output).toBe('Here is some text from a passage: Text from a passage.');
381
+ const script2 = `
382
+ [[section1]]:
383
+ Here is an updated script with text from a passage: {passage}
384
+
385
+ [passage]:
386
+ Updated text from a passage.
387
+ `;
388
+ const updated = await compile(script2);
389
+ squiffyApi.update(updated.story);
390
+ output = getSectionContent(element, 'section1');
391
+ // NOTE: The embedded text does not currently get updated. We would need to track where the embedded
392
+ // text has been written.
393
+ expect(output).toBe('Here is an updated script with text from a passage: Text from a passage.');
394
+ });
@@ -64,11 +64,9 @@ export class TextProcessor {
64
64
  return this.processTextCommand_Rotate('sequence', text);
65
65
  }
66
66
  else if (currentSection.passages && text in currentSection.passages) {
67
- console.log("Found passage");
68
67
  return this.process(currentSection.passages[text].text || '', data);
69
68
  }
70
69
  else if (text in this.story.sections) {
71
- console.log("Found section");
72
70
  return this.process(this.story.sections[text].text || '', data);
73
71
  }
74
72
  else if (startsWith(text, '@') && !startsWith(text, '@replace')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squiffy-runtime",
3
- "version": "6.0.0-alpha.13",
3
+ "version": "6.0.0-alpha.15",
4
4
  "type": "module",
5
5
  "main": "dist/squiffy.runtime.js",
6
6
  "types": "dist/squiffy.runtime.d.ts",
@@ -22,8 +22,9 @@
22
22
  "@types/jsdom": "^21.1.7",
23
23
  "global-jsdom": "^25.0.0",
24
24
  "jsdom": "^25.0.0",
25
- "squiffy-compiler": "^6.0.0-alpha.3",
25
+ "squiffy-compiler": "^6.0.0-alpha.15",
26
26
  "typescript": "^5.6.2",
27
27
  "vitest": "^2.1.1"
28
- }
28
+ },
29
+ "gitHead": "a326d226beb6121dcdf528e97d287deba553fe39"
29
30
  }
@@ -440,4 +440,66 @@ Text from a passage.
440
440
 
441
441
  let output = getSectionContent(element, 'section1');
442
442
  expect(output).toBe('Here is some text from a passage: Text from a passage.');
443
+ });
444
+
445
+ test('Update section with embedded text', async () => {
446
+ const script = `
447
+ [[section1]]:
448
+ Here is some text from the next section: {section2}
449
+
450
+ [[section2]]:
451
+ Text from next section.
452
+ `;
453
+
454
+ const { squiffyApi, element } = await initScript(script);
455
+
456
+ let output = getSectionContent(element, 'section1');
457
+ expect(output).toBe('Here is some text from the next section: Text from next section.');
458
+
459
+ const script2 = `
460
+ [[section1]]:
461
+ Here is an updated script with text from the next section: {section2}
462
+
463
+ [[section2]]:
464
+ Updated text from next section.
465
+ `;
466
+
467
+ const updated = await compile(script2);
468
+ squiffyApi.update(updated.story);
469
+ output = getSectionContent(element, 'section1');
470
+
471
+ // NOTE: The embedded text does not currently get updated. We would need to track where the embedded
472
+ // text has been written.
473
+ expect(output).toBe('Here is an updated script with text from the next section: Text from next section.');
474
+ });
475
+
476
+ test('Update passage with embedded text', async () => {
477
+ const script = `
478
+ [[section1]]:
479
+ Here is some text from a passage: {passage}
480
+
481
+ [passage]:
482
+ Text from a passage.
483
+ `;
484
+
485
+ const { squiffyApi, element } = await initScript(script);
486
+
487
+ let output = getSectionContent(element, 'section1');
488
+ expect(output).toBe('Here is some text from a passage: Text from a passage.');
489
+
490
+ const script2 = `
491
+ [[section1]]:
492
+ Here is an updated script with text from a passage: {passage}
493
+
494
+ [passage]:
495
+ Updated text from a passage.
496
+ `;
497
+
498
+ const updated = await compile(script2);
499
+ squiffyApi.update(updated.story);
500
+ output = getSectionContent(element, 'section1');
501
+
502
+ // NOTE: The embedded text does not currently get updated. We would need to track where the embedded
503
+ // text has been written.
504
+ expect(output).toBe('Here is an updated script with text from a passage: Text from a passage.');
443
505
  });
@@ -496,7 +496,7 @@ export const init = (options: SquiffyInitOptions): SquiffyApi => {
496
496
  else if (newSection.text && newSection.text != story.sections[existingSection].text) {
497
497
  // section has been updated
498
498
  for (const element of elements) {
499
- updateElementTextPreservingDisabledPassageLinks(element, newSection.text);
499
+ updateElementTextPreservingDisabledPassageLinks(element, ui.processText(newSection.text));
500
500
  }
501
501
  }
502
502
  }
@@ -518,7 +518,7 @@ export const init = (options: SquiffyInitOptions): SquiffyApi => {
518
518
  else if (newPassage.text && newPassage.text != story.sections[existingSection].passages[existingPassage].text) {
519
519
  // passage has been updated
520
520
  for (const element of elements) {
521
- updateElementTextPreservingDisabledPassageLinks(element, newPassage.text);
521
+ updateElementTextPreservingDisabledPassageLinks(element, ui.processText(newPassage.text));
522
522
  }
523
523
  }
524
524
  }
@@ -77,10 +77,8 @@ export class TextProcessor {
77
77
  } else if (/^sequence[: ]/.test(text)) {
78
78
  return this.processTextCommand_Rotate('sequence', text);
79
79
  } else if (currentSection.passages && text in currentSection.passages) {
80
- console.log("Found passage");
81
80
  return this.process(currentSection.passages[text].text || '', data);
82
81
  } else if (text in this.story.sections) {
83
- console.log("Found section");
84
82
  return this.process(this.story.sections[text].text || '', data);
85
83
  } else if (startsWith(text, '@') && !startsWith(text, '@replace')) {
86
84
  this.processAttributes(text.substring(1).split(","));