« get me outta code hell

data: Album.wallpaperParts - 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-01-06 19:41:24 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-06 19:42:00 -0400
commit405ccfd6c813398fc0e919caeff922bc1c3d9dd0 (patch)
tree8e6b8ea8d253da8690d1ecdd28a2d09163f59587 /src/data
parenta2488d2f5f5d1b9ef096c2d9968c56e6439adcac (diff)
data: Album.wallpaperParts
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/wiki-properties/index.js1
-rw-r--r--src/data/composite/wiki-properties/wallpaperParts.js9
-rw-r--r--src/data/things/album.js24
-rw-r--r--src/data/validators.js7
-rw-r--r--src/data/yaml.js15
5 files changed, 56 insertions, 0 deletions
diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js
index 2de76912..b55616c0 100644
--- a/src/data/composite/wiki-properties/index.js
+++ b/src/data/composite/wiki-properties/index.js
@@ -33,4 +33,5 @@ export {default as singleReference} from './singleReference.js';
 export {default as thing} from './thing.js';
 export {default as thingList} from './thingList.js';
 export {default as urls} from './urls.js';
+export {default as wallpaperParts} from './wallpaperParts.js';
 export {default as wikiData} from './wikiData.js';
diff --git a/src/data/composite/wiki-properties/wallpaperParts.js b/src/data/composite/wiki-properties/wallpaperParts.js
new file mode 100644
index 00000000..23049397
--- /dev/null
+++ b/src/data/composite/wiki-properties/wallpaperParts.js
@@ -0,0 +1,9 @@
+import {isWallpaperPartList} from '#validators';
+
+export default function() {
+  return {
+    flags: {update: true, expose: true},
+    update: {validate: isWallpaperPartList},
+    expose: {transform: value => value ?? []},
+  };
+}
diff --git a/src/data/things/album.js b/src/data/things/album.js
index af3c6a92..bd54a356 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -20,6 +20,7 @@ import {
   parseContributors,
   parseDate,
   parseDimensions,
+  parseWallpaperParts,
 } from '#yaml';
 
 import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue}
@@ -56,6 +57,7 @@ import {
   thing,
   thingList,
   urls,
+  wallpaperParts,
   wikiData,
 } from '#composite/wiki-properties';
 
@@ -143,6 +145,11 @@ export class Album extends Thing {
       simpleString(),
     ],
 
+    wallpaperParts: [
+      exitWithoutContribs({contribs: 'wallpaperArtistContribs'}),
+      wallpaperParts(),
+    ],
+
     bannerStyle: [
       exitWithoutContribs({contribs: 'bannerArtistContribs'}),
       simpleString(),
@@ -440,6 +447,11 @@ export class Album extends Thing {
       'Wallpaper Style': {property: 'wallpaperStyle'},
       'Wallpaper File Extension': {property: 'wallpaperFileExtension'},
 
+      'Wallpaper Parts': {
+        property: 'wallpaperParts',
+        transform: parseWallpaperParts,
+      },
+
       'Banner Artists': {
         property: 'bannerArtistContribs',
         transform: parseContributors,
@@ -488,6 +500,18 @@ export class Album extends Thing {
 
       'Review Points': {ignore: true},
     },
+
+    invalidFieldCombinations: [
+      {message: `Specify one wallpaper style or multiple wallpaper parts, not both`, fields: [
+        'Wallpaper Parts',
+        'Wallpaper Style',
+      ]},
+
+      {message: `Wallpaper file extensions are specified on asset, per part`, fields: [
+        'Wallpaper Parts',
+        'Wallpaper File Extension',
+      ]},
+    ],
   };
 
   static [Thing.getYamlLoadingSpec] = ({
diff --git a/src/data/validators.js b/src/data/validators.js
index a17a98cc..84e08cb8 100644
--- a/src/data/validators.js
+++ b/src/data/validators.js
@@ -724,6 +724,13 @@ export const isSeries = validateProperties({
 
 export const isSeriesList = validateArrayItems(isSeries);
 
+export const isWallpaperPart = validateProperties({
+  asset: optional(isString),
+  style: optional(isString),
+});
+
+export const isWallpaperPartList = validateArrayItems(isWallpaperPart);
+
 export function isDimensions(dimensions) {
   isArray(dimensions);
 
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 0bc2e298..64223662 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -479,6 +479,21 @@ export function parseSerieses(entries) {
   });
 }
 
+export function parseWallpaperParts(entries) {
+  return parseArrayEntries(entries, item => {
+    if (typeof item !== 'object') return item;
+
+    return {
+      asset:
+        (item['Asset'] === 'none'
+          ? null
+          : item['Asset'] ?? null),
+
+      style: item['Style'] ?? null,
+    };
+  });
+}
+
 export function parseDimensions(string) {
   // It's technically possible to pass an array like [30, 40] through here.
   // That's not really an issue because if it isn't of the appropriate shape,