squiffy-compiler 6.0.0-alpha.20 → 6.0.0-beta.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2024 Alex Warren, textadventures.co.uk and contributors
3
+ Copyright (c) 2014-2026 Alex Warren, textadventures.co.uk and contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/compiler.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import pkg from "../package.json" with { type: "json" };
2
2
  const version = pkg.version;
3
3
  export async function compile(settings) {
4
- const story = new Story(settings.scriptBaseFilename);
4
+ const story = new Story();
5
5
  const errors = [];
6
6
  let autoSectionCount = 0;
7
7
  async function getJs(storyData, excludeHeader) {
@@ -235,6 +235,7 @@ export async function compile(settings) {
235
235
  else if (textStarted || stripLine.length > 0) {
236
236
  if (inUiBlock) {
237
237
  errors.push(`ERROR: ${inputFilename} line ${lineCount}: Unexpected text in @ui block.`);
238
+ return false;
238
239
  }
239
240
  else if (!passage) {
240
241
  section = ensureThisSectionExists();
@@ -286,6 +287,35 @@ export async function compile(settings) {
286
287
  };
287
288
  }
288
289
  async function processText(input, section, passage) {
290
+ // Helper to get the next section name
291
+ const getNextSectionName = () => {
292
+ const sectionNames = Object.keys(story.sections);
293
+ const currentIndex = sectionNames.indexOf(section.name);
294
+ return sectionNames[currentIndex + 1] || null;
295
+ };
296
+ // nextSectionLinkRegex matches [[text>]] - a link to the next section
297
+ const nextSectionLinkRegex = /\[\[([^\]]*?)>\]\]/g;
298
+ input = input.replace(nextSectionLinkRegex, (_match, text) => {
299
+ const nextSectionName = getNextSectionName();
300
+ if (!nextSectionName) {
301
+ settings.onWarning?.(`WARNING: ${section.filename} line ${section.line}: In section '${section.name}', there is a [[${text}>]] link but no following section exists`);
302
+ return `[[${text}]]`; // fallback
303
+ }
304
+ return `{{section "${nextSectionName}" text="${text}"}}`;
305
+ });
306
+ // namedNextSectionLinkRegex matches [[text]](>) or [[text]](>, setter=value)
307
+ // - a named link where target starts with >
308
+ const namedNextSectionLinkRegex = /\[\[([^\]]*?)\]\]\(>(.*?)\)/g;
309
+ input = input.replace(namedNextSectionLinkRegex, (_match, text, rest) => {
310
+ const nextSectionName = getNextSectionName();
311
+ if (!nextSectionName) {
312
+ settings.onWarning?.(`WARNING: ${section.filename} line ${section.line}: In section '${section.name}', there is a [[${text}]](>) link but no following section exists`);
313
+ return `[[${text}]]`; // fallback
314
+ }
315
+ // rest could be empty or ", setter=value"
316
+ const parsedName = getAdditionalLinkParameters(nextSectionName + rest);
317
+ return `{{section "${parsedName.target}" text="${text}"${parsedName.additionalParameters}}}`;
318
+ });
289
319
  // namedSectionLinkRegex matches:
290
320
  // open [[
291
321
  // any text - the link text
@@ -408,7 +438,7 @@ export async function compile(settings) {
408
438
  }
409
439
  }
410
440
  class Story {
411
- constructor(inputFilename) {
441
+ constructor() {
412
442
  Object.defineProperty(this, "sections", {
413
443
  enumerable: true,
414
444
  configurable: true,
@@ -451,7 +481,7 @@ class Story {
451
481
  writable: true,
452
482
  value: []
453
483
  });
454
- this.id = inputFilename || null;
484
+ this.id = crypto.randomUUID();
455
485
  }
456
486
  addSection(name, filename, line) {
457
487
  const section = new Section(name, filename, line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squiffy-compiler",
3
- "version": "6.0.0-alpha.20",
3
+ "version": "6.0.0-beta.0",
4
4
  "description": "A tool for creating multiple-choice interactive stories",
5
5
  "author": "Alex Warren",
6
6
  "contributors": [
@@ -31,5 +31,5 @@
31
31
  "dist"
32
32
  ],
33
33
  "type": "module",
34
- "gitHead": "eee4b8836ed791b68d8d56b0d5071129e6214d2b"
34
+ "gitHead": "dadcab6940e5e7ffdd600e8821c9297fdbf93160"
35
35
  }