public void ApplyAttributesPatch(EntityTypeCollection entityTypeCollection, AttributesPatch attributesPatch) { foreach (var kvp in attributesPatch.Entities) { var entityTypeName = kvp.Key; var entityTypePatch = kvp.Value; var entityType = entityTypeCollection.GetEntityType(entityTypeName); using (logger.BeginScope($"EntityType: {entityTypeName}")) { if (entityType == null) { logger.Log($"NOTICE: EntityType not found"); continue; } applyUnnamedComponentPatch <ExperienceAttributesPatch, ExperienceAttributes, ExperienceAttributesWrapper>(entityType, entityTypePatch.ExperienceAttributes, x => new ExperienceAttributesWrapper(x), ApplyExperienceAttributesPatch); applyUnnamedComponentPatch <UnitAttributesPatch, UnitAttributes, UnitAttributesWrapper>(entityType, entityTypePatch.UnitAttributes, x => new UnitAttributesWrapper(x), ApplyUnitAttributesPatch); applyUnnamedComponentPatch <ResearchItemAttributesPatch, ResearchItemAttributes, ResearchItemAttributesWrapper>(entityType, entityTypePatch.ResearchItemAttributes, x => new ResearchItemAttributesWrapper(x), ApplyResearchItemAttributesPatch); applyUnnamedComponentPatch <UnitHangarAttributesPatch, UnitHangarAttributes, UnitHangarAttributesWrapper>(entityType, entityTypePatch.UnitHangarAttributes, x => new UnitHangarAttributesWrapper(x), ApplyUnitHangarAttributesPatch); applyUnnamedComponentPatch <DetectableAttributesPatch, DetectableAttributes, DetectableAttributesWrapper>(entityType, entityTypePatch.DetectableAttributes, x => new DetectableAttributesWrapper(x), ApplyDetectableAttributesPatch); applyUnnamedComponentPatch <UnitMovementAttributesPatch, UnitMovementAttributes, UnitMovementAttributesWrapper>(entityType, entityTypePatch.UnitMovementAttributes, x => new UnitMovementAttributesWrapper(x), ApplyUnitMovementAttributesPatch); applyNamedComponentPatch <AbilityAttributesPatch, AbilityAttributes, AbilityAttributesWrapper>(entityType, entityTypePatch.AbilityAttributes, x => new AbilityAttributesWrapper(x), ApplyAbilityAttributesPatch); applyNamedComponentPatch <StorageAttributesPatch, StorageAttributes, StorageAttributesWrapper>(entityType, entityTypePatch.StorageAttributes, x => new StorageAttributesWrapper(x), ApplyStorageAttributesPatch); applyNamedComponentPatch <WeaponAttributesPatch, WeaponAttributes, WeaponAttributesWrapper>(entityType, entityTypePatch.WeaponAttributes, x => new WeaponAttributesWrapper(x), (patch, wrapper) => { ApplyWeaponAttributesPatch(patch, wrapper); rebindWeaponAttributes(entityType, wrapper); }); } } File.WriteAllText(Path.Combine(Application.dataPath, "Subsystem.log"), writer.ToString()); Debug.Log($"[SUBSYSTEM] Applied attributes patch. See Subsystem.log for details."); }
public void ApplyAttributesPatch(EntityTypeCollection entityTypeCollection, AttributesPatch attributesPatch) { logger.Log("[ APPLYING ENTITY TYPE ATTRIBUTES ]"); foreach (var kvp in attributesPatch.Entities) { string entityTypeName = kvp.Key; EntityTypePatch entityTypePatch = kvp.Value; EntityTypeAttributes entityType; if (!entityTypePatch.CloneFrom.IsNullOrEmpty()) { EntityTypeAttributes toClone = entityTypeCollection.GetEntityType(entityTypePatch.CloneFrom); if (toClone == null) { logger.Log($"ERROR: CloneFrom {entityTypePatch.CloneFrom} attributes not found"); continue; } entityType = new EntityTypeAttributes(entityTypeName) { Flags = toClone.Flags }; var attributes = toClone.GetAll <object>(); foreach (var w in attributes) { entityType.Add(w); } entityTypeCollection.Add(entityType); logger.BeginScope($"Cloned {entityTypeName} from {entityTypePatch.CloneFrom}").Dispose(); } else { entityType = entityTypeCollection.GetEntityType(entityTypeName); } using (logger.BeginScope($"EntityType: {entityTypeName}")) { if (entityType == null) { if (entityTypePatch.CloneFrom.IsNullOrEmpty()) { logger.Log("NOTICE: EntityType not found"); } else { logger.Log("ERROR: Entity cloning failed"); } continue; } ApplyEntityTypePatch(entityType, entityTypePatch); } } if (attributesPatch.Global != null) { logger.Log("[ APPLYING GLOBAL TYPE ATTRIBUTES ]"); //logger.enable = false; notFoundErrors = false; foreach (var kvp in entityTypeCollection.GetAllEntityTypeNames()) { using (logger.BeginScope($"{kvp}:")) { ApplyEntityTypePatch(entityTypeCollection.GetEntityType(kvp), attributesPatch.Global); } } //logger.enable = true; notFoundErrors = true; } Debug.Log($"[SUBSYSTEM] Applied attributes patch. See Subsystem.log for details."); }