public IEnumerable <IPartModifier> CreatePartModifiers(Part part, ILinearScaleProvider linearScaleProvider, Action <string> onError) { AttachNode node = part.attachNodes.FirstOrDefault(n => (n.nodeType == AttachNode.NodeType.Stack || n.nodeType == AttachNode.NodeType.Dock) && nodeID.Match(n.id)); if (node == null) { onError($"Attach node with id matching '{nodeID}' not found for attach node modifier"); yield break; } // Explanation // Config has scale and rescaleFactor which both multiply node positions, but doesn't store scale directly // Instead it stores scaleFactor which is scale / rescaleFactor // So we have to multiply by rescaleFactor again to get it back // Use the prefab since TweakScale modifies rescaleFactor Part maybePrefab = part.partInfo?.partPrefab ?? part; float fixedScale = maybePrefab.scaleFactor * maybePrefab.rescaleFactor * maybePrefab.rescaleFactor; if (position != null) { yield return(new AttachNodeMover(node, position.Value * fixedScale, linearScaleProvider)); } if (size != null) { yield return(new AttachNodeSizeModifier(node, size.Value, linearScaleProvider)); } }
public AttachNodeMover(AttachNode attachNode, Vector3 position, ILinearScaleProvider linearScaleProvider) { attachNode.ThrowIfNullArgument(nameof(attachNode)); linearScaleProvider.ThrowIfNullArgument(nameof(linearScaleProvider)); this.attachNode = attachNode; this.position = position; this.linearScaleProvider = linearScaleProvider; }
public PartAttachNodeModifier(AttachNode partAttachNode, AttachNode referenceAttachNode, AttachNode newAttachNode, ILinearScaleProvider linearScaleProvider) { partAttachNode.ThrowIfNullArgument(nameof(partAttachNode)); linearScaleProvider.ThrowIfNullArgument(nameof(linearScaleProvider)); this.partAttachNode = partAttachNode; this.referenceAttachNode = referenceAttachNode; this.newAttachNode = newAttachNode; this.linearScaleProvider = linearScaleProvider; }
public AttachNodeSizeModifier(AttachNode attachNode, int size, ILinearScaleProvider linearScaleProvider) { attachNode.ThrowIfNullArgument(nameof(attachNode)); linearScaleProvider.ThrowIfNullArgument(nameof(linearScaleProvider)); this.attachNode = attachNode; this.size = size; this.linearScaleProvider = linearScaleProvider; originalSize = attachNode.size; }
public AttachNodeMover CreateAttachNodeModifier(Part part, ILinearScaleProvider linearScaleProvider) { if (position == null) { return(null); } AttachNode node = part.attachNodes.FirstOrDefault(n => (n.nodeType == AttachNode.NodeType.Stack || n.nodeType == AttachNode.NodeType.Dock) && n.id == nodeID); if (node == null) { part.LogError($"Attach node with id '{nodeID}' not found for attach node modifier"); return(null); } // Explanation // Config has scale and rescaleFactor which both multiply node positions, but doesn't store scale directly // Instead it stores scaleFactor which is scale / rescaleFactor // So we have to multiply by rescaleFactor again to get it back // Use the prefab since TweakScale modifies rescaleFactor Part maybePrefab = part.partInfo?.partPrefab ?? part; float fixedScale = maybePrefab.scaleFactor * maybePrefab.rescaleFactor * maybePrefab.rescaleFactor; return(new AttachNodeMover(node, position.Value * fixedScale, linearScaleProvider)); }