From 3b7adf38e6916f3be923d0ef86b60b5494f83f6b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 3 Apr 2024 13:30:01 -0300 Subject: data: FlashSide (data processing & loading) --- package.json | 1 + src/data/composite/things/flash-act/index.js | 1 + .../composite/things/flash-act/withFlashSide.js | 22 ++++ src/data/things/flash.js | 115 +++++++++++++++++---- src/data/yaml.js | 5 + src/upd8.js | 1 + 6 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 src/data/composite/things/flash-act/index.js create mode 100644 src/data/composite/things/flash-act/withFlashSide.js diff --git a/package.json b/package.json index 6b0d0d5..fc755f4 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 0000000..40fecd2 --- /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 0000000..64daa1f --- /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 54259f9..c311a57 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 f84f037..86f3014 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 4c79007..66765f1 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'); -- cgit 1.3.0-6-gf8a5