Skip to content

Commit b541871

Browse files
authored
Add layout reveal effect validation (#12)
1 parent 8219309 commit b541871

File tree

4 files changed

+327
-32
lines changed

4 files changed

+327
-32
lines changed

src/model.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const VARIABLE_SCOPE_KEYS = ["context", "global-device", "global-account"];
109109
const VARIABLE_TYPE_KEYS = ["string", "number", "boolean"];
110110
const LAYOUT_TYPE_KEYS = ["normal", "dialogue", "nvl", "choice"];
111111
const LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS = ["left", "center", "right"];
112+
const LAYOUT_TEXT_REVEAL_EFFECT_KEYS = ["typewriter", "softWipe", "none"];
112113
const LAYOUT_ELEMENT_BASE_TYPES = [
113114
"folder",
114115
"container",
@@ -2095,11 +2096,7 @@ const validateCharacterSpriteItems = ({ items, path, errorFactory }) => {
20952096
}
20962097
};
20972098

2098-
const validateLayoutElementTextStyle = ({
2099-
textStyle,
2100-
path,
2101-
errorFactory,
2102-
}) => {
2099+
const validateLayoutElementTextStyle = ({ textStyle, path, errorFactory }) => {
21032100
{
21042101
const result = validateAllowedKeys({
21052102
value: textStyle,
@@ -2202,6 +2199,7 @@ const validateLayoutElementData = ({
22022199
"text",
22032200
"textStyle",
22042201
"displaySpeed",
2202+
"revealEffect",
22052203
"imageId",
22062204
"hoverImageId",
22072205
"clickImageId",
@@ -2314,6 +2312,7 @@ const validateLayoutElementData = ({
23142312
"clickTextStyleId",
23152313
"containerType",
23162314
"variableId",
2315+
"revealEffect",
23172316
"thumbImageId",
23182317
"barImageId",
23192318
"hoverThumbImageId",
@@ -2335,6 +2334,16 @@ const validateLayoutElementData = ({
23352334
);
23362335
}
23372336

2337+
if (
2338+
data.revealEffect !== undefined &&
2339+
!LAYOUT_TEXT_REVEAL_EFFECT_KEYS.includes(data.revealEffect)
2340+
) {
2341+
return invalidFromErrorFactory(
2342+
errorFactory,
2343+
`${path}.revealEffect must be one of ${LAYOUT_TEXT_REVEAL_EFFECT_KEYS.join(", ")} when provided`,
2344+
);
2345+
}
2346+
23382347
if (
23392348
data.direction !== undefined &&
23402349
data.direction !== "horizontal" &&
@@ -2444,6 +2453,7 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
24442453
"text",
24452454
"textStyle",
24462455
"displaySpeed",
2456+
"revealEffect",
24472457
"imageId",
24482458
"hoverImageId",
24492459
"clickImageId",

tests/characters-and-layouts.spec.yaml

Lines changed: 171 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ in:
6060
type: character
6161
name: Hero
6262
description: Main actor
63-
shortcut: '1'
63+
shortcut: "1"
6464
out:
6565
state:
6666
project: {}
@@ -91,7 +91,7 @@ out:
9191
type: character
9292
name: Hero
9393
description: Main actor
94-
shortcut: '1'
94+
shortcut: "1"
9595
sprites:
9696
items: {}
9797
tree: []
@@ -440,7 +440,7 @@ in:
440440
id: color-ui
441441
type: color
442442
name: White
443-
hex: '#ffffff'
443+
hex: "#ffffff"
444444
tree:
445445
- id: color-ui
446446
children: []
@@ -454,7 +454,7 @@ in:
454454
colorId: color-ui
455455
fontSize: 32
456456
lineHeight: 1.4
457-
fontWeight: '700'
457+
fontWeight: "700"
458458
tree:
459459
- id: style-ui
460460
children: []
@@ -475,7 +475,7 @@ in:
475475
type: container
476476
name: Root
477477
x: 0
478-
'y': 0
478+
"y": 0
479479
width: 100
480480
height: 100
481481
anchorX: 0
@@ -499,7 +499,7 @@ in:
499499
type: text
500500
name: Title
501501
x: 10
502-
'y': 12
502+
"y": 12
503503
anchorX: 0
504504
anchorY: 0
505505
scaleX: 1
@@ -561,7 +561,7 @@ out:
561561
id: color-ui
562562
type: color
563563
name: White
564-
hex: '#ffffff'
564+
hex: "#ffffff"
565565
tree:
566566
- id: color-ui
567567
children: []
@@ -575,7 +575,7 @@ out:
575575
colorId: color-ui
576576
fontSize: 32
577577
lineHeight: 1.4
578-
fontWeight: '700'
578+
fontWeight: "700"
579579
tree:
580580
- id: style-ui
581581
children: []
@@ -596,7 +596,7 @@ out:
596596
type: container
597597
name: Root
598598
x: 0
599-
'y': 0
599+
"y": 0
600600
width: 100
601601
height: 100
602602
anchorX: 0
@@ -609,7 +609,7 @@ out:
609609
type: text
610610
name: Title
611611
x: 10
612-
'y': 12
612+
"y": 12
613613
anchorX: 0
614614
anchorY: 0
615615
scaleX: 1
@@ -681,7 +681,7 @@ in:
681681
id: color-ui
682682
type: color
683683
name: White
684-
hex: '#ffffff'
684+
hex: "#ffffff"
685685
tree:
686686
- id: color-ui
687687
children: []
@@ -695,7 +695,7 @@ in:
695695
colorId: color-ui
696696
fontSize: 32
697697
lineHeight: 1.4
698-
fontWeight: '700'
698+
fontWeight: "700"
699699
tree:
700700
- id: style-ui
701701
children: []
@@ -716,7 +716,7 @@ in:
716716
type: container
717717
name: Root
718718
x: 0
719-
'y': 0
719+
"y": 0
720720
width: 100
721721
height: 100
722722
anchorX: 0
@@ -729,7 +729,7 @@ in:
729729
type: text
730730
name: Title
731731
x: 10
732-
'y': 12
732+
"y": 12
733733
anchorX: 0
734734
anchorY: 0
735735
scaleX: 1
@@ -809,7 +809,7 @@ out:
809809
id: color-ui
810810
type: color
811811
name: White
812-
hex: '#ffffff'
812+
hex: "#ffffff"
813813
tree:
814814
- id: color-ui
815815
children: []
@@ -823,7 +823,7 @@ out:
823823
colorId: color-ui
824824
fontSize: 32
825825
lineHeight: 1.4
826-
fontWeight: '700'
826+
fontWeight: "700"
827827
tree:
828828
- id: style-ui
829829
children: []
@@ -844,7 +844,7 @@ out:
844844
type: container
845845
name: Root
846846
x: 0
847-
'y': 0
847+
"y": 0
848848
width: 100
849849
height: 100
850850
anchorX: 0
@@ -857,7 +857,7 @@ out:
857857
type: text
858858
name: Title
859859
x: 10
860-
'y': 12
860+
"y": 12
861861
anchorX: 0
862862
anchorY: 0
863863
scaleX: 1
@@ -877,6 +877,149 @@ out:
877877
- id: layout-dialogue
878878
children: []
879879
---
880+
case: layout.element.update applies revealEffect to a text-revealing element
881+
in:
882+
- state:
883+
project: {}
884+
story:
885+
initialSceneId: null
886+
scenes:
887+
items: {}
888+
tree: []
889+
files:
890+
items: {}
891+
tree: []
892+
images:
893+
items: {}
894+
tree: []
895+
sounds:
896+
items: {}
897+
tree: []
898+
videos:
899+
items: {}
900+
tree: []
901+
animations:
902+
items: {}
903+
tree: []
904+
characters:
905+
items: {}
906+
tree: []
907+
fonts:
908+
items: {}
909+
tree: []
910+
transforms:
911+
items: {}
912+
tree: []
913+
colors:
914+
items: {}
915+
tree: []
916+
textStyles:
917+
items: {}
918+
tree: []
919+
variables:
920+
items: {}
921+
tree: []
922+
layouts:
923+
items:
924+
layout-dialogue:
925+
id: layout-dialogue
926+
type: layout
927+
name: Dialogue
928+
layoutType: dialogue
929+
elements:
930+
items:
931+
text-dialogue:
932+
id: text-dialogue
933+
type: text-revealing-ref-dialogue-content
934+
name: Dialogue
935+
x: 10
936+
"y": 12
937+
anchorX: 0
938+
anchorY: 0
939+
scaleX: 1
940+
scaleY: 1
941+
rotation: 0
942+
tree:
943+
- id: text-dialogue
944+
tree:
945+
- id: layout-dialogue
946+
children: []
947+
command:
948+
type: layout.element.update
949+
payload:
950+
layoutId: layout-dialogue
951+
elementId: text-dialogue
952+
replace: false
953+
data:
954+
revealEffect: softWipe
955+
out:
956+
state:
957+
project: {}
958+
story:
959+
initialSceneId: null
960+
scenes:
961+
items: {}
962+
tree: []
963+
files:
964+
items: {}
965+
tree: []
966+
images:
967+
items: {}
968+
tree: []
969+
sounds:
970+
items: {}
971+
tree: []
972+
videos:
973+
items: {}
974+
tree: []
975+
animations:
976+
items: {}
977+
tree: []
978+
characters:
979+
items: {}
980+
tree: []
981+
fonts:
982+
items: {}
983+
tree: []
984+
transforms:
985+
items: {}
986+
tree: []
987+
colors:
988+
items: {}
989+
tree: []
990+
textStyles:
991+
items: {}
992+
tree: []
993+
variables:
994+
items: {}
995+
tree: []
996+
layouts:
997+
items:
998+
layout-dialogue:
999+
id: layout-dialogue
1000+
type: layout
1001+
name: Dialogue
1002+
layoutType: dialogue
1003+
elements:
1004+
items:
1005+
text-dialogue:
1006+
id: text-dialogue
1007+
type: text-revealing-ref-dialogue-content
1008+
name: Dialogue
1009+
x: 10
1010+
"y": 12
1011+
anchorX: 0
1012+
anchorY: 0
1013+
scaleX: 1
1014+
scaleY: 1
1015+
rotation: 0
1016+
revealEffect: softWipe
1017+
tree:
1018+
- id: text-dialogue
1019+
tree:
1020+
- id: layout-dialogue
1021+
children: []
1022+
---
8801023
suite: validatePayload
8811024
exportName: validatePayload
8821025
---
@@ -900,3 +1043,13 @@ in:
9001043
style:
9011044
align: center
9021045
throws: payload.data.style is not allowed
1046+
---
1047+
case: layout.element.update rejects invalid revealEffect
1048+
in:
1049+
- type: layout.element.update
1050+
payload:
1051+
layoutId: layout-dialogue
1052+
elementId: text-title
1053+
data:
1054+
revealEffect: sparkle
1055+
throws: payload.data.revealEffect must be one of typewriter, softWipe, none when provided

0 commit comments

Comments
 (0)