mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
24w19a
This commit is contained in:
@@ -5,7 +5,8 @@ import { useCallback, useContext, useMemo, useState } from 'preact/hooks'
|
||||
import config from '../Config.js'
|
||||
import type { VersionId } from '../services/index.js'
|
||||
import { Store } from '../Store.js'
|
||||
import { cleanUrl } from '../Utils.js'
|
||||
import { cleanUrl, genPath } from '../Utils.js'
|
||||
import { useVersion } from './Version.jsx'
|
||||
|
||||
export type Project = {
|
||||
name: string,
|
||||
@@ -62,6 +63,7 @@ export function useProject() {
|
||||
|
||||
export function ProjectProvider({ children }: { children: ComponentChildren }) {
|
||||
const [projects, setProjects] = useState<Project[]>(Store.getProjects())
|
||||
const { version } = useVersion()
|
||||
|
||||
const [projectName, setProjectName] = useState<string>(Store.getOpenProject())
|
||||
const project = useMemo(() => {
|
||||
@@ -119,13 +121,13 @@ export function ProjectProvider({ children }: { children: ComponentChildren }) {
|
||||
}, [updateProject, project, file])
|
||||
|
||||
const openFile = useCallback((type: string, id: string) => {
|
||||
const gen = config.generators.find(g => g.id === type || g.path === type)
|
||||
const gen = config.generators.find(g => g.id === type || genPath(g, version) === type)
|
||||
if (!gen) {
|
||||
throw new Error(`Cannot find generator of type ${type}`)
|
||||
}
|
||||
setFileId([gen.id, id])
|
||||
route(cleanUrl(gen.url))
|
||||
}, [])
|
||||
}, [version])
|
||||
|
||||
const closeFile = useCallback(() => {
|
||||
setFileId(undefined)
|
||||
@@ -149,7 +151,7 @@ export function ProjectProvider({ children }: { children: ComponentChildren }) {
|
||||
</Project.Provider>
|
||||
}
|
||||
|
||||
export function getFilePath(file: { id: string, type: string }) {
|
||||
export function getFilePath(file: { id: string, type: string }, version: VersionId) {
|
||||
const [namespace, id] = file.id.includes(':') ? file.id.split(':') : ['minecraft', file.id]
|
||||
if (file.type === 'pack_mcmeta') {
|
||||
if (file.id === 'pack') return 'pack.mcmeta'
|
||||
@@ -159,17 +161,17 @@ export function getFilePath(file: { id: string, type: string }) {
|
||||
if (!gen) {
|
||||
return undefined
|
||||
}
|
||||
return `data/${namespace}/${gen.path ?? gen.id}/${id}.json`
|
||||
return `data/${namespace}/${genPath(gen, version)}/${id}.json`
|
||||
}
|
||||
|
||||
export function disectFilePath(path: string) {
|
||||
export function disectFilePath(path: string, version: VersionId) {
|
||||
if (path === 'pack.mcmeta') {
|
||||
return { type: 'pack_mcmeta', id: 'pack' }
|
||||
}
|
||||
for (const p of FilePatterns) {
|
||||
const match = path.match(p)
|
||||
if (!match) continue
|
||||
const gen = config.generators.find(g => (g.path ?? g.id) === match[2])
|
||||
const gen = config.generators.find(g => (genPath(g, version) ?? g.id) === match[2])
|
||||
if (!gen) continue
|
||||
const namespace = match[1]
|
||||
const name = match[3].replace(/\.[a-z]+$/, '')
|
||||
|
||||
Reference in New Issue
Block a user