loathers / grimoire

Apache License 2.0
3 stars 8 forks source link

Handle foldables in `Outfit.from`/generally improved foldable handling in outfits #90

Open horrible-little-slime opened 1 year ago

horrible-little-slime commented 1 year ago

I recently had to write the following admittedly-shitty function for garbo's upcoming outfit revamp:

export function validateGarbageFoldable(spec: OutfitSpec): void {
  const garbageItems = getFoldGroup($item`January's Garbage Tote`);
  for (const garbageItem of garbageItems) {
    if (
      Object.values(spec).some(
        (specEntry) =>
          specEntry === garbageItem || (Array.isArray(specEntry) && specEntry.includes(garbageItem))
      )
    ) {
      if (!have(garbageItem)) cliExecute(`fold ${garbageItem}`);
      break;
    }
  }
}

because calling Outfit.from was throwing errors when we don't have our foldable folded.

Garbo currently doesn't actually use grimoire's task-engine framework in most places, which is admittedly an us problem. phccs handles the issue by either folding the thing we want as part of our outfit function (as this does; phccs outfits are a lot more predictable and less dynamic than garbo ones) or as part of a prepare function for a task. It would be nice to have a system embedded directly into grimoire's outfit and/or task handling to do folding, sort of like how it has native modeable handling.

Kasekopf commented 1 year ago

Yes, I think this would be a good idea to include in grimoire. Probably an outfit will have to keep track of the number of foldable versions of a given item that is about to be equipped, and then handle the folding in _dress.

I'm traveling right now but I might be able to look at this this weekend.