mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Better handling of pack.mcmeta in projects
This commit is contained in:
@@ -15,7 +15,7 @@ interface Props {
|
||||
export function FileCreation({ model, id, method, onClose }: Props) {
|
||||
const { locale } = useLocale()
|
||||
const { projects, project, updateFile } = useProject()
|
||||
const [fileId, setFileId] = useState('')
|
||||
const [fileId, setFileId] = useState(id === 'pack_mcmeta' ? 'pack' : '')
|
||||
|
||||
const doSave = () => {
|
||||
Analytics.saveProjectFile(id, projects.length, project.files.length, method as any)
|
||||
@@ -25,7 +25,7 @@ export function FileCreation({ model, id, method, onClose }: Props) {
|
||||
|
||||
return <Modal class="file-modal" onDismiss={onClose}>
|
||||
<p>{locale('project.save_current_file')}</p>
|
||||
<TextInput autofocus class="btn btn-input" value={fileId} onChange={setFileId} onEnter={doSave} onCancel={onClose} placeholder={locale('resource_location')} spellcheck={false} />
|
||||
<TextInput autofocus={id !== 'pack_mcmeta'} class="btn btn-input" value={fileId} onChange={setFileId} onEnter={doSave} onCancel={onClose} placeholder={locale('resource_location')} spellcheck={false} readOnly={id === 'pack_mcmeta'} />
|
||||
<Btn icon="file" label={locale('project.save')} onClick={doSave} />
|
||||
</Modal>
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
|
||||
}, [])
|
||||
|
||||
const disectEntry = useCallback((entry: string) => {
|
||||
if (treeViewMode === 'resources') {
|
||||
if (treeViewMode === 'resources' && entry !== 'pack.mcmeta') {
|
||||
const [type, id] = entry.split('/')
|
||||
return {
|
||||
type: type.replaceAll('\u2215', '/'),
|
||||
@@ -46,6 +46,7 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
|
||||
const entries = useMemo(() => project.files.flatMap(f => {
|
||||
const path = getFilePath(f)
|
||||
if (!path) return []
|
||||
if (f.type === 'pack_mcmeta') return 'pack.mcmeta'
|
||||
if (treeViewMode === 'resources') {
|
||||
return [`${f.type.replaceAll('/', '\u2215')}/${f.id.replaceAll('/', '\u2215')}`]
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ export function ProjectProvider({ children }: { children: ComponentChildren }) {
|
||||
if (!edits.id) { // remove
|
||||
updateProject({ files: project.files.filter(f => f.type !== type || f.id !== id) })
|
||||
} else {
|
||||
const newId = edits.id.includes(':') ? edits.id : `${project.namespace ?? 'minecraft'}:${edits.id}`
|
||||
const newId = type === 'pack_mcmeta' ? 'pack' : edits.id.includes(':') ? edits.id : `${project.namespace ?? 'minecraft'}:${edits.id}`
|
||||
const exists = project.files.some(f => f.type === type && f.id === newId)
|
||||
if (!id) { // create
|
||||
if (exists) return false
|
||||
|
||||
Reference in New Issue
Block a user