Skip to content

Commit d6deeb6

Browse files
committed
✨ Add node config property display configuration
Allows customization of how config properties values are represented in the UI. E.g. Makes it possible to differentiate between a file path and a string.
1 parent 475c34a commit d6deeb6

File tree

7 files changed

+134
-47
lines changed

7 files changed

+134
-47
lines changed

src/lang/en.yml

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,42 +89,43 @@ dialog:
8989
label: Storage-based
9090
description: 42% Slower than function-based, but creates far fewer function files.
9191

92+
config:
93+
common:
94+
label: Common
95+
options:
96+
billboard: Billboard
97+
brightnessOverride: Brightness
98+
glowColor: Glow Color
99+
glowing: Glowing
100+
inheritSettings: Inherit Settings
101+
invisible: Invisible
102+
nbt: NBT
103+
overrideBrightness: Override Brightness
104+
overrideGlowColor: Override Glow Color
105+
shadowRadius: Shadow Radius
106+
shadowStrength: Shadow Strength
107+
useNBT: Use NBT
108+
109+
animated_java:text_display:
110+
label: Text Display
111+
options:
112+
alignment: Alignment
113+
backgroundColor: Background Color
114+
lineWidth: Line Width
115+
seeThrough: See Through
116+
shadow: Shadow
117+
textComponent: Text Component
118+
119+
animated_java:item_display:
120+
label: Item Display
121+
122+
animated_java:block_display:
123+
label: Block Display
124+
92125
panel:
93126
display:
94127
title: Display
95128

96-
common:
97-
label: Common
98-
options:
99-
billboard: Billboard
100-
brightnessOverride: Brightness
101-
glowColor: Glow Color
102-
glowing: Glowing
103-
inheritSettings: Inherit Settings
104-
invisible: Invisible
105-
nbt: NBT
106-
overrideBrightness: Override Brightness
107-
overrideGlowColor: Override Glow Color
108-
shadowRadius: Shadow Radius
109-
shadowStrength: Shadow Strength
110-
useNBT: Use NBT
111-
112-
animated_java:text_display:
113-
label: Text Display
114-
options:
115-
alignment: Alignment
116-
backgroundColor: Background Color
117-
lineWidth: Line Width
118-
seeThrough: See Through
119-
shadow: Shadow
120-
textComponent: Text Component
121-
122-
animated_java:item_display:
123-
label: Item Display
124-
125-
animated_java:block_display:
126-
label: Block Display
127-
128129
node:
129130
structure.title: |-
130131
Structure - (Animated Java)

src/systems/node-configs/index.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,61 @@ export class BlockDisplayConfig extends SerializableConfig<BlockDisplayConfig> {
126126

127127
@SerializableConfig.decorate
128128
export class TextDisplayConfig extends SerializableConfig<TextDisplayConfig> {
129-
alignment: Alignment = 'center'
129+
@SerializableConfig.configurePropertyDisplay({
130+
get displayName() {
131+
return translate('config.animated_java:text_display.options.alignment')
132+
},
133+
displayMode: 'select',
134+
options: ['center', 'left', 'right'],
135+
})
136+
alignment?: Alignment = 'center'
137+
138+
@SerializableConfig.configurePropertyDisplay({
139+
get displayName() {
140+
return translate('config.animated_java:text_display.options.backgroundColor')
141+
},
142+
displayMode: 'color',
143+
})
130144
backgroundColor = '#0000003f'
145+
146+
@SerializableConfig.configurePropertyDisplay({
147+
get displayName() {
148+
return translate('config.animated_java:text_display.options.lineWidth')
149+
},
150+
displayMode: 'color',
151+
})
131152
lineWidth? = 200
132-
seeThrough = false
133-
shadow = false
153+
154+
@SerializableConfig.configurePropertyDisplay({
155+
get displayName() {
156+
return translate('config.animated_java:text_display.options.seeThrough')
157+
},
158+
displayMode: 'checkbox',
159+
})
160+
seeThrough? = false
161+
162+
@SerializableConfig.configurePropertyDisplay({
163+
get displayName() {
164+
return translate('config.animated_java:text_display.options.shadow')
165+
},
166+
displayMode: 'checkbox',
167+
})
168+
shadow? = false
169+
170+
@SerializableConfig.configurePropertyDisplay({
171+
get displayName() {
172+
return translate('config.animated_java:text_display.options.textComponent')
173+
},
174+
displayMode: 'code_editor',
175+
syntax: 'json',
176+
})
134177
textComponent?: string
135178

136179
public toNBT(compound = new NbtCompound()) {
137180
console.error('toNBT not implemented for TextDisplayConfig!')
138181
return compound
139182
}
140183
}
184+
185+
const TEST = new TextDisplayConfig()
186+
console.log(TEST, TEST.getPropertyDescription('alignment'))

src/systems/node-configs/serializableConfig.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class SerializableConfig<
4242
__inheritedKeys__: Array<keyof T>
4343
},
4444
> {
45+
private static __propertyDisplayConfigs__: Partial<Record<string, PropertyDisplayConfig>> = {}
46+
4547
private __defaultValues__ = {} as Record<string, any>
4648
private __inheritedKeys__ = new Set<keyof T>()
4749
private __getLocal__ = false
@@ -301,6 +303,10 @@ export class SerializableConfig<
301303
return entries
302304
}
303305

306+
getPropertyDescription<Key extends keyof T>(key: Key): PropertyDisplayConfig | undefined {
307+
return this.constructor.prototype.__propertyDisplayConfigs__?.[key]
308+
}
309+
304310
/**
305311
* Decorator to make a class a serializable config.
306312
*/
@@ -316,4 +322,34 @@ export class SerializableConfig<
316322
},
317323
})
318324
}
325+
326+
static configurePropertyDisplay(options: PropertyDisplayConfig) {
327+
return ((target, key) => {
328+
target.constructor.prototype.__propertyDisplayConfigs__ ??= {}
329+
target.constructor.prototype.__propertyDisplayConfigs__[key] = options
330+
}) satisfies PropertyDecorator
331+
}
332+
}
333+
334+
interface IPropertyDisplayConfig {
335+
displayName: string
336+
}
337+
338+
interface IPropertyDisplayConfigs {
339+
select: IPropertyDisplayConfig & {
340+
displayMode: 'select'
341+
options: string[]
342+
}
343+
color: IPropertyDisplayConfig & {
344+
displayMode: 'color'
345+
}
346+
checkbox: IPropertyDisplayConfig & {
347+
displayMode: 'checkbox'
348+
}
349+
code_editor: IPropertyDisplayConfig & {
350+
displayMode: 'code_editor'
351+
syntax: string
352+
}
319353
}
354+
355+
export type PropertyDisplayConfig = IPropertyDisplayConfigs[keyof IPropertyDisplayConfigs]

src/ui/dialogs/bone-config/boneConfig.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<script lang="ts">
2-
import Checkbox from '@svelte-components/dialog-items/checkbox.svelte'
3-
2+
43
import { Valuable } from '../../../util/stores'
54
import { translate } from '../../../util/translation'
65
76
import { JsonText } from '@aj/systems/minecraft-temp/jsonText'
87
import { NbtCompound, NbtTag } from 'deepslate/lib/nbt'
9-
import NodeConfigOption from './nodeConfigOption.svelte'
108
119
const IS_PLUGIN_MODE = Project?.animated_java?.environment === 'plugin'
1210

src/ui/panels/display-panel/displayPanel.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
}}
9292
>
9393
{translate(
94-
`panel.display.${selectedNode && Object.getPrototypeOf(selectedNode).constructor.type}.label`
94+
`config.${selectedNode && Object.getPrototypeOf(selectedNode).constructor.type}.label`
9595
)}
9696
</p>
9797
<!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -101,7 +101,7 @@
101101
commonTabSelected = true
102102
}}
103103
>
104-
{translate('panel.display.common.label')}
104+
{translate('config.common.label')}
105105
</p>
106106
</div>
107107

@@ -113,7 +113,7 @@
113113
<li>
114114
<div>
115115
<div class="option-title">
116-
{translate(`panel.display.common.options.${key}`)}
116+
{translate(`config.common.options.${key}`)}
117117
</div>
118118
<div class="option-mode">{commonOptionModes.get(key)}</div>
119119
<!-- svelte-ignore a11y-click-events-have-key-events -->

src/ui/panels/display-panel/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ TEXT_DISPLAY_ALIGNMENT_SELECT.get = function () {
144144
const selected = TextDisplay.selected[0]
145145
if (!selected) return 'left'
146146
const config = new TextDisplayConfig().fromJSON(selected.config)
147-
return config.alignment
147+
return config.alignment!
148148
}
149149
TEXT_DISPLAY_ALIGNMENT_SELECT.set = function (this: BarSelect<Alignment>, value: Alignment) {
150150
const selected = TextDisplay.selected[0]

src/ui/panels/display-panel/textDisplayPage.svelte

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
5252
import { TextDisplay } from '@aj/blockbench-additions/outliner-elements/textDisplay'
5353
import { TextDisplayConfig } from '@aj/systems/node-configs'
54-
import { translate } from '@aj/util/translation'
5554
import { MODE_ICONS, type OptionMode } from '.'
5655
5756
export let textDisplay: TextDisplay
@@ -100,10 +99,11 @@
10099

101100
<ul class="option-list">
102101
{#each config.keys(true) as key}
102+
{@const display = config.getPropertyDescription(key)}
103103
<li>
104104
<div>
105105
<div class="option-title">
106-
{translate(`panel.display.animated_java:text_display.options.${key}`)}
106+
{display?.displayName}
107107
</div>
108108
<div class="option-mode">{OPTION_MODES.get(key)}</div>
109109
<!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -115,9 +115,15 @@
115115
</i>
116116
</div>
117117
{#if OPTION_MODES.get(key) === 'custom'}
118-
<div class="option-value">
119-
<input type="text" value={config[key]} />
120-
</div>
118+
{#if display?.displayMode === 'checkbox'}
119+
<div class="option-value">
120+
<input type="checkbox" checked={!!config[key]} />
121+
</div>
122+
{:else}
123+
<div class="option-value">
124+
<input type="text" value={config[key]} />
125+
</div>
126+
{/if}
121127
{/if}
122128
</li>
123129
{/each}

0 commit comments

Comments
 (0)