Skip to content

Commit

Permalink
rename plugin to Iron Vault
Browse files Browse the repository at this point in the history
Fixes: #62
  • Loading branch information
zkat committed May 25, 2024
1 parent dcaa1f9 commit 0022a4e
Show file tree
Hide file tree
Showing 76 changed files with 255 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .vscode/jest.code-snippets
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// Place your forged workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// Place your iron-vault workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests.v2.forged",
"name": "vscode-jest-tests.v2.iron-vault",
"request": "launch",
"args": [
"--runInBand",
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Obsidian Forged
# Iron Vault

Obsidian plugin to play Ironsworn/Starforged system games, using the data in
[datasworn](https://github.com/rsek/datasworn) format.

This owes a lot to [Eric Bright's Forged_in_Obsidian](https://github.com/ericbright2002/Forged_in_Obsidian)
template vault. I started with that vault and then gradually replaced functionality
with this plugin.
This owes a lot to [Eric Bright's
Forged_in_Obsidian](https://github.com/ericbright2002/Forged_in_Obsidian)
template vault. I started with that vault and then gradually replaced
functionality with this plugin.

## Features

Expand Down
4 changes: 2 additions & 2 deletions esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const context = await esbuild.context({
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: prod ? "main.js" : "test-vault/.obsidian/plugins/forged/main.js",
outfile: prod ? "main.js" : "test-vault/.obsidian/plugins/iron-vault/main.js",
plugins: [typecheckPlugin({ watch: !prod })],
});

Expand All @@ -48,7 +48,7 @@ const cssCtx = await esbuild.context({
sourcemap: prod ? false : "inline",
outfile: prod
? "styles.css"
: "test-vault/.obsidian/plugins/forged/styles.css",
: "test-vault/.obsidian/plugins/iron-vault/styles.css",
loader: {
".svg": "dataurl",
},
Expand Down
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "forged",
"name": "Forged Plugin",
"id": "iron-vault",
"name": "Iron Vault",
"version": "0.19.1",
"minAppVersion": "0.15.0",
"description": "Ironsworn/Starforged gameplay plugin",
"description": "Gameplay plugin/VTT for the Ironsworn/Starforged family of tabletop RPGs",
"author": "Chris Wegrzyn",
"authorUrl": "https://github.com/cwegrzyn",
"fundingUrl": "https://obsidian.md/pricing",
"isDesktopOnly": false
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "forged",
"name": "iron-vault",
"version": "0.19.1",
"description": "",
"main": "main.js",
Expand All @@ -8,6 +8,7 @@
"node": ">=16",
"pnpm": ">=9"
},
"private": true,
"scripts": {
"test": "jest",
"build": "tsc --noEmit && node esbuild.config.js production",
Expand Down
14 changes: 7 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { syntaxTree } from "@codemirror/language";
import { App } from "obsidian";
import { CharacterTracker } from "./character-tracker";
import { Datastore } from "./datastore";
import ForgedPlugin from "./index";
import IronVaultPlugin from "./index";
import { RollWrapper } from "./model/rolls";
import { ProgressIndex } from "./tracks/progress";

function stripLinks(input: string): string {
return input.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1");
}

export class ForgedAPI {
constructor(public readonly plugin: ForgedPlugin) {}
export class IronVaultAPI {
constructor(public readonly plugin: IronVaultPlugin) {}

get datastore(): Datastore {
return this.plugin.datastore;
Expand Down Expand Up @@ -39,10 +39,10 @@ export class ForgedAPI {
}
}

export const getAPI = (app?: App): ForgedAPI | undefined => {
if (app) return app.plugins.plugins.forged?.api;
else return window.ForgedAPI;
export const getAPI = (app?: App): IronVaultAPI | undefined => {
if (app) return app.plugins.plugins["iron-vault"]?.api;
else return window.IronVaultAPI;
};

export const isPluginEnabled = (app: App) =>
app.plugins.enabledPlugins.has("forged");
app.plugins.enabledPlugins.has("iron-vault");
4 changes: 2 additions & 2 deletions src/characters/action-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
rollablesReader,
} from "../characters/lens";
import { type Datastore } from "../datastore";
import ForgedPlugin from "../index";
import IronVaultPlugin from "../index";
import { InfoModal } from "../utils/ui/info";

export interface IActionContext {
Expand Down Expand Up @@ -143,7 +143,7 @@ function renderError(e: Error, el: HTMLElement): void {
}

export async function determineCharacterActionContext(
plugin: ForgedPlugin,
plugin: IronVaultPlugin,
): Promise<ActionContext | undefined> {
if (plugin.settings.useCharacterSystem) {
try {
Expand Down
7 changes: 5 additions & 2 deletions src/characters/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CharReader,
CharWriter,
CharacterLens,
ForgedSheetAssetSchema,
IronVaultSheetAssetSchema,
} from "./lens";

export class AssetError extends Error {}
Expand All @@ -19,7 +19,10 @@ export function assetWithDefnReader(
index: DataIndex,
): CharReader<
Array<
Either<AssetError, { asset: ForgedSheetAssetSchema; defn: Datasworn.Asset }>
Either<
AssetError,
{ asset: IronVaultSheetAssetSchema; defn: Datasworn.Asset }
>
>
> {
return reader((source) => {
Expand Down
6 changes: 3 additions & 3 deletions src/characters/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Datasworn } from "@datasworn/core";
import ForgedPlugin from "index";
import IronVaultPlugin from "index";
import { Editor, FuzzyMatch, MarkdownView } from "obsidian";
import { vaultProcess } from "utils/obsidian";
import { firstUppercase } from "utils/strings";
Expand All @@ -14,7 +14,7 @@ import {
} from "./assets";

export async function addAssetToCharacter(
plugin: ForgedPlugin,
plugin: IronVaultPlugin,
_editor: Editor,
_view: MarkdownView,
): Promise<void> {
Expand All @@ -39,7 +39,7 @@ export async function addAssetToCharacter(
text:
asset.category +
(asset.requirement ? ` (requirement: ${asset.requirement})` : ""),
cls: "forged-suggest-hint",
cls: "iron-vault-suggest-hint",
});
},
`Choose an asset to add to character ${lens.name.get(character)}.`,
Expand Down
12 changes: 6 additions & 6 deletions src/characters/lens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ChallengeRanks } from "../tracks/progress";
import { Right } from "../utils/either";
import { Lens, updating } from "../utils/lens";
import {
BaseForgedSchema,
ForgedSheetAssetInput,
BaseIronVaultSchema,
IronVaultSheetAssetInput,
ImpactStatus,
characterLens,
momentumOps,
Expand Down Expand Up @@ -142,7 +142,7 @@ describe("characterLens", () => {
abilities: [true, false, false],
controls: { integrity: 2 },
},
] as ForgedSheetAssetInput[],
] as IronVaultSheetAssetInput[],
});
actsLikeLens(lens.assets, character, [
{
Expand Down Expand Up @@ -407,7 +407,7 @@ describe("movesReader", () => {
abilities: [false, false, false],
},
],
} satisfies BaseForgedSchema),
} satisfies BaseIronVaultSchema),
),
).toEqual(Right.create([]));
});
Expand All @@ -425,7 +425,7 @@ describe("movesReader", () => {
abilities: [false, true, false],
},
],
} satisfies BaseForgedSchema),
} satisfies BaseIronVaultSchema),
)
.unwrap(),
).toHaveLength(0);
Expand All @@ -442,7 +442,7 @@ describe("movesReader", () => {
abilities: [true, true, false],
},
],
} satisfies BaseForgedSchema),
} satisfies BaseIronVaultSchema),
)
.unwrap(),
).toMatchObject([
Expand Down
21 changes: 12 additions & 9 deletions src/characters/lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ export const characterAssetSchema = z.object({
.default({}),
});

export type ForgedSheetAssetInput = z.input<typeof characterAssetSchema>;
export type ForgedSheetAssetSchema = z.output<typeof characterAssetSchema>;
export type IronVaultSheetAssetInput = z.input<typeof characterAssetSchema>;
export type IronVaultSheetAssetSchema = z.output<typeof characterAssetSchema>;

export const baseForgedSchema = z
export const baseIronVaultSchema = z
.object({
name: z.string(),
momentum: z.number().int().gte(-10).lte(10),
assets: z.array(characterAssetSchema).optional(),
})
.passthrough();

export type BaseForgedSchema = z.input<typeof baseForgedSchema>;
export type BaseIronVaultSchema = z.input<typeof baseIronVaultSchema>;

export enum ImpactStatus {
Unmarked = "⬡",
Expand All @@ -65,7 +65,7 @@ export interface CharacterLens {
momentum: Lens<ValidatedCharacter, number>;
stats: Record<string, Lens<ValidatedCharacter, number>>;
condition_meters: Record<string, Lens<ValidatedCharacter, number>>;
assets: Lens<ValidatedCharacter, ForgedSheetAssetSchema[]>;
assets: Lens<ValidatedCharacter, IronVaultSheetAssetSchema[]>;
impacts: Lens<ValidatedCharacter, Record<string, ImpactStatus>>;
special_tracks: Record<string, Lens<ValidatedCharacter, ProgressTrack>>;
ruleset: Ruleset;
Expand Down Expand Up @@ -429,7 +429,7 @@ export function characterLens(ruleset: Ruleset): {
const specialTracks = objectMap(ruleset.special_tracks, (rule) =>
legacyTrack(rule),
);
const schema = baseForgedSchema.extend({
const schema = baseIronVaultSchema.extend({
...objectMap(stats, ({ schema }) => schema),
...objectMap(condition_meters, ({ schema }) => schema),
...Object.fromEntries(
Expand All @@ -441,18 +441,21 @@ export function characterLens(ruleset: Ruleset): {

const lens: CharacterLens = {
name: v(
lensForSchemaProp({ path: "name", schema: baseForgedSchema.shape.name }),
lensForSchemaProp({
path: "name",
schema: baseIronVaultSchema.shape.name,
}),
),
momentum: v(
lensForSchemaProp({
path: "momentum",
schema: baseForgedSchema.shape.momentum,
schema: baseIronVaultSchema.shape.momentum,
}),
),
assets: v(
lensForSchemaProp({
path: "assets",
schema: baseForgedSchema.shape.assets.default([]),
schema: baseIronVaultSchema.shape.assets.default([]),
}),
),
stats: objectMap(stats, (defn) => v(lensForSchemaProp(defn))),
Expand Down
6 changes: 3 additions & 3 deletions src/characters/meter-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { updating } from "utils/lens";
import { numberRange } from "utils/numbers";
import { vaultProcess } from "utils/obsidian";
import { CustomSuggestModal } from "utils/suggest";
import ForgedPlugin from "../index";
import IronVaultPlugin from "../index";
import {
ActionContext,
CharacterActionContext,
Expand All @@ -15,7 +15,7 @@ import {
import { MeterWithLens, MeterWithoutLens, momentumOps } from "./lens";

export async function burnMomentum(
plugin: ForgedPlugin,
plugin: IronVaultPlugin,
editor: Editor,
): Promise<void> {
const [path, charContext] = plugin.characters.activeCharacter();
Expand Down Expand Up @@ -86,7 +86,7 @@ export async function promptForMeter(
}

export const modifyMeterCommand = async (
plugin: ForgedPlugin,
plugin: IronVaultPlugin,
editor: Editor,
verb: string,
meterFilter: (
Expand Down
12 changes: 6 additions & 6 deletions src/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DataIndex } from "datastore/data-index";
import { indexDataForgedData } from "datastore/parsers/dataforged";
import { ParserReturn, parserForFrontmatter } from "datastore/parsers/markdown";
import { StandardIndex } from "datastore/priority-index";
import ForgedPlugin from "index";
import IronVaultPlugin from "index";
import { Oracle } from "model/oracle";
import {
Component,
Expand All @@ -29,7 +29,7 @@ export class Datastore extends Component {
// TODO: wtf
activeRuleset: string = "starforged";

constructor(public readonly plugin: ForgedPlugin) {
constructor(public readonly plugin: IronVaultPlugin) {
super();
this._ready = false;

Expand All @@ -53,7 +53,7 @@ export class Datastore extends Component {
starforgedRuleset as Datasworn.Ruleset,
);
this.index.updateIndexGroup(mainPath, new Set([mainPath]));
this.app.metadataCache.trigger("forged:index-changed");
this.app.metadataCache.trigger("iron-vault:index-changed");

// TODO: also handle folders
// const dataFiles = await this.app.vault.adapter.list(
Expand Down Expand Up @@ -86,7 +86,7 @@ export class Datastore extends Component {
// }
// }
console.log(
"forged: init complete. loaded: %d oracles, %d moves, %d assets",
"iron-vault: init complete. loaded: %d oracles, %d moves, %d assets",
this.index._oracleIndex.size,
this.index._moveIndex.size,
this.index._assetIndex.size,
Expand Down Expand Up @@ -175,7 +175,7 @@ export class Datastore extends Component {
format: string = "json",
): Promise<void> {
console.log(
"forged: datastore: indexing plugin file %s (format: %s priority: %d)",
"iron-vault: datastore: indexing plugin file %s (format: %s priority: %d)",
normalizedPath,
format,
priority,
Expand All @@ -193,7 +193,7 @@ export class Datastore extends Component {
indexDataForgedData(this.index, normalizedPath, priority, data);
this.index.updateIndexGroup(normalizedPath, new Set([normalizedPath]));

this.app.metadataCache.trigger("forged:index-changed");
this.app.metadataCache.trigger("iron-vault:index-changed");
}

get ready(): boolean {
Expand Down
8 changes: 4 additions & 4 deletions src/datastore/parsers/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ export function parserForFrontmatter(
file: TFile,
metadata: CachedMetadata | null,
): MarkdownDataParser | undefined {
if (metadata?.frontmatter?.forged == null) {
if (metadata?.frontmatter?.["iron-vault"] == null) {
return undefined;
}
switch (metadata.frontmatter.forged) {
switch (metadata.frontmatter["iron-vault"]) {
case "dataforged-inline":
return dataforgedInlineParser;
case "inline-oracle":
return inlineOracleParser(file.basename);
default:
console.warn(
"[file: %s] unexpected value for `forged` in frontmatter: %s",
"[file: %s] unexpected value for `iron-vault` in frontmatter: %s",
file.path,
metadata.frontmatter?.forged,
metadata.frontmatter?.["iron-vault"],
);
return undefined;
}
Expand Down
Loading

0 comments on commit 0022a4e

Please sign in to comment.