Spaces:
Paused
Paused
| import asyncio | |
| import os | |
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.staticfiles import StaticFiles | |
| app = FastAPI() | |
| # مسار بناء اللعبة باستخدام pygbag | |
| BUILD_PATH = "build/web" | |
| async def build_game(): | |
| # هي الخطوة بتحول كود game.py لملفات ويب وقت التشغيل | |
| print("Building game with pygbag...") | |
| os.system("python3 -m pygbag --build /code/game.py") | |
| async def get_game(): | |
| index_path = os.path.join(BUILD_PATH, "index.html") | |
| if os.path.exists(index_path): | |
| with open(index_path, "r") as f: | |
| return f.read() | |
| return """ | |
| <html> | |
| <body style="background:black; color:white; display:flex; justify-content:center; align-items:center; height:100vh;"> | |
| <h2>Building Orbit Wars... Please refresh in 10 seconds 🚀</h2> | |
| </body> | |
| </html> | |
| """ | |
| # مشاركة الملفات الناتجة (JS/WASM) | |
| if os.path.exists(BUILD_PATH): | |
| app.mount("/", StaticFiles(directory=BUILD_PATH), name="static") |