File tree Expand file tree Collapse file tree 9 files changed +99
-104
lines changed Expand file tree Collapse file tree 9 files changed +99
-104
lines changed Original file line number Diff line number Diff line change @@ -673,7 +673,7 @@ export function updateRotationLock() {
673
673
! ! AnimatedJava . API . TextDisplay . selected . length ||
674
674
! ! AnimatedJava . API . VanillaItemDisplay . selected . length ||
675
675
! ! AnimatedJava . API . VanillaBlockDisplay . selected . length ||
676
- ! ! ( OutlinerElement . types . camera ?. selected && OutlinerElement . types . camera ?. selected . length )
676
+ ! ! ( OutlinerElement . types . camera ?. selected && OutlinerElement . types . camera ?. selected )
677
677
)
678
678
BLUEPRINT_FORMAT . rotation_snap = BLUEPRINT_FORMAT . rotation_limit
679
679
}
Original file line number Diff line number Diff line change
1
+ import { isCurrentFormat } from '../blueprintFormat'
2
+ import { PACKAGE } from '../constants'
3
+ import { sanitizeOutlinerElementName } from '../outliner/util'
4
+ import { createBlockbenchMod } from '../util/moddingTools'
5
+
6
+ createBlockbenchMod (
7
+ `${ PACKAGE . name } :cameraNameMod` ,
8
+ {
9
+ originalRename : OutlinerElement . types . camera ?. prototype . saveName ,
10
+ originalSanitize : OutlinerElement . types . camera ?. prototype . sanitizeName ,
11
+ } ,
12
+ context => {
13
+ if ( OutlinerElement . types . camera ) {
14
+ OutlinerElement . types . camera . prototype . saveName = function (
15
+ this : OutlinerElement ,
16
+ save ?: boolean
17
+ ) {
18
+ if ( isCurrentFormat ( ) ) {
19
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
20
+ }
21
+ return context . originalRename . call ( this , save )
22
+ }
23
+ OutlinerElement . types . camera . prototype . sanitizeName = function ( this : OutlinerElement ) {
24
+ if ( isCurrentFormat ( ) ) {
25
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
26
+ }
27
+ return context . originalSanitize . call ( this )
28
+ }
29
+ }
30
+ return context
31
+ } ,
32
+ context => {
33
+ if ( OutlinerElement . types . camera ) {
34
+ OutlinerElement . types . camera . prototype . rename = context . originalRename
35
+ }
36
+ }
37
+ )
Original file line number Diff line number Diff line change 1
1
import { isCurrentFormat } from '../blueprintFormat'
2
2
import { PACKAGE } from '../constants'
3
- import { toSafeFuntionName } from '../util/minecraftUtil '
3
+ import { sanitizeOutlinerElementName } from '../outliner/util '
4
4
import { createBlockbenchMod } from '../util/moddingTools'
5
5
6
6
createBlockbenchMod (
@@ -12,13 +12,13 @@ createBlockbenchMod(
12
12
context => {
13
13
Group . prototype . saveName = function ( this : Group , save ?: boolean ) {
14
14
if ( isCurrentFormat ( ) ) {
15
- this . name = toSafeFuntionName ( this . name )
15
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
16
16
}
17
17
return context . originalRename . call ( this , save )
18
18
}
19
19
Group . prototype . sanitizeName = function ( this : Group ) {
20
20
if ( isCurrentFormat ( ) ) {
21
- this . name = toSafeFuntionName ( this . name )
21
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
22
22
}
23
23
return context . originalSanitize . call ( this )
24
24
}
Original file line number Diff line number Diff line change @@ -27,3 +27,4 @@ import './saveProjectActionMod'
27
27
import './saveProjectAsActionMod'
28
28
import './showDefaultPoseMod'
29
29
import './variantPreviewCubeFaceMod'
30
+ import './cameraNameMod'
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import { translate } from '../util/translation'
17
17
import { ResizableOutlinerElement } from './resizableOutlinerElement'
18
18
import { VanillaBlockDisplay } from './vanillaBlockDisplay'
19
19
import { VanillaItemDisplay } from './vanillaItemDisplay'
20
+ import { sanitizeOutlinerElementName } from './util'
20
21
21
22
interface TextDisplayOptions {
22
23
name ?: string
@@ -121,37 +122,8 @@ export class TextDisplay extends ResizableOutlinerElement {
121
122
}
122
123
123
124
public sanitizeName ( ) : string {
124
- this . name = toSafeFuntionName ( this . name )
125
- const otherNodes = [
126
- ...TextDisplay . all . filter ( v => v . uuid !== this . uuid ) ,
127
- ...Group . all ,
128
- ...VanillaBlockDisplay . all ,
129
- ...VanillaItemDisplay . all ,
130
- ]
131
- const otherNames = new Set ( otherNodes . map ( v => v . name ) )
132
-
133
- if ( ! otherNames . has ( this . name ) ) {
134
- return this . name
135
- }
136
-
137
- let i = 1
138
- const match = this . name . match ( / \d + $ / )
139
- if ( match ) {
140
- i = parseInt ( match [ 0 ] )
141
- this . name = this . name . slice ( 0 , - match [ 0 ] . length )
142
- }
143
-
144
- let maxTries = 10000
145
- while ( maxTries -- > 0 ) {
146
- const newName = `${ this . name } ${ i } `
147
- if ( ! otherNames . has ( newName ) ) {
148
- this . name = newName
149
- return newName
150
- }
151
- i ++
152
- }
153
-
154
- throw new Error ( 'Could not make TextDisplay name unique!' )
125
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
126
+ return this . name
155
127
}
156
128
157
129
get text ( ) {
Original file line number Diff line number Diff line change
1
+ import { toSafeFuntionName } from '../util/minecraftUtil'
2
+ import { TextDisplay } from './textDisplay'
3
+ import { VanillaBlockDisplay } from './vanillaBlockDisplay'
4
+ import { VanillaItemDisplay } from './vanillaItemDisplay'
5
+
6
+ export function sanitizeOutlinerElementName ( name : string , elementUUID : string ) : string {
7
+ name = toSafeFuntionName ( name )
8
+ const otherNodes : OutlinerElement [ ] = [
9
+ ...VanillaBlockDisplay . all . filter ( v => v . uuid !== elementUUID ) ,
10
+ ...Group . all ,
11
+ ...TextDisplay . all ,
12
+ ...VanillaItemDisplay . all ,
13
+ ]
14
+ if ( OutlinerElement . types . camera ) {
15
+ otherNodes . push ( OutlinerElement . types . camera )
16
+ }
17
+ const otherNames = new Set ( otherNodes . map ( v => v . name ) )
18
+
19
+ if ( ! otherNames . has ( name ) ) {
20
+ return name
21
+ }
22
+
23
+ let i = 1
24
+ const match = name . match ( / \d + $ / )
25
+ if ( match ) {
26
+ i = parseInt ( match [ 0 ] )
27
+ name = name . slice ( 0 , - match [ 0 ] . length )
28
+ }
29
+
30
+ let maxTries = 10000
31
+ while ( maxTries -- > 0 ) {
32
+ const newName = `${ name } ${ i } `
33
+ if ( ! otherNames . has ( newName ) ) {
34
+ name = newName
35
+ return newName
36
+ }
37
+ i ++
38
+ }
39
+
40
+ throw new Error ( `Could not make name unique for ${ name } (${ elementUUID } )!` )
41
+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { Valuable } from '../util/stores'
13
13
import { translate } from '../util/translation'
14
14
import { ResizableOutlinerElement } from './resizableOutlinerElement'
15
15
import { TextDisplay } from './textDisplay'
16
+ import { sanitizeOutlinerElementName } from './util'
16
17
import { VanillaItemDisplay } from './vanillaItemDisplay'
17
18
18
19
const ERROR_OUTLINE_MATERIAL = Canvas . outlineMaterial . clone ( )
@@ -116,37 +117,8 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
116
117
}
117
118
118
119
public sanitizeName ( ) : string {
119
- this . name = toSafeFuntionName ( this . name )
120
- const otherNodes = [
121
- ...VanillaBlockDisplay . all . filter ( v => v . uuid !== this . uuid ) ,
122
- ...Group . all ,
123
- ...TextDisplay . all ,
124
- ...VanillaItemDisplay . all ,
125
- ]
126
- const otherNames = new Set ( otherNodes . map ( v => v . name ) )
127
-
128
- if ( ! otherNames . has ( this . name ) ) {
129
- return this . name
130
- }
131
-
132
- let i = 1
133
- const match = this . name . match ( / \d + $ / )
134
- if ( match ) {
135
- i = parseInt ( match [ 0 ] )
136
- this . name = this . name . slice ( 0 , - match [ 0 ] . length )
137
- }
138
-
139
- let maxTries = 10000
140
- while ( maxTries -- > 0 ) {
141
- const newName = `${ this . name } ${ i } `
142
- if ( ! otherNames . has ( newName ) ) {
143
- this . name = newName
144
- return newName
145
- }
146
- i ++
147
- }
148
-
149
- throw new Error ( 'Could not make VanillaBlockDisplay name unique!' )
120
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
121
+ return this . name
150
122
}
151
123
152
124
getUndoCopy ( ) {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { Valuable } from '../util/stores'
12
12
import { translate } from '../util/translation'
13
13
import { ResizableOutlinerElement } from './resizableOutlinerElement'
14
14
import { TextDisplay } from './textDisplay'
15
+ import { sanitizeOutlinerElementName } from './util'
15
16
import { VanillaBlockDisplay } from './vanillaBlockDisplay'
16
17
17
18
interface VanillaItemDisplayOptions {
@@ -125,37 +126,8 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
125
126
}
126
127
127
128
public sanitizeName ( ) : string {
128
- this . name = toSafeFuntionName ( this . name )
129
- const otherNodes = [
130
- ...VanillaItemDisplay . all . filter ( v => v . uuid !== this . uuid ) ,
131
- ...Group . all ,
132
- ...TextDisplay . all ,
133
- ...VanillaBlockDisplay . all ,
134
- ]
135
- const otherNames = new Set ( otherNodes . map ( v => v . name ) )
136
-
137
- if ( ! otherNames . has ( this . name ) ) {
138
- return this . name
139
- }
140
-
141
- let i = 1
142
- const match = this . name . match ( / \d + $ / )
143
- if ( match ) {
144
- i = parseInt ( match [ 0 ] )
145
- this . name = this . name . slice ( 0 , - match [ 0 ] . length )
146
- }
147
-
148
- let maxTries = 10000
149
- while ( maxTries -- > 0 ) {
150
- const newName = `${ this . name } ${ i } `
151
- if ( ! otherNames . has ( newName ) ) {
152
- this . name = newName
153
- return newName
154
- }
155
- i ++
156
- }
157
-
158
- throw new Error ( 'Could not make VanillaItemDisplay name unique!' )
129
+ this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
130
+ return this . name
159
131
}
160
132
161
133
getUndoCopy ( ) {
Original file line number Diff line number Diff line change 41
41
},
42
42
"elements": [
43
43
{
44
- "name": "block_display ",
45
- "position": [-8 , 0, -8 ],
44
+ "name": "block_display1 ",
45
+ "position": [0 , 0, 0 ],
46
46
"rotation": [0, 0, 0],
47
47
"scale": [1, 1, 1],
48
48
"visibility": true,
49
+ "block": "minecraft:cobblestone_wall",
50
+ "config": {},
49
51
"item": "minecraft:diamond",
50
52
"item_display": "none",
51
- "config": {},
52
- "block": "cobblestone_wall[west=none]",
53
53
"text": "\"Hello World!\"",
54
54
"lineWidth": 200,
55
55
"backgroundColor": "#000000",
56
56
"backgroundAlpha": 0.25,
57
57
"align": "center",
58
58
"shadow": false,
59
59
"seeThrough": false,
60
- "uuid": "31411dd2-b8c3-79b4-8437-db3c8c27da55 ",
60
+ "uuid": "31d45ef8-ad50-c3aa-10fd-184027b767da ",
61
61
"type": "animated_java:vanilla_block_display"
62
62
}
63
63
],
64
- "outliner": ["31411dd2-b8c3-79b4-8437-db3c8c27da55 "],
64
+ "outliner": ["31d45ef8-ad50-c3aa-10fd-184027b767da "],
65
65
"textures": [
66
66
{
67
67
"path": "D:\\Dropbox\\Pictures\\memes\\images.png",
96
96
"default": {
97
97
"name": "default",
98
98
"display_name": "Default",
99
- "uuid": "5730fca2-be35-b294-f099-094000c29544 ",
99
+ "uuid": "291e925e-0d30-297a-dd08-40e0dd69ec24 ",
100
100
"texture_map": {},
101
101
"excluded_nodes": [],
102
102
"is_default": true
You can’t perform that action at this time.
0 commit comments