feat: load remote map config and constrain tile bounds
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { MapEngine, type MapEngineStageRect, type MapEngineViewState } from '../../engine/map/mapEngine'
|
||||
import { loadRemoteMapConfig } from '../../utils/remoteMapConfig'
|
||||
|
||||
type MapPageData = MapEngineViewState & {
|
||||
showDebugPanel: boolean
|
||||
}
|
||||
|
||||
const INTERNAL_BUILD_VERSION = 'map-build-75'
|
||||
const INTERNAL_BUILD_VERSION = 'map-build-82'
|
||||
const REMOTE_GAME_CONFIG_URL = 'https://oss-mbh5.colormaprun.com/wxmini/test/qyds-001/game.json'
|
||||
|
||||
let mapEngine: MapEngine | null = null
|
||||
|
||||
@@ -36,6 +38,7 @@ Page({
|
||||
|
||||
onReady() {
|
||||
this.measureStageAndCanvas()
|
||||
this.loadMapConfigFromRemote()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
@@ -45,6 +48,33 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
loadMapConfigFromRemote() {
|
||||
const currentEngine = mapEngine
|
||||
if (!currentEngine) {
|
||||
return
|
||||
}
|
||||
|
||||
loadRemoteMapConfig(REMOTE_GAME_CONFIG_URL)
|
||||
.then((config) => {
|
||||
if (mapEngine !== currentEngine) {
|
||||
return
|
||||
}
|
||||
|
||||
currentEngine.applyRemoteMapConfig(config)
|
||||
})
|
||||
.catch((error) => {
|
||||
if (mapEngine !== currentEngine) {
|
||||
return
|
||||
}
|
||||
|
||||
const errorMessage = error && error.message ? error.message : '未知错误'
|
||||
this.setData({
|
||||
configStatusText: `载入失败: ${errorMessage}`,
|
||||
statusText: `远程地图配置载入失败: ${errorMessage} (${INTERNAL_BUILD_VERSION})`,
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
measureStageAndCanvas() {
|
||||
const page = this
|
||||
const applyStage = (rawRect?: Partial<WechatMiniprogram.BoundingClientRectCallbackResult>) => {
|
||||
@@ -179,6 +209,18 @@ Page({
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user