« get me outta code hell

data: Adventure (wip!!!! wip!!!! wip!!!! wip!!!!) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-11-19 23:03:25 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-11-25 07:06:48 -0400
commit73c59a414c27c4b50647639f3459cd97ee8b9170 (patch)
tree8d73229ab154b4d3b4a41e5dd752170837e57289 /src/data
parentaefb53631314295e1574847683bbfa5fec98d536 (diff)
data: Adventure (wip!!!! wip!!!! wip!!!! wip!!!!)
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/adventure.js145
-rw-r--r--src/data/things/index.js2
2 files changed, 147 insertions, 0 deletions
diff --git a/src/data/things/adventure.js b/src/data/things/adventure.js
new file mode 100644
index 00000000..ed5da39b
--- /dev/null
+++ b/src/data/things/adventure.js
@@ -0,0 +1,145 @@
+export const DATA_ADVENTURE_DIRECTORY = 'adventure';
+
+import * as path from 'node:path';
+
+import {input} from '#composite';
+import {traverse} from '#node-utils';
+import Thing from '#thing';
+
+import {exposeDependency} from '#composite/control-flow';
+import {withPropertyFromObject} from '#composite/data';
+import {directory, name, thing, thingList}
+  from '#composite/wiki-properties';
+
+// *thumb-twiddling*
+import {Flash, FlashAct} from './flash.js';
+
+export class Adventure extends Thing {
+  static [Thing.referenceType] = 'adventure';
+
+  static [Thing.getPropertyDescriptors] = ({FlashAct}) => ({
+    // > Internal relationships
+
+    acts: thingList({
+      class: input.value(FlashAct),
+    }),
+
+    // > Identifying metadata
+
+    name: name('Unnamed Adventure'),
+    directory: directory(),
+  });
+
+  static [Thing.yamlDocumentSpec] = {
+    fields: {
+      // Identifying metadata
+
+      'Adventure': {property: 'name'},
+      'Directory': {property: 'directory'},
+    },
+  };
+
+  static [Thing.getYamlLoadingSpec] = ({
+    documentModes: {headerAndEntries},
+    thingConstructors: {
+      Adventure,
+      AdventureFlashAct,
+      AdventureFlash,
+    },
+  }) => ({
+    title: `Process adventure files`,
+
+    files: dataPath =>
+      traverse(path.join(dataPath, DATA_ADVENTURE_DIRECTORY), {
+        filterFile: name => path.extname(name) === '.yaml',
+        prefixPath: DATA_ADVENTURE_DIRECTORY,
+      }),
+
+    documentMode: headerAndEntries,
+
+    headerDocumentThing: Adventure,
+    entryDocumentThing: document =>
+      ('Act' in document
+        ? AdventureFlashAct
+        : AdventureFlash),
+
+    save(results) {
+      const adventureData = [];
+      const flashActData = [];
+      const flashData = [];
+
+      for (const {header: adventure, entries} of results) {
+        const acts = [];
+
+        let thing, i;
+        for (i = 0; thing = entries[i]; i++) {
+          if (thing.isFlashAct) {
+            const act = thing;
+            const flashes = [];
+
+            for (i++; thing = entries[i]; i++) {
+              if (thing.isFlash) {
+                const flash = thing;
+
+                flash.act = act;
+                flashes.push(flash);
+                flashData.push(flash);
+
+                continue;
+              }
+
+              i--;
+              break;
+            }
+
+            act.flashes = flashes;
+            acts.push(act);
+            flashActData.push(act);
+
+            continue;
+          }
+
+          if (thing.isFlash) {
+            throw new Error(`Flashes must be under a flash act`);
+          }
+        }
+
+        adventure.acts = acts;
+        adventureData.push(adventure);
+      }
+
+      return {
+        adventureData,
+        flashActData,
+        flashData,
+      };
+    },
+  });
+}
+
+export class AdventureFlash extends Flash {
+  static [Thing.getPropertyDescriptors] = ({Adventure}) => ({
+    // > Implicit relationships
+
+    adventure: [
+      withPropertyFromObject({
+        object: 'act',
+        property: input.value('adventure'),
+      }),
+
+      exposeDependency({
+        dependency: '#act.adventure',
+      }),
+    ],
+  });
+}
+
+export class AdventureFlashAct extends FlashAct {
+  static [Thing.getPropertyDescriptors] = ({Adventure}) => ({
+    // > Internal relationships
+
+    adventure: thing({
+      class: input.value(Adventure),
+    }),
+  });
+}
diff --git a/src/data/things/index.js b/src/data/things/index.js
index 676453ce..33fc933d 100644
--- a/src/data/things/index.js
+++ b/src/data/things/index.js
@@ -11,6 +11,7 @@ import Thing from '#thing';
 
 import * as additionalFileClasses from './additional-file.js';
 import * as additionalNameClasses from './additional-name.js';
+import * as adventureClasses from './adventure.js';
 import * as albumClasses from './album.js';
 import * as artTagClasses from './art-tag.js';
 import * as artistClasses from './artist.js';
@@ -30,6 +31,7 @@ import * as wikiInfoClasses from './wiki-info.js';
 const allClassLists = {
   'additional-file.js': additionalFileClasses,
   'additional-name.js': additionalNameClasses,
+  'adventure.js': adventureClasses,
   'album.js': albumClasses,
   'art-tag.js': artTagClasses,
   'artist.js': artistClasses,