adding-mod-parsers
ゲームのMOD設定文字列を、プログラムで扱いやすい形式のModオブジェクトに変換する新しい解析機能を追加する際に、テンプレートを使った解析パターンを案内するSkill。
📜 元の英語説明(参考)
Use when adding new mod parsers to convert game mod strings to typed Mod objects - guides the template-based parsing pattern (project)
🇯🇵 日本人クリエイター向け解説
ゲームのMOD設定文字列を、プログラムで扱いやすい形式のModオブジェクトに変換する新しい解析機能を追加する際に、テンプレートを使った解析パターンを案内するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o adding-mod-parsers.zip https://jpskill.com/download/9219.zip && unzip -o adding-mod-parsers.zip && rm adding-mod-parsers.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9219.zip -OutFile "$d\adding-mod-parsers.zip"; Expand-Archive "$d\adding-mod-parsers.zip" -DestinationPath $d -Force; ri "$d\adding-mod-parsers.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
adding-mod-parsers.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
adding-mod-parsersフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Modパーサーの追加
概要
modパーサーは、生のmod文字列(例:"+10% all stats")を、計算エンジンで使用される型付きのModオブジェクトに変換します。これは、パターンマッチングのためにテンプレートベースのシステムを使用します。
いつ使用するか
- 新しいmod文字列パターンのサポートを追加する場合
- 既存のmodタイプを拡張して新しいバリアントを処理する場合
- 新しいmodタイプをエンジンに追加する場合
プロジェクトファイルの場所
| 目的 | ファイルパス |
|---|---|
| Modタイプの定義 | src/tli/mod.ts |
| パーサーテンプレート | src/tli/mod-parser/templates.ts |
| Enumの登録 | src/tli/mod-parser/enums.ts |
| 計算ハンドラー | src/tli/calcs/offense.ts |
| テスト | src/tli/mod-parser.test.ts |
実装チェックリスト
1. Modタイプが存在するか確認する
src/tli/mod.tsのModDefinitionsを確認してください。modタイプが存在しない場合は、追加します。
interface ModDefinitions {
// ... 既存のタイプ ...
NewModType: { value: number; someField: string };
}
2. templates.tsにテンプレートを追加する
テンプレートは、パターンマッチングのためにDSLを使用します。templates.tsにコメントを追加しないでください - テンプレート文字列自体が自己文書化されています。
t("{value:dec%} all stats").output("StatPct", (c) => ({
value: c.value,
statModType: "all" as const,
})),
t("{value:dec%} {statModType:StatWord}")
.enum("StatWord", StatWordMapping)
.output("StatPct", (c) => ({ value: c.value, statModType: c.statModType })),
t("{value:dec%} [additional] [{modType:DmgModType}] damage").output("DmgPct", (c) => ({
value: c.value,
dmgModType: c.modType ?? "global",
addn: c.additional !== undefined,
})),
t("{value:dec%} attack and cast speed").outputMany([
spec("AspdPct", (c) => ({ value: c.value, addn: false })),
spec("CspdPct", (c) => ({ value: c.value, addn: false })),
]),
テンプレートキャプチャタイプ:
| タイプ | マッチするもの | 入力例 → 出力 |
|---|---|---|
{name:int} |
符号なし整数 | "5" → 5 |
{name:dec} |
符号なし10進数 | "21.5" → 21.5 |
{name:int%} |
符号なし整数パーセント | "30%" → 30 |
{name:dec%} |
符号なし10進数パーセント | "96%" → 96 |
{name:+int} |
符号付き整数(+または-が必要) |
"+5" → 5, "-3" → -3 |
{name:+dec} |
符号付き10進数(+または-が必要) |
"+21.5" → 21.5 |
{name:+int%} |
符号付き整数パーセント | "+30%" → 30, "-15%" → -15 |
{name:+dec%} |
符号付き10進数パーセント | "+96%" → 96 |
{name:EnumType} |
Enumルックアップ | {dmgType:DmgChunkType} |
符号付き vs 符号なしタイプ:
- 入力が
+または-で始まらない場合は、符号なし(dec%、int)を使用します(例:"8% additional damage applied to Life") - 入力が
+または-で始まる場合は、符号付き(+dec%、+int)を使用します(例:"+25% additional damage") - 符号付きタイプは符号なし入力と一致せず、その逆も同様です
オプションの構文:
[additional]- オプションのリテラル、c.additional?: trueを設定します[{modType:DmgModType}]- オプションのキャプチャ、c.modType?: DmgModTypeを設定します{(effect|damage)}- 選択肢(正規表現スタイル)
3. Enumマッピングを追加する(必要な場合)
カスタムの単語 → 値のマッピングが必要な場合は、enums.tsに追加します。
export const StatWordMapping: Record<string, string> = {
strength: "str",
dexterity: "dex",
intelligence: "int",
};
registerEnum("StatWord", ["strength", "dexterity", "intelligence"]);
4. offense.tsにハンドラーを追加する(新しいmodタイプの場合)
新しいmodタイプを追加した場合は、calculateOffense()または関連するヘルパーに関数を追加します。
case "NewModType": {
break;
}
新しいバリアントを持つ既存のmodタイプ(statModType: "all"の追加など)の場合は、既存のハンドラーを更新して、新しいバリアントもフィルタリングするようにします。
const flat = sumByValue(
statMods.filter((m) => m.statModType === statType || m.statModType === "all"),
);
5. テストを追加する
src/tli/mod_parser.test.tsにテストケースを追加します。
test("parse percentage all stats", () => {
const result = parseMod("+10% all stats");
expect(result).toEqual([
{
type: "StatPct",
statModType: "all",
value: 10,
},
]);
});
6. 検証する
pnpm test src/tli/mod_parser.test.ts
pnpm typecheck
pnpm check
テンプレートの順序
重要: より具体的なパターンは、allParsers配列内の一般的なパターンの前に記述する必要があります。
// 良い例:具体的なものが一般的なものの前にある
t("{value:dec%} all stats").output(...), // 具体的なもの
t("{value:dec%} {statModType:StatWord}").output(...), // 一般的なもの
// 悪い例:一般的なものが最初に一致し、「all stats」で失敗する
例
単純な値パーサー(符号付き)
入力: "+10% all stats"(+で始まる)
t("{value:+dec%} all stats").output("StatPct", (c) => ({
value: c.value,
statModType: "all" as const,
})),
単純な値パーサー(符号なし)
入力: "8% additional damage applied to Life"(符号なし)
t("{value:dec%} additional damage applied to life").output("DmgPct", (c) => ({
value: c.value,
dmgModType: "global" as const,
addn: true,
})),
条件付きパーサー(符号付き)
入力: "+40% damage if you have Blocked recently"
t("{value:+dec%} damage if you have blocked recently").output("DmgPct", (c) => ({
value: c.value,
dmgModType: "global" as const,
addn: false,
cond: "has_blocked_recently" as const,
})),
スタック可能なパー・スタック(「deals」の位置に符号付き)
入力: "Deals +1% additional damage to an enemy for every 2 points of Frostbite Rating the enemy has"
注: +は「deals」の後に表示されるため、{value:+dec%}を使用します。
t("deals {value:+dec%} additional damage to an enemy for every {amt:int} points of frostbite rating the enemy has")
.output("DmgPct", (c) => ({
value: c.value,
dmgModType: "global" as const,
addn: true,
per: { stackable: "frostbite_rating" as const, amt: c.amt },
})),
複数出力パーサー(符号付き)
入力: "+6% attack and cast speed"
t( 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Adding Mod Parsers
Overview
The mod parser converts raw mod strings (e.g., "+10% all stats") into typed Mod objects used by the calculation engine. It uses a template-based system for pattern matching.
When to Use
- Adding support for new mod string patterns
- Extending existing mod types to handle new variants
- Adding new mod types to the engine
Project File Locations
| Purpose | File Path |
|---|---|
| Mod type definitions | src/tli/mod.ts |
| Parser templates | src/tli/mod-parser/templates.ts |
| Enum registrations | src/tli/mod-parser/enums.ts |
| Calculation handlers | src/tli/calcs/offense.ts |
| Tests | src/tli/mod-parser.test.ts |
Implementation Checklist
1. Check if Mod Type Exists
Look in src/tli/mod.ts under ModDefinitions. If the mod type doesn't exist, add it:
interface ModDefinitions {
// ... existing types ...
NewModType: { value: number; someField: string };
}
2. Add Template in templates.ts
Templates use a DSL for pattern matching. Do not add comments to templates.ts - the template string itself is self-documenting.
t("{value:dec%} all stats").output("StatPct", (c) => ({
value: c.value,
statModType: "all" as const,
})),
t("{value:dec%} {statModType:StatWord}")
.enum("StatWord", StatWordMapping)
.output("StatPct", (c) => ({ value: c.value, statModType: c.statModType })),
t("{value:dec%} [additional] [{modType:DmgModType}] damage").output("DmgPct", (c) => ({
value: c.value,
dmgModType: c.modType ?? "global",
addn: c.additional !== undefined,
})),
t("{value:dec%} attack and cast speed").outputMany([
spec("AspdPct", (c) => ({ value: c.value, addn: false })),
spec("CspdPct", (c) => ({ value: c.value, addn: false })),
]),
Template capture types:
| Type | Matches | Example Input → Output |
|---|---|---|
{name:int} |
Unsigned integer | "5" → 5 |
{name:dec} |
Unsigned decimal | "21.5" → 21.5 |
{name:int%} |
Unsigned integer percent | "30%" → 30 |
{name:dec%} |
Unsigned decimal percent | "96%" → 96 |
{name:+int} |
Signed integer (requires + or -) |
"+5" → 5, "-3" → -3 |
{name:+dec} |
Signed decimal (requires + or -) |
"+21.5" → 21.5 |
{name:+int%} |
Signed integer percent | "+30%" → 30, "-15%" → -15 |
{name:+dec%} |
Signed decimal percent | "+96%" → 96 |
{name:EnumType} |
Enum lookup | {dmgType:DmgChunkType} |
Signed vs Unsigned Types:
- Use unsigned (
dec%,int) when input does NOT start with+or-(e.g.,"8% additional damage applied to Life") - Use signed (
+dec%,+int) when input STARTS with+or-(e.g.,"+25% additional damage") - Signed types will NOT match unsigned inputs, and vice versa
Optional syntax:
[additional]- Optional literal, setsc.additional?: true[{modType:DmgModType}]- Optional capture, setsc.modType?: DmgModType{(effect|damage)}- Alternation (regex-style)
3. Add Enum Mapping (if needed)
If you need custom word → value mapping, add to enums.ts:
export const StatWordMapping: Record<string, string> = {
strength: "str",
dexterity: "dex",
intelligence: "int",
};
registerEnum("StatWord", ["strength", "dexterity", "intelligence"]);
4. Add Handler in offense.ts (if new mod type)
If you added a new mod type, add handling in calculateOffense() or relevant helper:
case "NewModType": {
break;
}
For existing mod types with new variants (like adding statModType: "all"), update existing handlers to also filter for the new variant:
const flat = sumByValue(
statMods.filter((m) => m.statModType === statType || m.statModType === "all"),
);
5. Add Tests
Add test cases in src/tli/mod_parser.test.ts:
test("parse percentage all stats", () => {
const result = parseMod("+10% all stats");
expect(result).toEqual([
{
type: "StatPct",
statModType: "all",
value: 10,
},
]);
});
6. Verify
pnpm test src/tli/mod_parser.test.ts
pnpm typecheck
pnpm check
Template Ordering
IMPORTANT: More specific patterns must come before generic ones in allParsers array.
// Good: specific before generic
t("{value:dec%} all stats").output(...), // Specific
t("{value:dec%} {statModType:StatWord}").output(...), // Generic
// Bad: generic would match first and fail on "all stats"
Examples
Simple Value Parser (Signed)
Input: "+10% all stats" (starts with +)
t("{value:+dec%} all stats").output("StatPct", (c) => ({
value: c.value,
statModType: "all" as const,
})),
Simple Value Parser (Unsigned)
Input: "8% additional damage applied to Life" (no sign)
t("{value:dec%} additional damage applied to life").output("DmgPct", (c) => ({
value: c.value,
dmgModType: "global" as const,
addn: true,
})),
Parser with Condition (Signed)
Input: "+40% damage if you have Blocked recently"
t("{value:+dec%} damage if you have blocked recently").output("DmgPct", (c) => ({
value: c.value,
dmgModType: "global" as const,
addn: false,
cond: "has_blocked_recently" as const,
})),
Parser with Per-Stackable (Signed in "deals" position)
Input: "Deals +1% additional damage to an enemy for every 2 points of Frostbite Rating the enemy has"
Note: The + appears AFTER "deals", so use {value:+dec%}:
t("deals {value:+dec%} additional damage to an enemy for every {amt:int} points of frostbite rating the enemy has")
.output("DmgPct", (c) => ({
value: c.value,
dmgModType: "global" as const,
addn: true,
per: { stackable: "frostbite_rating" as const, amt: c.amt },
})),
Multi-Output Parser (Signed)
Input: "+6% attack and cast speed"
t("{value:+dec%} [additional] attack and cast speed").outputMany([
spec("AspdPct", (c) => ({ value: c.value, addn: c.additional !== undefined })),
spec("CspdPct", (c) => ({ value: c.value, addn: c.additional !== undefined })),
]),
Flat Stat Parser (Signed)
Input: "+166 Max Mana"
t("{value:+dec} max mana").output("MaxMana", (c) => ({ value: c.value })),
No-Op Parser (Recognized but produces no mods)
Input: "Energy Shield starts to Charge when Blocking"
Use outputNone() when a mod string should be recognized (not flagged as unparsed) but has no effect on calculations:
t("energy shield starts to charge when blocking").outputNone(),
Common Mistakes
| Mistake | Fix |
|---|---|
Using dec% for input with + prefix |
Use +dec% for inputs like "+25% damage" |
Using +dec% for input without sign |
Use dec% for inputs like "8% damage applied to life" |
| Template doesn't match input case | Templates are matched case-insensitively; input is normalized to lowercase |
Missing as const on string literals |
Add as const for type narrowing: statModType: "all" as const |
| Handler doesn't account for new variant | Update offense.ts to handle new values (e.g., statModType === "all") |
| Generic template before specific | Move specific templates earlier in allParsers array |
Data Flow
Raw string: "+10% all stats"
↓ normalize (lowercase, trim)
"10% all stats"
↓ template matching (allParsers)
{ type: "StatPct", value: 10, statModType: "all" }
↓ calculateStats() in offense.ts
Applied to str, dex, int calculations