Skip to content

Commit

Permalink
fix score bug (scores not working) and default player name
Browse files Browse the repository at this point in the history
  • Loading branch information
vmleon committed Oct 16, 2023
1 parent 1a41703 commit 24ea2b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CurrentScoreController(CurrentScoreRepository currentScoreRepository, Sco
CurrentScoreDAO getByUuid(@PathVariable("uuid") String uuid) {
logger.info("GET /api/score/" + uuid);
CurrentScore score = currentScoreRepository.findByUuid(uuid).orElseThrow(() -> new NotAuthorizedOrNotFound());
return new CurrentScoreDAO(score.getUuid(),score.getName(), score.getScore() );
return new CurrentScoreDAO(score.getUuid(), score.getName(), score.getScore());
}

@PutMapping("/api/score/{uuid}")
Expand All @@ -49,15 +49,15 @@ CurrentScoreDAO addScore(@PathVariable("uuid") String uuid, @RequestBody ScoreOp
scoreFromStore.setName(body.getName());
scoreFromStore.setUuid(uuid);
CurrentScore saved = currentScoreRepository.save(scoreFromStore);
return new CurrentScoreDAO(saved.getUuid(),saved.getName(), saved.getScore() );
return new CurrentScoreDAO(saved.getUuid(), saved.getName(), saved.getScore());
}

@DeleteMapping("/api/score/{uuid}")
@Transactional
ResponseEntity<Void> deleteByUuid(@PathVariable("uuid") String uuid) {
logger.info("DELETE /api/score/" + uuid);
CurrentScore currentScoreFromStore =
currentScoreRepository.findByUuid(uuid).orElseThrow(() -> new NotAuthorizedOrNotFound());
CurrentScore currentScoreFromStore = currentScoreRepository.findByUuid(uuid)
.orElseThrow(() -> new NotAuthorizedOrNotFound());
Score scoreFromStore = scoreRepository.findByUuid(uuid).orElse(new Score(uuid,
currentScoreFromStore.getName(), 0L));
if (currentScoreFromStore.getScore() > scoreFromStore.getScore()) {
Expand Down
7 changes: 5 additions & 2 deletions server/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const isProduction = process.env.NODE_ENV === "production";
const logger = pino({ level: isProduction ? "warn" : "debug" });

let scoreFeatureFlag = true;
let scoreServiceUrl;

const SCORE_SERVICE_HOST = process.env.SCORE_SERVICE_HOST;
if (!SCORE_SERVICE_HOST) {
Expand All @@ -20,7 +21,8 @@ if (!SCORE_SERVICE_PORT) {
}

if (scoreFeatureFlag) {
const scoreServiceUrl = `${SCORE_SERVICE_HOST}:${SCORE_SERVICE_PORT}`;
scoreServiceUrl = `${SCORE_SERVICE_HOST}:${SCORE_SERVICE_PORT}`;
logger.info({ scoreServiceUrl });
logger.info(`Connecting to Score on ${scoreServiceUrl}`);
}

Expand All @@ -32,7 +34,8 @@ export async function postCurrentScore(playerId, playerName, operationType) {
name: playerName,
});
// FIXME thrown exceptions will kill the process!
await fetch(`http://${scoreServiceUrl}/api/score/${playerId}`, {
const urlRequest = `http://${scoreServiceUrl}/api/score/${playerId}`;
await fetch(urlRequest, {
method: "PUT",
headers: { "Content-type": "application/json" },
body: stringifyBody,
Expand Down
7 changes: 4 additions & 3 deletions web/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (!localStorage.getItem("yourId")) {
localStorage.setItem("yourId", short());
}
const yourId = localStorage.getItem("yourId");
let playerName = localStorage.getItem("yourName") || "Default";
let playerName;

let renderer, scene, camera, sun, water;
let canvas;
Expand Down Expand Up @@ -57,6 +57,7 @@ const createGameButton = document.getElementById("create-game-button");
createGameButton.addEventListener("click", init);

async function init() {
playerName = localStorage.getItem("yourName") || "Default";
scene = new THREE.Scene();

function fibonacciGenerator(maxTerm) {
Expand Down Expand Up @@ -130,8 +131,8 @@ async function init() {
];

const materials = [
new THREE.MeshPhongMaterial({ color: 0x90EE90 }), // green material for wildlife
new THREE.MeshPhongMaterial({ color: 0xBB8E51 }), // brown material for trash
new THREE.MeshPhongMaterial({ color: 0x90ee90 }), // green material for wildlife
new THREE.MeshPhongMaterial({ color: 0xbb8e51 }), // brown material for trash
];

//add music loader
Expand Down

0 comments on commit 24ea2b9

Please sign in to comment.