11import { SCORM2004_INTERACTION_FORMAT } from '../interaction-format.js' ;
2- import type { Interaction } from '../interaction.js' ;
32import type { SavedState } from '../persistence.js' ;
43import { BaseScormAdapter , type ScormDialect } from './scorm-base.js' ;
54import {
@@ -75,7 +74,7 @@ export class SCORM2004Adapter extends BaseScormAdapter<SCORM2004API> {
7574 return this . #masteryScore;
7675 }
7776
78- get # canWrite( ) : boolean {
77+ protected canWrite ( ) : boolean {
7978 return this . #mode === 'normal' ;
8079 }
8180
@@ -98,80 +97,38 @@ export class SCORM2004Adapter extends BaseScormAdapter<SCORM2004API> {
9897 }
9998
10099 saveState ( state : SavedState ) : void {
101- if ( ! this . #canWrite) return ;
102100 super . saveState ( state ) ;
103101 // §4.2.1.4 — bookmark for LMS "Resume from page N" affordances.
104- this . queue . enqueue (
105- ( ) => this . api . SetValue ( 'cmi.location' , String ( state . b ) ) ,
106- 'cmi.location' ,
107- ) ;
108- }
109-
110- setDuration ( seconds : number ) : void {
111- if ( ! this . #canWrite) return ;
112- super . setDuration ( seconds ) ;
113- }
114-
115- reportInteraction (
116- questionId : string ,
117- interaction : Interaction ,
118- correct : boolean | null ,
119- ) : void {
120- if ( ! this . #canWrite) return ;
121- super . reportInteraction ( questionId , interaction , correct ) ;
102+ this . set ( 'cmi.location' , String ( state . b ) ) ;
122103 }
123104
124105 setScore ( score : number ) : void {
125- if ( ! this . #canWrite) return ;
126- const raw = formatReal107 ( score ) ;
106+ this . set ( 'cmi.score.raw' , formatReal107 ( score ) ) ;
107+ this . set ( 'cmi.score.min' , '0' ) ;
108+ this . set ( 'cmi.score.max' , '100' ) ;
127109 // §4.2.4.3.5 — score.scaled is bounded to [-1, 1].
128- const scaled = formatReal107 ( Math . max ( 0 , Math . min ( 1 , score / 100 ) ) ) ;
129- this . queue . enqueue (
130- ( ) => this . api . SetValue ( 'cmi.score.raw' , raw ) ,
131- 'cmi.score.raw' ,
132- ) ;
133- this . queue . enqueue (
134- ( ) => this . api . SetValue ( 'cmi.score.min' , '0' ) ,
135- 'cmi.score.min' ,
136- ) ;
137- this . queue . enqueue (
138- ( ) => this . api . SetValue ( 'cmi.score.max' , '100' ) ,
139- 'cmi.score.max' ,
140- ) ;
141- this . queue . enqueue (
142- ( ) => this . api . SetValue ( 'cmi.score.scaled' , scaled ) ,
110+ this . set (
143111 'cmi.score.scaled' ,
112+ formatReal107 ( Math . max ( 0 , Math . min ( 1 , score / 100 ) ) ) ,
144113 ) ;
145114 }
146115
147116 setCompletionStatus ( status : 'incomplete' | 'complete' ) : void {
148- if ( ! this . #canWrite) return ;
149- const value = status === 'complete' ? 'completed' : 'incomplete' ;
150- this . queue . enqueue (
151- ( ) => this . api . SetValue ( 'cmi.completion_status' , value ) ,
117+ this . set (
152118 'cmi.completion_status' ,
119+ status === 'complete' ? 'completed' : 'incomplete' ,
153120 ) ;
154121 // §4.2.4.2 — writing 1.0 surfaces a "100%" reading on LMS dashboards.
155- if ( status === 'complete' ) {
156- this . queue . enqueue (
157- ( ) => this . api . SetValue ( 'cmi.progress_measure' , '1' ) ,
158- 'cmi.progress_measure' ,
159- ) ;
160- }
122+ if ( status === 'complete' ) this . set ( 'cmi.progress_measure' , '1' ) ;
161123 }
162124
163125 setSuccessStatus ( status : 'passed' | 'failed' | 'unknown' ) : void {
164- if ( ! this . #canWrite) return ;
165126 // Setting "unknown" explicitly prevents SCORM Cloud from rolling up
166127 // a null status to "passed".
167- this . queue . enqueue (
168- ( ) => this . api . SetValue ( 'cmi.success_status' , status ) ,
169- 'cmi.success_status' ,
170- ) ;
128+ this . set ( 'cmi.success_status' , status ) ;
171129 }
172130
173131 setExit ( mode : 'suspend' | 'normal' ) : void {
174- if ( ! this . #canWrite) return ;
175- this . queue . enqueue ( ( ) => this . api . SetValue ( 'cmi.exit' , mode ) , 'cmi.exit' ) ;
132+ this . set ( 'cmi.exit' , mode ) ;
176133 }
177134}
0 commit comments