33 readServerToolConstants ,
44 requireServerConstant ,
55} from "../../../../src/api/server-api-client.js" ;
6+ import { getSessionCurrent } from "../../../../src/api/session-api-client.js" ;
67
78const constants = readServerToolConstants ( "game-design" ) ;
89
@@ -30,7 +31,9 @@ const elements = {
3031 capabilityDemoNotes : document . querySelector ( "[data-game-design-capability-notes]" ) ,
3132 capabilityDemoPanel : document . querySelector ( "[data-game-design-capability-panel]" ) ,
3233 configurationLink : document . querySelector ( "[data-game-design-configuration-link]" ) ,
34+ coreLoop : document . querySelector ( "[data-game-design-core-loop]" ) ,
3335 designSummary : document . querySelector ( "[data-game-design-summary]" ) ,
36+ designNotes : document . querySelector ( "[data-game-design-notes]" ) ,
3437 designStatus : document . querySelector ( "[data-game-design-status]" ) ,
3538 form : document . querySelector ( "[data-game-design-form]" ) ,
3639 gameType : document . querySelector ( "[data-game-design-type]" ) ,
@@ -40,20 +43,30 @@ const elements = {
4043 handoffProgress : document . querySelector ( "[data-game-design-game-progress]" ) ,
4144 handoffPublishing : document . querySelector ( "[data-game-design-publishing-progress]" ) ,
4245 handoffRecommended : document . querySelector ( "[data-game-design-recommended-tool]" ) ,
46+ loseCondition : document . querySelector ( "[data-game-design-lose-condition]" ) ,
47+ outputAudience : document . querySelector ( "[data-game-design-output-audience]" ) ,
4348 outputCapability : document . querySelector ( "[data-game-design-output-capability]" ) ,
49+ outputCoreLoop : document . querySelector ( "[data-game-design-output-core-loop]" ) ,
50+ outputLose : document . querySelector ( "[data-game-design-output-lose]" ) ,
4451 outputMissing : document . querySelector ( "[data-game-design-output-missing]" ) ,
4552 outputNextStep : document . querySelector ( "[data-game-design-output-next-step]" ) ,
53+ outputNotes : document . querySelector ( "[data-game-design-output-notes]" ) ,
4654 outputPlayerMode : document . querySelector ( "[data-game-design-output-player-mode]" ) ,
55+ outputStory : document . querySelector ( "[data-game-design-output-story]" ) ,
4756 outputSummary : document . querySelector ( "[data-game-design-output-summary]" ) ,
4857 outputValidation : document . querySelector ( "[data-game-design-output-validation]" ) ,
58+ outputWin : document . querySelector ( "[data-game-design-output-win]" ) ,
4959 playerMode : document . querySelector ( "[data-game-design-player-mode]" ) ,
5060 playStyle : document . querySelector ( "[data-game-design-play-style]" ) ,
61+ story : document . querySelector ( "[data-game-design-story]" ) ,
62+ targetAudience : document . querySelector ( "[data-game-design-target-audience]" ) ,
5163 gameContext : document . querySelector ( "[data-game-design-game-context]" ) ,
5264 gameOverlay : document . querySelector ( "[data-game-design-game-overlay]" ) ,
5365 statusLog : document . querySelector ( "[data-game-design-log]" ) ,
5466 tableCounts : document . querySelector ( "[data-game-design-table-counts]" ) ,
5567 validationList : document . querySelector ( "[data-game-design-validation-list]" ) ,
56- validationOverlay : document . querySelector ( "[data-game-design-validation-overlay]" )
68+ validationOverlay : document . querySelector ( "[data-game-design-validation-overlay]" ) ,
69+ winCondition : document . querySelector ( "[data-game-design-win-condition]" )
5770} ;
5871
5972function setText ( element , value ) {
@@ -92,11 +105,18 @@ function readForm() {
92105 return {
93106 capabilityDemoAuthoring : repository . getActiveGame ( ) ?. purpose === "Capability Demo" ,
94107 capabilityDemoNotes : elements . capabilityDemoNotes ?. value ,
108+ coreLoop : elements . coreLoop ?. value ,
109+ designNotes : elements . designNotes ?. value ,
95110 designSummary : elements . designSummary ?. value ,
96111 gameType : elements . gameType ?. value ,
97112 genre : elements . genre ?. value ,
113+ loseCondition : elements . loseCondition ?. value ,
98114 playerMode : elements . playerMode ?. value ,
99- playStyle : elements . playStyle ?. value
115+ playStyle : elements . playStyle ?. value ,
116+ story : elements . story ?. value ,
117+ summary : elements . designSummary ?. value ,
118+ targetAudience : elements . targetAudience ?. value ,
119+ winCondition : elements . winCondition ?. value
100120 } ;
101121}
102122
@@ -116,6 +136,24 @@ function clearForm() {
116136 if ( elements . designSummary ) {
117137 elements . designSummary . value = "" ;
118138 }
139+ if ( elements . story ) {
140+ elements . story . value = "" ;
141+ }
142+ if ( elements . coreLoop ) {
143+ elements . coreLoop . value = "" ;
144+ }
145+ if ( elements . winCondition ) {
146+ elements . winCondition . value = "" ;
147+ }
148+ if ( elements . loseCondition ) {
149+ elements . loseCondition . value = "" ;
150+ }
151+ if ( elements . targetAudience ) {
152+ elements . targetAudience . value = "" ;
153+ }
154+ if ( elements . designNotes ) {
155+ elements . designNotes . value = "" ;
156+ }
119157 if ( elements . capabilityDemoNotes ) {
120158 elements . capabilityDemoNotes . value = "" ;
121159 }
@@ -140,13 +178,48 @@ function applyDesignToForm(design) {
140178 elements . playerMode . value = design . playerMode || "1 Player" ;
141179 }
142180 if ( elements . designSummary ) {
143- elements . designSummary . value = design . designSummary ;
181+ elements . designSummary . value = design . summary || design . designSummary ;
182+ }
183+ if ( elements . story ) {
184+ elements . story . value = design . story ;
185+ }
186+ if ( elements . coreLoop ) {
187+ elements . coreLoop . value = design . coreLoop ;
188+ }
189+ if ( elements . winCondition ) {
190+ elements . winCondition . value = design . winCondition ;
191+ }
192+ if ( elements . loseCondition ) {
193+ elements . loseCondition . value = design . loseCondition ;
194+ }
195+ if ( elements . targetAudience ) {
196+ elements . targetAudience . value = design . targetAudience ;
197+ }
198+ if ( elements . designNotes ) {
199+ elements . designNotes . value = design . designNotes ;
144200 }
145201 if ( elements . capabilityDemoNotes ) {
146202 elements . capabilityDemoNotes . value = design . capabilityDemoNotes ;
147203 }
148204}
149205
206+ function currentSession ( ) {
207+ try {
208+ return getSessionCurrent ( ) ;
209+ } catch {
210+ return { authenticated : false } ;
211+ }
212+ }
213+
214+ function redirectGuestSaveAction ( ) {
215+ if ( currentSession ( ) ?. authenticated === true ) {
216+ return false ;
217+ }
218+ setText ( elements . statusLog , "Sign in before saving Game Design." ) ;
219+ window . location . href = new URL ( "/account/sign-in.html" , window . location . href ) . href ;
220+ return true ;
221+ }
222+
150223function renderValidation ( validation ) {
151224 if ( ! elements . validationList || ! elements . validationOverlay ) {
152225 return ;
@@ -225,7 +298,13 @@ function renderOutput(snapshot, validation) {
225298 const activeGame = snapshot . activeGame || snapshot . activeProject ;
226299 const missingRequirements = validation . findings . map ( ( finding ) => finding . label ) . join ( ", " ) ;
227300
228- setText ( elements . outputSummary , activeDesign ?. designSummary || "No design summary saved yet." ) ;
301+ setText ( elements . outputSummary , activeDesign ?. summary || activeDesign ?. designSummary || "No design summary saved yet." ) ;
302+ setText ( elements . outputStory , activeDesign ?. story || "No story saved yet." ) ;
303+ setText ( elements . outputCoreLoop , activeDesign ?. coreLoop || "No core loop saved yet." ) ;
304+ setText ( elements . outputWin , activeDesign ?. winCondition || "No win condition saved yet." ) ;
305+ setText ( elements . outputLose , activeDesign ?. loseCondition || "No lose condition saved yet." ) ;
306+ setText ( elements . outputAudience , activeDesign ?. targetAudience || "No audience saved yet." ) ;
307+ setText ( elements . outputNotes , activeDesign ?. designNotes || "No notes saved yet." ) ;
229308 setText ( elements . outputPlayerMode , activeDesign ?. playerMode || "1 Player" ) ;
230309 setText ( elements . outputValidation , validation . status ) ;
231310 setText ( elements . outputNextStep , snapshot . progressHandoff . recommendedNextTool ) ;
@@ -291,6 +370,9 @@ elements.form?.addEventListener("input", renderFormValidation);
291370
292371elements . form ?. addEventListener ( "submit" , ( event ) => {
293372 event . preventDefault ( ) ;
373+ if ( redirectGuestSaveAction ( ) ) {
374+ return ;
375+ }
294376 const result = repository . saveDesign ( readForm ( ) ) ;
295377 setText ( elements . statusLog , result . message ) ;
296378 render ( ) ;
0 commit comments