11import { JsonTextParser } from 'src/systems/jsonText/parser'
2- import { registerMountSvelteComponentMod } from 'src/util/mountSvelteComponent'
2+ import EVENTS from 'src/util/events'
3+ import { registerProjectMod } from 'src/util/moddingTools'
4+ import { mountSvelteComponent } from 'src/util/mountSvelteComponent'
35import TextDisplayElementPanel from '../../components/textDisplayElementPanel.svelte'
4- import { activeProjectIsBlueprintFormat } from '../../formats/blueprint'
6+ import { activeProjectIsBlueprintFormat , BLUEPRINT_FORMAT_ID } from '../../formats/blueprint'
57import { type Alignment , TextDisplay } from '../../outliner/textDisplay'
68import { translate } from '../../util/translation'
79
8- registerMountSvelteComponentMod ( {
9- id : 'animated-java:panel/text-display' ,
10- component : TextDisplayElementPanel ,
11- target : '#panel_element' ,
10+ let mounted : TextDisplayElementPanel | null = null
11+
12+ const destroyMounted = ( ) => {
13+ mounted ?. $destroy ( )
14+ mounted = null
15+ }
16+
17+ const updatePanel = ( ) => {
18+ destroyMounted ( )
19+ const textDisplay = TextDisplay . selected . at ( 0 )
20+ if ( textDisplay ) {
21+ mounted = mountSvelteComponent ( {
22+ component : TextDisplayElementPanel ,
23+ props : { selected : textDisplay } ,
24+ target : '#panel_element' ,
25+ } )
26+ }
27+ }
28+
29+ registerProjectMod ( {
30+ id : 'animated-java:append-element-panel/text-display' ,
31+
32+ condition : project => project . format . id === BLUEPRINT_FORMAT_ID ,
33+
34+ apply : ( ) => {
35+ const unsubscribers = [ EVENTS . UPDATE_SELECTION . subscribe ( updatePanel ) ]
36+ return { unsubscribers }
37+ } ,
38+
39+ revert : ( { unsubscribers } ) => {
40+ unsubscribers . forEach ( u => u ( ) )
41+ destroyMounted ( )
42+ } ,
1243} )
1344
1445type Grammar = ReturnType < typeof Prism . languages . extend >
@@ -103,6 +134,7 @@ export const TEXT_DISPLAY_WIDTH_SLIDER = new NumSlider(
103134 const newLineWidth = Math . clamp ( value ( selected . lineWidth ) , 1 , 10000 )
104135 if ( selected . lineWidth === newLineWidth ) return
105136 selected . lineWidth = newLineWidth
137+ selected . updateTextMesh ( )
106138 Project . saved = false
107139 } ,
108140 }
@@ -135,7 +167,13 @@ TEXT_DISPLAY_BACKGROUND_COLOR_PICKER.set = function (this: ColorPicker, color: t
135167
136168 const selected = TextDisplay . selected . at ( 0 )
137169 if ( ! selected ) return this
170+
171+ const value = color . toHex8String ( )
172+ if ( selected . backgroundColor === value ) return this
173+
138174 selected . backgroundColor = color . toHex8String ( )
175+ selected . updateTextMesh ( )
176+ Project ! . saved = false
139177 return this
140178}
141179TEXT_DISPLAY_BACKGROUND_COLOR_PICKER . change = function (
@@ -145,9 +183,13 @@ TEXT_DISPLAY_BACKGROUND_COLOR_PICKER.change = function (
145183 if ( ! Project ) return this
146184 const selected = TextDisplay . selected . at ( 0 )
147185 if ( ! selected ) return this
186+
148187 const newBackground = color . toHex8String ( )
188+
149189 if ( selected . backgroundColor === newBackground ) return this
190+
150191 selected . backgroundColor = newBackground
192+ selected . updateTextMesh ( )
151193 Project ! . saved = false
152194 return this
153195}
@@ -166,6 +208,7 @@ export const TEXT_DISPLAY_SHADOW_TOGGLE = new Toggle(`animated-java:text-display
166208 if ( ! selected ) return
167209 if ( selected . shadow === TEXT_DISPLAY_SHADOW_TOGGLE . value ) return
168210 selected . shadow = TEXT_DISPLAY_SHADOW_TOGGLE . value
211+ selected . updateTextMesh ( )
169212 Project ! . saved = false
170213 } ,
171214} )
@@ -205,7 +248,12 @@ TEXT_DISPLAY_ALIGNMENT_SELECT.set = function (this: BarSelect<Alignment>, value:
205248 if ( ! this . nodes . includes ( this . node ) ) {
206249 $ ( this . node ) . find ( 'bb-select' ) . text ( name )
207250 }
251+
252+ if ( selected . align === value ) return this
253+
208254 selected . align = value
255+ selected . updateTextMesh ( )
256+ Project ! . saved = false
209257 return this
210258}
211259
@@ -224,6 +272,7 @@ export const TEXT_DISPLAY_SEE_THROUGH_TOGGLE = new Toggle(
224272 if ( ! selected ) return
225273 if ( selected . seeThrough === TEXT_DISPLAY_SEE_THROUGH_TOGGLE . value ) return
226274 selected . seeThrough = TEXT_DISPLAY_SEE_THROUGH_TOGGLE . value
275+ selected . updateTextMesh ( )
227276 Project ! . saved = false
228277 } ,
229278 }
0 commit comments