Commit 4b5d6d2d authored by Zak Stephens's avatar Zak Stephens

Use CORS (free love), change snapshot format slightly.

parent 3744f833
'use strict';
const config = require('config');
const cors = require('cors');
const express = require('express');
const fs = require('fs');
const https = require('https');
......@@ -30,6 +31,12 @@ const app = express();
/* Don't start serving until dependency setup is complete.
* It makes the code easier to reason about. */
/* Free love, baby. */
app.use(cors({
credentials: true,
origin: true
}));
app.use('/api/v1/microtransactions', require('./routes/microtransactions'));
app.use('/api/v1/messages', require('./routes/messages')(gameState));
app.use('/api/v1/players', require('./routes/players')(gameState, playerRepository));
......
......@@ -36,11 +36,14 @@ function loadTiles(tiledExport, map) {
}
module.exports = (filePath, gameState) => {
const map = {};
const tiledExport = require(filePath);
assert(!tiledExport.infinite, 'infinite maps are not supported');
const map = {
width: tiledExport.width,
height: tiledExport.height
};
loadCollisions(tiledExport, map);
loadTiles(tiledExport, map);
......
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.2" orientation="orthogonal" renderorder="right-down" width="25" height="25" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#000000" nextlayerid="10" nextobjectid="1">
<map version="1.2" tiledversion="1.2.2" orientation="orthogonal" renderorder="right-down" width="25" height="25" tilewidth="32" tileheight="32" infinite="0" nextlayerid="10" nextobjectid="1">
<tileset firstgid="1" name="magecity" tilewidth="32" tileheight="32" tilecount="360" columns="8">
<image source="magecity.png" width="256" height="1450"/>
<image source="../../maps/magecity.png" width="256" height="1450"/>
</tileset>
<tileset firstgid="361" name="collision" tilewidth="32" tileheight="32" tilecount="1" columns="1">
<image source="collision.png" width="32" height="32"/>
<image source="../../maps/collision.png" width="32" height="32"/>
</tileset>
<layer id="6" name="Background" width="25" height="25">
<data encoding="csv">
......@@ -37,7 +37,7 @@
</layer>
<layer id="7" name="DecorationBack" width="25" height="25">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
361,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
......
......@@ -225,6 +225,15 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"dashdash": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
......
......@@ -19,6 +19,7 @@
"argon2": "^0.21.0",
"basic-auth": "^2.0.1",
"config": "^3.1.0",
"cors": "^2.8.5",
"express": "^4.16.4",
"sqlite3": "^4.0.6",
"uuid": "^3.3.2"
......
......@@ -28,9 +28,9 @@ module.exports = (gameState, playerRepository) => {
express.json(),
async (req, res) => {
const id = await playerRepository.getPlayerIdFromUsername(req.params.username);
const player = await playerUtils.getPlayerState(id);
const player = await playerUtil.getPlayerState(id, gameState, playerRepository);
let {x, y} = player.location;
let {x, y, map} = player.location;
switch (req.body.direction) {
case 'left':
......@@ -53,7 +53,8 @@ module.exports = (gameState, playerRepository) => {
return res.sendStatus(409);
}
player.location = {x, y};
player.location.x = x;
player.location.y = y;
res.sendStatus(204);
}
......
......@@ -11,11 +11,13 @@ module.exports = (gameState, playerRepository) => {
const currentPlayerState = await playerUtil.getPlayerState(currentPlayerId, gameState, playerRepository);
const snapshot = {
players: {},
map: {
collision: gameState.maps[currentPlayerState.location.map].collision,
width: gameState.maps[currentPlayerState.location.map].width,
height: gameState.maps[currentPlayerState.location.map].height,
tiles: gameState.maps[currentPlayerState.location.map].tiles
},
players: {},
messages: gameState.messages
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment