Skip to content

Commit b6d92ce

Browse files
SnaveSutitgitbutler-client
authored andcommitted
✨ Add support for custom namespaces
1 parent 7288b92 commit b6d92ce

51 files changed

Lines changed: 1226 additions & 1024 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ const CUSTOM_RULES: ConfigWithExtends['rules'] = {
6767
selector: ['import'],
6868
modifiers: ['default'],
6969
filter: {
70-
regex: '(old_)?v[\\d_]+(_pre\\d+)?$',
70+
regex: '(old_)?v[\\d_]+(_pre\\d+|_beta_\\d+)?$',
7171
match: true,
7272
},
7373
custom: {
7474
match: true,
75-
regex: '(old_)?v[\\d_]+(_pre\\d+)?$',
75+
regex: '(old_)?v[\\d_]+(_pre\\d+|_beta_\\d+)?$',
7676
},
7777
format: null,
7878
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"title": "Animated Java",
55
"icon": "icon.svg",
66
"description": "Effortlessly craft complex animations for Minecraft: Java Edition",
7-
"version": "1.10.0-beta.3",
7+
"version": "1.10.0-beta.4",
88
"min_blockbench_version": "4.12.6",
99
"max_blockbench_version": "4.12.6",
1010
"variant": "desktop",

src/formats/ajmodel/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { openUnexpectedErrorDialog } from '../../dialogs/unexpectedError/unexpec
55
import { localize as translate } from '../../util/lang'
66
import { sanitizeStorageKey } from '../../util/minecraftUtil'
77
import { BLUEPRINT_CODEC } from '../blueprint/codec'
8-
import * as modelDatFixerUpper from '../blueprint/dfu'
8+
import { upgradeAnimatedJavaBlueprint } from '../blueprint/dfu'
99
import FormatPage from './formatPage.svelte'
1010

1111
// Blockbench has a bug where it calls the onStart function multiple times when double-clicking it.
@@ -26,7 +26,7 @@ export async function openAJModel() {
2626
export function convertAJModelToBlueprint(path: string) {
2727
try {
2828
console.log(`Converting .ajmodel: ${path}`)
29-
const blueprint = modelDatFixerUpper.process(JSON.parse(fs.readFileSync(path, 'utf8')))
29+
const blueprint = upgradeAnimatedJavaBlueprint(JSON.parse(fs.readFileSync(path, 'utf8')))
3030

3131
const codec = BLUEPRINT_CODEC.get()
3232
if (!codec) throw new Error('Animated Java Blueprint codec is not registered!')
@@ -35,7 +35,8 @@ export function convertAJModelToBlueprint(path: string) {
3535
name: 'Upgrade .ajmodel to Blueprint',
3636
path,
3737
})
38-
blueprint.blueprint_settings!.export_namespace ??= sanitizeStorageKey(Project!.name)
38+
blueprint.blueprint_settings!.blueprint_id ??=
39+
'animated_java:' + sanitizeStorageKey(Project!.name)
3940

4041
requestAnimationFrame(() => {
4142
Project!.save_path = ''

src/formats/blueprint/codec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export const BLUEPRINT_CODEC = registerDeletableHandlerPatch({
9292
}
9393
}
9494

95-
Project.last_used_export_namespace =
96-
model.meta?.last_used_export_namespace ?? Project.animated_java.export_namespace
95+
Project.last_used_blueprint_id =
96+
model.meta?.last_used_blueprint_id ?? Project.animated_java.blueprint_id
9797

9898
if (model.textures) {
9999
for (const texture of model.textures) {
@@ -255,7 +255,7 @@ export const BLUEPRINT_CODEC = registerDeletableHandlerPatch({
255255
uuid: Project.uuid,
256256

257257
save_location: Project.save_path,
258-
last_used_export_namespace: Project.last_used_export_namespace,
258+
last_used_blueprint_id: Project.last_used_blueprint_id,
259259
},
260260
resolution: {
261261
width: Project.texture_width ?? 16,
@@ -393,7 +393,7 @@ export const BLUEPRINT_CODEC = registerDeletableHandlerPatch({
393393
extensions: [this.extension!],
394394
content: this.compile!(),
395395
// eslint-disable-next-line @typescript-eslint/naming-convention
396-
custom_writer: (content, path) => {
396+
custom_writer: (content: string, path: string) => {
397397
if (fs.existsSync(PathModule.dirname(path))) {
398398
Project!.save_path = path
399399
this.write!(content, path)

src/formats/blueprint/dfu.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import v1_0_0_pre1 from './versions/1.0.0-pre1'
1414
import v1_0_0_pre6 from './versions/1.0.0-pre6'
1515
import v1_0_0_pre7 from './versions/1.0.0-pre7'
1616
import v1_0_0_pre8 from './versions/1.0.0-pre8'
17-
import v1_10_0 from './versions/1.10.0'
17+
import v1_10_0_beta_1 from './versions/1.10.0-beta.1'
18+
import v1_10_0_beta_4 from './versions/1.10.0-beta.4'
1819
import v1_4_0 from './versions/1.4.0'
1920
import v1_6_3 from './versions/1.6.3'
2021
import v1_6_5 from './versions/1.6.5'
@@ -76,26 +77,28 @@ export function upgradeAnimatedJavaBlueprint(model: any): IBlueprintFormatJSON {
7677

7778
// Versions below this are post 0.3.10. I changed the versioning system to use the AJ version instead of a unique format version.
7879
switch (true) {
79-
case VersionUtil.compare('0.3.10', '>', model.meta.format_version):
80+
case VersionUtil.compare(model.meta.format_version, '<', '0.3.10'):
8081
model = v0_3_10(model)
81-
case VersionUtil.compare('0.5.0', '>', model.meta.format_version):
82+
case VersionUtil.compare(model.meta.format_version, '<', '0.5.0'):
8283
model = v1_0_0_pre1(model)
83-
case VersionUtil.compare('0.5.5', '>', model.meta.format_version):
84+
case VersionUtil.compare(model.meta.format_version, '<', '0.5.5'):
8485
model = v1_0_0_pre6(model)
85-
case VersionUtil.compare('0.5.6', '>', model.meta.format_version):
86+
case VersionUtil.compare(model.meta.format_version, '<', '0.5.6'):
8687
model = v1_0_0_pre7(model)
87-
case VersionUtil.compare('0.5.7', '>', model.meta.format_version):
88+
case VersionUtil.compare(model.meta.format_version, '<', '0.5.7'):
8889
model = v1_0_0_pre8(model)
89-
case VersionUtil.compare('1.4.0', '>', model.meta.format_version):
90+
case VersionUtil.compare(model.meta.format_version, '<', '1.4.0'):
9091
model = v1_4_0(model)
91-
case VersionUtil.compare('1.6.3', '>', model.meta.format_version):
92+
case VersionUtil.compare(model.meta.format_version, '<', '1.6.3'):
9293
model = v1_6_3(model)
93-
case VersionUtil.compare('1.6.5', '>', model.meta.format_version):
94+
case VersionUtil.compare(model.meta.format_version, '<', '1.6.5'):
9495
model = v1_6_5(model)
95-
case VersionUtil.compare('1.8.0', '>', model.meta.format_version):
96+
case VersionUtil.compare(model.meta.format_version, '<', '1.8.0'):
9697
model = v1_8_0(model)
97-
case VersionUtil.compare('1.10.0', '>', model.meta.format_version):
98-
model = v1_10_0(model)
98+
case VersionUtil.compare(model.meta.format_version, '<', '1.10.0-beta.1'):
99+
model = v1_10_0_beta_1(model)
100+
case VersionUtil.compare(model.meta.format_version, '<', '1.10.0-beta.4'):
101+
model = v1_10_0_beta_4(model)
99102
}
100103

101104
// Remove unknown blueprint settings

src/formats/blueprint/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12
import type { ModelProject } from '@blockbench-types/generated/io/project'
23
import { registerDeletableHandlerPatch } from 'blockbench-patch-manager'
34
import { mount, unmount } from 'svelte'
@@ -21,7 +22,7 @@ import * as blueprintSettings from './settings'
2122
declare module '@blockbench-types/generated/io/project' {
2223
export interface ModelProject {
2324
animated_java: BlueprintSettings
24-
last_used_export_namespace: string
25+
last_used_blueprint_id: string
2526
visualBoundingBox?: THREE.LineSegments
2627
pluginMode: Observable<boolean>
2728
transparentTexture: Texture
@@ -111,7 +112,7 @@ export interface IBlueprintFormatJSON {
111112
format?: string
112113
format_version?: string
113114
uuid?: string
114-
last_used_export_namespace?: string
115+
last_used_blueprint_id?: string
115116
box_uv?: boolean
116117
backup?: boolean
117118
save_location?: string
@@ -168,14 +169,15 @@ export function fixCubeRotation(cube: Cube) {
168169
export function convertToBlueprint() {
169170
// Convert the current project to a Blueprint
170171
Project!.save_path = ''
171-
Project!.last_used_export_namespace = ''
172+
Project!.last_used_blueprint_id = ''
172173

173174
for (const group of Group.all) {
174175
group.createUniqueName(Group.all.filter(g => g !== group))
175176
group.sanitizeName()
176177
}
177178

178179
for (const animation of Blockbench.Animation.all) {
180+
// @ts-expect-error - Broken BB types
179181
animation.createUniqueName(Blockbench.Animation.all.filter(a => a !== animation))
180182
animation.name = sanitizeStorageKey(animation.name)
181183
}
@@ -291,7 +293,7 @@ export const BLUEPRINT_FORMAT = registerDeletableHandlerPatch({
291293
const defaults = getDefaultProjectSettings()
292294
if (newModel) {
293295
project.animated_java = defaults
294-
project.last_used_export_namespace = ''
296+
project.last_used_blueprint_id = ''
295297
} else {
296298
project.animated_java = { ...defaults, ...project!.animated_java }
297299
}
@@ -374,6 +376,7 @@ export const BLUEPRINT_FORMAT = registerDeletableHandlerPatch({
374376
return format
375377
},
376378
})
379+
// @ts-expect-error - Broken BB types
377380
Language.data['format_category.animated_java'] = translate('format_category.animated_java')
378381

379382
export function activeProjectIsBlueprintFormat() {

0 commit comments

Comments
 (0)