chore: clean up
This commit is contained in:
parent
80471e8dd2
commit
1f5ee24a0f
|
|
@ -18,11 +18,3 @@ export { FileTreeNode, HeadingNode } from './FileTree';
|
|||
export type { DiceProps } from './md-dice';
|
||||
export type { TableProps } from './md-table';
|
||||
export type { BgProps } from './md-bg';
|
||||
export type {
|
||||
MdCommanderProps,
|
||||
MdCommanderCommand,
|
||||
MdCommanderOption,
|
||||
MdCommanderOptionType,
|
||||
CommanderEntry,
|
||||
CompletionItem,
|
||||
} from './md-commander';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export { useCommander, defaultCommands, parseInput, getCompletions, getResultClass } from './useCommander';
|
||||
export type { UseCommanderReturn } from './useCommander';
|
||||
export { useDiceRoller } from './useDiceRoller';
|
||||
export { rollFormula, rollSimple } from './useDiceRoller';
|
||||
export * from './dice-engine';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {
|
|||
CommanderEntry,
|
||||
CompletionItem,
|
||||
} from "../types";
|
||||
import { useDiceRoller } from "./useDiceRoller";
|
||||
import { rollSimple } from "./useDiceRoller";
|
||||
|
||||
// ==================== 默认命令 ====================
|
||||
|
||||
|
|
@ -57,7 +57,6 @@ export const defaultCommands: Record<string, MdCommanderCommand> = {
|
|||
],
|
||||
handler: (args) => {
|
||||
const formula = args.params.formula || "1d6";
|
||||
const { rollSimple } = useDiceRoller();
|
||||
const result = rollSimple(formula);
|
||||
return {
|
||||
message: result.text,
|
||||
|
|
|
|||
|
|
@ -19,69 +19,62 @@ export interface DiceRollerResult {
|
|||
* 骰子引擎 Hook
|
||||
* 提供高级骰子功能:骰池、修饰符、组合等
|
||||
*/
|
||||
export function useDiceRoller() {
|
||||
/**
|
||||
* 执行掷骰
|
||||
* @param formula 骰子公式,支持:
|
||||
* - 3d6: 标准骰子
|
||||
* - {d4, d8, 2d6}: 骰池字面量
|
||||
* - kh2/dl1: 修饰符
|
||||
* - +: 组合骰池
|
||||
* - -: 负数组合
|
||||
* - 5: 固定数字
|
||||
*/
|
||||
function roll(formula: string): DiceRollerResult {
|
||||
try {
|
||||
const result = rollDice(formula);
|
||||
/**
|
||||
* 执行掷骰
|
||||
* @param formula 骰子公式,支持:
|
||||
* - 3d6: 标准骰子
|
||||
* - {d4, d8, 2d6}: 骰池字面量
|
||||
* - kh2/dl1: 修饰符
|
||||
* - +: 组合骰池
|
||||
* - -: 负数组合
|
||||
* - 5: 固定数字
|
||||
*/
|
||||
export function rollFormula(formula: string): DiceRollerResult {
|
||||
try {
|
||||
const result = rollDice(formula);
|
||||
|
||||
return {
|
||||
formula,
|
||||
result: {
|
||||
total: result.total,
|
||||
detail: result.detail,
|
||||
pools: result.pools.map((pool) => ({
|
||||
rolls: pool.rolls.map((r) => r.value),
|
||||
keptRolls: pool.keptRolls.map((r) => r.value),
|
||||
subtotal: pool.subtotal,
|
||||
})),
|
||||
},
|
||||
success: true,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
formula,
|
||||
result: {
|
||||
total: 0,
|
||||
detail: "",
|
||||
pools: [],
|
||||
},
|
||||
success: false,
|
||||
error: e instanceof Error ? e.message : String(e),
|
||||
};
|
||||
}
|
||||
return {
|
||||
formula,
|
||||
result: {
|
||||
total: result.total,
|
||||
detail: result.detail,
|
||||
pools: result.pools.map((pool) => ({
|
||||
rolls: pool.rolls.map((r) => r.value),
|
||||
keptRolls: pool.keptRolls.map((r) => r.value),
|
||||
subtotal: pool.subtotal,
|
||||
})),
|
||||
},
|
||||
success: true,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
formula,
|
||||
result: {
|
||||
total: 0,
|
||||
detail: "",
|
||||
pools: [],
|
||||
},
|
||||
success: false,
|
||||
error: e instanceof Error ? e.message : String(e),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化版掷骰,返回 HTML 格式结果
|
||||
* 格式:[1] [2] [3] = <strong>6</strong>
|
||||
*/
|
||||
export function rollSimple(formula: string): { text: string; isHtml?: boolean } {
|
||||
try {
|
||||
const result = rollDice(formula);
|
||||
return {
|
||||
text: result.detail,
|
||||
isHtml: true, // detail 包含 HTML
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
text: `错误:${e instanceof Error ? e.message : String(e)}`,
|
||||
isHtml: false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化版掷骰,返回 HTML 格式结果
|
||||
* 格式:[1] [2] [3] = <strong>6</strong>
|
||||
*/
|
||||
function rollSimple(formula: string): { text: string; isHtml?: boolean } {
|
||||
try {
|
||||
const result = rollDice(formula);
|
||||
return {
|
||||
text: result.detail,
|
||||
isHtml: true, // detail 包含 HTML
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
text: `错误:${e instanceof Error ? e.message : String(e)}`,
|
||||
isHtml: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
roll,
|
||||
rollSimple,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
export { CommanderInput } from './CommanderInput';
|
||||
export type { CommanderInputProps } from './CommanderInput';
|
||||
export { CommanderEntries } from './CommanderEntries';
|
||||
export type { CommanderEntriesProps } from './CommanderEntries';
|
||||
export type {
|
||||
MdCommanderProps,
|
||||
MdCommanderCommand,
|
||||
MdCommanderOption,
|
||||
MdCommanderParameter,
|
||||
MdCommanderOptionType,
|
||||
CommanderEntry,
|
||||
CompletionItem,
|
||||
} from './types';
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { customElement, noShadowDOM } from "solid-element";
|
||||
import { onMount, onCleanup } from "solid-js";
|
||||
import { useCommander } from "./hooks/useCommander";
|
||||
import { useCommander } from "./hooks";
|
||||
import { CommanderInput } from "./CommanderInput";
|
||||
import { CommanderEntries } from "./CommanderEntries";
|
||||
import type { MdCommanderProps } from "./types";
|
||||
|
|
|
|||
Loading…
Reference in New Issue