Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -442,27 +442,42 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 441 unmodified lines | ||
| 442 | 442 | return true; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | −bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { | |
| 445 | +bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(LineEntityItem&)> actor) { | |
| 446 | 446 | if (!_entityTree) { |
| 447 | 447 | return false; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | − EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 451 | − if (!entity) { | |
| 452 | − qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | |
| 453 | − } | |
| 450 | + auto now = usecTimestampNow(); | |
| 454 | 451 | |
| 455 | − EntityTypes::EntityType entityType = entity->getType(); | |
| 452 | + LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get()); | |
| 453 | + _entityTree->lockForWrite(); | |
| 454 | + bool success = actor(*lineEntity); | |
| 455 | + entity->setLastEdited(now); | |
| 456 | + entity->setLastBroadcast(now); | |
| 457 | + _entityTree->unlock(); | |
| 456 | 458 | |
| 457 | − if (entityType != EntityTypes::Line) { | |
| 459 | + _entityTree->lockForRead(); | |
| 460 | + EntityItemProperties properties = entity->getProperties(); | |
| 461 | + _entityTree->unlock(); | |
| 462 | + | |
| 463 | + properties.setLinePointsDirty(); | |
| 464 | + properties.setLastEdited(now); | |
| 465 | + | |
| 466 | + | |
| 467 | + queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties); | |
| 468 | + return success; | |
| 469 | +} | |
| 470 | + | |
| 471 | +bool EntityScriptingInterface::setPoints(EntityItemPointer entity, std::function<bool(QuadEntityItem&)> actor) { | |
| 472 | + if (!_entityTree) { | |
| 458 | 473 | return false; |
| 459 | 474 | } |
| 460 | 475 | |
| 461 | 476 | auto now = usecTimestampNow(); |
| 462 | 477 | |
| 463 | − LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get()); | |
| 478 | + QuadEntityItem* quadEntity = static_cast<QuadEntityItem*>(entity.get()); | |
| 464 | 479 | _entityTree->lockForWrite(); |
| 465 | − bool success = actor(*lineEntity); | |
| 480 | + bool success = actor(*quadEntity); | |
| 466 | 481 | entity->setLastEdited(now); |
| 467 | 482 | entity->setLastBroadcast(now); |
| 468 | 483 | _entityTree->unlock(); |
| @@ -475,7 +490,7 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 6 unmodified lines | ||
| 475 | 490 | properties.setLastEdited(now); |
| 476 | 491 | |
| 477 | 492 | |
| 478 | − queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | |
| 493 | + queueEntityMessage(PacketTypeEntityEdit, entity->getID(), properties); | |
| 479 | 494 | return success; |
| 480 | 495 | } |
| 481 | 496 | |
| @@ -498,17 +513,53 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { · 16 unmodified lines | ||
| 498 | 513 | } |
| 499 | 514 | |
| 500 | 515 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { |
| 501 | − return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool | |
| 502 | − { | |
| 503 | − return lineEntity.setLinePoints(points); | |
| 504 | − }); | |
| 516 | + EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 517 | + if (!entity) { | |
| 518 | + qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | |
| 519 | + } | |
| 520 | + | |
| 521 | + EntityTypes::EntityType entityType = entity->getType(); | |
| 522 | + | |
| 523 | + if (entityType == EntityTypes::Line) { | |
| 524 | + return setPoints(entity, [points](LineEntityItem& lineEntity) -> bool | |
| 525 | + { | |
| 526 | + return lineEntity.setLinePoints(points); | |
| 527 | + }); | |
| 528 | + } | |
| 529 | + | |
| 530 | + if (entityType == EntityTypes::Quad) { | |
| 531 | + return setPoints(entity, [points](QuadEntityItem& quadEntity) -> bool | |
| 532 | + { | |
| 533 | + return quadEntity.setLinePoints(points); | |
| 534 | + }); | |
| 535 | + } | |
| 536 | + | |
| 537 | + return false; | |
| 505 | 538 | } |
| 506 | 539 | |
| 507 | 540 | bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& point) { |
| 508 | − return setPoints(entityID, [point](LineEntityItem& lineEntity) -> bool | |
| 509 | − { | |
| 510 | − return lineEntity.appendPoint(point); | |
| 511 | − }); | |
| 541 | + EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | |
| 542 | + if (!entity) { | |
| 543 | + qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | |
| 544 | + } | |
| 545 | + | |
| 546 | + EntityTypes::EntityType entityType = entity->getType(); | |
| 547 | + | |
| 548 | + if (entityType == EntityTypes::Line) { | |
| 549 | + return setPoints(entity, [point](LineEntityItem& lineEntity) -> bool | |
| 550 | + { | |
| 551 | + return lineEntity.appendPoint(point); | |
| 552 | + }); | |
| 553 | + } | |
| 554 | + | |
| 555 | + if (entityType == EntityTypes::Quad) { | |
| 556 | + return setPoints(entity, [point](QuadEntityItem& quadEntity) -> bool | |
| 557 | + { | |
| 558 | + return quadEntity.appendPoint(point); | |
| 559 | + }); | |
| 560 | + } | |
| 561 | + | |
| 562 | + return false; | |
| 512 | 563 | |
| 513 | 564 | } |
| 514 | 565 | |