« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--package.json1
-rw-r--r--src/data/composite/things/flash-act/index.js1
-rw-r--r--src/data/composite/things/flash-act/withFlashSide.js22
-rw-r--r--src/data/things/flash.js115
-rw-r--r--src/data/yaml.js5
-rwxr-xr-xsrc/upd8.js1
6 files changed, 124 insertions, 21 deletions
diff --git a/package.json b/package.json
index 6b0d0d56..fc755f41 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
         "#composite/wiki-properties": "./src/data/composite/wiki-properties/index.js",
         "#composite/things/album": "./src/data/composite/things/album/index.js",
         "#composite/things/flash": "./src/data/composite/things/flash/index.js",
+        "#composite/things/flash-act": "./src/data/composite/things/flash-act/index.js",
         "#composite/things/track": "./src/data/composite/things/track/index.js",
         "#content-dependencies": "./src/content/dependencies/index.js",
         "#content-function": "./src/content-function.js",
diff --git a/src/data/composite/things/flash-act/index.js b/src/data/composite/things/flash-act/index.js
new file mode 100644
index 00000000..40fecd2f
--- /dev/null
+++ b/src/data/composite/things/flash-act/index.js
@@ -0,0 +1 @@
+export {default as withFlashSide} from './withFlashSide.js';
diff --git a/src/data/composite/things/flash-act/withFlashSide.js b/src/data/composite/things/flash-act/withFlashSide.js
new file mode 100644
index 00000000..64daa1fb
--- /dev/null
+++ b/src/data/composite/things/flash-act/withFlashSide.js
@@ -0,0 +1,22 @@
+// Gets the flash act's side. This will early exit if flashSideData is missing.
+// If there's no side whose list of flash acts includes this act, the output
+// dependency will be null.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {withUniqueReferencingThing} from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `withFlashSide`,
+
+  outputs: ['#flashSide'],
+
+  steps: () => [
+    withUniqueReferencingThing({
+      data: 'flashSideData',
+      list: input.value('acts'),
+    }).outputs({
+      ['#uniqueReferencingThing']: '#flashSide',
+    }),
+  ],
+});
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index 54259f95..c311a57b 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -25,6 +25,7 @@ import {
 } from '#composite/wiki-properties';
 
 import {withFlashAct} from '#composite/things/flash';
+import {withFlashSide} from '#composite/things/flash-act';
 
 export class Flash extends Thing {
   static [Thing.referenceType] = 'flash';
@@ -109,6 +110,17 @@ export class Flash extends Thing {
       withFlashAct(),
       exposeDependency({dependency: '#flashAct'}),
     ],
+
+    side: [
+      withFlashAct(),
+
+      withPropertyFromObject({
+        object: '#flashAct',
+        property: input.value('side'),
+      }),
+
+      exposeDependency({dependency: '#flashAct.side'}),
+    ],
   });
 
   static [Thing.getSerializeDescriptors] = ({
@@ -192,6 +204,17 @@ export class FlashAct extends Thing {
     flashData: wikiData({
       class: input.value(Flash),
     }),
+
+    flashSideData: wikiData({
+      class: input.value(FlashSide),
+    }),
+
+    // Expose only
+
+    side: [
+      withFlashSide(),
+      exposeDependency({dependency: '#flashSide'}),
+    ],
   });
 
   static [Thing.findSpecs] = {
@@ -215,6 +238,46 @@ export class FlashAct extends Thing {
       'Review Points': {ignore: true},
     },
   };
+}
+
+export class FlashSide extends Thing {
+  static [Thing.referenceType] = 'flash-side';
+  static [Thing.friendlyName] = `Flash Side`;
+
+  static [Thing.getPropertyDescriptors] = () => ({
+    // Update & expose
+
+    name: name('Unnamed Flash Side'),
+    directory: directory(),
+    color: color(),
+
+    acts: referenceList({
+      class: input.value(FlashAct),
+      find: input.value(find.flashAct),
+      data: 'flashActData',
+    }),
+
+    // Update only
+
+    flashActData: wikiData({
+      class: input.value(FlashAct),
+    }),
+  });
+
+  static [Thing.yamlDocumentSpec] = {
+    fields: {
+      'Side': {property: 'name'},
+      'Directory': {property: 'directory'},
+      'Color': {property: 'color'},
+    },
+  };
+
+  static [Thing.findSpecs] = {
+    flashSide: {
+      referenceTypes: ['flash-side'],
+      bindTo: 'flashSideData',
+    },
+  };
 
   static [Thing.getYamlLoadingSpec] = ({
     documentModes: {allInOne},
@@ -225,39 +288,49 @@ export class FlashAct extends Thing {
 
     documentMode: allInOne,
     documentThing: document =>
-      ('Act' in document
+      ('Side' in document
+        ? FlashSide
+     : 'Act' in document
         ? FlashAct
         : Flash),
 
     save(results) {
-      let flashAct;
-      let flashRefs = [];
-
-      if (results[0] && !(results[0] instanceof FlashAct)) {
-        throw new Error(`Expected an act at top of flash data file`);
-      }
+      let thing;
+      for (let index = 0; thing = results[index]; index++) {
+        if (index === 0 && !(thing instanceof FlashSide)) {
+          throw new Error(`Expected a side at top of flash data file`);
+        }
 
-      for (const thing of results) {
-        if (thing instanceof FlashAct) {
-          if (flashAct) {
-            Object.assign(flashAct, {flashes: flashRefs});
+        // JavaScript likes you.
+        const flashSide = thing;
+        const flashActRefs = [];
+        for (
+          index++;
+          (thing = results[index]) && thing instanceof FlashAct;
+          index++
+        ) {
+          const flashAct = thing;
+          const flashRefs = [];
+          for (
+            index++;
+            (thing = results[index]) && thing instanceof Flash;
+            index++
+          ) {
+            flashRefs.push(Thing.getReference(thing));
           }
-
-          flashAct = thing;
-          flashRefs = [];
-        } else {
-          flashRefs.push(Thing.getReference(thing));
+          index--;
+          flashAct.flashes = flashRefs;
+          flashActRefs.push(Thing.getReference(flashAct));
         }
-      }
-
-      if (flashAct) {
-        Object.assign(flashAct, {flashes: flashRefs});
+        index--;
+        flashSide.acts = flashActRefs;
       }
 
       const flashData = results.filter(x => x instanceof Flash);
       const flashActData = results.filter(x => x instanceof FlashAct);
+      const flashSideData = results.filter(x => x instanceof FlashSide);
 
-      return {flashData, flashActData};
+      return {flashData, flashActData, flashSideData};
     },
 
     sort({flashData}) {
diff --git a/src/data/yaml.js b/src/data/yaml.js
index f84f0378..86f30143 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -942,6 +942,11 @@ export function linkWikiDataArrays(wikiData) {
 
     [wikiData.flashActData, [
       'flashData',
+      'flashSideData',
+    ]],
+
+    [wikiData.flashSideData, [
+      'flashActData',
     ]],
 
     [wikiData.groupData, [
diff --git a/src/upd8.js b/src/upd8.js
index 4c790075..66765f1d 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -981,6 +981,7 @@ async function main() {
       if (wikiData.flashData) {
         logThings('flashData', 'flashes');
         logThings('flashActData', 'flash acts');
+        logThings('flashSideData', 'flash sides');
       }
       logThings('groupData', 'groups');
       logThings('groupCategoryData', 'group categories');