Преглед изворни кода

Require boss assets when boss gameplay is enabled

bang пре 2 недеља
родитељ
комит
298b565bc9
3 измењених фајлова са 46 додато и 0 уклоњено
  1. 15 0
      exporter.py
  2. 25 0
      pipeline.py
  3. 6 0
      web/index.html

+ 15 - 0
exporter.py

@@ -602,6 +602,21 @@ def export(game, out_root, log=print):
         raise FileNotFoundError(f"找不到 game「{game}」的 library.json")
         raise FileNotFoundError(f"找不到 game「{game}」的 library.json")
 
 
     lib = json.load(open(os.path.join(base, "library.json"), encoding="utf-8"))
     lib = json.load(open(os.path.join(base, "library.json"), encoding="utf-8"))
+    boss = lib.get("slot_config", {}).get("boss", {})
+    if boss.get("enabled"):
+        boss_id = boss.get("id") or "boss_demon_lord"
+        lib_char_ids = {c.get("id") for c in lib.get("characters", [])}
+        missing_files = [
+            f"characters/{boss_id}.{ext}"
+            for ext in ("json", "atlas", "png")
+            if not os.path.isfile(os.path.join(base, "characters", f"{boss_id}.{ext}"))
+        ]
+        if boss_id not in lib_char_ids or missing_files:
+            raise RuntimeError(
+                f"当前资源库缺少关主大魔王资源:{boss_id}。请重新生成图片资源,"
+                "生成成功后才会包含 idle/watch/coin_throw/taunt/stomp/explode 等动作。"
+            )
+
     pack = os.path.join(base, "cocos-pack")
     pack = os.path.join(base, "cocos-pack")
     if os.path.exists(pack):
     if os.path.exists(pack):
         shutil.rmtree(pack)
         shutil.rmtree(pack)

+ 25 - 0
pipeline.py

@@ -85,6 +85,22 @@ def run(manifest, out_root, creds=None, log=print):
             return fixed
             return fixed
         raise RuntimeError("百度智能抠图返回结果仍没有真实 Alpha 透明通道")
         raise RuntimeError("百度智能抠图返回结果仍没有真实 Alpha 透明通道")
 
 
+    def boss_config():
+        boss = manifest.get("slot_config", {}).get("boss", {})
+        return boss if boss.get("enabled", False) else {}
+
+    def required_boss_id():
+        boss = boss_config()
+        if not boss:
+            return ""
+        return boss.get("id") or "boss_demon_lord"
+
+    def is_required_boss(c):
+        boss_id = required_boss_id()
+        return bool(boss_id and (c.get("role") == "boss" or c.get("id") == boss_id))
+
+    required_failures = []
+
     # ---- A. 角色(Spine)----
     # ---- A. 角色(Spine)----
     for i, c in enumerate(manifest.get("characters", [])):
     for i, c in enumerate(manifest.get("characters", [])):
         cid = c.get("id", f"char_{i}")
         cid = c.get("id", f"char_{i}")
@@ -135,8 +151,17 @@ def run(manifest, out_root, creds=None, log=print):
             progress(f"{cid}")
             progress(f"{cid}")
         except Exception as e:
         except Exception as e:
             log(f"❌ [{cid}] 失败: {e}")
             log(f"❌ [{cid}] 失败: {e}")
+            if is_required_boss(c):
+                required_failures.append(f"{cid}: {e}")
             progress(f"{cid}")
             progress(f"{cid}")
 
 
+    boss_id = required_boss_id()
+    if boss_id and not any(c.get("id") == boss_id for c in library["characters"]):
+        detail = ";".join(required_failures) if required_failures else "生成结果中没有关主资源"
+        raise RuntimeError(
+            f"关主大魔王资源缺失:{boss_id}。已开启关主玩法,必须生成 boss 拆件和动作后才能继续。原因:{detail}"
+        )
+
     # ---- A2. UI 美术(背景 / Logo / 卷轴框 / 按钮 等整图)----
     # ---- A2. UI 美术(背景 / Logo / 卷轴框 / 按钮 等整图)----
     ui_art_out = os.path.join(base_out, "ui_art")
     ui_art_out = os.path.join(base_out, "ui_art")
     for a in manifest.get("ui_art", []):
     for a in manifest.get("ui_art", []):

+ 6 - 0
web/index.html

@@ -239,6 +239,12 @@ async function loadLibrary(game){
      o.value=g;o.textContent=g+(pending&&g===lib.game?'(待生成)':''); if(g===lib.game)o.selected=true; sel.appendChild(o); });
      o.value=g;o.textContent=g+(pending&&g===lib.game?'(待生成)':''); if(g===lib.game)o.selected=true; sel.appendChild(o); });
   if(!games.length){ const o=document.createElement('option');o.textContent='(暂无)';sel.appendChild(o); }
   if(!games.length){ const o=document.createElement('option');o.textContent='(暂无)';sel.appendChild(o); }
   if(pending) opMsg(`已载入 ${lib.game} 的 manifest,但还没有图片资源;点“开始生成”后才会进入资源库。`, false);
   if(pending) opMsg(`已载入 ${lib.game} 的 manifest,但还没有图片资源;点“开始生成”后才会进入资源库。`, false);
+  const boss = lib.slot_config && lib.slot_config.boss;
+  if(boss && boss.enabled){
+    const bossId = boss.id || 'boss_demon_lord';
+    const hasBoss = (lib.characters||[]).some(c=>c.id===bossId);
+    if(!hasBoss) opMsg(`当前资源库缺少关主大魔王 ${bossId},请重新生成图片资源;旧库不会有大魔王动作。`, false);
+  }
   render();
   render();
 }
 }