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:
@@ -58,6 +58,8 @@ func _ready() -> void:
|
||||
resized.connect(_update_responsive_layout)
|
||||
if not theme_service.theme_changed.is_connected(_on_theme_changed):
|
||||
theme_service.theme_changed.connect(_on_theme_changed)
|
||||
if not CCSService.text_scale_changed.is_connected(_apply_text_scale):
|
||||
CCSService.text_scale_changed.connect(_apply_text_scale)
|
||||
_apply_theme()
|
||||
call_deferred("_update_responsive_layout")
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ func _ready() -> void:
|
||||
status = Label.new(); Style.set_label(status, 14, Style.RED); row.add_child(status)
|
||||
CCSService.request_failed.connect(_request_failed)
|
||||
if not theme_service.theme_changed.is_connected(_on_theme_changed): theme_service.theme_changed.connect(_on_theme_changed)
|
||||
if not CCSService.text_scale_changed.is_connected(_apply_text_scale): CCSService.text_scale_changed.connect(_apply_text_scale)
|
||||
|
||||
func _study_label(region: String) -> RichTextLabel:
|
||||
var label := RichTextLabel.new(); label.bbcode_enabled = true; label.fit_content = true; label.selection_enabled = true; label.set_meta("ccs_region", region); label.gui_input.connect(_text_input.bind(label)); return label
|
||||
|
||||
@@ -18,9 +18,6 @@ const CORRECT_ADVANCE_DELAY_SECONDS := 1.25
|
||||
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 := "question_text_scale"
|
||||
const REPORT_DETAILS_MIN := 10
|
||||
const REPORT_DETAILS_MAX := 2000
|
||||
const MEDIA_ZOOM_MIN := 0.25
|
||||
@@ -149,7 +146,9 @@ var shake_origin := Vector2.ZERO
|
||||
|
||||
func _ready() -> void:
|
||||
theme_service = get_node("/root/UIThemeService")
|
||||
question_text_scale = _load_text_scale_preference()
|
||||
question_text_scale = _synced_question_text_scale()
|
||||
if not AccountProfileService.profile_changed.is_connected(_on_account_profile_changed):
|
||||
AccountProfileService.profile_changed.connect(_on_account_profile_changed)
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
add_theme_constant_override("separation", 10)
|
||||
if not QuestionBankService.choice_percentages_updated.is_connected(_on_choice_percentages_updated):
|
||||
@@ -2125,26 +2124,25 @@ func _adjust_question_text_scale(delta: float) -> void:
|
||||
if is_equal_approx(next_scale, question_text_scale):
|
||||
return
|
||||
question_text_scale = next_scale
|
||||
_save_text_scale_preference(next_scale)
|
||||
AccountProfileService.update_text_scale(next_scale)
|
||||
_refresh_scaled_fonts(self)
|
||||
_render_stem()
|
||||
_apply_saved_choice_state()
|
||||
|
||||
|
||||
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 clamp(saved, TEXT_SCALE_MIN, TEXT_SCALE_MAX)
|
||||
return 1.0
|
||||
func _synced_question_text_scale() -> float:
|
||||
var saved: float = AccountProfileService.preferences.get("questionTextScale", 1.0)
|
||||
return clamp(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 question text scale preference.")
|
||||
func _on_account_profile_changed() -> void:
|
||||
var synced := _synced_question_text_scale()
|
||||
if is_equal_approx(synced, question_text_scale):
|
||||
return
|
||||
question_text_scale = synced
|
||||
_refresh_scaled_fonts(self)
|
||||
_render_stem()
|
||||
_apply_saved_choice_state()
|
||||
|
||||
|
||||
func _set_scaled_label(label: Label, base_size: int, color: Color = Style.TEXT) -> void:
|
||||
|
||||
Reference in New Issue
Block a user