From 73c59a414c27c4b50647639f3459cd97ee8b9170 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 19 Nov 2025 23:03:25 -0400 Subject: data: Adventure (wip!!!! wip!!!! wip!!!! wip!!!!) --- src/data/things/adventure.js | 145 +++++++++++++++++++++++++++++++++++++++++++ src/data/things/index.js | 2 + 2 files changed, 147 insertions(+) create mode 100644 src/data/things/adventure.js diff --git a/src/data/things/adventure.js b/src/data/things/adventure.js new file mode 100644 index 00000000..ed5da39b --- /dev/null +++ b/src/data/things/adventure.js @@ -0,0 +1,145 @@ +export const DATA_ADVENTURE_DIRECTORY = 'adventure'; + +import * as path from 'node:path'; + +import {input} from '#composite'; +import {traverse} from '#node-utils'; +import Thing from '#thing'; + +import {exposeDependency} from '#composite/control-flow'; +import {withPropertyFromObject} from '#composite/data'; +import {directory, name, thing, thingList} + from '#composite/wiki-properties'; + +// *thumb-twiddling* +import {Flash, FlashAct} from './flash.js'; + +export class Adventure extends Thing { + static [Thing.referenceType] = 'adventure'; + + static [Thing.getPropertyDescriptors] = ({FlashAct}) => ({ + // > Internal relationships + + acts: thingList({ + class: input.value(FlashAct), + }), + + // > Identifying metadata + + name: name('Unnamed Adventure'), + directory: directory(), + }); + + static [Thing.yamlDocumentSpec] = { + fields: { + // Identifying metadata + + 'Adventure': {property: 'name'}, + 'Directory': {property: 'directory'}, + }, + }; + + static [Thing.getYamlLoadingSpec] = ({ + documentModes: {headerAndEntries}, + thingConstructors: { + Adventure, + AdventureFlashAct, + AdventureFlash, + }, + }) => ({ + title: `Process adventure files`, + + files: dataPath => + traverse(path.join(dataPath, DATA_ADVENTURE_DIRECTORY), { + filterFile: name => path.extname(name) === '.yaml', + prefixPath: DATA_ADVENTURE_DIRECTORY, + }), + + documentMode: headerAndEntries, + + headerDocumentThing: Adventure, + entryDocumentThing: document => + ('Act' in document + ? AdventureFlashAct + : AdventureFlash), + + save(results) { + const adventureData = []; + const flashActData = []; + const flashData = []; + + for (const {header: adventure, entries} of results) { + const acts = []; + + let thing, i; + for (i = 0; thing = entries[i]; i++) { + if (thing.isFlashAct) { + const act = thing; + const flashes = []; + + for (i++; thing = entries[i]; i++) { + if (thing.isFlash) { + const flash = thing; + + flash.act = act; + flashes.push(flash); + flashData.push(flash); + + continue; + } + + i--; + break; + } + + act.flashes = flashes; + acts.push(act); + flashActData.push(act); + + continue; + } + + if (thing.isFlash) { + throw new Error(`Flashes must be under a flash act`); + } + } + + adventure.acts = acts; + adventureData.push(adventure); + } + + return { + adventureData, + flashActData, + flashData, + }; + }, + }); +} + +export class AdventureFlash extends Flash { + static [Thing.getPropertyDescriptors] = ({Adventure}) => ({ + // > Implicit relationships + + adventure: [ + withPropertyFromObject({ + object: 'act', + property: input.value('adventure'), + }), + + exposeDependency({ + dependency: '#act.adventure', + }), + ], + }); +} + +export class AdventureFlashAct extends FlashAct { + static [Thing.getPropertyDescriptors] = ({Adventure}) => ({ + // > Internal relationships + + adventure: thing({ + class: input.value(Adventure), + }), + }); +} diff --git a/src/data/things/index.js b/src/data/things/index.js index 676453ce..33fc933d 100644 --- a/src/data/things/index.js +++ b/src/data/things/index.js @@ -11,6 +11,7 @@ import Thing from '#thing'; import * as additionalFileClasses from './additional-file.js'; import * as additionalNameClasses from './additional-name.js'; +import * as adventureClasses from './adventure.js'; import * as albumClasses from './album.js'; import * as artTagClasses from './art-tag.js'; import * as artistClasses from './artist.js'; @@ -30,6 +31,7 @@ import * as wikiInfoClasses from './wiki-info.js'; const allClassLists = { 'additional-file.js': additionalFileClasses, 'additional-name.js': additionalNameClasses, + 'adventure.js': adventureClasses, 'album.js': albumClasses, 'art-tag.js': artTagClasses, 'artist.js': artistClasses, -- cgit 1.3.0-6-gf8a5