1+ import { getSessionCurrent } from "../../../../src/api/session-api-client.js" ;
12import {
23 createServerRepositoryClient ,
34 readServerToolConstants ,
@@ -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 ) {
@@ -62,6 +75,23 @@ function setText(element, value) {
6275 }
6376}
6477
78+ function currentSession ( ) {
79+ try {
80+ return getSessionCurrent ( ) ;
81+ } catch {
82+ return { authenticated : false } ;
83+ }
84+ }
85+
86+ function redirectGuestWriteAction ( ) {
87+ if ( currentSession ( ) ?. authenticated === true ) {
88+ return false ;
89+ }
90+ setText ( elements . statusLog , "Sign in before saving Game Design." ) ;
91+ window . location . href = new URL ( "/account/sign-in.html" , window . location . href ) . href ;
92+ return true ;
93+ }
94+
6595function populateSelect ( select , values , placeholder ) {
6696 if ( ! select ) {
6797 return ;
@@ -92,11 +122,18 @@ function readForm() {
92122 return {
93123 capabilityDemoAuthoring : repository . getActiveGame ( ) ?. purpose === "Capability Demo" ,
94124 capabilityDemoNotes : elements . capabilityDemoNotes ?. value ,
125+ coreLoop : elements . coreLoop ?. value ,
126+ designNotes : elements . designNotes ?. value ,
95127 designSummary : elements . designSummary ?. value ,
96128 gameType : elements . gameType ?. value ,
97129 genre : elements . genre ?. value ,
130+ loseCondition : elements . loseCondition ?. value ,
98131 playerMode : elements . playerMode ?. value ,
99- playStyle : elements . playStyle ?. value
132+ playStyle : elements . playStyle ?. value ,
133+ story : elements . story ?. value ,
134+ summary : elements . designSummary ?. value ,
135+ targetAudience : elements . targetAudience ?. value ,
136+ winCondition : elements . winCondition ?. value
100137 } ;
101138}
102139
@@ -116,6 +153,24 @@ function clearForm() {
116153 if ( elements . designSummary ) {
117154 elements . designSummary . value = "" ;
118155 }
156+ if ( elements . story ) {
157+ elements . story . value = "" ;
158+ }
159+ if ( elements . coreLoop ) {
160+ elements . coreLoop . value = "" ;
161+ }
162+ if ( elements . winCondition ) {
163+ elements . winCondition . value = "" ;
164+ }
165+ if ( elements . loseCondition ) {
166+ elements . loseCondition . value = "" ;
167+ }
168+ if ( elements . targetAudience ) {
169+ elements . targetAudience . value = "" ;
170+ }
171+ if ( elements . designNotes ) {
172+ elements . designNotes . value = "" ;
173+ }
119174 if ( elements . capabilityDemoNotes ) {
120175 elements . capabilityDemoNotes . value = "" ;
121176 }
@@ -140,7 +195,25 @@ function applyDesignToForm(design) {
140195 elements . playerMode . value = design . playerMode || "1 Player" ;
141196 }
142197 if ( elements . designSummary ) {
143- elements . designSummary . value = design . designSummary ;
198+ elements . designSummary . value = design . summary || design . designSummary ;
199+ }
200+ if ( elements . story ) {
201+ elements . story . value = design . story ;
202+ }
203+ if ( elements . coreLoop ) {
204+ elements . coreLoop . value = design . coreLoop ;
205+ }
206+ if ( elements . winCondition ) {
207+ elements . winCondition . value = design . winCondition ;
208+ }
209+ if ( elements . loseCondition ) {
210+ elements . loseCondition . value = design . loseCondition ;
211+ }
212+ if ( elements . targetAudience ) {
213+ elements . targetAudience . value = design . targetAudience ;
214+ }
215+ if ( elements . designNotes ) {
216+ elements . designNotes . value = design . designNotes ;
144217 }
145218 if ( elements . capabilityDemoNotes ) {
146219 elements . capabilityDemoNotes . value = design . capabilityDemoNotes ;
@@ -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 ( redirectGuestWriteAction ( ) ) {
374+ return ;
375+ }
294376 const result = repository . saveDesign ( readForm ( ) ) ;
295377 setText ( elements . statusLog , result . message ) ;
296378 render ( ) ;
0 commit comments