tmp.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import os
  2. import json
  3. from game.const import rouge_theme as rt
  4. def main(root_dir="."):
  5. for dirpath, _, filenames in os.walk(root_dir):
  6. for filename in filenames:
  7. if filename.lower().endswith(".json"):
  8. file_path = os.path.join(dirpath, filename)
  9. try:
  10. with open(file_path, "r", encoding="utf-8") as f:
  11. try:
  12. data = json.load(f)
  13. except json.JSONDecodeError:
  14. print(f"[跳过] {file_path} 不是有效的 JSON 文件")
  15. continue
  16. if data.get("skills", None) is None:
  17. continue
  18. mon_type = "normal"
  19. if data.get("elite", False):
  20. mon_type = "elite"
  21. elif data.get("boss", False):
  22. mon_type = "boss"
  23. speed = "极慢"
  24. if 1 <= data["speed"] <= 2.5:
  25. speed = "慢"
  26. elif 2.5 < data["speed"] <= 3.5:
  27. speed = "中"
  28. elif 3.5 < data["speed"] <= 4.5:
  29. speed = "快"
  30. elif 4.5 < data["speed"]:
  31. speed = "极快"
  32. sight = "极小"
  33. if 2 < data["resent_dist"] <= 3:
  34. sight = "小"
  35. elif 3 < data["resent_dist"] <= 5:
  36. sight = "中"
  37. elif 5 < data["resent_dist"] <= 7:
  38. sight = "大"
  39. elif 7 < data["resent_dist"]:
  40. sight = "极大"
  41. new_data = {
  42. "chs_name": data["chs_name"],
  43. "character": data["character"],
  44. "type": mon_type,
  45. "blood": data["blood"],
  46. "speed": speed,
  47. "contact": data["contact"],
  48. "defense": data["defense"],
  49. "resent_dist": sight,
  50. "info": "???",
  51. "strategy": "???"
  52. }
  53. # 覆盖写回文件
  54. with open(file_path, "w", encoding="utf-8") as f:
  55. json.dump(new_data, f, ensure_ascii=False, indent=4)
  56. print(f"[更新完成] {file_path}")
  57. except Exception as e:
  58. print(f"[错误] {file_path}: {e}")
  59. def test():
  60. l = []
  61. for k in rt.theme_skyland_mon_dic.keys():
  62. l.append(k)
  63. print(l)
  64. if __name__ == "__main__":
  65. main(".")
  66. # test()
  67. pass