@lippelt/srd-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ clearRegistry: () => clearRegistry,
24
+ getSystem: () => getSystem,
25
+ listRegisteredSystems: () => listRegisteredSystems,
26
+ register: () => register
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var registry = /* @__PURE__ */ new Map();
30
+ function register(system) {
31
+ const existing = registry.get(system.id);
32
+ if (existing && existing !== system) {
33
+ throw new Error(
34
+ `[gmcr-srd-core] sistema "${system.id}" j\xE1 registrado por outra inst\xE2ncia`
35
+ );
36
+ }
37
+ registry.set(system.id, system);
38
+ }
39
+ function getSystem(id) {
40
+ return registry.get(id) ?? null;
41
+ }
42
+ function listRegisteredSystems() {
43
+ return [...registry.keys()];
44
+ }
45
+ function clearRegistry() {
46
+ registry.clear();
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ clearRegistry,
51
+ getSystem,
52
+ listRegisteredSystems,
53
+ register
54
+ });
55
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @lippelt/srd-core — contrato + registry para sistemas RPG plugáveis.\n *\n * Padrão de uso (lado do consumidor):\n *\n * import { register, getSystem } from '@lippelt/srd-core'\n * import { dnd5e2014 } from '@lippelt/srd-dnd5e-2014'\n *\n * register(dnd5e2014)\n * const sys = getSystem('dnd5e-2014') // System | null\n */\n\nexport type {\n System,\n SystemId,\n SystemRules,\n DicePreset,\n ConditionDef,\n TrackerField,\n RollResult,\n} from './types.js'\n\nimport type { System, SystemId } from './types.js'\n\nconst registry = new Map<SystemId, System>()\n\n/**\n * Registra um sistema. Idempotente: registrar o mesmo `system` (mesma\n * referência) duas vezes é no-op. Registrar uma instância DIFERENTE com\n * id já existente lança erro — proteção contra conflitos.\n */\nexport function register(system: System): void {\n const existing = registry.get(system.id)\n if (existing && existing !== system) {\n throw new Error(\n `[gmcr-srd-core] sistema \"${system.id}\" já registrado por outra instância`,\n )\n }\n registry.set(system.id, system)\n}\n\n/** Resolve um sistema pelo id, ou null se não registrado. */\nexport function getSystem(id: SystemId): System | null {\n return registry.get(id) ?? null\n}\n\n/** Lista os ids de sistemas atualmente registrados. */\nexport function listRegisteredSystems(): SystemId[] {\n return [...registry.keys()]\n}\n\n/** Remove todos os registros. Útil em testes; raro em produção. */\nexport function clearRegistry(): void {\n registry.clear()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,IAAM,WAAW,oBAAI,IAAsB;AAOpC,SAAS,SAAS,QAAsB;AAC7C,QAAM,WAAW,SAAS,IAAI,OAAO,EAAE;AACvC,MAAI,YAAY,aAAa,QAAQ;AACnC,UAAM,IAAI;AAAA,MACR,4BAA4B,OAAO,EAAE;AAAA,IACvC;AAAA,EACF;AACA,WAAS,IAAI,OAAO,IAAI,MAAM;AAChC;AAGO,SAAS,UAAU,IAA6B;AACrD,SAAO,SAAS,IAAI,EAAE,KAAK;AAC7B;AAGO,SAAS,wBAAoC;AAClD,SAAO,CAAC,GAAG,SAAS,KAAK,CAAC;AAC5B;AAGO,SAAS,gBAAsB;AACpC,WAAS,MAAM;AACjB;","names":[]}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Contrato comum para sistemas RPG plugáveis.
3
+ *
4
+ * Cada implementação (pacote separado) exporta um `System` e o consumidor
5
+ * registra com `register()` deste pacote. O consumidor escolhe quais
6
+ * sistemas instalar — `@lippelt/srd-core` por si só não traz nenhum.
7
+ */
8
+ /**
9
+ * ID estável de um sistema. Convenção: `<sistema>-<edição>` em kebab-case
10
+ * (ex: `dnd5e-2014`, `lancer`, `vampire-v5`). Cada implementação define
11
+ * o seu; conflitos entre pacotes registrados são erro.
12
+ */
13
+ type SystemId = string;
14
+ /**
15
+ * Preset de rolagem rápida — botões que aparecem no painel de dados,
16
+ * adaptados ao sistema.
17
+ */
18
+ interface DicePreset {
19
+ /** Identificador único dentro do sistema. */
20
+ id: string;
21
+ /** Texto exibido no botão (curto: "d20+mod", "Pool", "Hunger"). */
22
+ label: string;
23
+ /** Notação a rolar (formato GM Control Room: NdM+K, ou string especial). */
24
+ notation: string;
25
+ /** Categoria — ajuda a agrupar visualmente (ex: 'attack', 'save', 'damage'). */
26
+ category?: string;
27
+ /** Descrição expandida pra tooltip. */
28
+ description?: string;
29
+ }
30
+ interface ConditionDef {
31
+ /** ID estável (snake-case, ex: 'frightened'). */
32
+ id: string;
33
+ /** Nome de exibição (ex: 'Frightened', 'Amedrontado'). */
34
+ label: string;
35
+ /** Resumo do efeito mecânico (uma linha). */
36
+ summary?: string;
37
+ }
38
+ /**
39
+ * Definição de um campo numérico extra no tracker do sistema
40
+ * (além dos genéricos initiative/hp).
41
+ */
42
+ interface TrackerField {
43
+ /** Chave estável usada na ficha (ex: 'ac', 'hunger'). */
44
+ key: string;
45
+ /** Rótulo curto (4–8 chars) — vai num pill compacto no tracker. */
46
+ label: string;
47
+ /** Tipo do valor — define UI (stepper, pair max/current, toggle). */
48
+ kind: 'integer' | 'maxCurrent' | 'boolean';
49
+ /** Faixa válida (inclusiva). */
50
+ min?: number;
51
+ max?: number;
52
+ /** Valor inicial pra novos combatentes. */
53
+ default?: number;
54
+ /** Descrição/tooltip. */
55
+ description?: string;
56
+ }
57
+ interface RollResult {
58
+ /** Rolagens individuais (todos os dados antes de filtragem). */
59
+ rolls: number[];
60
+ /** Modificador somado ao total. */
61
+ modifier: number;
62
+ /** Total final. */
63
+ total: number;
64
+ /** Notação humana do que foi rolado. */
65
+ notation: string;
66
+ /** Anotações estruturadas (ex: 'crit', 'fumble', 'advantage'). */
67
+ notes?: string[];
68
+ }
69
+ interface SystemRules {
70
+ /**
71
+ * Rola uma checagem do sistema. `kind` é definido por cada sistema
72
+ * (ex: 'attack', 'save', 'check', 'damage'). Retorna null se a mecânica
73
+ * não existe no sistema.
74
+ */
75
+ roll?: (kind: string, params: Record<string, unknown>) => RollResult | null;
76
+ /**
77
+ * Reduz dano conforme regras do sistema (resistência, vulnerabilidade,
78
+ * imunidade, armadura, etc).
79
+ */
80
+ applyDamage?: (incoming: number, target: Record<string, unknown>) => {
81
+ final: number;
82
+ notes?: string[];
83
+ };
84
+ }
85
+ interface System {
86
+ id: SystemId;
87
+ /** Nome humano (ex: "Dungeons & Dragons 5e (2014)"). */
88
+ name: string;
89
+ /** Versão da regra/SRD (ex: "SRD 5.1"). */
90
+ ruleVersion: string;
91
+ /** Atribuição obrigatória (se vier de SRD CC-BY etc). Vazio = MIT puro. */
92
+ attribution?: string;
93
+ /** Botões rápidos de rolagem que aparecem na UI. */
94
+ dicePresets: DicePreset[];
95
+ /** Condições/status pra autocomplete no tracker. */
96
+ conditions: ConditionDef[];
97
+ /** Campos extras do tracker (além de initiative/hp genéricos). */
98
+ trackerFields: TrackerField[];
99
+ /** Regras automatizáveis (opcionais). */
100
+ rules?: SystemRules;
101
+ }
102
+
103
+ /**
104
+ * @lippelt/srd-core — contrato + registry para sistemas RPG plugáveis.
105
+ *
106
+ * Padrão de uso (lado do consumidor):
107
+ *
108
+ * import { register, getSystem } from '@lippelt/srd-core'
109
+ * import { dnd5e2014 } from '@lippelt/srd-dnd5e-2014'
110
+ *
111
+ * register(dnd5e2014)
112
+ * const sys = getSystem('dnd5e-2014') // System | null
113
+ */
114
+
115
+ /**
116
+ * Registra um sistema. Idempotente: registrar o mesmo `system` (mesma
117
+ * referência) duas vezes é no-op. Registrar uma instância DIFERENTE com
118
+ * id já existente lança erro — proteção contra conflitos.
119
+ */
120
+ declare function register(system: System): void;
121
+ /** Resolve um sistema pelo id, ou null se não registrado. */
122
+ declare function getSystem(id: SystemId): System | null;
123
+ /** Lista os ids de sistemas atualmente registrados. */
124
+ declare function listRegisteredSystems(): SystemId[];
125
+ /** Remove todos os registros. Útil em testes; raro em produção. */
126
+ declare function clearRegistry(): void;
127
+
128
+ export { type ConditionDef, type DicePreset, type RollResult, type System, type SystemId, type SystemRules, type TrackerField, clearRegistry, getSystem, listRegisteredSystems, register };
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Contrato comum para sistemas RPG plugáveis.
3
+ *
4
+ * Cada implementação (pacote separado) exporta um `System` e o consumidor
5
+ * registra com `register()` deste pacote. O consumidor escolhe quais
6
+ * sistemas instalar — `@lippelt/srd-core` por si só não traz nenhum.
7
+ */
8
+ /**
9
+ * ID estável de um sistema. Convenção: `<sistema>-<edição>` em kebab-case
10
+ * (ex: `dnd5e-2014`, `lancer`, `vampire-v5`). Cada implementação define
11
+ * o seu; conflitos entre pacotes registrados são erro.
12
+ */
13
+ type SystemId = string;
14
+ /**
15
+ * Preset de rolagem rápida — botões que aparecem no painel de dados,
16
+ * adaptados ao sistema.
17
+ */
18
+ interface DicePreset {
19
+ /** Identificador único dentro do sistema. */
20
+ id: string;
21
+ /** Texto exibido no botão (curto: "d20+mod", "Pool", "Hunger"). */
22
+ label: string;
23
+ /** Notação a rolar (formato GM Control Room: NdM+K, ou string especial). */
24
+ notation: string;
25
+ /** Categoria — ajuda a agrupar visualmente (ex: 'attack', 'save', 'damage'). */
26
+ category?: string;
27
+ /** Descrição expandida pra tooltip. */
28
+ description?: string;
29
+ }
30
+ interface ConditionDef {
31
+ /** ID estável (snake-case, ex: 'frightened'). */
32
+ id: string;
33
+ /** Nome de exibição (ex: 'Frightened', 'Amedrontado'). */
34
+ label: string;
35
+ /** Resumo do efeito mecânico (uma linha). */
36
+ summary?: string;
37
+ }
38
+ /**
39
+ * Definição de um campo numérico extra no tracker do sistema
40
+ * (além dos genéricos initiative/hp).
41
+ */
42
+ interface TrackerField {
43
+ /** Chave estável usada na ficha (ex: 'ac', 'hunger'). */
44
+ key: string;
45
+ /** Rótulo curto (4–8 chars) — vai num pill compacto no tracker. */
46
+ label: string;
47
+ /** Tipo do valor — define UI (stepper, pair max/current, toggle). */
48
+ kind: 'integer' | 'maxCurrent' | 'boolean';
49
+ /** Faixa válida (inclusiva). */
50
+ min?: number;
51
+ max?: number;
52
+ /** Valor inicial pra novos combatentes. */
53
+ default?: number;
54
+ /** Descrição/tooltip. */
55
+ description?: string;
56
+ }
57
+ interface RollResult {
58
+ /** Rolagens individuais (todos os dados antes de filtragem). */
59
+ rolls: number[];
60
+ /** Modificador somado ao total. */
61
+ modifier: number;
62
+ /** Total final. */
63
+ total: number;
64
+ /** Notação humana do que foi rolado. */
65
+ notation: string;
66
+ /** Anotações estruturadas (ex: 'crit', 'fumble', 'advantage'). */
67
+ notes?: string[];
68
+ }
69
+ interface SystemRules {
70
+ /**
71
+ * Rola uma checagem do sistema. `kind` é definido por cada sistema
72
+ * (ex: 'attack', 'save', 'check', 'damage'). Retorna null se a mecânica
73
+ * não existe no sistema.
74
+ */
75
+ roll?: (kind: string, params: Record<string, unknown>) => RollResult | null;
76
+ /**
77
+ * Reduz dano conforme regras do sistema (resistência, vulnerabilidade,
78
+ * imunidade, armadura, etc).
79
+ */
80
+ applyDamage?: (incoming: number, target: Record<string, unknown>) => {
81
+ final: number;
82
+ notes?: string[];
83
+ };
84
+ }
85
+ interface System {
86
+ id: SystemId;
87
+ /** Nome humano (ex: "Dungeons & Dragons 5e (2014)"). */
88
+ name: string;
89
+ /** Versão da regra/SRD (ex: "SRD 5.1"). */
90
+ ruleVersion: string;
91
+ /** Atribuição obrigatória (se vier de SRD CC-BY etc). Vazio = MIT puro. */
92
+ attribution?: string;
93
+ /** Botões rápidos de rolagem que aparecem na UI. */
94
+ dicePresets: DicePreset[];
95
+ /** Condições/status pra autocomplete no tracker. */
96
+ conditions: ConditionDef[];
97
+ /** Campos extras do tracker (além de initiative/hp genéricos). */
98
+ trackerFields: TrackerField[];
99
+ /** Regras automatizáveis (opcionais). */
100
+ rules?: SystemRules;
101
+ }
102
+
103
+ /**
104
+ * @lippelt/srd-core — contrato + registry para sistemas RPG plugáveis.
105
+ *
106
+ * Padrão de uso (lado do consumidor):
107
+ *
108
+ * import { register, getSystem } from '@lippelt/srd-core'
109
+ * import { dnd5e2014 } from '@lippelt/srd-dnd5e-2014'
110
+ *
111
+ * register(dnd5e2014)
112
+ * const sys = getSystem('dnd5e-2014') // System | null
113
+ */
114
+
115
+ /**
116
+ * Registra um sistema. Idempotente: registrar o mesmo `system` (mesma
117
+ * referência) duas vezes é no-op. Registrar uma instância DIFERENTE com
118
+ * id já existente lança erro — proteção contra conflitos.
119
+ */
120
+ declare function register(system: System): void;
121
+ /** Resolve um sistema pelo id, ou null se não registrado. */
122
+ declare function getSystem(id: SystemId): System | null;
123
+ /** Lista os ids de sistemas atualmente registrados. */
124
+ declare function listRegisteredSystems(): SystemId[];
125
+ /** Remove todos os registros. Útil em testes; raro em produção. */
126
+ declare function clearRegistry(): void;
127
+
128
+ export { type ConditionDef, type DicePreset, type RollResult, type System, type SystemId, type SystemRules, type TrackerField, clearRegistry, getSystem, listRegisteredSystems, register };
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ // src/index.ts
2
+ var registry = /* @__PURE__ */ new Map();
3
+ function register(system) {
4
+ const existing = registry.get(system.id);
5
+ if (existing && existing !== system) {
6
+ throw new Error(
7
+ `[gmcr-srd-core] sistema "${system.id}" j\xE1 registrado por outra inst\xE2ncia`
8
+ );
9
+ }
10
+ registry.set(system.id, system);
11
+ }
12
+ function getSystem(id) {
13
+ return registry.get(id) ?? null;
14
+ }
15
+ function listRegisteredSystems() {
16
+ return [...registry.keys()];
17
+ }
18
+ function clearRegistry() {
19
+ registry.clear();
20
+ }
21
+ export {
22
+ clearRegistry,
23
+ getSystem,
24
+ listRegisteredSystems,
25
+ register
26
+ };
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @lippelt/srd-core — contrato + registry para sistemas RPG plugáveis.\n *\n * Padrão de uso (lado do consumidor):\n *\n * import { register, getSystem } from '@lippelt/srd-core'\n * import { dnd5e2014 } from '@lippelt/srd-dnd5e-2014'\n *\n * register(dnd5e2014)\n * const sys = getSystem('dnd5e-2014') // System | null\n */\n\nexport type {\n System,\n SystemId,\n SystemRules,\n DicePreset,\n ConditionDef,\n TrackerField,\n RollResult,\n} from './types.js'\n\nimport type { System, SystemId } from './types.js'\n\nconst registry = new Map<SystemId, System>()\n\n/**\n * Registra um sistema. Idempotente: registrar o mesmo `system` (mesma\n * referência) duas vezes é no-op. Registrar uma instância DIFERENTE com\n * id já existente lança erro — proteção contra conflitos.\n */\nexport function register(system: System): void {\n const existing = registry.get(system.id)\n if (existing && existing !== system) {\n throw new Error(\n `[gmcr-srd-core] sistema \"${system.id}\" já registrado por outra instância`,\n )\n }\n registry.set(system.id, system)\n}\n\n/** Resolve um sistema pelo id, ou null se não registrado. */\nexport function getSystem(id: SystemId): System | null {\n return registry.get(id) ?? null\n}\n\n/** Lista os ids de sistemas atualmente registrados. */\nexport function listRegisteredSystems(): SystemId[] {\n return [...registry.keys()]\n}\n\n/** Remove todos os registros. Útil em testes; raro em produção. */\nexport function clearRegistry(): void {\n registry.clear()\n}\n"],"mappings":";AAwBA,IAAM,WAAW,oBAAI,IAAsB;AAOpC,SAAS,SAAS,QAAsB;AAC7C,QAAM,WAAW,SAAS,IAAI,OAAO,EAAE;AACvC,MAAI,YAAY,aAAa,QAAQ;AACnC,UAAM,IAAI;AAAA,MACR,4BAA4B,OAAO,EAAE;AAAA,IACvC;AAAA,EACF;AACA,WAAS,IAAI,OAAO,IAAI,MAAM;AAChC;AAGO,SAAS,UAAU,IAA6B;AACrD,SAAO,SAAS,IAAI,EAAE,KAAK;AAC7B;AAGO,SAAS,wBAAoC;AAClD,SAAO,CAAC,GAAG,SAAS,KAAK,CAAC;AAC5B;AAGO,SAAS,gBAAsB;AACpC,WAAS,MAAM;AACjB;","names":[]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@lippelt/srd-core",
3
+ "version": "0.1.0",
4
+ "description": "Plugin core for tabletop RPG system modules (types + registry). Each system ships in its own package.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "dev": "tsup --watch",
27
+ "typecheck": "tsc --noEmit",
28
+ "lint": "eslint .",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest"
31
+ },
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/flippelt/gmcr-srd-systems.git",
36
+ "directory": "packages/core"
37
+ }
38
+ }