3#include "EditorCommand.h"
17 :
EditorCommand(state, state->context), entityIds(entityIds), fieldInfo(fieldInfo), fieldData(fieldData)
28 for (
auto &
id : entityIds) {
30 auto component = entity->
getComponent(fieldInfo.componentId);
32 auto field = fieldType.getField(fieldInfo.fieldId);
33 auto fieldPtr = field->template getPtr<T>(component);
35 previousDatas.push_back(*fieldPtr);
37 *fieldPtr = fieldData;
39 component->setFieldChanged(fieldInfo.fieldId);
45 for (
size_t i = 0; i < entityIds.size(); ++i) {
47 auto component = entity->
getComponent(fieldInfo.componentId);
49 auto field = fieldType.getField(fieldInfo.fieldId);
50 auto fieldPtr = field->template getPtr<T>(component);
52 *fieldPtr = previousDatas[i];
54 component->setFieldChanged(fieldInfo.fieldId);
57 previousDatas.clear();
64 if (!setFieldCommand) {
68 if (entityIds != setFieldCommand->entityIds) {
72 if (fieldInfo.componentId != setFieldCommand->fieldInfo.componentId || fieldInfo.fieldId != setFieldCommand->fieldInfo.fieldId) {
76 fieldData = setFieldCommand->fieldData;
86 std::vector<T> previousDatas;
T * getComponent() const
Get a pointer to the first component implementing the given type in the entity.
class EntityStore * store
Entity store.
ComponentModel::Entity * getEntityPtr(const EntityId entityId)
Get a raw pointer to the entity with the given id.
static const Type & getType()
Get the Type of the given template argument.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
uint16_t FieldId
Type used to index fields.
Base class for Cogs Editor commands.
bool mergeWith(const EditorCommand *command) override
void close() override
Close command, i.e. prevent merging with another command.
void apply() override
Run the command.