Skip to content

Commit 8e18234

Browse files
authored
Rename layout text override field to textStyle (#9)
* Rename layout element style overrides to textStyle * Add YAML coverage for layout textStyle overrides
1 parent 4caeb10 commit 8e18234

File tree

5 files changed

+604
-13
lines changed

5 files changed

+604
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@routevn/creator-model",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"private": false,
55
"type": "module",
66
"license": "MIT",

src/model.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,10 +2095,14 @@ const validateCharacterSpriteItems = ({ items, path, errorFactory }) => {
20952095
}
20962096
};
20972097

2098-
const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2098+
const validateLayoutElementTextStyle = ({
2099+
textStyle,
2100+
path,
2101+
errorFactory,
2102+
}) => {
20992103
{
21002104
const result = validateAllowedKeys({
2101-
value: style,
2105+
value: textStyle,
21022106
allowedKeys: ["align", "wordWrapWidth"],
21032107
path,
21042108
errorFactory,
@@ -2109,8 +2113,8 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
21092113
}
21102114

21112115
if (
2112-
style.align !== undefined &&
2113-
!LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS.includes(style.align)
2116+
textStyle.align !== undefined &&
2117+
!LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS.includes(textStyle.align)
21142118
) {
21152119
return invalidFromErrorFactory(
21162120
errorFactory,
@@ -2119,8 +2123,8 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
21192123
}
21202124

21212125
if (
2122-
style.wordWrapWidth !== undefined &&
2123-
!isFiniteNumber(style.wordWrapWidth)
2126+
textStyle.wordWrapWidth !== undefined &&
2127+
!isFiniteNumber(textStyle.wordWrapWidth)
21242128
) {
21252129
return invalidFromErrorFactory(
21262130
errorFactory,
@@ -2196,7 +2200,7 @@ const validateLayoutElementData = ({
21962200
"fill",
21972201
"border",
21982202
"text",
2199-
"style",
2203+
"textStyle",
22002204
"displaySpeed",
22012205
"imageId",
22022206
"hoverImageId",
@@ -2359,11 +2363,11 @@ const validateLayoutElementData = ({
23592363
);
23602364
}
23612365

2362-
if (data.style !== undefined) {
2366+
if (data.textStyle !== undefined) {
23632367
{
2364-
const result = validateLayoutElementStyle({
2365-
style: data.style,
2366-
path: `${path}.style`,
2368+
const result = validateLayoutElementTextStyle({
2369+
textStyle: data.textStyle,
2370+
path: `${path}.textStyle`,
23672371
errorFactory,
23682372
});
23692373
if (result?.valid === false) {
@@ -2438,7 +2442,7 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
24382442
"fill",
24392443
"border",
24402444
"text",
2441-
"style",
2445+
"textStyle",
24422446
"displaySpeed",
24432447
"imageId",
24442448
"hoverImageId",

tests/characters-and-layouts.spec.yaml

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,257 @@ out:
626626
- id: layout-dialogue
627627
children: []
628628
---
629+
case: layout.element.update applies textStyle overrides to a text element
630+
in:
631+
- state:
632+
project: {}
633+
story:
634+
initialSceneId: null
635+
scenes:
636+
items: {}
637+
tree: []
638+
files:
639+
items:
640+
file-font:
641+
id: file-font
642+
type: font
643+
mimeType: font/ttf
644+
size: 1
645+
sha256: file-font-sha256
646+
tree:
647+
- id: file-font
648+
children: []
649+
images:
650+
items: {}
651+
tree: []
652+
sounds:
653+
items: {}
654+
tree: []
655+
videos:
656+
items: {}
657+
tree: []
658+
animations:
659+
items: {}
660+
tree: []
661+
characters:
662+
items: {}
663+
tree: []
664+
fonts:
665+
items:
666+
font-ui:
667+
id: font-ui
668+
type: font
669+
name: UI Font
670+
fileId: file-font
671+
fontFamily: Suit
672+
tree:
673+
- id: font-ui
674+
children: []
675+
transforms:
676+
items: {}
677+
tree: []
678+
colors:
679+
items:
680+
color-ui:
681+
id: color-ui
682+
type: color
683+
name: White
684+
hex: '#ffffff'
685+
tree:
686+
- id: color-ui
687+
children: []
688+
textStyles:
689+
items:
690+
style-ui:
691+
id: style-ui
692+
type: textStyle
693+
name: Dialogue
694+
fontId: font-ui
695+
colorId: color-ui
696+
fontSize: 32
697+
lineHeight: 1.4
698+
fontWeight: '700'
699+
tree:
700+
- id: style-ui
701+
children: []
702+
variables:
703+
items: {}
704+
tree: []
705+
layouts:
706+
items:
707+
layout-dialogue:
708+
id: layout-dialogue
709+
type: layout
710+
name: Dialogue
711+
layoutType: dialogue
712+
elements:
713+
items:
714+
container-root:
715+
id: container-root
716+
type: container
717+
name: Root
718+
x: 0
719+
'y': 0
720+
width: 100
721+
height: 100
722+
anchorX: 0
723+
anchorY: 0
724+
scaleX: 1
725+
scaleY: 1
726+
rotation: 0
727+
text-title:
728+
id: text-title
729+
type: text
730+
name: Title
731+
x: 10
732+
'y': 12
733+
anchorX: 0
734+
anchorY: 0
735+
scaleX: 1
736+
scaleY: 1
737+
rotation: 0
738+
text: Hello
739+
textStyleId: style-ui
740+
tree:
741+
- id: container-root
742+
children:
743+
- id: text-title
744+
children: []
745+
tree:
746+
- id: layout-dialogue
747+
children: []
748+
command:
749+
type: layout.element.update
750+
payload:
751+
layoutId: layout-dialogue
752+
elementId: text-title
753+
replace: false
754+
data:
755+
textStyle:
756+
align: center
757+
wordWrapWidth: 480
758+
out:
759+
state:
760+
project: {}
761+
story:
762+
initialSceneId: null
763+
scenes:
764+
items: {}
765+
tree: []
766+
files:
767+
items:
768+
file-font:
769+
id: file-font
770+
type: font
771+
mimeType: font/ttf
772+
size: 1
773+
sha256: file-font-sha256
774+
tree:
775+
- id: file-font
776+
children: []
777+
images:
778+
items: {}
779+
tree: []
780+
sounds:
781+
items: {}
782+
tree: []
783+
videos:
784+
items: {}
785+
tree: []
786+
animations:
787+
items: {}
788+
tree: []
789+
characters:
790+
items: {}
791+
tree: []
792+
fonts:
793+
items:
794+
font-ui:
795+
id: font-ui
796+
type: font
797+
name: UI Font
798+
fileId: file-font
799+
fontFamily: Suit
800+
tree:
801+
- id: font-ui
802+
children: []
803+
transforms:
804+
items: {}
805+
tree: []
806+
colors:
807+
items:
808+
color-ui:
809+
id: color-ui
810+
type: color
811+
name: White
812+
hex: '#ffffff'
813+
tree:
814+
- id: color-ui
815+
children: []
816+
textStyles:
817+
items:
818+
style-ui:
819+
id: style-ui
820+
type: textStyle
821+
name: Dialogue
822+
fontId: font-ui
823+
colorId: color-ui
824+
fontSize: 32
825+
lineHeight: 1.4
826+
fontWeight: '700'
827+
tree:
828+
- id: style-ui
829+
children: []
830+
variables:
831+
items: {}
832+
tree: []
833+
layouts:
834+
items:
835+
layout-dialogue:
836+
id: layout-dialogue
837+
type: layout
838+
name: Dialogue
839+
layoutType: dialogue
840+
elements:
841+
items:
842+
container-root:
843+
id: container-root
844+
type: container
845+
name: Root
846+
x: 0
847+
'y': 0
848+
width: 100
849+
height: 100
850+
anchorX: 0
851+
anchorY: 0
852+
scaleX: 1
853+
scaleY: 1
854+
rotation: 0
855+
text-title:
856+
id: text-title
857+
type: text
858+
name: Title
859+
x: 10
860+
'y': 12
861+
anchorX: 0
862+
anchorY: 0
863+
scaleX: 1
864+
scaleY: 1
865+
rotation: 0
866+
text: Hello
867+
textStyleId: style-ui
868+
textStyle:
869+
align: center
870+
wordWrapWidth: 480
871+
tree:
872+
- id: container-root
873+
children:
874+
- id: text-title
875+
children: []
876+
tree:
877+
- id: layout-dialogue
878+
children: []
879+
---
629880
suite: validatePayload
630881
exportName: validatePayload
631882
---
@@ -638,3 +889,14 @@ in:
638889
data:
639890
opacity: 2
640891
throws: payload.data.opacity must be a finite number between 0 and 1 when provided
892+
---
893+
case: layout.element.update rejects legacy style overrides
894+
in:
895+
- type: layout.element.update
896+
payload:
897+
layoutId: layout-dialogue
898+
elementId: text-title
899+
data:
900+
style:
901+
align: center
902+
throws: payload.data.style is not allowed

0 commit comments

Comments
 (0)