Skip to content

Commit 0d216f6

Browse files
committed
Rework game configuration foundation onto DB API services
1 parent d0ce8eb commit 0d216f6

34 files changed

Lines changed: 3252 additions & 2701 deletions

assets/toolbox/game-configuration/js/index.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { getSessionCurrent } from "../../../../src/api/session-api-client.js";
12
import {
23
createServerRepositoryClient,
34
readServerToolConstants,
45
requireServerConstant,
56
} from "../../../../src/api/server-api-client.js";
6-
import { getSessionCurrent } from "../../../../src/api/session-api-client.js";
77

88
const constants = readServerToolConstants("game-configuration");
99

@@ -82,6 +82,23 @@ function setText(element, value) {
8282
}
8383
}
8484

85+
function currentSession() {
86+
try {
87+
return getSessionCurrent();
88+
} catch {
89+
return { authenticated: false };
90+
}
91+
}
92+
93+
function redirectGuestWriteAction() {
94+
if (currentSession()?.authenticated === true) {
95+
return false;
96+
}
97+
setText(elements.statusLog, "Sign in before saving Game Configuration.");
98+
window.location.href = new URL("/account/sign-in.html", window.location.href).href;
99+
return true;
100+
}
101+
85102
function createListItem(text) {
86103
const item = document.createElement("li");
87104
item.textContent = text;
@@ -113,6 +130,15 @@ function clearForm() {
113130
input.value = "";
114131
}
115132
});
133+
if (elements.version) {
134+
elements.version.value = "";
135+
}
136+
if (elements.resolution) {
137+
elements.resolution.value = "1280x720";
138+
}
139+
if (elements.visibility) {
140+
elements.visibility.value = "Private";
141+
}
116142
}
117143

118144
function applyConfigurationToForm(configuration) {
@@ -127,23 +153,15 @@ function applyConfigurationToForm(configuration) {
127153
input.value = configuration[section] || "";
128154
}
129155
});
130-
}
131-
132-
function currentSession() {
133-
try {
134-
return getSessionCurrent();
135-
} catch {
136-
return { authenticated: false };
156+
if (elements.version) {
157+
elements.version.value = configuration.version || "";
137158
}
138-
}
139-
140-
function redirectGuestSaveAction() {
141-
if (currentSession()?.authenticated === true) {
142-
return false;
159+
if (elements.resolution) {
160+
elements.resolution.value = configuration.resolution || "1280x720";
161+
}
162+
if (elements.visibility) {
163+
elements.visibility.value = configuration.visibility || "Private";
143164
}
144-
setText(elements.statusLog, "Sign in before saving Game Configuration.");
145-
window.location.href = new URL("/account/sign-in.html", window.location.href).href;
146-
return true;
147165
}
148166

149167
function renderValidation(validation) {
@@ -250,6 +268,9 @@ elements.form?.addEventListener("change", renderFormValidation);
250268

251269
elements.form?.addEventListener("submit", (event) => {
252270
event.preventDefault();
271+
if (redirectGuestWriteAction()) {
272+
return;
273+
}
253274
const snapshot = repository.getSnapshot();
254275
const projectId = snapshot.handoff.activeProject?.id || "";
255276

@@ -259,10 +280,6 @@ elements.form?.addEventListener("submit", (event) => {
259280
return;
260281
}
261282

262-
if (redirectGuestSaveAction()) {
263-
return;
264-
}
265-
266283
const configuration = repository.updateConfiguration(projectId, readForm());
267284
const nextSnapshot = repository.getSnapshot();
268285
const message = configuration?.status === "Ready" || nextSnapshot.progressHandoff.readinessStatus === "Ready"

assets/toolbox/game-design/js/index.js

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getSessionCurrent } from "../../../../src/api/session-api-client.js";
12
import {
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

5972
function 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+
6595
function 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

292371
elements.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

Comments
 (0)