"""
SSBO Editor Component Demo
==========================
Demonstrates how to usage the SSBOEditor component in a new project.
"""
import sys
import os

# ============================================================
# [CRITICAL] RenderPipeline Python Compatibility Fix
# ============================================================
if "d:/panda3d/RenderPipeline" not in sys.path:
    sys.path.insert(0, "d:/panda3d/RenderPipeline")

try:
    import rplibs.six
    import six
    if not hasattr(rplibs.six, 'moves'):
        rplibs.six.moves = six.moves
    sys.modules['rplibs.six.moves'] = six.moves
except ImportError:
    import six
    import types
    if "rplibs" not in sys.modules:
        rplibs = types.ModuleType("rplibs")
        sys.modules["rplibs"] = rplibs
    if "rplibs.six" not in sys.modules:
        rplibs.six = six
        sys.modules["rplibs.six"] = six
    sys.modules["rplibs.six.moves"] = six.moves

# ============================================================
# Main Application
# ============================================================
from direct.showbase.ShowBase import ShowBase
from panda3d.core import loadPrcFileData, Filename
from rpcore import RenderPipeline

# Import our new component
# Assuming d:/panda3d is in python path, or running from d:/panda3d
from ssbo_component.ssbo_editor import SSBOEditor

loadPrcFileData("", "show-frame-rate-meter true")
loadPrcFileData("", "sync-video false")

class MyGame(ShowBase):
    def __init__(self):
        # 1. RP Init
        self.rp = RenderPipeline()
        self.rp.pre_showbase_init()
        super().__init__()
        
        # Position camera before RP create to avoid huge motion blur jump
        self.cam.setPos(0, -500, 200)
        self.cam.lookAt(0, 0, 0)
        
        self.rp.create(self)
        self.rp.daytime_mgr.time = 0.415
        
        # 2. Use the Component
        # Point to your model
        model_path = "d:/panda3d/panda3d/jyc.glb"
        font_path = "d:/panda3d/font/msyh.ttc"
        
        print("Initializing SSBO Editor Component...")
        self.editor = SSBOEditor(
            base_app=self,
            render_pipeline=self.rp,
            model_path=model_path,
            font_path=font_path
        )
        
        print("Demo ready.")

if __name__ == "__main__":
    app = MyGame()
    app.run()
