@@ -2,17 +2,27 @@ import { Type as RecsType, Schema } from "@dojoengine/recs";
2
2
3
3
export function convertValues ( schema : Schema , values : any ) {
4
4
return Object . keys ( schema ) . reduce < any > ( ( acc , key ) => {
5
- const schemaType = schema [ key ] ;
6
- const value = values [ key ] ;
5
+ let schemaType = schema [ key ] ;
6
+ let value = values [ key ] ;
7
7
8
8
if ( value == null ) {
9
9
acc [ key ] = value ;
10
10
return acc ;
11
11
}
12
12
13
13
if ( value . type === "enum" ) {
14
- acc [ key ] = value . value . option ;
15
- return acc ;
14
+ if ( value . type_name && value . type_name . includes ( "Option" ) ) {
15
+ if ( value . value . option === "None" ) {
16
+ acc [ key ] = null ;
17
+ return acc ;
18
+ } else {
19
+ schemaType = mapOptionalToRealType ( schemaType ) ;
20
+ value = value . value . value ;
21
+ }
22
+ } else {
23
+ acc [ key ] = value . value . option ;
24
+ return acc ;
25
+ }
16
26
}
17
27
18
28
switch ( schemaType ) {
@@ -45,6 +55,31 @@ export function convertValues(schema: Schema, values: any) {
45
55
} , { } ) ;
46
56
}
47
57
58
+ function mapOptionalToRealType ( schemaType : any ) {
59
+ switch ( schemaType ) {
60
+ case RecsType . OptionalNumber :
61
+ return RecsType . Number ;
62
+ case RecsType . OptionalBigInt :
63
+ return RecsType . BigInt ;
64
+ case RecsType . OptionalString :
65
+ return RecsType . String ;
66
+ case RecsType . OptionalNumberArray :
67
+ return RecsType . NumberArray ;
68
+ case RecsType . OptionalBigIntArray :
69
+ return RecsType . BigIntArray ;
70
+ case RecsType . OptionalStringArray :
71
+ return RecsType . StringArray ;
72
+ case RecsType . OptionalEntity :
73
+ return RecsType . Entity ;
74
+ case RecsType . OptionalEntityArray :
75
+ return RecsType . EntityArray ;
76
+ case RecsType . OptionalT :
77
+ return RecsType . T ;
78
+ default :
79
+ return schemaType ;
80
+ }
81
+ }
82
+
48
83
function handleStringArray ( value : any ) {
49
84
if ( value . type === "array" && value . value . length === 0 ) {
50
85
return [ ] ;
0 commit comments