Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ben/obsidian-13th-age-statblocks
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.0
Choose a base ref
...
head repository: ben/obsidian-13th-age-statblocks
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jan 13, 2022

  1. Wups fix the plugin id

    ben committed Jan 13, 2022
    Copy the full SHA
    c3f801e View commit details
  2. Update README.md

    ben committed Jan 13, 2022
    Copy the full SHA
    2e9f97a View commit details
  3. Cleanup template leftovers

    ben committed Jan 13, 2022
    Copy the full SHA
    c355180 View commit details
  4. 0.1.2

    ben committed Jan 13, 2022
    Copy the full SHA
    40a81a9 View commit details
  5. Create LICENSE

    ben authored Jan 13, 2022
    Copy the full SHA
    cf9e1d7 View commit details
  6. Update README.md

    ben authored Jan 13, 2022
    Copy the full SHA
    e8f3a53 View commit details

Commits on Jan 21, 2022

  1. Include source

    ben committed Jan 21, 2022
    Copy the full SHA
    f86fcf7 View commit details
  2. Adjust margins

    ben committed Jan 21, 2022
    Copy the full SHA
    7dd2209 View commit details
  3. Luminari

    ben committed Jan 21, 2022
    Copy the full SHA
    b7aacc5 View commit details
  4. Copy the full SHA
    d75af22 View commit details

Commits on Jan 23, 2022

  1. Copy the full SHA
    f8ec0e9 View commit details
  2. 0.1.3

    ben committed Jan 23, 2022
    Copy the full SHA
    6f8df14 View commit details

Commits on Feb 4, 2022

  1. Vulnerability line

    ben committed Feb 4, 2022
    Copy the full SHA
    a1a118e View commit details

Commits on Feb 21, 2022

  1. Copy the full SHA
    1375e35 View commit details
  2. 0.1.5

    ben committed Feb 21, 2022
    Copy the full SHA
    824275f View commit details
  3. Fix vuln tag

    ben committed Feb 21, 2022
    Copy the full SHA
    81ade38 View commit details
  4. 0.1.6

    ben committed Feb 21, 2022
    Copy the full SHA
    380f128 View commit details

Commits on Mar 6, 2024

  1. Names matter

    ben committed Mar 6, 2024
    Copy the full SHA
    04da8c9 View commit details
  2. New import script

    ben committed Mar 6, 2024
    Copy the full SHA
    910b72e View commit details
  3. Update imported monster data

    More monsters, cleaner data
    ben committed Mar 6, 2024
    Copy the full SHA
    64a06a5 View commit details
  4. 0.1.7

    ben committed Mar 6, 2024
    Copy the full SHA
    25d72d3 View commit details
  5. Strip "/r" from descriptions

    ben committed Mar 6, 2024
    Copy the full SHA
    75d1a0b View commit details
  6. Copy the full SHA
    0b36971 View commit details
  7. 0.1.8

    ben committed Mar 6, 2024
    Copy the full SHA
    37c9b24 View commit details
Showing with 26,810 additions and 9,887 deletions.
  1. +2 −0 .gitignore
  2. +21 −0 LICENSE
  3. +7 −42 README.md
  4. +1 −1 esbuild.config.mjs
  5. +94 −0 import-from-archmage-db.ts
  6. +111 −0 import-from-archmage-yaml.ts
  7. +4 −64 main.ts
  8. +2 −2 manifest.json
  9. +26,541 −9,769 monsters.json
  10. +3 −2 package.json
  11. +14 −6 statblockrenderer.ts
  12. +10 −1 styles.css
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ package-lock.json
# They should be uploaded to GitHub releases instead.
main.js
import-from-archmage.js
import-from-archmage-db.js
import-from-archmage-yaml.js

# Exclude sourcemaps
*.map
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Ben Straub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 7 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,24 @@
## Obsidian Sample Plugin
# 13th Age Statblocks

This is a sample plugin for Obsidian (https://obsidian.md).
This plugin renders 13th-Age plugins, and includes SRD content to base your monsters from.

This project uses Typescript to provide type checking and documentation.
The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains TSDoc comments describing what it does.
![](https://user-images.githubusercontent.com/39902/149404290-3dcb6793-0437-496d-b066-b2d7d5355374.png)

**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
![](https://user-images.githubusercontent.com/39902/149404315-5a9d6d45-55da-421b-b424-9596d2f95d55.png)

This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Changes the default font color to red using `styles.css`.
- Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open Sample Modal" which opens a Modal.
- Adds a plugin setting tab to the settings page.
- Registers a global click event and output 'click' to the console.
- Registers a global interval which logs 'setInterval' to the console.

### First time developing plugins?

Quick starting guide for new plugin devs:

- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
- Install NodeJS, then run `npm i` in the command line under your repo folder.
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
- Reload Obsidian to load the new version of your plugin.
- Enable plugin in settings window.
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.

### Releasing new releases

- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
- Publish the release.

### Adding your plugin to the community plugin list

- Publish an initial version.
- Make sure you have a `README.md` file in the root of your repo.
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.

### How to use
### Development

- Clone this repo.
- `npm i` or `yarn` to install dependencies
- `npm run dev` to start compilation in watch mode.

### Manually installing the plugin

- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/13th-age-statblocks/`.

### Improve code quality with eslint (optional)
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- To use eslint with this project, make sure to install eslint from terminal:
- `npm install -g eslint`
- To use eslint to analyze this project use this command:
2 changes: 1 addition & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ esbuild.build({
banner: {
js: banner,
},
entryPoints: ['main.ts', 'import-from-archmage.ts'],
entryPoints: ['main.ts', 'import-from-archmage.ts', 'import-from-archmage-db.ts', 'import-from-archmage-yaml.ts'],
bundle: true,
external: ['obsidian', 'electron', ...builtins],
format: 'cjs',
94 changes: 94 additions & 0 deletions import-from-archmage-db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { readFile, writeFile } from "fs/promises";

const debug = require("debug")("import");

async function doit() {
// This relies on having the archmage repo cloned at ../archmange, and the packs built
const rawData = await readFile("../archmage/packs/dist/srd-monsters.db", {
encoding: "utf-8",
});
const lines = rawData.toString().split("\n");

const monsters = [];
for (const json of lines) {
if (json.trim() === '') continue
const parsed = JSON.parse(json);
debug(`Processing ${parsed.name}`);

let size = parsed.data.details.size.value;
if (size === "2x") size = "Double-strength";
if (size === "3x") size = "Triple-strength";
if (size.toLowerCase() === "normal") size = undefined;

const monster = {
name: parsed.name,
level: parsed.data.attributes.level.value,
size,
tag: parsed.data.details.type.value,
role: parsed.data.details.role.value || undefined,
vuln: parsed.data.details.vulnerability.value || undefined,
ac: parsed.data.attributes.ac.value,
pd: parsed.data.attributes.pd.value,
md: parsed.data.attributes.md.value,
hp: parsed.data.attributes.hp.value,
initiative: parsed.data.attributes.init.mod,
attacks: [] as any[],
traits: [] as any[],
specials: [] as any[],
};

for (const item of parsed.items) {
if (item.type === "action") {
let name = item.name as string;
let tag = undefined;
const m = name.match(/\[(.*)\](.*)/);
if (m) {
tag = m[1].trim();
name = m[2].trim();
}

const roll = item.data.attack.value
.replace("[[d20", "")
.replace("]]", "")
.replace(/\+\s*(\d+)/, "+$1")
.trim();

const extras = [] as any[];
for (const k of ["hit1", "hit2", "hit3", "hit4", "hit5"]) {
const extraHit = item.data[k];
if (extraHit?.name) {
extras.push({
name: extraHit.name,
description: extraHit.value,
});
}
}

monster.attacks.push({
name,
tag,
attack: roll,
hit: item.data.hit.value,
extras,
});
} else {
const thing = {
name: item.name,
description: item.data.description.value,
};
const monsterKey = {
trait: "traits",
nastierSpecial: "specials",
}[item.type];
monster[monsterKey].push(thing);
}
}

monsters.push(monster);
}

// Write the results to a file
await writeFile("monsters.json", JSON.stringify(monsters, null, 2));
}

doit().then(console.log, console.error);
111 changes: 111 additions & 0 deletions import-from-archmage-yaml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { readFile, writeFile, readdir } from 'fs/promises'
import yaml from 'yaml'

const debug = require('debug')('import')

function stripFoundryMarkup (input?: string): string {
return (input ?? '')
.replace(/\[\[(d20)?(\/r(oll)?\s+)?/g, '') // Remove [[ and [[d20 and [[/r and [[/roll
.replace(/\]\]/g, '') // Remove ]]
.replace(/\+\s*(\d+)/g, '+$1') // convert "+ 1" to "+1"
.replace(/\*(\w+)\*/g, '$1') // convert *word* to word
.trim()
}

async function doit () {
// This relies on having the archmage repo cloned at ../archmange, and the packs built

// Find all the *.yaml files in the archmage/packs/dist directory
const yamlFiles = await readdir('../archmage/src/packs/src/srd-monsters/')

const monsters = []
for (const yamlFilename of yamlFiles) {
// Parse the yaml file
const rawData = await readFile(
`../archmage/src/packs/src/srd-monsters/${yamlFilename}`,
{
encoding: 'utf-8'
}
)
const parsed = yaml.parse(rawData)
debug(`Processing ${parsed.name}`)

let size = parsed.system.details.size.value
if (size === '2x') size = 'Double-strength'
if (size === '3x') size = 'Triple-strength'
if (size.toLowerCase() === 'normal') size = undefined

const monster = {
name: parsed.name,
level: parsed.system.attributes.level.value,
size: size,
tag: parsed.system.details.type.value,
role: parsed.system.details.role.value || undefined,
vuln: parsed.system.details.vulnerability.value || undefined,
ac: parsed.system.attributes.ac.value,
pd: parsed.system.attributes.pd.value,
md: parsed.system.attributes.md.value,
hp: parsed.system.attributes.hp.value,
initiative: parsed.system.attributes.init.mod,
attacks: [] as any[],
traits: [] as any[],
specials: [] as any[]
}

for (const item of parsed.items) {
if (item.type === 'action') {
let name = item.name as string
let tag = undefined
const m = name.match(/\[(.*)\](.*)/)
if (m) {
tag = m[1].trim()
name = m[2].trim()
}

const roll = stripFoundryMarkup(item.system.attack.value)
// .replace('[[d20', '')
// .replace(']]', '')
// .replace(/\+\s*(\d+)/, '+$1')
// .trim()

const extras = [] as any[]
for (const k of ['hit1', 'hit2', 'hit3', 'hit4', 'hit5']) {
const extraHit = item.system[k]
if (extraHit?.name) {
extras.push({
name: extraHit.name,
description: stripFoundryMarkup(extraHit.value)
})
}
}

monster.attacks.push({
name,
tag,
attack: roll,
hit: stripFoundryMarkup(item.system.hit.value),
extras
})
} else {
const thing = {
name: item.name,
description: stripFoundryMarkup(
item.system.description.value
)
}
const monsterKey = {
trait: 'traits',
nastierSpecial: 'specials'
}[item.type]
monster[monsterKey].push(thing)
}
}

monsters.push(monster)
}

// Write the results to a file
await writeFile('monsters.json', JSON.stringify(monsters, null, 2))
}

doit().then(console.log, console.error)
Loading