Orbit-Wars / main.py
ONYX-APP's picture
Create main.py
4b8820e verified
Raw
History Blame Contribute Delete
1.13 kB
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"
@app.on_event("startup")
async def build_game():
# هي الخطوة بتحول كود game.py لملفات ويب وقت التشغيل
print("Building game with pygbag...")
os.system("python3 -m pygbag --build /code/game.py")
@app.get("/", response_class=HTMLResponse)
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")