<!--
 * @Author: ChenChanghua
 * @Date: 2022-01-25 09:56:46
 * @LastEditors: Please set LastEditors
-->
<script setup>
import { DefaultKeyCodeMap, jJsvRuntimeBridge } from "jsview";
import { useRouter } from "vue-router";
import { SprFestivalScene } from "./SpringFestivalScene";
import { onMounted } from "vue";

const router = useRouter();

const fncOnKeyDown = (ev) => {
  if (
    ev.keyCode == 8 ||
    ev.keyCode == 27 ||
    ev.keyCode == DefaultKeyCodeMap.Back
  ) {
    router.go(-1); // 有router时，是从DemoHomepage进入，回退
    return true;
  }
  switch (ev.keyCode) {
    case DefaultKeyCodeMap.Up:
    case DefaultKeyCodeMap.Down:
    case DefaultKeyCodeMap.left:
    case DefaultKeyCodeMap.Right:
    case DefaultKeyCodeMap.Ok:
      return true;
  }
};

let cRunningInBox = typeof window.JsView != "undefined";

onMounted(() => {
  jJsvRuntimeBridge.notifyPageLoaded();
});
</script>

<template>
  <jsv-focus-block
    autoFocus
    :onAction="{
      onKeyDown: fncOnKeyDown,
    }"
  >
    <div
      v-if="cRunningInBox"
      :style="{
        width: 1920,
        height: 1080,
        transform: 'scale3d(0.67,0.67,1)',
        transformOrigin: 'left top',
      }"
    >
      <SprFestivalScene />
    </div>
    <div
      v-else
      id="LudlScale"
      :style="{
        top: 210,
        left: 490,
        width: 300,
        height: 300,
        fontSize: 25,
        lineHeight: 300,
      }"
    >
      {{ "PC不支持此组件显示" }}
    </div>
  </jsv-focus-block>
</template>
