File size: 3,360 Bytes
5acd9c3
 
 
a3d40b4
5acd9c3
 
 
 
5ca5f4b
8d1d1b5
 
7dadc22
 
6a787b8
 
5acd9c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ca5f4b
 
 
 
 
 
 
5acd9c3
 
 
 
 
 
8d1d1b5
 
 
 
 
 
 
 
 
 
 
 
 
 
5acd9c3
7dadc22
 
 
 
 
 
 
 
 
 
 
 
 
 
233cefb
6a787b8
 
 
 
 
 
233cefb
6a787b8
 
 
 
 
 
5acd9c3
 
 
 
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
import 'dart:async';

import 'package:shared_preferences/shared_preferences.dart';
import 'package:tikslop/config/config.dart';

class SettingsService {
  static const String _promptPrefixKey = 'video_prompt_prefix';
  static const String _hfApiKeyKey = 'huggingface_api_key';
  static const String _negativePromptKey = 'negative_video_prompt';
  static const String _showSceneDebugInfoKey = 'show_scene_debug_info';
  static const String _enableSimulationKey = 'enable_simulation';
  static const String _simLoopDelayKey = 'sim_loop_delay_in_sec';
  static const String _gameMasterPromptKey = 'game_master_prompt';
  static const String _llmProviderKey = 'llm_provider';
  static const String _llmModelKey = 'llm_model';
  static final SettingsService _instance = SettingsService._internal();
  
  factory SettingsService() => _instance;
  SettingsService._internal();

  late SharedPreferences _prefs;
  final _settingsController = StreamController<void>.broadcast();

  Stream<void> get settingsStream => _settingsController.stream;

  Future<void> initialize() async {
    _prefs = await SharedPreferences.getInstance();
  }

  String get videoPromptPrefix => _prefs.getString(_promptPrefixKey) ?? '';

  Future<void> setVideoPromptPrefix(String prefix) async {
    await _prefs.setString(_promptPrefixKey, prefix);
    _settingsController.add(null);
  }

  String get negativeVideoPrompt => _prefs.getString(_negativePromptKey) ?? Configuration.instance.defaultNegativePrompt;

  Future<void> setNegativeVideoPrompt(String negativePrompt) async {
    await _prefs.setString(_negativePromptKey, negativePrompt);
    _settingsController.add(null);
  }

  String get huggingfaceApiKey => _prefs.getString(_hfApiKeyKey) ?? '';

  Future<void> setHuggingfaceApiKey(String apiKey) async {
    await _prefs.setString(_hfApiKeyKey, apiKey);
    _settingsController.add(null);
  }
  
  bool get showSceneDebugInfo => _prefs.getBool(_showSceneDebugInfoKey) ?? false;
  
  Future<void> setShowSceneDebugInfo(bool value) async {
    await _prefs.setBool(_showSceneDebugInfoKey, value);
    _settingsController.add(null);
  }
  
  bool get enableSimulation => _prefs.getBool(_enableSimulationKey) ?? Configuration.instance.enableSimLoop;
  
  Future<void> setEnableSimulation(bool value) async {
    await _prefs.setBool(_enableSimulationKey, value);
    _settingsController.add(null);
  }

  int get simLoopDelayInSec => _prefs.getInt(_simLoopDelayKey) ?? 5;
  
  Future<void> setSimLoopDelayInSec(int value) async {
    await _prefs.setInt(_simLoopDelayKey, value);
    _settingsController.add(null);
  }

  String get gameMasterPrompt => _prefs.getString(_gameMasterPromptKey) ?? '';
  
  Future<void> setGameMasterPrompt(String value) async {
    await _prefs.setString(_gameMasterPromptKey, value);
    _settingsController.add(null);
  }

  String get llmProvider => _prefs.getString(_llmProviderKey) ?? 'built-in';
  
  Future<void> setLlmProvider(String provider) async {
    await _prefs.setString(_llmProviderKey, provider);
    _settingsController.add(null);
  }

  String get llmModel => _prefs.getString(_llmModelKey) ?? 'meta-llama/Llama-3.2-3B-Instruct';
  
  Future<void> setLlmModel(String model) async {
    await _prefs.setString(_llmModelKey, model);
    _settingsController.add(null);
  }

  void dispose() {
    _settingsController.close();
  }
}