From eb8b316bb9af7d34720de1fa8f8dbd4b81513b32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 29 Jan 2024 08:10:30 -0400 Subject: data, yaml: store data step info on Thing constructors --- src/data/things/flash.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/data/things/flash.js') diff --git a/src/data/things/flash.js b/src/data/things/flash.js index 945d80dd..ad80cbf2 100644 --- a/src/data/things/flash.js +++ b/src/data/things/flash.js @@ -1,3 +1,5 @@ +export const FLASH_DATA_FILE = 'flashes.yaml'; + import {input} from '#composite'; import find from '#find'; import Thing from '#thing'; @@ -204,4 +206,49 @@ export class FlashAct extends Thing { 'Review Points': {ignore: true}, }, }; + + static [Thing.getYamlLoadingSpec] = ({ + documentModes: {allInOne}, + thingConstructors: {Flash, FlashAct}, + }) => ({ + title: `Process flashes file`, + file: FLASH_DATA_FILE, + + documentMode: allInOne, + documentThing: document => + ('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`); + } + + for (const thing of results) { + if (thing instanceof FlashAct) { + if (flashAct) { + Object.assign(flashAct, {flashes: flashRefs}); + } + + flashAct = thing; + flashRefs = []; + } else { + flashRefs.push(Thing.getReference(thing)); + } + } + + if (flashAct) { + Object.assign(flashAct, {flashes: flashRefs}); + } + + const flashData = results.filter(x => x instanceof Flash); + const flashActData = results.filter(x => x instanceof FlashAct); + + return {flashData, flashActData}; + }, + }); } -- cgit 1.3.0-6-gf8a5