Skip to content

Commit 57b5c8c

Browse files
committed
✨ JSON Text shadow_color property (#336)
1 parent 5a33793 commit 57b5c8c

File tree

4 files changed

+114
-52
lines changed

4 files changed

+114
-52
lines changed

src/systems/minecraft/fontManager.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,16 @@ export class MinecraftFont {
514514
? new THREE.Color(style.color)
515515
: new THREE.Color(COLOR_MAP[style.color]) || color
516516
}
517-
const shadowColor = color.clone().multiplyScalar(0.25)
517+
518+
let shadowColor: THREE.Color
519+
if (typeof style.shadow_color === 'string') {
520+
shadowColor =
521+
style.shadow_color.startsWith('#') && style.shadow_color.length === 7
522+
? new THREE.Color(style.shadow_color)
523+
: new THREE.Color(COLOR_MAP[style.shadow_color]) || color
524+
} else {
525+
shadowColor = color.clone().multiplyScalar(0.25)
526+
}
518527

519528
const boldExtra = style.bold ? 1 : 0
520529

src/systems/minecraft/jsonText.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type JsonTextObject = {
4444
text?: string
4545
font?: string
4646
color?: JsonTextColor
47+
shadow_color?: JsonTextColor
4748
extra?: JsonTextArray
4849
bold?: true | false
4950
italic?: true | false
@@ -296,12 +297,17 @@ class JsonTextParser {
296297
case 'fallback':
297298
obj[key] = this.parseString()
298299
break
299-
case 'color': {
300+
case 'color':
301+
case 'shadow_color': {
300302
const color = this.parseString() as JsonTextColor
301303
if (!(color.startsWith('#') || COLOR_MAP[color])) {
302304
throw new ParserError(`Unknown color '${color}'`, this.s)
303305
}
304-
obj.color = color
306+
if (key === 'color') {
307+
obj.color = color
308+
} else {
309+
obj.shadow_color = color
310+
}
305311
break
306312
}
307313
case 'bold':

src/systems/minecraft/textWrapping.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const STYLE_KEYS = [
1919
'obfuscated',
2020
'color',
2121
'font',
22+
'shadow_color',
2223
] as const
2324

2425
export type StyleRecord = Partial<Record<(typeof STYLE_KEYS)[number], boolean | string>>

0 commit comments

Comments
 (0)