diff --git a/books/core-rules-document/core-rules-document.adoc b/books/core-rules-document/core-rules-document.adoc index f9545eb..e85b979 100644 --- a/books/core-rules-document/core-rules-document.adoc +++ b/books/core-rules-document/core-rules-document.adoc @@ -34,7 +34,21 @@ The game is decided through rounds of engagement, in which players take turns in This page contains various rules that are referred to elsewhere in this rulebook, and gives an overview of some key concepts that form the basis of the rules in general. [stat-sheet] -Yooooo I'm uppercase? +-- +name = "Cool Unit Name Here" + +[[abilities]] +name = "Favored Terrain" +description = "Do not take speed penalties when moving through Urbain terrain." + +[[abilities]] +name = "Calm" +description = "This unit reduces their suppression condition by 1 at the end of their initiative." + +[[abilities]] +name = "Sharpshooter" +description = "Automatically become Aiming 2 when taking the Aim action." +-- === Scenario diff --git a/packages/stat-sheet-block/.swrc b/packages/stat-sheet-block/.swrc deleted file mode 100644 index d19fb0c..0000000 --- a/packages/stat-sheet-block/.swrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/swcrc", - "jsc": { - "target": "es2019" - } -} diff --git a/packages/stat-sheet-block/jest.config.js b/packages/stat-sheet-block/jest.config.js index c5d7811..52dcdf7 100644 --- a/packages/stat-sheet-block/jest.config.js +++ b/packages/stat-sheet-block/jest.config.js @@ -1,5 +1,10 @@ -module.exports = { +/** @type {import('@jest/types').Config.InitialOptions} */ +const config = { + testEnvironment: "jsdom", + extensionsToTreatAsEsm: [".ts", ".tsx"], transform: { - "^.+\\.(c)?(t|j)sx?$": "@swc/jest", + "^.+\\.tsx?$": "@swc/jest", }, }; + +module.exports = config; diff --git a/packages/stat-sheet-block/jsconfig.json b/packages/stat-sheet-block/jsconfig.json deleted file mode 100644 index 45c8120..0000000 --- a/packages/stat-sheet-block/jsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "typeAcquisition": { - "include": ["jest"] - } -} diff --git a/packages/stat-sheet-block/main.js b/packages/stat-sheet-block/main.js deleted file mode 100644 index 0950d14..0000000 --- a/packages/stat-sheet-block/main.js +++ /dev/null @@ -1,3 +0,0 @@ -const StatSheetBlock = require("./src/stat-sheet-block"); - -module.exports = StatSheetBlock; diff --git a/packages/stat-sheet-block/main.ts b/packages/stat-sheet-block/main.ts new file mode 100644 index 0000000..dc2d6dd --- /dev/null +++ b/packages/stat-sheet-block/main.ts @@ -0,0 +1,3 @@ +import StatSheetBlock from "./src/stat-sheet-block" + +export = StatSheetBlock \ No newline at end of file diff --git a/packages/stat-sheet-block/package.json b/packages/stat-sheet-block/package.json index eb78080..6ee0a00 100644 --- a/packages/stat-sheet-block/package.json +++ b/packages/stat-sheet-block/package.json @@ -2,19 +2,26 @@ "name": "@conflict/stat-sheet-block", "main": "dist/main.js", "scripts": { - "build": "spack", + "build": "rollup -c", "test": "jest" }, "dependencies": { "@asciidoctor/core": "^2.2.6", - "@ltd/j-toml": "^1.30.0" + "@ltd/j-toml": "^1.30.0", + "htm": "^3.1.1", + "vhtml": "^2.2.0" }, "devDependencies": { "@jest/globals": "^28.1.1", + "@rollup/plugin-node-resolve": "^13.3.0", "@swc/cli": "^0.1.57", "@swc/core": "^1.2.204", "@swc/jest": "^0.2.21", "@types/jest": "^28.1.3", - "jest": "^28.1.1" + "jest": "^28.1.1", + "jest-environment-jsdom": "^28.1.1", + "rollup": "^2.75.7", + "rollup-plugin-swc": "^0.2.1", + "typescript": "^4.7.4" } } diff --git a/packages/stat-sheet-block/rollup.config.js b/packages/stat-sheet-block/rollup.config.js new file mode 100644 index 0000000..0fc63dd --- /dev/null +++ b/packages/stat-sheet-block/rollup.config.js @@ -0,0 +1,22 @@ +// rollup.config.js + +import nodeResolve from "@rollup/plugin-node-resolve"; +import swc from "rollup-plugin-swc"; + +export default { + input: "main.ts", + output: { + dir: "dist", + }, + plugins: [ + nodeResolve({ extensions: [".ts", ".tsx"] }), + swc({ + jsc: { + parser: { + syntax: "typescript", + }, + target: "es2020", + }, + }), + ], +}; diff --git a/packages/stat-sheet-block/spack.config.js b/packages/stat-sheet-block/spack.config.js deleted file mode 100644 index 078adea..0000000 --- a/packages/stat-sheet-block/spack.config.js +++ /dev/null @@ -1,17 +0,0 @@ -const path = require("path"); -const { config } = require("@swc/core/spack"); - -module.exports = config({ - target: "browser", - entry: { - main: path.resolve(__dirname, "main.js"), - }, - output: { - path: path.resolve(__dirname, "dist"), - }, - options: { - jsc: { - target: "es2019", - }, - }, -}); diff --git a/packages/stat-sheet-block/src/stat-sheet-block.js b/packages/stat-sheet-block/src/stat-sheet-block.js deleted file mode 100644 index c70d962..0000000 --- a/packages/stat-sheet-block/src/stat-sheet-block.js +++ /dev/null @@ -1,18 +0,0 @@ -function StatSheetBlock() { - this.named("stat-sheet"); - this.onContext("paragraph"); - this.process((parent, reader) => { - const lines = reader.getLines().map((line) => line.toUpperCase()); - return this.createBlock(parent, "paragraph", lines); - }); -} - -module.exports.register = function register(registry) { - if (registry.register) { - registry.register(function () { - this.block(StatSheetBlock); - }); - } else { - registry.block(StatSheetBlock); - } -}; diff --git a/packages/stat-sheet-block/src/stat-sheet-block.test.js b/packages/stat-sheet-block/src/stat-sheet-block.test.js deleted file mode 100644 index 5d2c802..0000000 --- a/packages/stat-sheet-block/src/stat-sheet-block.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import Asciidoctor from "@asciidoctor/core"; -import StatSheetBlock from "./stat-sheet-block"; - -const asciidoctor = Asciidoctor(); -const registry = asciidoctor.Extensions.create(); -StatSheetBlock.register(registry); - -const asciidoc = ` -[stat-sheet] -bob marley -`; - -test("it works", () => { - expect( - asciidoctor.convert(asciidoc, { extension_registry: registry }) - ).toEqual(expect.stringContaining("BOB MARLEY")); -}); diff --git a/packages/stat-sheet-block/src/stat-sheet-block.test.ts b/packages/stat-sheet-block/src/stat-sheet-block.test.ts new file mode 100644 index 0000000..ef15fba --- /dev/null +++ b/packages/stat-sheet-block/src/stat-sheet-block.test.ts @@ -0,0 +1,53 @@ +/** + * @jest-environment jsdom + */ + +import Asciidoctor from "@asciidoctor/core"; +import StatSheetBlock from "./stat-sheet-block"; + +const asciidoctor = Asciidoctor(); +const registry = asciidoctor.Extensions.create(); +StatSheetBlock.register(registry); + +const asciidoc = ` +[stat-sheet] +-- +name = "Test Unit" +ac = 1 +damage_threshold = 1 +rating = 4 +melee = 2 +ranged = 2 +attributes.strength = 2 +attributes.dexterity = 1 +attributes.intelligence = 0 +attributes.wisdom = 0 +traits = ["Trooper", "Marksman"] + +[[actions]] +duration = 3 +name = "My Name is Sean" +description = "Bah Gawd you instantly win the game." + +[[abilities]] +name = "Favored Terrain" +description = "Do not take speed penalties when moving through Urbain terrain." + +[[abilities]] +name = "Calm" +description = "This unit reduces their suppression condition by 1 at the end of their initiative." + +[[abilities]] +name = "Sharpshooter" +description = "Automatically become Aiming 2 when taking the Aim action." +-- +`; + +test("it works", () => { + const el = document.createElement("div"); + el.innerHTML = asciidoctor.convert(asciidoc, { + extension_registry: registry, + }) as string; + + expect(el.querySelector(".stat-sheet .name")).toBeDefined(); +}); diff --git a/packages/stat-sheet-block/src/stat-sheet-block.tsx b/packages/stat-sheet-block/src/stat-sheet-block.tsx new file mode 100644 index 0000000..65680ec --- /dev/null +++ b/packages/stat-sheet-block/src/stat-sheet-block.tsx @@ -0,0 +1,37 @@ +import Toml from "@ltd/j-toml"; + +/** @jsx h */ +const h = require('vhtml') + +function Template(props: any) { + return

{props.data.name}

; +} + +function statSheetTemplate(lines) { + const data = Toml.parse(lines.join("\n"), { bigint: false }); + return