diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-29 08:10:30 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-30 07:59:40 -0400 |
commit | eb8b316bb9af7d34720de1fa8f8dbd4b81513b32 (patch) | |
tree | 22d435e702b89344304928b7a860a5326357f192 /src/data/things/flash.js | |
parent | b30585187480a270826767eaf97e1acc66126072 (diff) |
data, yaml: store data step info on Thing constructors
Diffstat (limited to 'src/data/things/flash.js')
-rw-r--r-- | src/data/things/flash.js | 47 |
1 files changed, 47 insertions, 0 deletions
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}; + }, + }); } |