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