forked from forcedotcom/pub-sub-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansr
More file actions
347 lines (319 loc) · 10.5 KB
/
Copy pathansr
File metadata and controls
347 lines (319 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
package com.example.superbaseapp
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.superbaseapp.ui.theme.SuperbaseappTheme
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.createSupabaseClient
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.postgrest.from
import io.github.jan.supabase.postgrest.query.Columns
import io.github.jan.supabase.realtime.Realtime
import io.github.jan.supabase.realtime.selectAsFlow
import kotlinx.coroutines.launch
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
sealed interface Stats {
val average: Int
}
data class PlayerStats(
val pace: Int,
val shooting: Int,
val passing: Int,
val dribbling: Int,
val defending: Int,
val physical: Int
) : Stats {
override val average: Int
get() = listOf(pace, shooting, passing, dribbling, defending, physical).average().toInt()
}
data class GoalkeeperStats(
val diving: Int,
val handling: Int,
val kicking: Int,
val reflexes: Int,
val speed: Int,
val positioning: Int
) : Stats {
override val average: Int
get() = listOf(diving, handling, kicking, reflexes, speed, positioning).average().toInt()
}
fun generateStatsForBombo(bombo: Int): PlayerStats {
val (min, max) = when (bombo) {
1 -> 89 to 99
2 -> 78 to 88
3 -> 67 to 77
4 -> 56 to 66
5 -> 45 to 55
else -> 30 to 44
}
fun rand() = (min..max).random()
return PlayerStats(rand(), rand(), rand(), rand(), rand(), rand())
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
SuperbaseappTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
PreviewFifaGrid()
}
}
}
}
}
@Preview
@Composable
fun PreviewFifaGrid() {
FifaCardGridCanvas()
}
@Composable
fun FifaExactCard(
name: String,
position: String,
rating: Int,
stats: PlayerStats,
bombo: Int,
modifier: Modifier = Modifier
) {
Box(
modifier = modifier
.aspectRatio(0.65f)
.padding(8.dp)
) {
val gradient = when (bombo) {
1 -> Brush.linearGradient(listOf(Color(0xFFFFD700), Color(0xFFFFA500))) // dorado
2 -> Brush.linearGradient(listOf(Color.LightGray, Color.DarkGray)) // plata
3 -> Brush.linearGradient(listOf(Color(0xFF8B4513), Color(0xFFCD7F32))) // bronce
else -> Brush.linearGradient(listOf(Color.DarkGray, Color.Black))
}
Canvas(modifier = Modifier.matchParentSize()) {
val path = Path().fifaExactShape(size.width, size.height)
drawPath(path = path, brush = gradient)
}
// ZONA DE TEXTO SUPERIOR (media y posición)
Box(
modifier = Modifier
.fillMaxSize()
.padding(top = 40.dp, start = 24.dp, end = 24.dp)
) {
Text(
text = rating.toString(),
color = Color.White,
fontSize = 28.sp,
fontWeight = FontWeight.ExtraBold,
modifier = Modifier.align(Alignment.TopStart)
)
Text(
text = position.uppercase(),
color = Color.White,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier.align(Alignment.TopEnd)
)
}
// CONTENIDO INTERIOR
Column(
modifier = Modifier
.fillMaxSize()
.padding(top = 80.dp, bottom = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceBetween
) {
// Imagen ficticia
Box(
modifier = Modifier
.size(80.dp)
.clip(CircleShape)
.background(Color.White.copy(alpha = 0.3f)),
contentAlignment = Alignment.Center
) {
Text("IMG", color = Color.White, fontSize = 14.sp)
}
Text(name, color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.Bold)
Row(Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, bottom = 10.dp), horizontalArrangement = Arrangement.SpaceBetween) {
Column {
StatItem("PAC", stats.pace)
StatItem("SHO", stats.shooting)
StatItem("PAS", stats.passing)
}
Column {
StatItem("DRI", stats.dribbling)
StatItem("DEF", stats.defending)
StatItem("PHY", stats.physical)
}
}
}
}
}
@Composable
fun FifaCardGridCanvas() {
val players = remember {
listOf(
"Mbappé" to "ST",
"Modric" to "CM",
"Vinicius" to "LW",
"Haaland" to "CF",
"Pedri" to "CAM",
"Nico" to "RW"
).mapIndexed { index, (name, pos) ->
Triple(name, pos, generateStatsForBombo(index + 1))
}
}
LazyVerticalGrid(
columns = GridCells.Fixed(2),
contentPadding = PaddingValues(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
items(players) { (name, pos, stats) ->
val bombo = stats.average
FifaExactCard(name, pos, bombo, stats,players.indexOfFirst { it.first == name } + 1)
}
}
}
@Composable
fun StatItem(label: String, value: Int) {
Text(
text = "$label $value",
fontSize = 14.sp,
color = Color.White,
fontWeight = FontWeight.Medium,
modifier = Modifier.padding(start = 12.dp, end = 12.dp)
)
}
fun Path.fifaExactShape(width: Float, height: Float): Path {
val rawPoints = listOf(
154 to 31,
141 to 43,
106 to 37,
27 to 73,
27 to 341,
41 to 368,
29 to 356,
53 to 372,
110 to 373,
81 to 376,
140 to 391,
260 to 391,
311 to 376,
278 to 373,
349 to 372,
366 to 356,
354 to 368,
372 to 341,
372 to 73,
290 to 37,
256 to 43,
243 to 31
)
val maxX = 400f
val maxY = 400f
val scaled = rawPoints.map { (x, y) ->
Offset(x / maxX * width, y / maxY * height)
}
moveTo(scaled[0].x, scaled[0].y)
for (point in scaled.drop(1)) {
lineTo(point.x, point.y)
}
close()
return this
}
fun generarJugadorAleatorio(nombre: String, posicion: String, bombo: Bombo): Jugador {
val range = bombo.range
val stats: Stats = if (posicion == "GK") {
GoalkeeperStats(
diving = range.random(),
handling = range.random(),
kicking = range.random(),
reflexes = range.random(),
speed = range.random(),
positioning = range.random()
)
} else {
PlayerStats(
pace = range.random(),
shooting = range.random(),
passing = range.random(),
dribbling = range.random(),
defending = range.random(),
physical = range.random()
)
}
return Jugador(nombre = nombre, posicion = posicion, bombo = bombo, stats = stats)
}
data class Jugador(
val nombre: String,
val posicion: String, // Ej: "ST", "GK"
val bombo: Bombo,
val stats: Stats
) {
val media: Int
get() = stats.average
}
enum class Bombo(val range: IntRange) {
BOMBO1(89..99),
BOMBO2(78..88),
BOMBO3(67..77),
BOMBO4(56..66),
BOMBO5(45..55),
BOMBO6(34..44)
}