Skip to content

Commit

Permalink
24w19a
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed May 10, 2024
1 parent bf36ecd commit 44b97e3
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 43 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"@mcschema/java-1.20": "^0.0.20",
"@mcschema/java-1.20.2": "^0.0.9",
"@mcschema/java-1.20.3": "^0.0.10",
"@mcschema/java-1.20.5": "^0.0.28",
"@mcschema/java-1.21": "^0.0.9",
"@mcschema/java-1.20.5": "^0.0.29",
"@mcschema/java-1.21": "^0.0.10",
"@mcschema/locales": "^0.1.98",
"@zip.js/zip.js": "^2.4.5",
"brace": "^0.11.1",
Expand Down
12 changes: 12 additions & 0 deletions src/app/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { quat, vec2 } from 'gl-matrix'
import yaml from 'js-yaml'
import { route } from 'preact-router'
import rfdc from 'rfdc'
import type { ConfigGenerator } from './Config.js'
import config from './Config.js'
import type { VersionId } from './services/index.js'
import { checkVersion } from './services/index.js'

export function isPromise(obj: any): obj is Promise<any> {
return typeof (obj as any)?.then === 'function'
Expand Down Expand Up @@ -581,3 +584,12 @@ export function parseGitPatch(patch: string) {
}
return result
}

const legacyTags = new Set(['tag/item', 'tag/block', 'tag/fluid', 'tag/entity_type', 'tag/game_event'])
export function genPath(gen: ConfigGenerator, version: VersionId) {
const path = gen.path ?? gen.id
if (!checkVersion(version, '1.21') && legacyTags.has(gen.id)) {
return path + 's'
}
return path
}
2 changes: 1 addition & 1 deletion src/app/components/generator/ProjectCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function ProjectCreation({ onClose }: Props) {
readZip(file).then(async (entries) => {
const project: Partial<Project> = { files: [] }
await Promise.all(entries.map(async (entry) => {
const file = disectFilePath(entry[0])
const file = disectFilePath(entry[0], version)
if (file) {
try {
const data = await parseSource(entry[1], 'json')
Expand Down
20 changes: 10 additions & 10 deletions src/app/components/generator/ProjectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { DataModel } from '@mcschema/core'
import { useCallback, useMemo, useRef, useState } from 'preact/hooks'
import { Analytics } from '../../Analytics.js'
import config from '../../Config.js'
import { Store } from '../../Store.js'
import { writeZip } from '../../Utils.js'
import { DRAFT_PROJECT, disectFilePath, getFilePath, useLocale, useProject, useVersion } from '../../contexts/index.js'
import { disectFilePath, DRAFT_PROJECT, getFilePath, useLocale, useProject, useVersion } from '../../contexts/index.js'
import { useFocus } from '../../hooks/useFocus.js'
import type { VersionId } from '../../services/index.js'
import { stringifySource } from '../../services/index.js'
import { Store } from '../../Store.js'
import { writeZip } from '../../Utils.js'
import { Btn } from '../Btn.js'
import { BtnMenu } from '../BtnMenu.js'
import { Octicon } from '../Octicon.jsx'
Expand Down Expand Up @@ -44,20 +44,20 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
id: id.replaceAll('\u2215', '/'),
}
}
return disectFilePath(entry)
}, [treeViewMode])
return disectFilePath(entry, version)
}, [treeViewMode, version])

const entries = useMemo(() => project.files.flatMap(f => {
const path = getFilePath(f)
const path = getFilePath(f, version)
if (!path) return []
if (f.type === 'pack_mcmeta') return 'pack.mcmeta'
if (treeViewMode === 'resources') {
return [`${f.type.replaceAll('/', '\u2215')}/${f.id.replaceAll('/', '\u2215')}`]
}
return [path]
}), [treeViewMode, ...project.files])
}), [treeViewMode, version, ...project.files])

const selected = useMemo(() => file && getFilePath(file), [file])
const selected = useMemo(() => file && getFilePath(file, version), [file, version])

const selectFile = useCallback((entry: string) => {
const file = disectEntry(entry)
Expand All @@ -72,7 +72,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
if (!download.current) return
let hasPack = false
const entries = project.files.flatMap(file => {
const path = getFilePath(file)
const path = getFilePath(file, version)
if (path === undefined) return []
if (path === 'pack.mcmeta') hasPack = true
return [[path, stringifySource(file.data)]] as [string, string][]
Expand Down Expand Up @@ -126,7 +126,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
}
const file = disectEntry(entry)

return <div class={`entry ${file && getFilePath(file) === selected ? 'active' : ''} ${focused ? 'focused' : ''}`} onClick={() => selectFile(entry)} onContextMenu={onContextMenu} >
return <div class={`entry ${file && getFilePath(file, version) === selected ? 'active' : ''} ${focused ? 'focused' : ''}`} onClick={() => selectFile(entry)} onContextMenu={onContextMenu} >
{Octicon.file}
<span>{entry.split('/').at(-1)}</span>
{focused && <div class="entry-menu">
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/generator/SchemaGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { useCallback, useEffect, useErrorBoundary, useMemo, useRef, useState } f
import { Analytics } from '../../Analytics.js'
import type { ConfigGenerator } from '../../Config.js'
import config from '../../Config.js'
import { Store } from '../../Store.js'
import { cleanUrl, deepEqual } from '../../Utils.js'
import { DRAFT_PROJECT, useLocale, useProject, useVersion } from '../../contexts/index.js'
import { AsyncCancel, useActiveTimeout, useAsync, useModel, useSearchParam } from '../../hooks/index.js'
import { getOutput } from '../../schema/transformOutput.js'
import type { VersionId } from '../../services/index.js'
import { checkVersion, fetchPreset, getBlockStates, getCollections, getModel, getSnippet, shareSnippet } from '../../services/index.js'
import { Store } from '../../Store.js'
import { cleanUrl, deepEqual, genPath } from '../../Utils.js'
import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, FileRenaming, Footer, HasPreview, Octicon, PreviewPanel, ProjectCreation, ProjectDeletion, ProjectPanel, SearchList, SourcePanel, TextInput, Tree, VersionSwitcher } from '../index.js'

export const SHARE_KEY = 'share'
Expand Down Expand Up @@ -167,7 +167,7 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) {

const loadPreset = async (id: string) => {
try {
const preset = await fetchPreset(version, gen.path ?? gen.id, id)
const preset = await fetchPreset(version, genPath(gen, version), id)
const seed = model?.get(new Path(['generator', 'seed']))
if (preset?.generator?.seed !== undefined && seed !== undefined) {
preset.generator.seed = seed
Expand Down
16 changes: 9 additions & 7 deletions src/app/contexts/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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)
Expand All @@ -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'
Expand All @@ -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]+$/, '')
Expand Down
12 changes: 6 additions & 6 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"id": "1.21",
"dynamic": true,
"name": "1.21",
"pack_format": 42,
"pack_format": 43,
"show": true
}
],
Expand Down Expand Up @@ -421,31 +421,31 @@
"id": "tag/block",
"url": "tags/block",
"tags": ["tags"],
"path": "tags/blocks",
"path": "tags/block",
"schema": "block_tag",
"wiki": "https://minecraft.wiki/w/Tag#Java_Edition"
},
{
"id": "tag/entity_type",
"url": "tags/entity-type",
"tags": ["tags"],
"path": "tags/entity_types",
"path": "tags/entity_type",
"schema": "entity_type_tag",
"wiki": "https://minecraft.wiki/w/Tag#Java_Edition"
},
{
"id": "tag/fluid",
"url": "tags/fluid",
"tags": ["tags"],
"path": "tags/fluids",
"path": "tags/fluid",
"schema": "fluid_tag",
"wiki": "https://minecraft.wiki/w/Tag#Java_Edition"
},
{
"id": "tag/game_event",
"url": "tags/game-event",
"tags": ["tags"],
"path": "tags/game_events",
"path": "tags/game_event",
"schema": "game_event_tag",
"minVersion": "1.17",
"wiki": "https://minecraft.wiki/w/Tag#Java_Edition"
Expand All @@ -454,7 +454,7 @@
"id": "tag/item",
"url": "tags/item",
"tags": ["tags"],
"path": "tags/items",
"path": "tags/item",
"schema": "item_tag",
"wiki": "https://minecraft.wiki/w/Tag#Java_Edition"
},
Expand Down

0 comments on commit 44b97e3

Please sign in to comment.