Skip to content

Commit

Permalink
🎨 (swiftformat): Format melody, xylophone files after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Dec 9, 2023
1 parent ce410aa commit 9ef564e
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

// swiftlint:disable nesting
public enum MidiRecordingPlayer {

public struct Payload: Codable {
// MARK: Lifecycle

public struct Instructions: Codable {
public let textMusicSelection: String
public let textButtonPlay: String
public let textKeyboardPartial: String
public let textKeyboardFull: String
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.instructions = try container.decode(Instructions.self, forKey: .instructions)
self.instrument = try container.decode(String.self, forKey: .instrument)

enum CodingKeys: String, CodingKey {
case textMusicSelection = "text_music_selection"
case textButtonPlay = "text_button_play"
case textKeyboardPartial = "text_keyboard_partial"
case textKeyboardFull = "text_keyboard_full"
}
let midiRecordingSongs = try container.decode([MidiRecording.Song].self, forKey: .songs)
self.songs = midiRecordingSongs.map { MidiRecording($0) }
}

// MARK: Public

public struct Instructions: Codable {
// MARK: Lifecycle

public init(
textMusicSelection: String, textButtonPlay: String, textKeyboardPartial: String,
Expand All @@ -38,25 +39,36 @@ public enum MidiRecordingPlayer {
self.textKeyboardPartial = try container.decode(String.self, forKey: .textKeyboardPartial)
self.textKeyboardFull = try container.decode(String.self, forKey: .textKeyboardFull)
}

// MARK: Public

public let textMusicSelection: String
public let textButtonPlay: String
public let textKeyboardPartial: String
public let textKeyboardFull: String

// MARK: Internal

enum CodingKeys: String, CodingKey {
case textMusicSelection = "text_music_selection"
case textButtonPlay = "text_button_play"
case textKeyboardPartial = "text_keyboard_partial"
case textKeyboardFull = "text_keyboard_full"
}
}

public let instructions: Instructions
public let instrument: String
public let songs: [MidiRecording]

enum CodingKeys: String, CodingKey {
case instructions, instrument, songs
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.instructions = try container.decode(Instructions.self, forKey: .instructions)
self.instrument = try container.decode(String.self, forKey: .instrument)
// MARK: Internal

let midiRecordingSongs = try container.decode([MidiRecording.Song].self, forKey: .songs)
self.songs = midiRecordingSongs.map { MidiRecording($0) }
enum CodingKeys: String, CodingKey {
case instructions
case instrument
case songs
}
}

}

// swiftlint:enable nesting
2 changes: 1 addition & 1 deletion Modules/ContentKit/Sources/Exercise/Exercise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct Exercise: Codable {
self.payload = try container.decode(MusicalInstrument.Payload.self, forKey: .payload)

case (.melody, .none):
payload = try container.decode(MidiRecordingPlayer.Payload.self, forKey: .payload)
self.payload = try container.decode(MidiRecordingPlayer.Payload.self, forKey: .payload)

case (.remoteStandard, .none),
(.remoteArrow, .none):
Expand Down
58 changes: 31 additions & 27 deletions Modules/ContentKit/Sources/Utils/MidiRecording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
import Foundation

public struct MidiRecording: Codable, Hashable, Equatable {
// MARK: Lifecycle

public init(name: String, file: String, scale: [UInt8]) {
self.name = name
self.file = file
self.scale = scale
}

public init(_ song: Song) {
self.name = song.details.name
self.file = song.details.file
self.scale = song.scale
}

// MARK: Public

public enum Song: String, Codable {
case none
Expand All @@ -15,67 +30,56 @@ public struct MidiRecording: Codable, Hashable, Equatable {
case ohTheCrocodiles
case happyBirthday

// MARK: Internal

var details: (name: String, file: String) {
switch self {
case .none:
return (name: "", file: "")
(name: "", file: "")
case .underTheMoonlight:
return (
(
name: "Under The Moonlight", file: "Under_The_Moonlight"
)
case .aGreenMouse:
return (name: "A Green Mouse", file: "A_Green_Mouse")
(name: "A Green Mouse", file: "A_Green_Mouse")
case .twinkleTwinkleLittleStar:
return (
(
name: "Twinkle Twinkle Little Star", file: "Twinkle_Twinkle_Little_Star"
)
case .londonBridgeIsFallingDown:
return (
(
name: "London Bridge Is Falling Down", file: "London_Bridge_Is_Falling_Down"
)
case .ohTheCrocodiles:
return (
(
name: "Oh The Crocodiles", file: "Oh_The_Crocodiles"
)
case .happyBirthday:
return (name: "Happy Birthday", file: "Happy_Birthday")
(name: "Happy Birthday", file: "Happy_Birthday")
}
}

var scale: [UInt8] {
switch self {
case .none:
return []
[]
case .underTheMoonlight:
return [24, 26, 28, 29, 31, 33, 35, 36]
[24, 26, 28, 29, 31, 33, 35, 36]
case .aGreenMouse:
return [24, 26, 28, 29, 31, 33, 34, 36]
[24, 26, 28, 29, 31, 33, 34, 36]
case .twinkleTwinkleLittleStar:
return [24, 26, 28, 29, 31, 33, 35, 36]
[24, 26, 28, 29, 31, 33, 35, 36]
case .londonBridgeIsFallingDown:
return [24, 26, 28, 29, 31, 33, 35, 36]
[24, 26, 28, 29, 31, 33, 35, 36]
case .ohTheCrocodiles:
return [24, 28, 29, 31, 33, 34, 35, 36]
[24, 28, 29, 31, 33, 34, 35, 36]
case .happyBirthday:
return [24, 26, 28, 29, 31, 33, 34, 36]
[24, 26, 28, 29, 31, 33, 34, 36]
}
}
}

public let name: String
public let file: String
public let scale: [UInt8]

public init(name: String, file: String, scale: [UInt8]) {
self.name = name
self.file = file
self.scale = scale
}

public init(_ song: Song) {
self.name = song.details.name
self.file = song.details.file
self.scale = song.scale
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import SwiftUI

// TODO(@hugo/@ladislas): Make a general Button struct
extension MelodyView {

struct ButtonLabel: View {
let text: String
let color: Color
// MARK: Lifecycle

init(_ text: String, color: Color) {
self.text = text
self.color = color
}

// MARK: Internal

let text: String
let color: Color

var body: some View {
Text(text)
Text(self.text)
.font(.title2)
.foregroundColor(.white)
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.center)
.frame(width: 400, height: 50)
.scaledToFit()
.background(Capsule().fill(color).shadow(radius: 3))
.background(Capsule().fill(self.color).shadow(radius: 3))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ContentKit
import SwiftUI

extension MelodyView {

struct LauncherView: View {
@Binding var selectedSong: MidiRecording
@Binding var mode: Stage
Expand All @@ -28,8 +27,8 @@ extension MelodyView {
GameEngineKitAsset.Exercises.Melody.iconKeyboardPartial.swiftUIImage
.resizable()
.scaledToFit()
Text(instructions.textKeyboardPartial)
.foregroundStyle(keyboard == .partial ? .black : .gray.opacity(0.4))
Text(self.instructions.textKeyboardPartial)
.foregroundStyle(self.keyboard == .partial ? .black : .gray.opacity(0.4))
}

Toggle(
Expand All @@ -45,8 +44,8 @@ extension MelodyView {
GameEngineKitAsset.Exercises.Melody.iconKeyboardFull.swiftUIImage
.resizable()
.scaledToFit()
Text(instructions.textKeyboardFull)
.foregroundStyle(keyboard == .full ? .black : .gray.opacity(0.4))
Text(self.instructions.textKeyboardFull)
.foregroundStyle(self.keyboard == .full ? .black : .gray.opacity(0.4))
}
}
.padding(.horizontal)
Expand All @@ -55,8 +54,8 @@ extension MelodyView {
.clipShape(RoundedRectangle(cornerRadius: 10))

SongSelectorView(
songs: songs, selectedMidiRecording: $selectedSong,
textMusicSelection: instructions.textMusicSelection
songs: self.songs, selectedMidiRecording: self.$selectedSong,
textMusicSelection: self.instructions.textMusicSelection
)
.frame(maxHeight: 260)
}
Expand All @@ -65,9 +64,9 @@ extension MelodyView {
.padding(.horizontal, 100)

Button {
mode = .selectionConfirmed
self.mode = .selectionConfirmed
} label: {
ButtonLabel(instructions.textButtonPlay, color: .cyan)
ButtonLabel(self.instructions.textButtonPlay, color: .cyan)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ import DesignKit
import SwiftUI

extension MelodyView {

struct SongSelectorView: View {
// MARK: Lifecycle

init(songs: [MidiRecording], selectedMidiRecording: Binding<MidiRecording>, textMusicSelection: String) {
self.songs = songs
self._selectedMidiRecording = selectedMidiRecording
self.textMusicSelection = textMusicSelection
}

// MARK: Internal

@Binding var selectedMidiRecording: MidiRecording
let songs: [MidiRecording]
let textMusicSelection: String
Expand All @@ -18,37 +27,30 @@ extension MelodyView {
GridItem(.flexible()),
]

init(songs: [MidiRecording], selectedMidiRecording: Binding<MidiRecording>, textMusicSelection: String) {
self.songs = songs
self._selectedMidiRecording = selectedMidiRecording
self.textMusicSelection = textMusicSelection
}

var body: some View {

VStack {
HStack {
Image(systemName: "music.note.list")
Text(textMusicSelection)
Text(self.textMusicSelection)
Image(systemName: "music.note.list")
}

Divider()

ScrollView {
LazyVGrid(columns: columns, alignment: .listRowSeparatorLeading, spacing: 20) {
ForEach(songs, id: \.self) { midiRecording in
LazyVGrid(columns: self.columns, alignment: .listRowSeparatorLeading, spacing: 20) {
ForEach(self.songs, id: \.self) { midiRecording in
Button {
selectedMidiRecording = midiRecording
self.selectedMidiRecording = midiRecording
} label: {
HStack {
Image(
systemName: midiRecording == selectedMidiRecording
systemName: midiRecording == self.selectedMidiRecording
? "checkmark.circle.fill" : "circle"
)
.imageScale(.large)
.foregroundColor(
midiRecording == selectedMidiRecording
midiRecording == self.selectedMidiRecording
? .green : DesignKitAsset.Colors.lekaDarkGray.swiftUIColor
)
Text(midiRecording.name)
Expand All @@ -67,7 +69,6 @@ extension MelodyView {
.clipShape(RoundedRectangle(cornerRadius: 10))
}
}

}

#Preview {
Expand Down
Loading

0 comments on commit 9ef564e

Please sign in to comment.