Skip to content

Commit e6cd132

Browse files
authored
Merge pull request #11 from oracle-devrel/default-score-issue
fix score bug (scores not working) and default player name
2 parents 1a41703 + 24ea2b9 commit e6cd132

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

score/src/main/java/com/oracle/developer/multiplayer/score/CurrentScoreController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public CurrentScoreController(CurrentScoreRepository currentScoreRepository, Sco
3232
CurrentScoreDAO getByUuid(@PathVariable("uuid") String uuid) {
3333
logger.info("GET /api/score/" + uuid);
3434
CurrentScore score = currentScoreRepository.findByUuid(uuid).orElseThrow(() -> new NotAuthorizedOrNotFound());
35-
return new CurrentScoreDAO(score.getUuid(),score.getName(), score.getScore() );
35+
return new CurrentScoreDAO(score.getUuid(), score.getName(), score.getScore());
3636
}
3737

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

5555
@DeleteMapping("/api/score/{uuid}")
5656
@Transactional
5757
ResponseEntity<Void> deleteByUuid(@PathVariable("uuid") String uuid) {
5858
logger.info("DELETE /api/score/" + uuid);
59-
CurrentScore currentScoreFromStore =
60-
currentScoreRepository.findByUuid(uuid).orElseThrow(() -> new NotAuthorizedOrNotFound());
59+
CurrentScore currentScoreFromStore = currentScoreRepository.findByUuid(uuid)
60+
.orElseThrow(() -> new NotAuthorizedOrNotFound());
6161
Score scoreFromStore = scoreRepository.findByUuid(uuid).orElse(new Score(uuid,
6262
currentScoreFromStore.getName(), 0L));
6363
if (currentScoreFromStore.getScore() > scoreFromStore.getScore()) {

server/score.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const isProduction = process.env.NODE_ENV === "production";
77
const logger = pino({ level: isProduction ? "warn" : "debug" });
88

99
let scoreFeatureFlag = true;
10+
let scoreServiceUrl;
1011

1112
const SCORE_SERVICE_HOST = process.env.SCORE_SERVICE_HOST;
1213
if (!SCORE_SERVICE_HOST) {
@@ -20,7 +21,8 @@ if (!SCORE_SERVICE_PORT) {
2021
}
2122

2223
if (scoreFeatureFlag) {
23-
const scoreServiceUrl = `${SCORE_SERVICE_HOST}:${SCORE_SERVICE_PORT}`;
24+
scoreServiceUrl = `${SCORE_SERVICE_HOST}:${SCORE_SERVICE_PORT}`;
25+
logger.info({ scoreServiceUrl });
2426
logger.info(`Connecting to Score on ${scoreServiceUrl}`);
2527
}
2628

@@ -32,7 +34,8 @@ export async function postCurrentScore(playerId, playerName, operationType) {
3234
name: playerName,
3335
});
3436
// FIXME thrown exceptions will kill the process!
35-
await fetch(`http://${scoreServiceUrl}/api/score/${playerId}`, {
37+
const urlRequest = `http://${scoreServiceUrl}/api/score/${playerId}`;
38+
await fetch(urlRequest, {
3639
method: "PUT",
3740
headers: { "Content-type": "application/json" },
3841
body: stringifyBody,

web/src/script.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (!localStorage.getItem("yourId")) {
2828
localStorage.setItem("yourId", short());
2929
}
3030
const yourId = localStorage.getItem("yourId");
31-
let playerName = localStorage.getItem("yourName") || "Default";
31+
let playerName;
3232

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

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

6263
function fibonacciGenerator(maxTerm) {
@@ -130,8 +131,8 @@ async function init() {
130131
];
131132

132133
const materials = [
133-
new THREE.MeshPhongMaterial({ color: 0x90EE90 }), // green material for wildlife
134-
new THREE.MeshPhongMaterial({ color: 0xBB8E51 }), // brown material for trash
134+
new THREE.MeshPhongMaterial({ color: 0x90ee90 }), // green material for wildlife
135+
new THREE.MeshPhongMaterial({ color: 0xbb8e51 }), // brown material for trash
135136
];
136137

137138
//add music loader

0 commit comments

Comments
 (0)