Ejemplo n.º 1
0
        //as Parts evolve, the blueprints won't keep up. different ways we could handle, one might be to cycle through
        // every blueprint in the folder and load/rewrite it, that will at least get new props in as nulls.

        /// <summary>
        /// Get a blueprint for an entity. Blueprint part Ids are all forced to 0 (to reduce possible
        /// confusion when reading by hand). This method has a limited exception to the no-references rule
        /// --an entity with Container or Anatomy parts will automatically have the entity related values emptied
        /// before writing (which makes them safe).
        /// </summary>
        internal static string GetBlueprintForEntity(EcsRegistrar rgs, long entityId)
        {
            //make a copy before changing anything, just in case the user wants to continue working with original.
            string originalPartsJson = rgs.SerializeEntityParts(entityId);
            var    revisedPartsList  = rgs.DeserializeParts(originalPartsJson);

            foreach (var part in revisedPartsList)
            {
                part.Id = 0;
                if (part is Parts.Container)
                {
                    ((Parts.Container)part).EntityIds.Clear();
                }
                if (part is Parts.Anatomy)
                {
                    var anatomy = (Parts.Anatomy)part;
                    //anatomy.SlotsEquipped = GetClearedAnatomySlotsEquipped(anatomy.SlotsEquipped);
                    anatomy.SlotsEquipped = anatomy.SlotsEquipped.ToDictionary(k => k.Key, v => 0L);
                }
            }

            return(rgs.SerializeEntityParts(revisedPartsList));
        }