// The face the music player wears in Listening, as the core answers it// (`shell.player`: `face`, and the hand's ring in `faces`); the core keeps// the `player` row of face_settings, the face and the knobs alike.importCottonKitimportCottonValuesimportFoundation/// The faces a song plays on, by their catalogue ids.enumPlayerFace: String, CaseIterable, Sendable {case hifi, turntable, amp, party, tray, cassette/// The face's id in the catalogue (`song.hifi`).var face: DefinitionCardKind {switchself {case .hifi: .songHificase .turntable: .songTurntablecase .amp: .songAmpcase .party: .songPartycase .tray: .songTraycase .cassette: .songCassette } }/// The face whose catalogue id is `id`, if it is one of them.init?(face id: String) {guardlet face = Self.allCases.first(where: { $0.face.rawValue == id }) else { returnnil }self = face }/// Its name on the hand, as the core's ring says it. @MainActor var said: String {MusicNowPlaying.shared.faces.first { $0.id == face.rawValue }?.label ?? "" }}structPlayerSettings: Equatable, Sendable {/// The face worn.var face: PlayerFace = .hifi/// The face worn, as the core answers it.staticfunc read(_ core: any CottonCalling) async -> PlayerSettings {do {let answer = tryawait core.call(CottonMethod.shellPlayer, [String: RecordValue](), as: PlayerAnswer.self)awaitMusicNowPlaying.shared.hold(faces: answer.faces)guardlet face = PlayerFace(face: answer.face) else {Log.write("player: the core wears a face this build does not draw: \(answer.face)")returnPlayerSettings() }returnPlayerSettings(face: face) } catch {Log.write("player: the face worn could not be read: \(error.localizedDescription)")returnPlayerSettings() } }/// The face the hand chose, written on the player's row by the core.staticfunc wear(_ face: PlayerFace, core: any CottonCalling) asyncthrows {let answer = tryawait core.call(CottonMethod.shellPlayer, ["op": RecordValue.text("settings"), "face": .text(face.face.rawValue)],as: PlayerAnswer.self)awaitMusicNowPlaying.shared.hold(faces: answer.faces) }}