Files
TankIC/build_bundle.py
T
2026-07-28 01:16:15 +08:00

70 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""3DTank 工具链 bundle 构建脚本
将各分开编写的 JS 文件按依赖顺序 concat 成一个 3dtank_bundle.js
输出到项目根目录,粘贴到浏览器控制台即可一键加载全部功能
"""
import os
import sys
BASE = os.path.dirname(os.path.abspath(__file__))
TOOLS = os.path.join(BASE, "tools")
OUTPUT = os.path.join(BASE, "3dtank_bundle.js")
# 同时复制到 unpacked 目录供 main.b7114b43.js 自动加载
UNPACKED_DIR = os.path.join(BASE, "3dtank.com", "play", "static", "js", "unpacked")
UNPACKED_OUTPUT = os.path.join(UNPACKED_DIR, "hornet_bundle.js")
# 按依赖顺序加载
FILES = [
"hook_gamemode.js", # 1. Hook 捕获 GameMode(异步)
"hornet_lib.js", # 2. 公共库(软警告,不阻塞加载)
"hornet_radar.js", # 3. 雷达模块 -> __hornetTools__.Radar
"hornet_3d_wireframe.js",# 4. 3D透视模块 -> __hornetTools__.Wireframe
"hornet_rearview.js", # 5. 后视镜模块 -> __hornetTools__.Rearview
"hornet_aim_warning.js", # 6. 瞄准警告模块 -> __hornetTools__.AimWarning
"hornet_freelook.js", # 7. 自由视角模块 -> __hornetTools__.FreeLook
"hornet_warsandbox.js", # 8. 战争沙盘模块 -> __hornetTools__.WarSandbox
"hornet_panel.js", # 9. 控制面板(Alt+T + HUD)
]
HEADER = """// ============================================================
// 3DTank 工具链 Bundle (自动生成,请勿手动编辑)
// 构建: python build_bundle.py
// 用法: 全选粘贴到 3DTank 游戏页面控制台
// 操作: Alt+T 打开控制面板 | 左上角 HUD 显示状态
// ============================================================
"""
def main():
parts = []
total = 0
for fn in FILES:
fp = os.path.join(TOOLS, fn)
if not os.path.exists(fp):
print("[ERROR] 文件不存在: " + fp)
sys.exit(1)
with open(fp, 'r', encoding='utf-8') as f:
content = f.read()
size = len(content.encode('utf-8'))
parts.append("// ===== " + fn + " =====\n" + content)
print("[OK] " + fn + " (" + str(size) + " bytes)")
total += size
bundle = HEADER + "\n\n".join(parts) + "\n"
with open(OUTPUT, 'w', encoding='utf-8') as f:
f.write(bundle)
print("\n[DONE] 输出: " + OUTPUT)
print(" 大小: " + str(len(bundle.encode('utf-8'))) + " bytes")
print(" 模块: " + str(len(FILES)) + " 个文件")
# 复制到 unpacked 目录供 main.b7114b43.js 自动加载
try:
with open(UNPACKED_OUTPUT, 'w', encoding='utf-8') as f:
f.write(bundle)
print(" 已复制到: " + UNPACKED_OUTPUT)
except Exception as e:
print(" [WARN] 复制到 unpacked 失败: " + str(e))
if __name__ == '__main__':
main()