| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 根据JSON配置文件更新Excel表格
- """
- import json
- import pandas as pd
- import os
- from pathlib import Path
- def load_json_file(file_path):
- """加载JSON文件"""
- with open(file_path, 'r', encoding='utf-8') as f:
- return json.load(f)
- def create_weapons_excel():
- """根据weapons.json创建武器配置Excel表格"""
- # 加载武器配置
- weapons_data = load_json_file('d:/CocosGame/Pong/assets/resources/data/weapons.json')
-
- # 创建武器基础信息表
- weapons_basic = []
- for weapon in weapons_data['weapons']:
- weapons_basic.append({
- 'ID': weapon['id'],
- '名称': weapon['name'],
- '类型': weapon['type'],
- '稀有度': weapon['rarity'],
- '权重': weapon['weight'],
- '伤害': weapon['stats']['damage'],
- '射速': weapon['stats']['fireRate'],
- '射程': weapon['stats']['range'],
- '子弹速度': weapon['stats']['bulletSpeed']
- })
-
- # 创建子弹配置表
- bullet_configs = []
- for weapon in weapons_data['weapons']:
- bullet_config = weapon['bulletConfig']
- bullet_configs.append({
- '武器ID': weapon['id'],
- '武器名称': weapon['name'],
- '子弹数量类型': bullet_config['count']['type'],
- '子弹数量': bullet_config['count']['amount'],
- '散射角度': bullet_config['count']['spreadAngle'],
- '连发数量': bullet_config['count']['burstCount'],
- '连发延迟': bullet_config['count']['burstDelay'],
- '轨迹类型': bullet_config['trajectory']['type'],
- '轨迹速度': bullet_config['trajectory']['speed'],
- '重力': bullet_config['trajectory']['gravity'],
- '生命周期类型': bullet_config['lifecycle']['type'],
- '最大生存时间': bullet_config['lifecycle']['maxLifetime'],
- '穿透次数': bullet_config['lifecycle']['penetration'],
- '反弹次数': bullet_config['lifecycle']['ricochetCount'],
- '是否返回原点': bullet_config['lifecycle']['returnToOrigin']
- })
-
- # 创建方块形状配置表
- block_shapes = []
- for block in weapons_data['blockSizes']:
- # 将4x4矩阵转换为字符串表示
- shape_str = ''
- for row in block['shape']:
- shape_str += ''.join(map(str, row)) + '\n'
-
- block_shapes.append({
- 'ID': block['id'],
- '名称': block['name'],
- '形状矩阵': shape_str.strip()
- })
-
- # 创建稀有度权重表
- rarity_weights = []
- for rarity, weight in weapons_data['rarityWeights'].items():
- rarity_weights.append({
- '稀有度': rarity,
- '权重': weight
- })
-
- # 创建Excel文件
- with pd.ExcelWriter('d:/CocosGame/Pong/assets/resources/data/excel/方块武器配置/方块武器配置表_更新_v2.xlsx', engine='openpyxl') as writer:
- pd.DataFrame(weapons_basic).to_excel(writer, sheet_name='武器基础配置', index=False)
- pd.DataFrame(bullet_configs).to_excel(writer, sheet_name='子弹配置', index=False)
- pd.DataFrame(block_shapes).to_excel(writer, sheet_name='方块形状配置', index=False)
- pd.DataFrame(rarity_weights).to_excel(writer, sheet_name='稀有度权重', index=False)
-
- print("武器配置Excel表格已更新完成!")
- def create_levels_excel():
- """根据levels目录下的JSON文件创建关卡配置Excel表格"""
- levels_dir = Path('d:/CocosGame/Pong/assets/resources/data/levels')
-
- # 关卡基础信息表
- levels_basic = []
- # 关卡波次配置表
- waves_config = []
- # 敌人配置表
- enemies_config = []
- # 敌人名称映射表
- enemy_name_mapping = []
-
- # 加载敌人配置以获取名称映射
- try:
- enemies_data = load_json_file('d:/CocosGame/Pong/assets/resources/data/enemies.json')
- if 'nameToIdMapping' in enemies_data:
- for chinese_name, enemy_id in enemies_data['nameToIdMapping'].items():
- enemy_name_mapping.append({
- '中文名称': chinese_name,
- '英文ID': enemy_id,
- '说明': '关卡配置中使用的敌人名称映射'
- })
- except Exception as e:
- print(f"加载敌人名称映射时出错: {e}")
-
- # 遍历所有关卡文件
- for level_file in levels_dir.glob('Level*.json'):
- try:
- level_data = load_json_file(level_file)
- level_id = level_file.stem
-
- # 关卡基础信息
- levels_basic.append({
- '关卡ID': level_id,
- '关卡名称': level_data['name'],
- '场景': level_data['scene'],
- '描述': level_data['description'],
- '可用武器': ', '.join(level_data['weapons'])
- })
-
- # 波次和敌人配置
- for wave in level_data['waves']:
- wave_id = wave['waveId']
-
- # 波次基础信息
- waves_config.append({
- '关卡ID': level_id,
- '波次ID': wave_id,
- '敌人种类数': len(wave['enemies'])
- })
-
- # 每个敌人的详细配置
- for enemy in wave['enemies']:
- enemies_config.append({
- '关卡ID': level_id,
- '波次ID': wave_id,
- '敌人类型': enemy['enemyType'],
- '数量': enemy['count'],
- '生成间隔': enemy['spawnInterval'],
- '生成延迟': enemy['spawnDelay'],
- '特性': ', '.join(enemy['characteristics'])
- })
- except Exception as e:
- print(f"处理关卡文件 {level_file} 时出错: {e}")
- continue
-
- # 创建Excel文件
- try:
- with pd.ExcelWriter('d:/CocosGame/Pong/assets/resources/data/excel/关卡配置/关卡配置表_完整版_更新_v2.xlsx', engine='openpyxl') as writer:
- pd.DataFrame(levels_basic).to_excel(writer, sheet_name='关卡基础配置', index=False)
- pd.DataFrame(waves_config).to_excel(writer, sheet_name='波次配置', index=False)
- pd.DataFrame(enemies_config).to_excel(writer, sheet_name='敌人配置', index=False)
- pd.DataFrame(enemy_name_mapping).to_excel(writer, sheet_name='敌人名称映射', index=False)
-
- print("关卡配置Excel表格已更新完成!")
- print(f"生成的工作表包括: 关卡基础配置, 波次配置, 敌人配置, 敌人名称映射")
- except Exception as e:
- print(f"创建关卡配置Excel文件时出错: {e}")
- def main():
- """主函数"""
- print("开始更新Excel配置表格...")
-
- try:
- # 更新武器配置表
- create_weapons_excel()
-
- # 更新关卡配置表
- create_levels_excel()
-
- print("\n所有Excel表格更新完成!")
- print("生成的文件:")
- print("- d:/CocosGame/Pong/assets/resources/data/excel/方块武器配置/方块武器配置表_更新_v2.xlsx")
- print("- d:/CocosGame/Pong/assets/resources/data/excel/关卡配置/关卡配置表_完整版_更新_v2.xlsx")
-
- except Exception as e:
- print(f"更新过程中出现错误: {e}")
- import traceback
- traceback.print_exc()
- if __name__ == '__main__':
- main()
|