这是一个用于解析和操作 Warcraft 3 地图文件(.w3x/.w3m)的 TypeScript 库。
- 解析 Warcraft 3 地图的各种文件格式
- 读取和修改地图数据
- 支持 MPQ 存档格式
- 完整的触发器系统支持
- 浏览器和 Node.js 双端支持
# 使用 pnpm
pnpm install
# 使用 npm
npm install
# 使用 yarn
yarn install<!DOCTYPE html>
<html>
<head>
<title>Warcraft 3 地图解析器示例</title>
</head>
<body>
<input type="file" id="map" accept=".w3x,.w3m">
<script type="module">
import Map from './dist/parsers/w3x/index.js'
document.getElementById('map').addEventListener('change', async (event) => {
const input = event.target;
if (input.files && input.files.length > 0) {
const file = input.files[0];
const arrayBuffer = await file.arrayBuffer();
const map = new Map(new Uint8Array(arrayBuffer));
console.log(map);
}
});
</script>
</body>
</html>import Map from './src/parsers/w3x/index';
// 从 Uint8Array 加载地图
const mapData = new Uint8Array(/* ... 从文件或其他来源获取的数据 ... */);
const map = new Map(mapData);
// 读取地图基本信息
const info = map.getMapInformation();
console.log('地图名称:', info.name);
console.log('地图作者:', info.author);
console.log('地图描述:', info.description);
// 读取触发器
const triggers = map.readTriggers(triggerData);
if (triggers) {
console.log('触发器数量:', triggers.triggers.length);
}
// 读取自定义文本触发器
const customTriggers = map.readCustomTextTriggers();
if (customTriggers) {
console.log('自定义触发器:', customTriggers);
}
// 读取字符串表
const stringTable = map.readStringTable();
if (stringTable) {
console.log('字符串映射:', stringTable.stringMap);
}
// 读取所有修改表(单位、物品、技能等)
const modifications = map.readModifications();
console.log('单位修改:', modifications.w3u);
console.log('物品修改:', modifications.w3t);
console.log('技能修改:', modifications.w3a);
// 保存修改后的地图
const modifiedMapData = map.save();- w3i: 地图基本信息(名称、作者、玩家设置等)
- w3e: 地图环境(地形、瓦片设置等)
- w3f: 地图过滤器设置
- w3u: 单位修改
- w3t: 物品修改
- w3b: 可破坏物修改
- unitsdoo: 单位和物品数据
- w3a: 技能修改
- w3h: 魔法效果修改
- w3q: 升级修改
- w3d: 装饰物修改
- wtg: 触发器数据
- wct: 自定义文本触发器
- wts: 字符串表
- w3c: 摄像机设置
- w3r: 地区设置
- w3s: 音效设置
- w3o: 组合修改文件
- wpm: 寻路图
- doo: 装饰物和可破坏物
- imp: 导入文件列表
new W3XParser(buffer: Uint8Array, readonly: boolean = true)buffer: 包含地图数据的 Uint8Arrayreadonly: 是否以只读模式打开地图(默认为 true)
保存地图并返回新的 Uint8Array 数据。
获取存档中所有文件的名称。
获取地图中导入的文件名称列表。
获取存档中的特定文件。
检查存档中是否存在特定文件。
设置存档中的文件(需要非只读模式)。
删除存档中的文件(需要非只读模式)。
重命名存档中的文件(需要非只读模式)。
导入文件到地图(需要非只读模式)。
获取地图的基本信息。
读取地图触发器。
读取自定义文本触发器。
读取字符串表。
读取所有修改表(单位、物品、技能等)。
# 开发模式
npm run dev
# 构建
npm run buildsrc/common/: 通用工具函数src/mpq/: MPQ 存档格式解析src/parsers/: 各种地图文件解析器w3x/: 主地图解析器w3i/: 地图信息解析器w3e/: 环境解析器- 等等...
欢迎提交 Issue 和 Pull Request 来改进这个项目。
[请在此处添加许可证信息]