Skip to content

Commit b50c64f

Browse files
committed
Blackout screen while exporting to prevent user interference
1 parent 8ecc816 commit b50c64f

File tree

6 files changed

+95
-35
lines changed

6 files changed

+95
-35
lines changed

exporters/datapackExporter/datapackExporter.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ export function loadExporter() {
4242
'animated_java.datapack_exporter.settings.interpolation_duration.description'
4343
).split('\n'),
4444
},
45-
outdated_rig_warning: {
46-
name: API.translate('animated_java.datapack_exporter.settings.outdated_rig_warning'),
45+
enable_outdated_rig_warning: {
46+
name: API.translate(
47+
'animated_java.datapack_exporter.settings.enable_outdated_rig_warning'
48+
),
4749
description: API.translate(
48-
'animated_java.datapack_exporter.settings.outdated_rig_warning.description'
50+
'animated_java.datapack_exporter.settings.enable_outdated_rig_warning.description'
4951
).split('\n'),
5052
},
5153
include_convenience_functions: {
@@ -56,6 +58,14 @@ export function loadExporter() {
5658
'animated_java.datapack_exporter.settings.include_convenience_functions.description'
5759
).split('\n'),
5860
},
61+
// enable_single_rig_optimizations: {
62+
// name: API.translate(
63+
// 'animated_java.datapack_exporter.settings.enable_single_rig_optimizations'
64+
// ),
65+
// description: API.translate(
66+
// 'animated_java.datapack_exporter.settings.enable_single_rig_optimizations.description'
67+
// ).split('\n'),
68+
// },
5969
root_entity_nbt: {
6070
name: API.translate('animated_java.datapack_exporter.settings.root_entity_nbt'),
6171
description: API.translate(
@@ -87,25 +97,17 @@ export function loadExporter() {
8797
)
8898
}
8999

90-
const _export: (typeof API.Exporter)['prototype']['export'] = async (
91-
ajSettings,
92-
projectSettings,
93-
exporterSettings,
94-
renderedAnimations,
95-
rig
96-
) => {
100+
const _export: (typeof API.Exporter)['prototype']['export'] = async exportData => {
97101
if (!Project?.animated_java_variants) throw new Error('No variants found')
98-
console.log('Animated Java Settings', ajSettings)
99-
console.log('Project Settings', projectSettings)
100-
console.log('Exporter Settings', exporterSettings)
101-
console.log('Rendered Animations', renderedAnimations)
102-
console.log('Rig', rig)
102+
console.log('Export Options', exportData)
103103

104104
console.log('Beginning export process...')
105105

106106
//--------------------------------------------
107-
// ANCHOR Settings
107+
// ANCHOR Settings and Export Options
108108
//--------------------------------------------
109+
const { ajSettings, projectSettings, exporterSettings, renderedAnimations, rig } =
110+
exportData
109111
const NAMESPACE = projectSettings.project_namespace.value
110112
const RIG_ITEM = projectSettings.rig_item.value
111113
const EXPORT_FOLDER = PathModule.parse(exporterSettings.datapack_mcmeta.value).dir
@@ -1070,8 +1072,8 @@ export function loadExporter() {
10701072
}),
10711073
outdated_rig_warning: new API.Settings.CheckboxSetting({
10721074
id: 'animated_java:datapack_exporter/outdated_rig_warning',
1073-
displayName: TRANSLATIONS.outdated_rig_warning.name,
1074-
description: TRANSLATIONS.outdated_rig_warning.description,
1075+
displayName: TRANSLATIONS.enable_outdated_rig_warning.name,
1076+
description: TRANSLATIONS.enable_outdated_rig_warning.description,
10751077
defaultValue: true,
10761078
}),
10771079
include_convenience_functions: new API.Settings.CheckboxSetting({
@@ -1080,6 +1082,12 @@ export function loadExporter() {
10801082
description: TRANSLATIONS.include_convenience_functions.description,
10811083
defaultValue: true,
10821084
}),
1085+
// enable_single_rig_optimizations: new API.Settings.CheckboxSetting({
1086+
// id: 'animated_java:datapack_exporter/enable_single_rig_optimizations',
1087+
// displayName: TRANSLATIONS.enable_single_rig_optimizations.name,
1088+
// description: TRANSLATIONS.enable_single_rig_optimizations.description,
1089+
// defaultValue: false,
1090+
// }),
10831091
root_entity_nbt: new API.Settings.CodeboxSetting(
10841092
{
10851093
id: 'animated_java:datapack_exporter/root_entity_nbt',
@@ -1115,6 +1123,10 @@ export function loadExporter() {
11151123
type: 'setting',
11161124
settingId: 'animated_java:datapack_exporter/include_convenience_functions',
11171125
},
1126+
// {
1127+
// type: 'setting',
1128+
// settingId: 'animated_java:datapack_exporter/enable_single_rig_optimizations',
1129+
// },
11181130
{
11191131
type: 'setting',
11201132
settingId: 'animated_java:datapack_exporter/root_entity_nbt',

exporters/datapackExporter/lang/en.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ animated_java.datapack_exporter.settings.interpolation_duration.description: |-
1616
Setting this higher than 1 will cause the animation to be smoother, but lose precision.
1717
Setting this to 0 will disable interpolation.
1818
19-
animated_java.datapack_exporter.settings.outdated_rig_warning: Outdated Rig Warning
20-
animated_java.datapack_exporter.settings.outdated_rig_warning.description: |-
19+
animated_java.datapack_exporter.settings.enable_outdated_rig_warning: Enable Outdated Rig Warning
20+
animated_java.datapack_exporter.settings.enable_outdated_rig_warning.description: |-
2121
Whether to show a warning in-game when a Rig is found that was summoned before the most recent export.
2222
23+
# animated_java.datapack_exporter.settings.enable_single_rig_optimizations: Enable Single Rig Optimizations
24+
# animated_java.datapack_exporter.settings.enable_single_rig_optimizations.description: |-
25+
# Whether to enable optimizations that are only possible when there is only one Rig in the world at a time.
26+
# These optimizations will reduce the performance impact of the generated Data Pack, but will prevent you from having multiple Rigs in the world at once.
27+
2328
animated_java.datapack_exporter.settings.include_convenience_functions: Include Convenience Functions
2429
animated_java.datapack_exporter.settings.include_convenience_functions.description: |-
2530
Whether to include convenience functions in the generated Data Pack.

exporters/rawExporter/rawExporter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export function loadExporter() {
2828
settingId: 'animated_java:raw_exporter/foo',
2929
},
3030
],
31-
async export(ajSettings, projectSettings, exporterSettings) {
32-
console.log(ajSettings, projectSettings, exporterSettings)
31+
async export(exportOptions) {
32+
console.log('Export Options:', exportOptions)
33+
const { ajSettings, projectSettings, exporterSettings } = exportOptions
3334
// Temporary placeholder to hide "no await" warning
3435
await new Promise(resolve => setTimeout(resolve, 100))
3536
},

src/exporter.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ import { translate } from './util/translation'
1414

1515
type ProjectSettings = Record<NamespacedString, AJSetting<any>>
1616

17+
export interface IAnimatedJavaExportData<S> {
18+
ajSettings: typeof animatedJavaSettings
19+
projectSettings: ProjectSettings
20+
exporterSettings: S
21+
renderedAnimations: IRenderedAnimation[]
22+
rig: IRenderedRig
23+
}
24+
1725
interface IAnimatedJavaExporterOptions<S extends ProjectSettings> {
1826
id: NamespacedString
1927
name: string
2028
description: string
2129
getSettings(): S
2230
settingsStructure: GUIStructure
2331
onStartup?: () => void
24-
export(
25-
ajSettings: typeof animatedJavaSettings,
26-
projectSettings: NotUndefined<ModelProject['animated_java_settings']>,
27-
exporterSettings: S,
28-
renderedAnimations: IRenderedAnimation[],
29-
rig: IRenderedRig
30-
): Promise<void> | void
32+
export(exportData: IAnimatedJavaExportData<S>): Promise<void> | void
3133
}
3234

3335
export class AnimatedJavaExporter<
@@ -83,6 +85,11 @@ export const exportProject = consoleGroupCollapsed('exportProject', async () =>
8385
verifyProjectExportReadiness()
8486
if (!Project?.animated_java_settings) return // Project being optional is annoying
8587

88+
// Pre-export
89+
const selectedVariant = Project.animated_java_variants!.selectedVariant!
90+
Project.animated_java_variants?.select()
91+
jQuery('#blackout').show()
92+
8693
const selectedExporterId = Project?.animated_java_settings?.exporter?.selected
8794
?.value as NamespacedString
8895

@@ -143,9 +150,18 @@ export const exportProject = consoleGroupCollapsed('exportProject', async () =>
143150
rigItemModelExportPath
144151
)
145152
// Resources MUST be exported before the exporter is ran
146-
await exporter.export(ajSettings, projectSettings, exporterSettings, renderedAnimations, rig)
153+
await exporter.export({
154+
ajSettings,
155+
projectSettings: projectSettings as any,
156+
exporterSettings,
157+
renderedAnimations,
158+
rig,
159+
})
147160

148161
Blockbench.showQuickMessage(translate('animated_java.quickmessage.exported_successfully'), 2000)
162+
// Post-export
163+
Project.animated_java_variants?.select(selectedVariant)
164+
jQuery('#blackout').hide()
149165
})
150166

151167
function verifySettings(structure: GUIStructure, settings: Array<Setting<any>>) {

src/modelDataFixerUpper.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FORMAT_VERSION, IAnimatedJavaModel } from './modelFormat'
2+
import { openUnexpectedErrorDialog } from './ui/popups/unexpectedError'
23

34
export function process(model: any) {
45
if (model.meta.model_format === 'animatedJava/ajmodel') {
@@ -11,16 +12,41 @@ export function process(model: any) {
1112

1213
console.log('Upgrading model from version', model.meta.format_version, 'to', FORMAT_VERSION)
1314

14-
if (compareVersions('1.0', model.meta.format_version)) updateModelTo1_0(model)
15-
if (compareVersions('1.1', model.meta.format_version)) updateModelTo1_1(model)
16-
if (compareVersions('1.2', model.meta.format_version)) updateModelTo1_2(model)
17-
if (compareVersions('1.3', model.meta.format_version)) updateModelTo1_3(model)
15+
try {
16+
if (compareVersions('1.0', model.meta.format_version)) updateModelTo1_0(model)
17+
if (compareVersions('1.1', model.meta.format_version)) updateModelTo1_1(model)
18+
if (compareVersions('1.2', model.meta.format_version)) updateModelTo1_2(model)
19+
if (compareVersions('1.3', model.meta.format_version)) updateModelTo1_3(model)
20+
if (compareVersions('1.4', model.meta.format_version)) updateModelTo1_4(model)
21+
} catch (e) {
22+
console.error(e)
23+
openUnexpectedErrorDialog(e)
24+
void Project?.close(true)
25+
return
26+
}
1827

1928
model.meta.format_version ??= FORMAT_VERSION
2029

2130
console.log('Upgrade complete')
2231
}
2332

33+
// eslint-disable-next-line @typescript-eslint/naming-convention
34+
function updateModelTo1_4(model: any) {
35+
if (
36+
model.animated_java.exporter_settings['animated_java:datapack_exporter']
37+
.outdated_rig_warning
38+
) {
39+
model.animated_java.exporter_settings[
40+
'animated_java:datapack_exporter'
41+
].enable_outdated_rig_warning =
42+
model.animated_java.exporter_settings[
43+
'animated_java:datapack_exporter'
44+
].outdated_rig_warning
45+
delete model.animated_java.exporter_settings['animated_java:datapack_exporter']
46+
.outdated_rig_warning
47+
}
48+
}
49+
2450
// eslint-disable-next-line @typescript-eslint/naming-convention
2551
function updateModelTo1_3(model: any) {
2652
if (model.animated_java.settings.exporter === 'animated_java:animation_exporter') {

src/modelFormat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { consoleGroup, consoleGroupCollapsed } from './util/console'
99
import { createBlockbenchMod } from './util/moddingTools'
1010
import { IBoneConfig, TextureMap, Variant, VariantsContainer } from './variants'
1111

12-
export const FORMAT_VERSION = '1.3'
12+
export const FORMAT_VERSION = '1.4'
1313

1414
function addProjectToRecentProjects(file: FileResult) {
1515
if (!Project || !file.path) return

0 commit comments

Comments
 (0)