Skip to content

Commit 4e76edf

Browse files
committed
🎨 Renderer name sanitization improvements & data pack compiler consistency fixes
- Renamed `safe_name` to `path_name` in `IRenderedAnimation` and `IRenderedNode` - Added `storage_name` to `IRenderedAnimation` and `IRenderedNode` - Renamed `minecraftUtil`'s `toSafeFunctionName` to `sanitizePathName` - Added `sanitizeStorageKey` to `minecraftUtil` - Fixed `sanitizePathName` replacing repeated underscores from source name with a single underscore. - Fixed some minor inconsistencies in .mcb files between data pack compiler versions.
1 parent f356972 commit 4e76edf

File tree

21 files changed

+549
-521
lines changed

21 files changed

+549
-521
lines changed

‎src/blueprintFormat.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BillboardMode, BoneConfig, LocatorConfig } from './nodeConfigs'
66
import { process } from './systems/modelDataFixerUpper'
77
import { events } from './util/events'
88
import { injectSvelteCompomponent } from './util/injectSvelteComponent'
9-
import { toSafeFuntionName } from './util/minecraftUtil'
9+
import { sanitizePathName } from './util/minecraftUtil'
1010
import { addProjectToRecentProjects } from './util/misc'
1111
import { Valuable } from './util/stores'
1212
import { translate } from './util/translation'
@@ -164,7 +164,7 @@ export function convertToBlueprint() {
164164
}
165165
for (const animation of Blockbench.Animation.all) {
166166
animation.createUniqueName(Blockbench.Animation.all.filter(a => a !== animation))
167-
animation.name = toSafeFuntionName(animation.name)
167+
animation.name = sanitizePathName(animation.name)
168168
}
169169
for (const cube of Cube.all) {
170170
cube.setUVMode(false)
@@ -340,7 +340,7 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
340340
parseGroups(model.outliner)
341341

342342
for (const group of Group.all) {
343-
group.name = toSafeFuntionName(group.name)
343+
group.name = sanitizePathName(group.name)
344344
}
345345
}
346346

‎src/interface/dialog/blueprintSettings.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defaultValues, ExportMode } from '../../blueprintSettings'
33
import BlueprintSettingsDialogSvelteComponent from '../../components/blueprintSettingsDialog.svelte'
44
import { PACKAGE } from '../../constants'
55
import { MinecraftVersion } from '../../systems/datapackCompiler/mcbFiles'
6-
import { toSafeFuntionName } from '../../util/minecraftUtil'
6+
import { sanitizePathName } from '../../util/minecraftUtil'
77
import { Valuable } from '../../util/stores'
88
import { SvelteDialog } from '../../util/svelteDialog'
99
import { translate } from '../../util/translation'
@@ -28,7 +28,7 @@ function getSettings() {
2828
if (!value) {
2929
return defaultValues.export_namespace
3030
}
31-
return toSafeFuntionName(value)
31+
return sanitizePathName(value)
3232
}),
3333
resourcePackExportMode: new Valuable(
3434
Project!.animated_java.resource_pack_export_mode as string

‎src/interface/importAJModelLoader.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { SvelteComponentDev } from 'svelte/internal'
2+
import { BLUEPRINT_CODEC, IBlueprintFormatJSON } from '../blueprintFormat'
23
import ImportAjModelLoaderDialog from '../components/importAJModelLoaderDialog.svelte'
34
import { PACKAGE } from '../constants'
5+
import * as ModelDatFixerUpper from '../systems/modelDataFixerUpper'
46
import { injectSvelteCompomponent } from '../util/injectSvelteComponent'
7+
import { sanitizePathName } from '../util/minecraftUtil'
58
import { createModelLoader } from '../util/moddingTools'
69
import { translate } from '../util/translation'
710
import { openUnexpectedErrorDialog } from './dialog/unexpectedError'
8-
import * as ModelDatFixerUpper from '../systems/modelDataFixerUpper'
9-
import { BLUEPRINT_CODEC, IBlueprintFormatJSON } from '../blueprintFormat'
10-
import { toSafeFuntionName } from '../util/minecraftUtil'
1111

1212
let activeComponent: SvelteComponentDev | null = null
1313

@@ -52,7 +52,7 @@ export function convertAJModelToBlueprint(path: string) {
5252
name: 'Upgrade .ajmodel to Blueprint',
5353
path,
5454
})
55-
blueprint.blueprint_settings!.export_namespace ??= toSafeFuntionName(Project!.name)
55+
blueprint.blueprint_settings!.export_namespace ??= sanitizePathName(Project!.name)
5656

5757
requestAnimationFrame(() => {
5858
Project!.save_path = ''

‎src/outliner/util.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { toSafeFuntionName } from '../util/minecraftUtil'
1+
import { sanitizePathName } from '../util/minecraftUtil'
22
import { TextDisplay } from './textDisplay'
33
import { VanillaBlockDisplay } from './vanillaBlockDisplay'
44
import { VanillaItemDisplay } from './vanillaItemDisplay'
55

66
export function sanitizeOutlinerElementName(name: string, elementUUID: string): string {
7-
name = toSafeFuntionName(name)
7+
name = sanitizePathName(name)
88
let otherNodes: OutlinerElement[] = [
99
...VanillaBlockDisplay.all,
1010
...Group.all,

‎src/systems/animationRenderer.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as crypto from 'crypto'
12
import {
23
getKeyframeCommands,
34
getKeyframeExecuteCondition,
@@ -8,10 +9,9 @@ import {
89
import { TextDisplay } from '../outliner/textDisplay'
910
import { VanillaBlockDisplay } from '../outliner/vanillaBlockDisplay'
1011
import { VanillaItemDisplay } from '../outliner/vanillaItemDisplay'
11-
import { toSafeFuntionName } from '../util/minecraftUtil'
12+
import { sanitizePathName, sanitizeStorageKey } from '../util/minecraftUtil'
1213
import { eulerFromQuaternion, roundToNth } from '../util/misc'
1314
import { AnyRenderedNode, IRenderedRig } from './rigRenderer'
14-
import * as crypto from 'crypto'
1515

1616
export function correctSceneAngle() {
1717
main_preview.controls.rotateLeft(Math.PI)
@@ -86,8 +86,11 @@ export interface IRenderedFrame {
8686

8787
export interface IRenderedAnimation {
8888
name: string
89+
/** A sanitized version of {@link IRenderedAnimation.name} that is safe to use in a path in a data pack or resource pack.*/
90+
path_name: string
91+
/** A sanitized version of {@link IRenderedAnimation.name} that is safe to use as a key in a storage object. */
92+
storage_name: string
8993
uuid: string
90-
safe_name: string
9194
loop_delay: number
9295
frames: IRenderedFrame[]
9396
/**
@@ -302,8 +305,9 @@ export function updatePreview(animation: _Animation, time: number) {
302305
export function renderAnimation(animation: _Animation, rig: IRenderedRig) {
303306
const rendered = {
304307
name: animation.name,
308+
path_name: sanitizePathName(animation.name),
309+
storage_name: sanitizeStorageKey(animation.name),
305310
uuid: animation.uuid,
306-
safe_name: toSafeFuntionName(animation.name).replaceAll('.', '_'),
307311
loop_delay: Number(animation.loop_delay) || 0,
308312
frames: [],
309313
duration: 0,

0 commit comments

Comments
 (0)