Skip to content

Commit 995dda2

Browse files
committed
✨ Add support for multi-version data pack exporting
1 parent 8f232d6 commit 995dda2

File tree

12 files changed

+469
-313
lines changed

12 files changed

+469
-313
lines changed

src/lang/en.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ animated_java.dialog.unexpected_error.paragraph: 'Please report this error by jo
5252
## Blueprint Settings Dialog
5353
animated_java.dialog.blueprint_settings.title: Blueprint Settings
5454
animated_java.dialog.blueprint_settings.advanced_settings_warning: Advanced settings should only be used if absolutely needed!
55+
5556
animated_java.dialog.blueprint_settings.blueprint_name.title: Blueprint Name
56-
animated_java.dialog.blueprint_settings.blueprint_name.description: The name of the Blueprint. Only used to identify the project in the workspace.
57+
animated_java.dialog.blueprint_settings.blueprint_name.description: The filename of the Blueprint.
5758

5859
animated_java.dialog.blueprint_settings.texture_size.title: Texture Size
5960
animated_java.dialog.blueprint_settings.texture_size.description: The resolution of the UV editor. This should be the same size as the largest texture. For best results use a square texture, and make sure it's size is a power of 2.

src/systems/animationRenderer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as crypto from 'crypto'
2+
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../interface/dialog/exportProgress'
23
import {
34
getKeyframeCommands,
45
getKeyframeExecuteCondition,
@@ -12,6 +13,7 @@ import { VanillaItemDisplay } from '../outliner/vanillaItemDisplay'
1213
import { sanitizePathName, sanitizeStorageKey } from '../util/minecraftUtil'
1314
import { eulerFromQuaternion, roundToNth } from '../util/misc'
1415
import { AnyRenderedNode, IRenderedRig } from './rigRenderer'
16+
import { sleepForAnimationFrame } from './util'
1517

1618
export function correctSceneAngle() {
1719
main_preview.controls.rotateLeft(Math.PI)
@@ -388,14 +390,18 @@ export function getAnimatableNodes(): OutlinerElement[] {
388390
]
389391
}
390392

391-
export function renderProjectAnimations(project: ModelProject, rig: IRenderedRig) {
393+
export async function renderProjectAnimations(project: ModelProject, rig: IRenderedRig) {
392394
// Clear the cache
393395
lastAnimation = undefined
394396
lastFrameCache = new Map()
395397
keyframeCache = new Map()
396398
excludedNodesCache = new Set()
397399
nodeCache = new Map()
398400

401+
PROGRESS_DESCRIPTION.set('Rendering Animations...')
402+
PROGRESS.set(0)
403+
MAX_PROGRESS.set(project.animations.length)
404+
399405
console.time('Rendering animations took')
400406
let selectedAnimation: _Animation | undefined
401407
let currentTime = 0
@@ -410,6 +416,8 @@ export function renderProjectAnimations(project: ModelProject, rig: IRenderedRig
410416
const animations: IRenderedAnimation[] = []
411417
for (const animation of project.animations) {
412418
animations.push(renderAnimation(animation, rig))
419+
PROGRESS.set(PROGRESS.get() + 1)
420+
await sleepForAnimationFrame()
413421
}
414422
restoreSceneAngle()
415423

src/systems/cleaner.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { isFunctionTagPath } from '../util/fileUtil'
22
import { IFunctionTag, parseDataPackPath } from '../util/minecraftUtil'
3-
import { DataPackAJMeta } from './datapackCompiler'
43
import { getExportPaths } from './exporter'
5-
import { ResourcePackAJMeta } from './resourcepackCompiler/global'
4+
import { AJMeta } from './global'
65
import { replacePathPart } from './util'
76

87
export async function cleanupExportedFiles() {
@@ -17,7 +16,7 @@ export async function cleanupExportedFiles() {
1716

1817
if (aj.resource_pack_export_mode === 'raw') {
1918
const assetsMetaPath = PathModule.join(resourcePackFolder, 'assets.ajmeta')
20-
const assetsMeta = new ResourcePackAJMeta(
19+
const assetsMeta = new AJMeta(
2120
assetsMetaPath,
2221
aj.export_namespace,
2322
Project!.last_used_export_namespace,
@@ -69,7 +68,7 @@ export async function cleanupExportedFiles() {
6968

7069
if (aj.data_pack_export_mode === 'raw') {
7170
const dataMetaPath = PathModule.join(dataPackFolder, 'data.ajmeta')
72-
const dataMeta = new DataPackAJMeta(
71+
const dataMeta = new AJMeta(
7372
dataMetaPath,
7473
aj.export_namespace,
7574
Project!.last_used_export_namespace,
@@ -81,7 +80,7 @@ export async function cleanupExportedFiles() {
8180
// PROGRESS.set(0)
8281
// MAX_PROGRESS.set(dataMeta.oldFiles.size)
8382
const removedFolders = new Set<string>()
84-
for (const file of dataMeta.oldFiles) {
83+
for (const file of [...dataMeta.previousCoreFiles, ...dataMeta.previousVersionedFiles]) {
8584
if (isFunctionTagPath(file) && fs.existsSync(file)) {
8685
if (aj.export_namespace !== Project!.last_used_export_namespace) {
8786
const resourceLocation = parseDataPackPath(file)!.resourceLocation

src/systems/datapackCompiler/compiler.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import { Parser, SyncIo, Tokenizer } from 'mc-build'
22
import { Compiler, VariableMap } from 'mc-build/dist/mcl/Compiler'
33
import { getDataPackFormat } from '../../util/minecraftUtil'
4+
import { MinecraftVersion } from '../global'
5+
import { ExportedFile } from '../util'
46

5-
export function compile(
6-
path: string,
7-
mcbFile: string,
8-
destPath: string,
7+
interface CompilerOptions {
8+
path: string
9+
mcbFile: string
10+
destPath: string
911
variables: Record<string, any>
10-
) {
12+
version: MinecraftVersion
13+
exportedFiles: Map<string, ExportedFile>
14+
}
15+
16+
export function compile({
17+
path,
18+
mcbFile,
19+
destPath,
20+
variables,
21+
version,
22+
exportedFiles,
23+
}: CompilerOptions) {
1124
console.group('Compiling', path)
1225
console.log('Variables:', variables)
1326

14-
const exportedFiles = new Map<string, string>()
1527
const compiler = new Compiler('src/', {
1628
libDir: null,
1729
generatedDirName: 'zzz',
@@ -22,7 +34,7 @@ export function compile(
2234
ioThreadCount: null,
2335
dontEmitComments: true,
2436
setup: null,
25-
formatVersion: getDataPackFormat(Project!.animated_java.target_minecraft_versions),
37+
formatVersion: getDataPackFormat(version),
2638
})
2739
compiler.disableRequire = true
2840
compiler.templateParsingEnabled = false
@@ -31,7 +43,10 @@ export function compile(
3143
const io = new SyncIo()
3244
io.write = (localPath, content) => {
3345
const writePath = PathModule.join(destPath, localPath)
34-
exportedFiles.set(writePath, content)
46+
exportedFiles.set(writePath, {
47+
content,
48+
includeInAJMeta: true,
49+
})
3550
}
3651
return io
3752
}

0 commit comments

Comments
 (0)