@@ -7,28 +7,20 @@ import { BLUEPRINT_CODEC } from '../blueprint/codec'
77import * as modelDatFixerUpper from '../blueprint/dfu'
88import FormatPage from './formatPage.svelte'
99
10- registerModelLoader (
11- { id : `animated-java:upgrade-aj-model-loader` } ,
12- {
13- icon : 'upload_file' ,
14- category : 'animated_java' ,
15- name : translate ( 'action.upgrade_old_aj_model_loader.name' ) ,
16- condition : true ,
17- format_page : {
18- component : {
19- template : `<div id="animated-java:upgrade-aj-model-loader-target" style="flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between;"></div>` ,
20- mounted ( ) {
21- // Don't need to worry about unmounting since the whole panel gets replaced when switching formats
22- mountSvelteComponent ( {
23- component : FormatPage ,
24- target : `#animated-java\\:upgrade-aj-model-loader-target` ,
25- injectIndex : 2 ,
26- } )
27- } ,
28- } ,
29- } ,
30- }
31- )
10+ // Blockbench has a bug where it calls the onStart function multiple times when double-clicking it.
11+ let waitingForAJModel = false
12+ export async function openAJModel ( ) {
13+ if ( waitingForAJModel ) return
14+ waitingForAJModel = true
15+ const result = await electron . dialog . showOpenDialog ( {
16+ properties : [ 'openFile' ] ,
17+ filters : [ { name : '.ajmodel' , extensions : [ 'ajmodel' ] } ] ,
18+ message : translate ( 'action.upgrade_old_aj_model_loader.select_file' ) ,
19+ } )
20+ waitingForAJModel = false
21+ if ( result . canceled ) return
22+ convertAJModelToBlueprint ( result . filePaths [ 0 ] )
23+ }
3224
3325export function convertAJModelToBlueprint ( path : string ) {
3426 try {
@@ -54,3 +46,27 @@ export function convertAJModelToBlueprint(path: string) {
5446 openUnexpectedErrorDialog ( e as Error )
5547 }
5648}
49+
50+ registerModelLoader (
51+ { id : `animated-java:upgrade-aj-model-loader` } ,
52+ {
53+ icon : 'upload_file' ,
54+ category : 'animated_java' ,
55+ name : translate ( 'action.upgrade_old_aj_model_loader.name' ) ,
56+ condition : true ,
57+ format_page : {
58+ component : {
59+ template : `<div id="animated-java:upgrade-aj-model-loader-target" style="flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between;"></div>` ,
60+ mounted ( ) {
61+ // Don't need to worry about unmounting since the whole panel gets replaced when switching formats
62+ mountSvelteComponent ( {
63+ component : FormatPage ,
64+ target : `#animated-java\\:upgrade-aj-model-loader-target` ,
65+ injectIndex : 2 ,
66+ } )
67+ } ,
68+ } ,
69+ } ,
70+ onStart : openAJModel ,
71+ }
72+ )
0 commit comments