private static void ApplyRotationMetadata(BaseGhost baseGhost, BuilderMetadata builderMetadata) { switch (baseGhost) { case BaseAddCorridorGhost corridor when builderMetadata is CorridorBuilderMetadata corridorRotationMetadata: { corridor.rotation = corridorRotationMetadata.Rotation; int corridorType = corridor.CalculateCorridorType(); corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.RebuildGhostGeometry(); break; } case BaseAddMapRoomGhost mapRoom when builderMetadata is MapRoomBuilderMetadata mapRoomRotationMetadata: { mapRoom.cellType = (Base.CellType)mapRoomRotationMetadata.CellType; mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask; mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.RebuildGhostGeometry(); break; } case BaseAddModuleGhost ghost when builderMetadata is BaseModuleBuilderMetadata baseModuleRotationMetadata: { ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); ghost.RebuildGhostGeometry(); break; } case BaseAddFaceGhost faceGhost when builderMetadata is AnchoredFaceBuilderMetadata baseModuleRotationMetadata: { Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); faceGhost.anchoredFace = face; Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType; faceGhost.ghostBase.SetFace(face, faceType); faceGhost.RebuildGhostGeometry(); break; } default: Log.Error($"Was unable to apply rotation metadata for {baseGhost.GetType()} and {builderMetadata}"); break; } }
public Optional <BuilderMetadata> From(object baseGhost) { BuilderMetadata builderMetadata = null; switch (baseGhost) { case BaseAddCorridorGhost corridorGhost: { int rotation = corridorGhost.rotation; Vector3 position = corridorGhost.GetComponentInParent <ConstructableBase>().transform.position; bool hasTargetBase = corridorGhost.targetBase != null; Int3 targetCell = hasTargetBase ? corridorGhost.targetBase.WorldToGrid(position): default; builderMetadata = new CorridorBuilderMetadata(position.ToDto(), rotation, hasTargetBase, targetCell.ToDto()); break; } case BaseAddMapRoomGhost mapRoomGhost: { Base.CellType cellType = mapRoomGhost.cellType; int connectionMask = mapRoomGhost.connectionMask; builderMetadata = new MapRoomBuilderMetadata((byte)cellType, connectionMask); break; } case BaseAddModuleGhost module: { Int3 cell = module.anchoredFace !.Value.cell; int direction = (int)module.anchoredFace.Value.direction; builderMetadata = new BaseModuleBuilderMetadata(cell.ToDto(), direction); break; } case BaseAddFaceGhost faceGhost: { Base.Face anchoredFace = faceGhost.anchoredFace !.Value; builderMetadata = new AnchoredFaceBuilderMetadata(anchoredFace.cell.ToDto(), (int)anchoredFace.direction, (int)faceGhost.faceType); break; } } return(Optional.OfNullable(builderMetadata)); }