import { TestSceneC } from "../controllers/TestSceneC";
import { FollowCameraC } from "../controllers/FollowCameraC";
import { PlayerC } from "../controllers/PlayerC";
import { JoystickC, SoundC, Template } from "@24tools/playable_template";

export const afterResourcesLoadedCb: (() => void) | undefined = async () => {
  TestSceneC.init();
  SoundC.init();

  const joystickZone = document.getElementById("joystick_zone") as HTMLDivElement;
  if (!joystickZone) {
    console.warn("[JoystickC] #joystick_zone element not found in DOM");
  } else {
    JoystickC.init({
      zone: joystickZone,
      fadeTime: 0,
      mode: "dynamic",
      restJoystick: true,
      catchDistance: 1,
      restOpacity: 0,
      follow: false,
    });
  }

  // Player is now a cannon body — collisions with the floor and boundary
  // walls are handled by the physics world (no more raycasting).
  PlayerC.init(TestSceneC.characterObject);

  FollowCameraC.init(TestSceneC.characterObject);

  if (import.meta.env.DEV) {
    const { CameraDebugUI } = await import("../controllers/CameraDebugUI");
    CameraDebugUI.init();
  }

  Template.disableLoader();
};
