@@ -2,9 +2,12 @@ import {
2
2
Component ,
3
3
ComponentValue ,
4
4
Entity ,
5
+ getComponentValue ,
6
+ hasComponent ,
5
7
Metadata ,
6
8
Schema ,
7
9
setComponent ,
10
+ updateComponent ,
8
11
} from "@dojoengine/recs" ;
9
12
import {
10
13
Clause ,
@@ -405,26 +408,23 @@ export const setEntities = async <S extends Schema>(
405
408
406
409
if ( logging ) console . log ( "Entities to set:" , entities ) ;
407
410
408
- for ( let key in entities ) {
411
+ for ( const key in entities ) {
409
412
if ( ! Object . hasOwn ( entities , key ) ) {
410
413
continue ;
411
414
}
412
415
413
- for ( let componentName in entities [ key ] ) {
416
+ for ( const componentName in entities [ key ] ) {
414
417
if ( ! Object . hasOwn ( entities [ key ] , componentName ) ) {
415
418
continue ;
416
419
}
417
- let recsComponent = Object . values ( components ) . find (
418
- ( component ) =>
419
- component . metadata ?. namespace +
420
- "-" +
421
- component . metadata ?. name ===
422
- componentName
420
+ const recsComponent = Object . values ( components ) . find (
421
+ ( component ) => component . metadata ?. name === componentName
423
422
) ;
424
423
425
424
if ( recsComponent ) {
426
425
try {
427
426
const rawValue = entities [ key ] [ componentName ] ;
427
+
428
428
if ( logging )
429
429
console . log (
430
430
`Raw value for ${ componentName } on ${ key } :` ,
@@ -448,6 +448,19 @@ export const setEntities = async <S extends Schema>(
448
448
) ;
449
449
}
450
450
451
+ if ( hasComponent ( recsComponent , key as Entity ) ) {
452
+ updateComponent (
453
+ recsComponent ,
454
+ key as Entity ,
455
+ convertedValue as Partial < ComponentValue > ,
456
+ getComponentValue ( recsComponent , key as Entity )
457
+ ) ;
458
+ if ( logging )
459
+ console . log (
460
+ `Update component ${ recsComponent . metadata ?. name } on ${ key } `
461
+ ) ;
462
+ continue ;
463
+ }
451
464
setComponent ( recsComponent , key as Entity , convertedValue ) ;
452
465
453
466
if ( logging )
0 commit comments