Juego de deducción social para 3-20 jugadores. Modo un solo móvil completamente funcional. 1000 palabras en 10 categorías. Notas privadas, votación, adivinanza, revancha. Material 3 dark theme. Package: es.freetimelab.elimpostor
45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'dart:convert';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
/// Servicio para persistir las notas de los jugadores localmente
|
|
class ServicioNotas {
|
|
static const _clavePrefix = 'notas_';
|
|
|
|
/// Guarda las notas de un jugador para una partida
|
|
static Future<void> guardarNotas(
|
|
String jugadorId,
|
|
Map<String, String> notas,
|
|
String notaLibre,
|
|
) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final datos = {
|
|
'notas': notas,
|
|
'notaLibre': notaLibre,
|
|
};
|
|
await prefs.setString('$_clavePrefix$jugadorId', json.encode(datos));
|
|
}
|
|
|
|
/// Carga las notas de un jugador
|
|
static Future<Map<String, dynamic>> cargarNotas(String jugadorId) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final str = prefs.getString('$_clavePrefix$jugadorId');
|
|
if (str == null) {
|
|
return {'notas': <String, String>{}, 'notaLibre': ''};
|
|
}
|
|
final datos = json.decode(str) as Map<String, dynamic>;
|
|
return {
|
|
'notas': Map<String, String>.from(datos['notas'] ?? {}),
|
|
'notaLibre': datos['notaLibre'] ?? '',
|
|
};
|
|
}
|
|
|
|
/// Limpia todas las notas (al iniciar nueva partida)
|
|
static Future<void> limpiarNotas() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final claves = prefs.getKeys().where((k) => k.startsWith(_clavePrefix));
|
|
for (final clave in claves) {
|
|
await prefs.remove(clave);
|
|
}
|
|
}
|
|
}
|