scense/app/scense.py

62 lines
2.0 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.

# -*- coding: utf-8 -*-
"""元景 scense 应用唯一入口(一个应用 = 一个入口 = 一个端口 9380
挂载 6 个业务模块world / scene / entity / script_engine / world_snapshot / world_sync。
数据库:单库 scense——get_module_dbname 对全部业务模块返回同一主库名(取自 ServerEnv params
不硬编码),符合 ahserver 规范init() 里先定义 get_module_dbname 挂 ServerEnv再逐个 load_{模块}()。
"""
from ahserver.webapp import webapp
from ahserver.serverenv import ServerEnv
import bricks_for_python # 注册 bui processor
from bricks_for_python.init import load_pybricks # 注册 UiWindow 等
from appbase.init import load_appbase
from rbac.init import load_rbac
def get_module_dbname(m):
"""模块 → 库名映射。单库应用:全部模块返回同一主库 scense。
库名来源ServerEnv params 表appbase 初始化时写入 'dbname' 参数),禁止硬编码。
"""
env = ServerEnv()
try:
return env.params.get('dbname', 'scense')
except Exception:
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
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()
if __name__ == '__main__':
webapp(init)