Add event-driven gameplay feedback framework
This commit is contained in:
@@ -19,6 +19,7 @@ export interface TileStoreEntry {
|
||||
lastUsedAt: number
|
||||
lastAttemptAt: number
|
||||
lastVisibleKey: string
|
||||
retryable: boolean
|
||||
}
|
||||
|
||||
export interface TileStoreStats {
|
||||
@@ -174,6 +175,7 @@ export class TileStore {
|
||||
lastUsedAt: usedAt,
|
||||
lastAttemptAt: 0,
|
||||
lastVisibleKey: '',
|
||||
retryable: true,
|
||||
}
|
||||
this.tileCache.set(url, entry)
|
||||
return entry
|
||||
@@ -274,9 +276,10 @@ export class TileStore {
|
||||
return
|
||||
}
|
||||
|
||||
if (entry.status === 'idle' || (entry.status === 'error' && usedAt - entry.lastAttemptAt > ERROR_RETRY_DELAY_MS)) {
|
||||
if (entry.status === 'idle' || (entry.status === 'error' && entry.retryable && usedAt - entry.lastAttemptAt > ERROR_RETRY_DELAY_MS)) {
|
||||
if (entry.status === 'error') {
|
||||
entry.status = 'idle'
|
||||
entry.retryable = true
|
||||
}
|
||||
this.queueTile(url)
|
||||
}
|
||||
@@ -288,9 +291,10 @@ export class TileStore {
|
||||
continue
|
||||
}
|
||||
|
||||
if (entry.status === 'idle' || (entry.status === 'error' && usedAt - entry.lastAttemptAt > ERROR_RETRY_DELAY_MS)) {
|
||||
if (entry.status === 'idle' || (entry.status === 'error' && entry.retryable && usedAt - entry.lastAttemptAt > ERROR_RETRY_DELAY_MS)) {
|
||||
if (entry.status === 'error') {
|
||||
entry.status = 'idle'
|
||||
entry.retryable = true
|
||||
}
|
||||
this.queueTile(tile.url)
|
||||
}
|
||||
@@ -358,8 +362,9 @@ export class TileStore {
|
||||
}
|
||||
}
|
||||
|
||||
const markError = (message: string) => {
|
||||
const markError = (message: string, retryable = true) => {
|
||||
entry.status = 'error'
|
||||
entry.retryable = retryable
|
||||
finish()
|
||||
if (this.onTileError) {
|
||||
this.onTileError(`${message}: ${url}`)
|
||||
@@ -425,6 +430,11 @@ export class TileStore {
|
||||
}
|
||||
|
||||
const resolvedPath = res.filePath || filePath || res.tempFilePath
|
||||
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||
markError(`瓦片资源不存在(${res.statusCode})`, false)
|
||||
return
|
||||
}
|
||||
|
||||
if (res.statusCode !== 200 || !resolvedPath) {
|
||||
tryRemoteImage()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user