11import SwiftUI
22
3- struct ScoreboardEffectModularView : View {
4- let modular : SettingsWidgetModularScoreboard
5- let config : RemoteControlScoreboardMatchConfig
3+ private func getHistoricScore( team: RemoteControlScoreboardTeam , indexPlusOne: Int ) -> String ? {
4+ switch indexPlusOne {
5+ case 1 :
6+ return team. secondaryScore1
7+ case 2 :
8+ return team. secondaryScore2
9+ case 3 :
10+ return team. secondaryScore3
11+ case 4 :
12+ return team. secondaryScore4
13+ case 5 :
14+ return team. secondaryScore5
15+ default :
16+ return nil
17+ }
18+ }
619
7- private func calculateMaxHistory( config: RemoteControlScoreboardMatchConfig ) -> Int {
8- var maxHistory = 0
9- for indexPlusOne in 1 ... 5 {
10- let homeHas = getHistoricScore ( team: config. team1, indexPlusOne: indexPlusOne) != nil
11- let awayHas = getHistoricScore ( team: config. team2, indexPlusOne: indexPlusOne) != nil
12- if homeHas || awayHas {
13- maxHistory = indexPlusOne
14- }
20+ private func calculateMaxHistory( config: RemoteControlScoreboardMatchConfig ) -> Int {
21+ var maxHistory = 0
22+ for indexPlusOne in 1 ... 5 {
23+ let homeHas = getHistoricScore ( team: config. team1, indexPlusOne: indexPlusOne) != nil
24+ let awayHas = getHistoricScore ( team: config. team2, indexPlusOne: indexPlusOne) != nil
25+ if homeHas || awayHas {
26+ maxHistory = indexPlusOne
1527 }
16- return maxHistory
1728 }
29+ return maxHistory
30+ }
31+
32+ struct ScoreboardEffectModularView : View {
33+ let modular : SettingsWidgetModularScoreboard
34+ let config : RemoteControlScoreboardMatchConfig
1835
1936 @ViewBuilder
2037 private func renderStackHistory(
@@ -23,13 +40,13 @@ struct ScoreboardEffectModularView: View {
2340 ) -> some View {
2441 let fontSize = modular. fontSize ( )
2542 let rowH = CGFloat ( modular. rowHeight)
26- let teamRowFullH = rowH + ( modular. showMoreStats ? rowH * 0.6 : 0 )
27- let totalH = teamRowFullH * 2
28- let periodFull = " \( config. global. periodLabel ) \( config . global . period ) "
43+ let teamRowFullHeight = rowH + ( modular. showMoreStats ? rowH * 0.6 : 0 )
44+ let totalHeight = teamRowFullHeight * 2
45+ let periodFull = config. global. periodFull ( )
2946 let activeStats = [ config. global. timer, periodFull, config. global. subPeriod] . filter {
3047 !$0. isEmpty
3148 }
32- let subH = activeStats. isEmpty ? 0 : totalH / CGFloat( activeStats. count)
49+ let subH = activeStats. isEmpty ? 0 : totalHeight / CGFloat( activeStats. count)
3350 let histW = fontSize * 1.5
3451 let maxHistory = calculateMaxHistory ( config: config)
3552 let finalWidth = CGFloat ( modular. width) + CGFloat( maxHistory) * histW
@@ -58,7 +75,7 @@ struct ScoreboardEffectModularView: View {
5875 )
5976 }
6077 . frame ( width: finalWidth)
61- renderInfoBox ( stats: activeStats, height: subH, totalHeight: totalH , modular: modular)
78+ renderInfoBox ( stats: activeStats, height: subH, totalHeight: totalHeight , modular: modular)
6279 }
6380 }
6481
@@ -139,35 +156,18 @@ struct ScoreboardEffectModularView: View {
139156 . foregroundStyle ( textColor)
140157 }
141158
142- private func getHistoricScore( team: RemoteControlScoreboardTeam , indexPlusOne: Int ) -> String ? {
143- switch indexPlusOne {
144- case 1 :
145- return team. secondaryScore1
146- case 2 :
147- return team. secondaryScore2
148- case 3 :
149- return team. secondaryScore3
150- case 4 :
151- return team. secondaryScore4
152- case 5 :
153- return team. secondaryScore5
154- default :
155- return nil
156- }
157- }
158-
159159 @ViewBuilder
160160 private func renderStacked( modular: SettingsWidgetModularScoreboard ,
161161 config: RemoteControlScoreboardMatchConfig ) -> some View
162162 {
163163 let rowH = CGFloat ( modular. rowHeight)
164- let teamRowFullH = rowH + ( modular. showMoreStats ? rowH * 0.6 : 0 )
165- let totalH = teamRowFullH * 2
166- let periodFull = " \( config. global. periodLabel ) \( config . global . period ) "
164+ let teamRowFullHeight = rowH + ( modular. showMoreStats ? rowH * 0.6 : 0 )
165+ let totalHeight = teamRowFullHeight * 2
166+ let periodFull = config. global. periodFull ( )
167167 let activeStats = [ config. global. timer, periodFull, config. global. subPeriod] . filter {
168168 !$0. isEmpty
169169 }
170- let subH = activeStats. isEmpty ? 0 : totalH / CGFloat( activeStats. count)
170+ let subH = activeStats. isEmpty ? 0 : totalHeight / CGFloat( activeStats. count)
171171 renderTitle ( title: config. global. title, modular: modular)
172172 HStack ( alignment: . top, spacing: 0 ) {
173173 VStack ( spacing: 0 ) {
@@ -185,7 +185,7 @@ struct ScoreboardEffectModularView: View {
185185 )
186186 }
187187 . frame ( width: CGFloat ( modular. width) )
188- renderInfoBox ( stats: activeStats, height: subH, totalHeight: totalH , modular: modular)
188+ renderInfoBox ( stats: activeStats, height: subH, totalHeight: totalHeight , modular: modular)
189189 }
190190 }
191191
@@ -196,8 +196,8 @@ struct ScoreboardEffectModularView: View {
196196 ) -> some View {
197197 let fontSize = modular. fontSize ( )
198198 let height = CGFloat ( modular. rowHeight)
199- let teamRowFullH = height + ( modular. showMoreStats ? height * 0.6 : 0 )
200- let periodFull = " \( config. global. periodLabel ) \( config . global . period ) "
199+ let teamRowFullHeight = height + ( modular. showMoreStats ? height * 0.6 : 0 )
200+ let periodFull = config. global. periodFull ( )
201201 renderTitle ( title: config. global. title, modular: modular)
202202 HStack ( spacing: 0 ) {
203203 renderSideBySideHalf (
@@ -219,11 +219,11 @@ struct ScoreboardEffectModularView: View {
219219 . font ( . system( size: fontSize * 0.9 , weight: . black) )
220220 . monospacedDigit ( )
221221 }
222- . frame ( width: fontSize * 3.5 , height: teamRowFullH )
222+ . frame ( width: fontSize * 3.5 , height: teamRowFullHeight )
223223 } else {
224224 Text ( " - " )
225225 . font ( . system( size: fontSize, weight: . black) )
226- . frame ( width: fontSize * 0.8 , height: teamRowFullH )
226+ . frame ( width: fontSize * 0.8 , height: teamRowFullHeight )
227227 }
228228 }
229229 . background ( . black)
0 commit comments