diff --git a/src/mechanics/node-builders.ts b/src/mechanics/node-builders.ts index 96d9f97c..2d968ccb 100644 --- a/src/mechanics/node-builders.ts +++ b/src/mechanics/node-builders.ts @@ -102,7 +102,7 @@ export function generateMechanicsNode(move: MoveDescription): Document { }), ); } else { - throw new Error("what kind of move is this?"); + // Nothing to do for a no-roll move } const doc: Document = [ diff --git a/src/moves/action/index.ts b/src/moves/action/index.ts index b5f4fa60..d20eb04e 100644 --- a/src/moves/action/index.ts +++ b/src/moves/action/index.ts @@ -25,6 +25,7 @@ import { vaultProcess } from "../../utils/obsidian"; import { CustomSuggestModal } from "../../utils/suggest"; import { ActionMoveAdd, + NoRollMoveDescription, type ActionMoveDescription, type MoveDescription, type ProgressMoveDescription, @@ -235,6 +236,11 @@ export async function runMoveCommand( break; } case "no_roll": + moveDescription = { + id: move._id, + name: move.name, + } satisfies NoRollMoveDescription; + break; case "special_track": default: // TODO: this probably makes sense with new mechanics format? diff --git a/src/moves/block.ts b/src/moves/block.ts index 05d9a728..cec7d0b5 100644 --- a/src/moves/block.ts +++ b/src/moves/block.ts @@ -3,6 +3,7 @@ import { Datastore } from "datastore"; import { MarkdownRenderChild, MarkdownRenderer, type App } from "obsidian"; import ForgedPlugin from "../index"; import { + NoRollMoveDescription, moveIsAction, moveIsProgress, type ActionMoveDescription, @@ -88,7 +89,9 @@ class MoveMarkdownRenderChild extends MarkdownRenderChild { } } - labelForResult(wrap: MoveWrapper): string { + labelForResult( + wrap: MoveWrapper, + ): string { switch (wrap.result()) { case RollResult.Miss: return "Miss" + (wrap.isMatch() ? " with Match" : ""); @@ -104,8 +107,9 @@ class MoveMarkdownRenderChild extends MarkdownRenderChild { return this.actionTemplate(move); } else if (moveIsProgress(move)) { return this.progressTemplate(move); + } else { + return this.noRollTemplate(move); } - throw new Error("What kind of bizarre move is this?"); } actionTemplate(move: ActionMoveDescription): string { @@ -139,6 +143,10 @@ class MoveMarkdownRenderChild extends MarkdownRenderChild { >`; } + noRollTemplate(move: NoRollMoveDescription): string { + return `> [!challenge-strong] ${move.name}\n> \n`; + } + async onload(): Promise { await MarkdownRenderer.render( this.app, diff --git a/src/moves/desc.ts b/src/moves/desc.ts index cfbdebc7..5b4dab12 100644 --- a/src/moves/desc.ts +++ b/src/moves/desc.ts @@ -55,7 +55,7 @@ export type ProgressMoveDescription = z.infer< >; export const NoRollMoveDescriptionSchema = z.object({ - id: z.string(), + id: z.string().optional(), name: z.string(), }); @@ -65,7 +65,7 @@ export const AllMoveDescriptionSchemas = z.union([ ActionMoveDescriptionSchemaV2, ProgressMoveDescriptionSchema, ActionMoveDescriptionSchemaV1, - // NoRollMoveDescriptionSchema, + NoRollMoveDescriptionSchema, ]); export type AllMoveDescriptions = z.infer; @@ -73,7 +73,7 @@ export type AllMoveDescriptions = z.infer; export const MoveDescriptionSchema = z.union([ ActionMoveDescriptionSchemaV2, ProgressMoveDescriptionSchema, - // NoRollMoveDescriptionSchema, + NoRollMoveDescriptionSchema, ]); export type MoveDescription = z.infer; diff --git a/src/moves/move-modal.ts b/src/moves/move-modal.ts index 79d4faf2..536531ee 100644 --- a/src/moves/move-modal.ts +++ b/src/moves/move-modal.ts @@ -26,19 +26,17 @@ export class MoveModal extends Modal { contentEl.empty(); contentEl.toggleClass("forged-modal-content", true); (async () => { - if (move.roll_type !== "no_roll") { - new ButtonComponent(contentEl) - .setButtonText("Roll this move") - .onClick(() => { - const { workspace } = this.plugin.app; - const view = workspace.getActiveFileView(); - if (view && view instanceof MarkdownView) { - const editor = view.editor; - runMoveCommand(this.plugin, editor, view, move); - this.close(); - } - }); - } + new ButtonComponent(contentEl) + .setButtonText("Make this move") + .onClick(() => { + const { workspace } = this.plugin.app; + const view = workspace.getActiveFileView(); + if (view && view instanceof MarkdownView) { + const editor = view.editor; + runMoveCommand(this.plugin, editor, view, move); + this.close(); + } + }); await MarkdownRenderer.render( this.app, move.text, diff --git a/src/moves/wrapper.ts b/src/moves/wrapper.ts index d5ae731e..0877eba4 100644 --- a/src/moves/wrapper.ts +++ b/src/moves/wrapper.ts @@ -3,7 +3,6 @@ import { moveIsAction, moveIsProgress, type ActionMoveDescription, - type MoveDescription, type ProgressMoveDescription, } from "./desc"; @@ -32,9 +31,15 @@ export enum MoveKind { Progress, } -export function wrapMove( - move: T, -): MoveWrapper { +export function wrapMove( + move: ActionMoveDescription, +): ActionMoveWrapper; +export function wrapMove( + move: ProgressMoveDescription, +): ProgressMoveWrapper; +export function wrapMove< + T extends ActionMoveDescription | ProgressMoveDescription, +>(move: T): ActionMoveWrapper | ProgressMoveWrapper { if (moveIsAction(move)) { return new ActionMoveWrapper(move); } else if (moveIsProgress(move)) { @@ -44,7 +49,9 @@ export function wrapMove( } } -export abstract class MoveWrapper { +export abstract class MoveWrapper< + T extends ActionMoveDescription | ProgressMoveDescription, +> { public readonly move: T; public constructor(move: T) {