Skip to content

Commit

Permalink
Fix #319 keep unknown files when importing and downloading a project
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Oct 4, 2024
1 parent 394beea commit 5d08f15
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"deepslate-1.18": "npm:[email protected]",
"deepslate-1.18.2": "npm:[email protected]",
"deepslate-1.20.4": "npm:[email protected]",
"deepslate": "^0.22.1",
"deepslate": "^0.22.2",
"highlight.js": "^11.5.1",
"howler": "^2.2.3",
"js-yaml": "^3.14.1",
Expand Down
7 changes: 6 additions & 1 deletion src/app/components/generator/ProjectCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ export function ProjectCreation({ onClose }: Props) {
try {
const data = await parseSource(entry[1], 'json')
project.files!.push({ ...file, data })
return
} catch (e) {
console.error(`Failed parsing ${file.type} ${file.id}: ${message(e)}`)
console.warn(`Failed parsing ${file.type} ${file.id}: ${message(e)}`)
}
}
if (project.unknownFiles === undefined) {
project.unknownFiles = []
}
project.unknownFiles.push({ path: entry[0], data: entry[1] })
}))
projectUpdater.current(project)
onClose()
Expand Down
3 changes: 3 additions & 0 deletions src/app/components/generator/ProjectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export function ProjectPanel({ onRename, onCreate, onDeleteProject }: Props) {
if (path === 'pack.mcmeta') hasPack = true
return [[path, stringifySource(file.data)]] as [string, string][]
})
project.unknownFiles?.forEach(({ path, data }) => {
entries.push([path, data])
})
if (!hasPack) {
const pack_format = config.versions.find(v => v.id === version)!.pack_format
entries.push(['pack.mcmeta', stringifySource({ pack: { pack_format, description: '' } })])
Expand Down
6 changes: 6 additions & 0 deletions src/app/contexts/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Project = {
namespace?: string,
version?: VersionId,
files: ProjectFile[],
unknownFiles?: UnknownFile[],
}
export const DRAFT_PROJECT: Project = {
name: 'Drafts',
Expand All @@ -26,6 +27,11 @@ export type ProjectFile = {
data: any,
}

export type UnknownFile = {
path: string,
data: string,
}

export const FilePatterns = [
'worldgen/[a-z_]+',
'tags/worldgen/[a-z_]+',
Expand Down

0 comments on commit 5d08f15

Please sign in to comment.