« get me outta code hell

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:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/track.js35
-rw-r--r--src/data/yaml.js2
2 files changed, 37 insertions, 0 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index e176acb4..14510d96 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -36,6 +36,41 @@ export class Track extends Thing {
     urls: Thing.common.urls(),
     dateFirstReleased: Thing.common.simpleDate(),
 
+    // Controls how find.track works - it'll never be matched by a reference
+    // just to the track's name, which means you don't have to always reference
+    // some *other* (much more commonly referenced) track by directory instead
+    // of more naturally by name.
+    alwaysReferenceByDirectory: {
+      flags: {update: true, expose: true},
+
+      // Deliberately defaults to null - this will fall back to false in most
+      // cases.
+      update: {validate: isBoolean, default: null},
+
+      expose: {
+        dependencies: ['name', 'originalReleaseTrackByRef', 'trackData'],
+
+        transform(value, {
+          name,
+          originalReleaseTrackByRef,
+          trackData,
+          [Track.instance]: thisTrack,
+        }) {
+          if (value !== null) return value;
+
+          const original =
+            find.track(
+              originalReleaseTrackByRef,
+              trackData.filter(track => track !== thisTrack),
+              {quiet: true});
+
+          if (!original) return false;
+
+          return name === original.name;
+        }
+      },
+    },
+
     artistContribsByRef: Thing.common.contribsByRef(),
     contributorContribsByRef: Thing.common.contribsByRef(),
     coverArtistContribsByRef: Thing.common.contribsByRef(),
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 35943199..07e0a3d2 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -338,6 +338,8 @@ export const processTrackDocument = makeProcessDocument(T.Track, {
     coverArtFileExtension: 'Cover Art File Extension',
     hasCoverArt: 'Has Cover Art',
 
+    alwaysReferenceByDirectory: 'Always Reference By Directory',
+
     lyrics: 'Lyrics',
     commentary: 'Commentary',
     additionalFiles: 'Additional Files',