forked from JannisX11/blockbench-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
168 lines (158 loc) · 5.35 KB
/
Copy pathindex.js
File metadata and controls
168 lines (158 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* AzureLib Animator — Blockbench Plugin Entry
* -------------------------------------------
* Registers the AzureLib animation format and editor utilities.
*
* © 2025 AzureDoom — MIT License
*/
import semverCoerce from 'semver/functions/coerce.js';
import semverSatisfies from 'semver/functions/satisfies.js';
import pkg from './package.json' assert { type: 'json' };
import {
initializeAnimationUI,
unloadAnimationUI
} from './animation/azure-animation-ui.js';
import {
registerKeyframeOverrides,
unregisterKeyframeOverrides
} from './animation/azure-keyframes.js';
import AzureConfig, {
TYPE_OPTIONS,
onSettingsChanged
} from './core/azure-settings.js';
import codec, {
registerAzureCodec,
unregisterAzureCodec,
maybeExportItemJson,
maybeImportItemJson
} from './core/azure-codec.js';
import { restoreOverrides } from './core/azure-utils.js';
const { version, blockbenchConfig } = pkg;
const RANGE = `${blockbenchConfig.min_version} - ${blockbenchConfig.max_version}`;
if (!semverSatisfies(semverCoerce(Blockbench.version), RANGE)) {
alert(`AzureLib Animator supports Blockbench ${RANGE}. Update for best results.`);
}
(function () {
let exportAction, exportDisplay, importDisplay, settingsButton;
Plugin.register('azurelib_utils', {
...blockbenchConfig,
version,
await_loading: true,
onload() {
registerAzureCodec();
initializeAnimationUI();
registerKeyframeOverrides();
console.log('[AzureLib] Animator loaded');
Blockbench.on('ready', () => {
setTimeout(() => {
if (!Keyframe.prototype._azurePatched) {
console.log('[AzureLib] Reattaching keyframe overrides after ready()');
registerKeyframeOverrides();
}
}, 0);
});
// Auto show settings for Azure model
Blockbench.on('new_project', () => {
if (Format?.id === 'azure_model') {
setTimeout(() => {
try {
Interface.dialog?.close();
} catch {}
new Dialog({
id: 'azurelib_model_settings',
title: 'AzureLib Model Settings',
width: 540,
lines: [
`<b class="tl"><a href="https://wiki.azuredoom.com/">AzureLib</a> Animator v${version}</b>`,
'<p>Select your model type to begin.</p>',
],
form: {
objectType: {
label: 'Object Type',
type: 'select',
default: AzureConfig.objectType,
options: TYPE_OPTIONS,
},
},
onConfirm(form) {
Object.assign(AzureConfig, form);
onSettingsChanged();
},
}).show();
}, 150);
}
});
exportAction = new Action({
id: 'export_AzureLib_model',
name: 'Export AzureLib .geo Model',
icon: 'archive',
description: 'Export your .geo model for AzureLib.',
category: 'file',
condition: () => Format.id === 'azure_model',
click: () => codec.export(),
});
MenuBar.addAction(exportAction, 'file.export');
exportDisplay = new Action({
id: 'export_AzureLib_display',
name: 'Export AzureLib Display Settings',
icon: 'icon-bb_interface',
category: 'file',
description: 'Export display settings for AzureLib.',
condition: () => Format.id === 'azure_model',
click: maybeExportItemJson,
});
MenuBar.addAction(exportDisplay, 'file.export');
importDisplay = new Action({
id: 'import_AzureLib_display',
name: 'Import AzureLib Display Settings',
icon: 'icon-bow',
category: 'file',
condition: () => Format.id === 'azure_model',
click: maybeImportItemJson,
});
MenuBar.addAction(importDisplay, 'file.import');
settingsButton = new Action('azurelib_settings', {
name: 'AzureLib Model Settings',
description: 'Change model type',
icon: 'info',
condition: () => Format.id === 'azure_model',
click: () => {
const dialog = new Dialog({
id: 'project',
title: 'AzureLib Model Settings',
width: 540,
lines: [
`<b class="tl"><a href="https://wiki.azuredoom.com/">AzureLib</a> Animator v${version}</b>`,
],
form: {
objectType: {
label: 'Object Type',
type: 'select',
default: AzureConfig.objectType,
options: TYPE_OPTIONS,
},
},
onConfirm: result => {
Object.assign(AzureConfig, result);
onSettingsChanged();
dialog.hide();
},
});
dialog.show();
},
});
MenuBar.addAction(settingsButton, 'file.1');
},
onunload() {
exportAction.delete();
exportDisplay.delete();
importDisplay.delete();
settingsButton.delete();
unregisterKeyframeOverrides();
unloadAnimationUI();
unregisterAzureCodec();
restoreOverrides();
console.log('[AzureLib] Animator unloaded.');
},
});
})();