|
| 1 | +import type * as aj from '../animatedJava' |
| 2 | +import { CustomError } from '../util/customError' |
| 3 | +import { store } from '../util/store' |
| 4 | + |
| 5 | +interface rawAnimationExporterSettings { |
| 6 | + outputJsonPath: string |
| 7 | +} |
| 8 | + |
| 9 | +function rawExport(exportData: aj.ExportData) { |
| 10 | + const ajSettings = exportData.settings.animatedJava |
| 11 | + const exporterSettings = exportData.settings |
| 12 | + .rawAnimationExporter as rawAnimationExporterSettings |
| 13 | + |
| 14 | + const FILE = { |
| 15 | + meta: { |
| 16 | + head_item: ajSettings.rigItem, |
| 17 | + }, |
| 18 | + animations: exportData.animations, |
| 19 | + } |
| 20 | + |
| 21 | + if (!exporterSettings.outputJsonPath) { |
| 22 | + throw new CustomError( |
| 23 | + 'animatedJava.exporters.rawAnimation.dialogs.errors.outputJsonPath.title', |
| 24 | + { |
| 25 | + intentional: true, |
| 26 | + dialog: { |
| 27 | + id: 'animatedJava.exporters.rawAnimation.dialogs.errors.outputJsonPath', |
| 28 | + title: tl( |
| 29 | + 'animatedJava.exporters.rawAnimation.dialogs.errors.outputJsonPath.title' |
| 30 | + ), |
| 31 | + lines: [ |
| 32 | + tl( |
| 33 | + 'animatedJava.exporters.rawAnimation.dialogs.errors.outputJsonPath.body' |
| 34 | + ), |
| 35 | + ], |
| 36 | + width: 512, |
| 37 | + singleButton: true, |
| 38 | + }, |
| 39 | + } |
| 40 | + ) |
| 41 | + } |
| 42 | + |
| 43 | + Blockbench.writeFile(exporterSettings.outputJsonPath, { |
| 44 | + content: JSON.stringify(FILE, null, '\t'), |
| 45 | + custom_writer: null, |
| 46 | + }) |
| 47 | +} |
| 48 | + |
| 49 | +const genericEmptySettingText = tl( |
| 50 | + 'animatedJava.settings.generic.errors.emptyValue' |
| 51 | +) |
| 52 | + |
| 53 | +const Exporter = (AJ: any) => { |
| 54 | + AJ.settings.registerPluginSettings( |
| 55 | + 'animatedJava.exporters.rawAnimation', // Exporter ID |
| 56 | + 'rawAnimationExporter', // Exporter Settings Key |
| 57 | + { |
| 58 | + outputJsonPath: { |
| 59 | + title: tl( |
| 60 | + 'animatedJava.exporters.rawAnimation.settings.outputJson.title' |
| 61 | + ), |
| 62 | + description: tl( |
| 63 | + 'animatedJava.exporters.rawAnimations.settings.outputJson.description' |
| 64 | + ), |
| 65 | + type: 'filepath', |
| 66 | + default: '', |
| 67 | + optional: true, |
| 68 | + props: { |
| 69 | + dialogOpts: { |
| 70 | + get defaultPath() { |
| 71 | + return `output.json` |
| 72 | + }, |
| 73 | + promptToCreate: true, |
| 74 | + properties: ['openFile'], |
| 75 | + }, |
| 76 | + }, |
| 77 | + onUpdate(d: aj.SettingDescriptor) { |
| 78 | + if (d.value === '') { |
| 79 | + d.isValid = false |
| 80 | + d.error = genericEmptySettingText |
| 81 | + } |
| 82 | + return d |
| 83 | + }, |
| 84 | + }, |
| 85 | + } |
| 86 | + ) |
| 87 | + AJ.registerExportFunc('rawAnimationExporter', function () { |
| 88 | + AJ.build( |
| 89 | + (exportData: aj.ExportData) => { |
| 90 | + console.log('Input Data:', exportData) |
| 91 | + rawExport(exportData) |
| 92 | + }, |
| 93 | + { |
| 94 | + generate_static_animation: true, |
| 95 | + } |
| 96 | + ) |
| 97 | + }) |
| 98 | +} |
| 99 | + |
| 100 | +if (Reflect.has(window, 'ANIMATED_JAVA')) { |
| 101 | + Exporter(window['ANIMATED_JAVA']) |
| 102 | +} else { |
| 103 | + // @ts-ignore |
| 104 | + Blockbench.on('animated-java-ready', Exporter) |
| 105 | +} |
0 commit comments