mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-03 14:12:54 +00:00
Support 1.15
This commit is contained in:
+7
-4
@@ -1,4 +1,5 @@
|
||||
import { CollectionRegistry, DataModel, ObjectNode, SchemaRegistry } from '@mcschema/core';
|
||||
import * as java15 from '@mcschema/java-1.15'
|
||||
import * as java16 from '@mcschema/java-1.16'
|
||||
import * as java17 from '@mcschema/java-1.17'
|
||||
import { LocalStorageProperty } from './state/LocalStorageProperty';
|
||||
@@ -19,6 +20,7 @@ const Versions: {
|
||||
getSchemas: (collections: CollectionRegistry) => SchemaRegistry,
|
||||
}
|
||||
} = {
|
||||
'1.15': java15,
|
||||
'1.16': java16,
|
||||
'1.17': java17
|
||||
}
|
||||
@@ -98,7 +100,7 @@ async function updateSchemas(version: string) {
|
||||
const schemas = Versions[version].getSchemas(collections)
|
||||
config.models
|
||||
.filter(m => m.schema)
|
||||
.filter(m => checkVersion(App.version.get(), m.minVersion ?? config.versions[0].id))
|
||||
.filter(m => checkVersion(App.version.get(), m.minVersion))
|
||||
.forEach(m => {
|
||||
const model = Models[m.id]
|
||||
const schema = schemas.get(m.schema!)
|
||||
@@ -120,10 +122,11 @@ async function updateLocale(language: string) {
|
||||
Locales[language] = data
|
||||
}
|
||||
|
||||
export function checkVersion(versionId: string, minVersionId: string) {
|
||||
export function checkVersion(versionId: string, minVersionId: string | undefined, maxVersionId?: string) {
|
||||
const version = config.versions.findIndex(v => v.id === versionId)
|
||||
const minVersion = config.versions.findIndex(v => v.id === minVersionId)
|
||||
return minVersion <= version
|
||||
const minVersion = minVersionId ? config.versions.findIndex(v => v.id === minVersionId) : 0
|
||||
const maxVersion = maxVersionId ? config.versions.findIndex(v => v.id === maxVersionId) : config.versions.length - 1
|
||||
return minVersion <= version && version <= maxVersion
|
||||
}
|
||||
|
||||
document.addEventListener('keyup', (evt) => {
|
||||
|
||||
+61
-28
@@ -2,6 +2,13 @@ import { CollectionRegistry } from '@mcschema/core'
|
||||
import { checkVersion } from './App'
|
||||
import config from '../config.json'
|
||||
|
||||
type RegistryConfig = {
|
||||
id: string
|
||||
minVersion?: string
|
||||
maxVersion?: string
|
||||
path?: string
|
||||
}
|
||||
|
||||
const localStorageCache = (version: string) => `cache_${version}`
|
||||
declare var __MCDATA_MASTER_HASH__: string;
|
||||
|
||||
@@ -18,36 +25,62 @@ export const RegistryFetcher = async (target: CollectionRegistry, versionId: str
|
||||
const cacheValid = version.mcdata_ref !== 'master' || cache.mcdata_hash === __MCDATA_MASTER_HASH__
|
||||
let cacheDirty = false
|
||||
|
||||
await Promise.all(config.registries.map(async r => {
|
||||
const id = typeof r === 'string' ? r : r.id
|
||||
if (checkVersion('1.15', versionId)) {
|
||||
const url = `${baseUrl}/${version.mcdata_ref}/generated/reports/registries.json`
|
||||
if (cacheValid && cache.registries) {
|
||||
config.registries.forEach((r: string | RegistryConfig) => {
|
||||
if (typeof r === 'string') r = { id: r }
|
||||
if (!checkVersion(versionId, r.minVersion, r.maxVersion)) return
|
||||
|
||||
if (typeof r !== 'string' && r.minVersion) {
|
||||
if (!checkVersion(versionId, r.minVersion)) return
|
||||
target.register(r.id, cache.registries[r.id])
|
||||
})
|
||||
} else {
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
const data = await res.json()
|
||||
config.registries.forEach(async (r: string | RegistryConfig) => {
|
||||
if (typeof r === 'string') r = { id: r }
|
||||
if (!checkVersion(versionId, r.minVersion, r.maxVersion)) return
|
||||
|
||||
if (!cache.registries) cache.registries = {}
|
||||
const values = Object.keys(data[`minecraft:${r.id}`].entries)
|
||||
target.register(r.id, values)
|
||||
cache.registries[r.id] = values
|
||||
cacheDirty = true
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn(`Error occurred while fetching registries for version ${versionId}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cache.registries) {
|
||||
cache.registries = {}
|
||||
}
|
||||
if (cacheValid && cache.registries?.[id]) {
|
||||
target.register(id, cache.registries[id])
|
||||
return
|
||||
}
|
||||
|
||||
const url = typeof r !== 'string' && r.path
|
||||
? `${baseUrl}/${version.mcdata_ref}/${r.path}/data.min.json`
|
||||
: mcdata(version.mcdata_ref, typeof r === 'string' ? r : r.id)
|
||||
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
const data = await res.json()
|
||||
|
||||
target.register(id, data.values)
|
||||
cache.registries[id] = data.values
|
||||
cacheDirty = true
|
||||
} catch (e) {
|
||||
console.warn(`Error occurred while fetching registry "${id}":`, e)
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
await Promise.all(config.registries.map(async (r: string | RegistryConfig) => {
|
||||
if (typeof r === 'string') r = { id: r }
|
||||
|
||||
if (r.minVersion && !checkVersion(versionId, r.minVersion)) return
|
||||
if (r.maxVersion && !checkVersion(r.maxVersion, versionId)) return
|
||||
|
||||
if (!cache.registries) cache.registries = {}
|
||||
if (cacheValid && cache.registries?.[r.id]) {
|
||||
target.register(r.id, cache.registries[r.id])
|
||||
return
|
||||
}
|
||||
|
||||
const url = r.path
|
||||
? `${baseUrl}/${version.mcdata_ref}/${r.path}/data.min.json`
|
||||
: mcdata(version.mcdata_ref, typeof r === 'string' ? r : r.id)
|
||||
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
const data = await res.json()
|
||||
|
||||
target.register(r.id, data.values)
|
||||
cache.registries[r.id] = data.values
|
||||
cacheDirty = true
|
||||
} catch (e) {
|
||||
console.warn(`Error occurred while fetching registry "${r.id}":`, e)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
if (cacheDirty) {
|
||||
if (version.mcdata_ref === 'master') {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ const router = async () => {
|
||||
let title = locale('title.home')
|
||||
|
||||
if (urlParts.length === 0){
|
||||
App.model.set({ id: '', name: 'Data Pack', category: true})
|
||||
App.model.set({ id: '', name: 'Data Pack', category: true, minVersion: '1.15'})
|
||||
target.innerHTML = Home(view)
|
||||
} else if (urlParts[0] === 'settings' && urlParts[1] === 'fields') {
|
||||
target.innerHTML = FieldSettings(view)
|
||||
|
||||
@@ -62,7 +62,7 @@ export const TreePanel = (view: View, model: DataModel) => {
|
||||
</div>
|
||||
<div class="panel-menu-list btn-group">
|
||||
${config.versions
|
||||
.filter(v => checkVersion(v.id, App.model.get()!.minVersion ?? '1.16'))
|
||||
.filter(v => checkVersion(v.id, App.model.get()!.minVersion ?? '1.15'))
|
||||
.reverse()
|
||||
.map(v => `
|
||||
<div class="btn" data-id="${view.onClick(() => {
|
||||
|
||||
Reference in New Issue
Block a user