public Ob_Part GetObjectBuilder() { using (LockSharedUsing()) { var res = new Ob_Part { BuilderVersion = Ob_Part.PartBuilderVersion, BlockCountByType = BlockSetInfo.BlockCountByType.Select(x => SerializableTuple.Create((SerializableDefinitionId)x.Key, x.Value)).ToArray(), ComponentCost = BlockSetInfo.ComponentCost.Select(x => SerializableTuple.Create((SerializableDefinitionId)x.Key.Id, x.Value)).ToArray(), OccupiedLocations = m_blocks.Keys.Select(x => (SerializableVector3I)x).ToArray(), PowerConsumptionByGroup = BlockSetInfo.PowerConsumptionByGroup.Select(x => SerializableTuple.Create(x.Key, x.Value)).ToArray(), ReservedSpaces = m_reservedSpaces.Select(x => x.GetObjectBuilder()).ToArray(), MountPoints = m_mountPoints.Values.SelectMany(x => x.Values).Select(x => x.GetObjectBuilder()).ToArray() }; return(res); } }
public virtual void Init(Ob_Part v) { BlockSetInfo.BlockCountByType.Clear(); foreach (var kv in v.BlockCountByType) { BlockSetInfo.BlockCountByType[kv.Item1] = kv.Item2; } BlockSetInfo.ComponentCost.Clear(); foreach (var kv in v.ComponentCost) { BlockSetInfo.ComponentCost[MyDefinitionManager.Static.GetComponentDefinition(kv.Item1)] = kv.Item2; } m_blocks.Clear(); foreach (var kv in v.OccupiedLocations) { m_blocks[kv] = null; } BlockSetInfo.PowerConsumptionByGroup.Clear(); foreach (var kv in v.PowerConsumptionByGroup) { BlockSetInfo.PowerConsumptionByGroup[kv.Item1] = kv.Item2; } m_reservedSpaces.Clear(); m_reservedSpaces.AddRange(v.ReservedSpaces.Select(x => new ReservedSpace(x))); m_mountPoints.Clear(); m_mountPointBlocks.Clear(); foreach (var mp in v.MountPoints) { var block = new PartMount(this, mp.Type, mp.Name); block.Init(mp); Dictionary <string, PartMount> partsOfType; if (!m_mountPoints.TryGetValue(mp.Type, out partsOfType)) { partsOfType = m_mountPoints[mp.Type] = new Dictionary <string, PartMount>(); } partsOfType[mp.Name] = block; foreach (var kv in block.Blocks) { m_mountPointBlocks[kv.AnchorLocation] = kv; } } // Load AABBs BoundingBox = BoundingBox.CreateInvalid(); foreach (var p in v.OccupiedLocations) { BoundingBox = BoundingBox.Include((Vector3I)p); } ReservedSpace = BoundingBox.CreateInvalid(); foreach (var r in v.ReservedSpaces) { ReservedSpace = ReservedSpace.Include(r.Min); ReservedSpace = ReservedSpace.Include(r.Max); } BlockSetInfo.UpdateCache(); Logger.Info("Loaded {0} lazily with {1} mount points, {2} reserved spaces, and {3} occupied cubes.", Name, MountPoints.Count(), m_reservedSpaces.Count, m_blocks.Count); foreach (var type in MountPointTypes) { Logger.Info(" ...of type \"{0}\" there are {1}", type, MountPointsOfType(type).Count()); } }
public override void Init(Ob_Part v) { Initialized = false; base.Init(v); }