<commit_before>﻿using Entitas.Serialization.Blueprints;

namespace Entitas {

    public partial class Entity {

        public Entity ApplyBlueprint(Blueprint blueprint) {
            for (int i = 0, componentsLength = blueprint.components.Length; i < componentsLength; i++) {
                var componentBlueprint = blueprint.components[i];
                AddComponent(componentBlueprint.index, componentBlueprint.CreateComponent(this));
            }

            return this;
        }
    }
}
<commit_msg>entity.ApplyBlueprint() can optionally replace existing components.<commit_after>﻿using Entitas.Serialization.Blueprints;

namespace Entitas {

    public partial class Entity {

        /// Adds all components from the blueprint to the entity.
        /// When 'replaceComponents' is set to true entity.ReplaceComponent() will be used instead of entity.AddComponent().
        public Entity ApplyBlueprint(Blueprint blueprint, bool replaceComponents = false) {
            for (int i = 0, componentsLength = blueprint.components.Length; i < componentsLength; i++) {
                var componentBlueprint = blueprint.components[i];
                if (replaceComponents) {
                    ReplaceComponent(componentBlueprint.index, componentBlueprint.CreateComponent(this));
                } else {
                    AddComponent(componentBlueprint.index, componentBlueprint.CreateComponent(this));
                }
            }

            return this;
        }
    }
}

{'fraction_non_alphanumeric': 0.08160535117056857, 'fraction_numerical': 0.0013377926421404682, 'mean_word_length': 2.4709976798143853, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936834', 'n_tokens_mistral': 359, 'n_tokens_neox': 342, 'n_words': 91}