Skip to content

Commit d02e771

Browse files
Merge branch 'add-stub-preview' into 'master'
[FEAT][SDK] add stub preview See merge request codingame/game-engine!234
2 parents 4e8e05b + 8be10a6 commit d02e771

File tree

6 files changed

+238
-353
lines changed

6 files changed

+238
-353
lines changed

playground/misc/misc-3-release-notes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## 3.7.0
6+
7+
### 🎁 New features
8+
9+
- Add possibility to edit and preview the stub: http://localhost:8888/stub.html
10+
11+
### 🐞 Bug fix
12+
13+
- Fix display of error messages
14+
515
## 3.6.1
616

717
### 🐞 Bug fix

runner/src/main/java/com/codingame/gameengine/runner/Renderer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.net.JarURLConnection;
1111
import java.net.URISyntaxException;
1212
import java.net.URL;
13+
import java.nio.charset.StandardCharsets;
1314
import java.nio.file.FileVisitResult;
1415
import java.nio.file.Files;
1516
import java.nio.file.NoSuchFileException;
@@ -675,6 +676,23 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
675676
}
676677

677678
exchange.setStatusCode(StatusCodes.OK);
679+
} if (exchange.getRelativePath().equals("/stub")) {
680+
File stubFile = sourceFolderPath.resolve("config/stub.txt").toFile();
681+
if (exchange.getRequestMethod().equalToString("GET")) {
682+
String stub = FileUtils.readFileToString(stubFile, StandardCharsets.UTF_8);
683+
exchange.getResponseSender().send(stub);
684+
} else if (exchange.getRequestMethod().equalToString("PUT")) {
685+
exchange.getRequestReceiver().receiveFullString((e, data) -> {
686+
try {
687+
FileUtils.writeStringToFile(stubFile, data);
688+
exchange.setStatusCode(StatusCodes.CREATED);
689+
} catch (IOException ex) {
690+
sendException(e, ex, StatusCodes.BAD_REQUEST);
691+
}
692+
});
693+
} else {
694+
exchange.setStatusCode(StatusCodes.NOT_FOUND);
695+
}
678696
}
679697
} catch (MissingConfigException e) {
680698
sendException(exchange, e, StatusCodes.UNPROCESSABLE_ENTITY);

runner/src/main/resources/view/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as config from '../config.js'
22
import { demo as defaultDemo } from '../demo.js'
3-
import Parser from './lib/Parser.js'
3+
import './lib/cginput.js'
44
import './player.js'
55

66
const createCGPlayer = (opts) => {
@@ -279,10 +279,9 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
279279
const exportResponseString = await data.text()
280280
let exportResponse = JSON.parse(exportResponseString)
281281

282-
let stubParser = new Parser()
283282
for (let stub in exportResponse.stubs) {
284283
try {
285-
stubParser.parse(exportResponse.stubs[stub], 0)
284+
window.cginput.parseStubInput(exportResponse.stubs[stub], 0)
286285
} catch (e) {
287286
exportResponse.reportItems.push({
288287
'type': 'WARNING',

0 commit comments

Comments
 (0)