Sync text zoom preference through the account instead of local settings

Local user://settings.cfg meant zoom level didn't follow a student
across devices/browsers. Question bank and CCS text scale now live on
the user's study profile in Mongo (QuestionTextScale/CcsTextScale),
synced through a new PUT /api/profile/me/text-scale endpoint and the
existing preferences GET/cache already used for study preferences.

Both question_player.gd and ccs_service.gd read the synced value at
startup and react to AccountProfileService.profile_changed so a value
pulled down after login (or changed from another session) applies
without a restart. Backend validates the 0.85-1.35 range and updates
only the field(s) provided via a targeted $set, so it can't clobber
the other scale or the unrelated study-profile preferences.
This commit is contained in:
hz
2026-07-23 03:59:02 -05:00
parent b88f38f29b
commit d69a1fd0e3
10 changed files with 124 additions and 36 deletions
+17 -17
View File
@@ -13,13 +13,11 @@ signal attempt_abandoned
signal report_submitted(report_id: String)
signal report_failed(message: String)
signal request_failed(message: String)
signal text_scale_changed
const TEXT_SCALE_MIN := 0.85
const TEXT_SCALE_MAX := 1.35
const TEXT_SCALE_STEP := 0.1
const TEXT_SCALE_SETTINGS_PATH := "user://settings.cfg"
const TEXT_SCALE_SETTINGS_SECTION := "study"
const TEXT_SCALE_SETTINGS_KEY := "ccs_text_scale"
var api_url := DEFAULT_API_URL
var request: HTTPRequest
@@ -40,11 +38,16 @@ var request_access_token := ""
func _ready() -> void:
api_url = EndpointConfig.resolve(str(ProjectSettings.get_setting("step3/ccs_api_url", DEFAULT_API_URL)), "/api/ccs")
text_scale = _load_text_scale_preference()
request = HTTPRequest.new()
request.request_completed.connect(_on_request_completed)
add_child(request)
AuthState.auth_changed.connect(_on_auth_changed)
call_deferred("_connect_account_profile_service")
func _connect_account_profile_service() -> void:
text_scale = _synced_text_scale()
AccountProfileService.profile_changed.connect(_on_account_profile_changed)
func load_cases() -> void:
@@ -104,23 +107,20 @@ func submit_report(attempt_id: String, category: String, details: String) -> voi
func adjust_text_scale(delta: float) -> void:
text_scale = clampf(text_scale + delta, TEXT_SCALE_MIN, TEXT_SCALE_MAX)
_save_text_scale_preference(text_scale)
AccountProfileService.update_text_scale(null, text_scale)
func _load_text_scale_preference() -> float:
var config := ConfigFile.new()
if config.load(TEXT_SCALE_SETTINGS_PATH) == OK:
var saved: float = config.get_value(TEXT_SCALE_SETTINGS_SECTION, TEXT_SCALE_SETTINGS_KEY, 1.0)
return clampf(saved, TEXT_SCALE_MIN, TEXT_SCALE_MAX)
return 1.0
func _synced_text_scale() -> float:
var saved: float = AccountProfileService.preferences.get("ccsTextScale", 1.0)
return clampf(saved, TEXT_SCALE_MIN, TEXT_SCALE_MAX)
func _save_text_scale_preference(value: float) -> void:
var config := ConfigFile.new()
config.load(TEXT_SCALE_SETTINGS_PATH)
config.set_value(TEXT_SCALE_SETTINGS_SECTION, TEXT_SCALE_SETTINGS_KEY, value)
if config.save(TEXT_SCALE_SETTINGS_PATH) != OK:
push_warning("Unable to save CCS text scale preference.")
func _on_account_profile_changed() -> void:
var synced := _synced_text_scale()
if is_equal_approx(synced, text_scale):
return
text_scale = synced
text_scale_changed.emit()
func toggle_highlight(attempt_id: String, region_id: String, start: int, end: int) -> void: