示例#1
0
        public void LoadAttributes(EntityTypeCollection entityTypeCollection, string customFile = "")
        {
            AttributesPatch attributesPatch = GetPatchObject(GetPatchData(customFile));

            if (attributesPatch != null)
            {
                statsSheetSettings = attributesPatch.StatsSheetSettings;

                ApplyAttributesPatch(entityTypeCollection, attributesPatch);

                if (statsSheetSettings.Generate)
                {
                    Console.WriteLine("[SUBSYSTEM] Generating stats sheet...");
                    new StatsSheetGenerator(statsSheetSettings).Generate(entityTypeCollection);
                    Console.WriteLine("[SUBSYSTEM] Stats sheet generated!");
                }
            }
            else
            {
                writer.WriteLine("Patch file empty, not found or json parse failed. See output_log.txt for details");
            }

            string logName;

            if (customFile.Length > 0)
            {
                logName = MakeValidFileName($"Subsystem_{customFile}.log");
            }
            else
            {
                logName = "Subsystem.log";
            }

            File.WriteAllText(Path.Combine(DataFolderPath(), logName), writer.ToString());
        }
示例#2
0
        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.");
        }
示例#3
0
        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.");
        }