HumanBreak/src/ui/load.vue

110 lines
2.8 KiB
Vue
Raw Normal View History

2024-04-20 16:13:48 +08:00
<template>
2024-04-21 13:37:27 +08:00
<div id="load">
<a-progress
class="task-progress"
type="circle"
:percent="(loading / totalTask) * 100"
:success="{ percent: (loaded / totalTask) * 100 }"
>
<template #format>
<span>{{ loaded }} / {{ totalTask }}</span>
</template>
</a-progress>
<div class="byte-div">
<span class="byte-progress-tip"
>{{ formatSize(loadedByte) }} /
{{ formatSize(totalByte) }}</span
>
<a-progress
class="byte-progress"
type="line"
:percent="loadedPercent"
></a-progress>
</div>
</div>
2024-04-20 16:13:48 +08:00
</template>
2024-04-21 13:37:27 +08:00
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
2024-05-03 20:44:43 +08:00
import {
loadCompressedResource,
loadDefaultResource,
LoadTask
} from '@/core/common/resource';
2024-04-21 13:37:27 +08:00
import { GameUi } from '@/core/main/custom/ui';
import { formatSize } from '@/plugin/utils';
import { logger } from '@/core/common/logger';
import { fixedUi } from '@/core/main/init/ui';
import { sleep } from 'mutate-animate';
const props = defineProps<{
ui: GameUi;
num: number;
callback?: () => void;
}>();
const loading = ref(0);
const loaded = ref(0);
const loadedByte = ref(0);
const loadedPercent = ref(0);
const totalByte = ref(0);
const totalTask = ref(0);
let loadDiv: HTMLDivElement;
2024-05-03 20:44:43 +08:00
onMounted(async () => {
if (import.meta.env.DEV) loadDefaultResource();
else await loadCompressedResource();
2024-04-21 13:37:27 +08:00
2024-05-03 20:44:43 +08:00
LoadTask.onProgress(() => {
const loadingNum = [...LoadTask.taskList].filter(v => v.loading).length;
2024-04-21 13:37:27 +08:00
2024-05-03 20:44:43 +08:00
loadedByte.value = LoadTask.loadedByte;
loadedPercent.value = parseFloat(
((LoadTask.loadedByte / LoadTask.totalByte) * 100).toFixed(2)
);
loading.value = loadingNum;
loaded.value = LoadTask.loadedTask;
totalByte.value = LoadTask.totalByte;
totalTask.value = LoadTask.totalTask;
});
2024-04-21 13:37:27 +08:00
2024-05-03 20:44:43 +08:00
LoadTask.load().then(async () => {
core.loader._loadMaterials_afterLoad();
core._afterLoadResources(props.callback);
logger.log(`Resource load end.`);
loadDiv.style.opacity = '0';
await sleep(1000);
fixedUi.close(props.num);
fixedUi.open('start');
});
2024-04-21 13:37:27 +08:00
loadDiv = document.getElementById('load') as HTMLDivElement;
});
</script>
2024-04-20 16:13:48 +08:00
<style lang="less" scoped>
#load {
2024-04-21 13:37:27 +08:00
width: 100%;
height: 100%;
2024-04-20 16:13:48 +08:00
display: flex;
justify-content: center;
align-items: center;
2024-04-21 13:37:27 +08:00
flex-direction: column;
font-family: 'Arial';
transition: opacity 1s linear;
position: fixed;
left: 0;
top: 0;
background-color: black;
}
.byte-div {
width: 50%;
margin-top: 10vh;
}
.byte-progress {
width: 100%;
2024-04-20 16:13:48 +08:00
}
</style>