scense/app/scense.py

75 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""唤景平台世界模式scense——应用唯一入口。
一个应用 = 一个入口 = 一个端口9380
init() 里先挂 ServerEnv再挂载基础模块 + 6 个业务模块。
"""
from ahserver.webapp import webapp
from ahserver.serverenv import ServerEnv
import bricks_for_python # registers bui processor
from bricks_for_python.init import load_pybricks # registers UiWindow etc.
from appbase.init import load_appbase
from rbac.init import load_rbac
def get_module_dbname(m):
"""返回模块 m 对应的数据库名。
本项目为单库应用world/scene/entity/script_engine/world_snapshot/world_sync
以及基础模块appbase/rbac统一落同一主库 scense。
"""
return "scense"
def password_encode(s):
if s is None:
return ""
from ahserver.globalEnv import password_encode as _orig
return _orig(s)
def init():
env = ServerEnv() # MUST be before load_rbac / load_appbase
env.get_module_dbname = get_module_dbname
env.password_encode = password_encode
load_appbase()
load_rbac()
load_pybricks()
# ── 业务模块导入(一个入口一个端口,所有模块挂在这里)──
from world.init import load_world
from scene.init import load_scene
from entity.init import load_entity
from script_engine.init import load_script_engine
from world_snapshot.init import load_world_snapshot
from world_sync.init import load_world_sync
load_world()
load_scene()
load_entity()
load_script_engine()
load_world_snapshot()
load_world_sync()
# ── /healthz 健康检查部署门禁GET /healthz 必须 200──
# ahapp_built 钩子在应用构建完成时由 ConfiguredServer 触发,拿到 aiohttp app 注册路由。
from appPublic.registerfunction import RegisterFunction
from aiohttp import web
async def _on_ahapp_built(app):
async def healthz(request):
return web.json_response({"status": "ok", "app": "scense", "port": 9380})
app.router.add_get("/healthz", healthz)
RegisterFunction().register("ahapp_built", _on_ahapp_built)
if __name__ == "__main__":
webapp(init)