feat: engine utils, editor and asset prefix improvements

This commit is contained in:
2026-06-14 17:39:07 +08:00
parent e0331ab5a7
commit 271c909398
3 changed files with 9 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted } from 'vue' import { ref, computed, onMounted } from 'vue'
import type { GameData, SceneNode } from '@engine/types' import type { GameData, SceneNode } from '@engine/types'
import { resolveAsset } from '@engine/utils'
import { useGraphEditor } from './composables/useGraphEditor' import { useGraphEditor } from './composables/useGraphEditor'
import SceneGraph from './components/SceneGraph.vue' import SceneGraph from './components/SceneGraph.vue'
import NodeEditor from './components/NodeEditor.vue' import NodeEditor from './components/NodeEditor.vue'
@@ -21,7 +22,7 @@ const selectedScene = computed<SceneNode | null>(() => {
const previewVideoUrl = computed(() => { const previewVideoUrl = computed(() => {
const url = selectedScene.value?.videoUrl const url = selectedScene.value?.videoUrl
if (!url) return null if (!url) return null
return url.startsWith('/') ? url : '/' + url return resolveAsset(editor.gameData.value.assetBase || '', url)
}) })
function newNode() { function newNode() {

6
engine/utils.ts Normal file
View File

@@ -0,0 +1,6 @@
export function resolveAsset(base: string, path: string): string {
if (!path || path.startsWith('http://') || path.startsWith('https://') || path.startsWith('data:')) return path
const b = base.endsWith('/') ? base.slice(0, -1) : base
const p = path.startsWith('/') ? path : '/' + path
return b + p
}

View File

@@ -4,6 +4,7 @@ import { SaveSystem } from '@engine/systems/SaveSystem'
import type { GameData } from '@engine/types' import type { GameData } from '@engine/types'
import { useGameStore } from '@/stores/gameStore' import { useGameStore } from '@/stores/gameStore'
import { useI18n } from '@/composables/useI18n' import { useI18n } from '@/composables/useI18n'
import { resolveAsset } from '@engine/utils'
export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVideoElement | null]) { export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVideoElement | null]) {
const engine = new Engine() const engine = new Engine()
@@ -120,13 +121,6 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
store.setVideoTime(t) store.setVideoTime(t)
}) })
function resolveAsset(base: string, path: string): string {
if (!path || path.startsWith('http://') || path.startsWith('https://') || path.startsWith('data:')) return path
const b = base.endsWith('/') ? base.slice(0, -1) : base
const p = path.startsWith('/') ? path : '/' + path
return b + p
}
function applyAssetBase(data: GameData) { function applyAssetBase(data: GameData) {
const base = data.assetBase || '' const base = data.assetBase || ''
if (!base) return if (!base) return