diff --git a/src/app.ts b/src/app.ts index 84527cf..caf772f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,6 +2,7 @@ import * as graphqlHTTP from "express-graphql"; import {buildSchema} from "graphql"; import { GameServer } from "./GameServer"; +import { Direction, MazeTile } from "./MazeMap"; import { createSampleMaps } from "./SampleMaps"; const port = 8080; @@ -9,28 +10,67 @@ const app = express(); const schema = buildSchema(` + enum Direction { + none + top + left + bottom + right + } + """ Representing a tile with it's possible pathways. """ - type MazeTile { + type MazeTileQL { id: String! - paths: [Int!]! + paths: [Direction!]! + } + + type Mutation { + "Start a new game" + startGame(userID: String!, mapID: String!): MazeTileQL } type Query { - currentPostition(userID: String!): MazeTile + "Tells you your where you currently are and how it looks there in case you forgot." + currentPostition(userID: String!): MazeTileQL + "Lists currently available maps." listMaps: [String!]! } `); +class MazeTileQL +{ + public static DirectionToString(dir:Direction): string + { + switch (dir) { + case Direction.none: return "none"; + case Direction.top: return "top"; + case Direction.left: return "left"; + case Direction.bottom: return "bottom"; + case Direction.right: return "right"; + } + } + + public id:string; + public paths:string[]; + + constructor(tile:MazeTile) + { + this.id = tile.id; + this.paths = tile.paths.map(MazeTileQL.DirectionToString); + } +} + const games = new GameServer(); const maps = createSampleMaps(); maps.forEach(m => games.addMap(m)); const root = { - currentPostition: ({userID}) => games.currentPosition(userID), + currentPostition: ({userID}) => new MazeTileQL(games.currentPosition(userID)), listMaps: () => games.listMaps(), + startGame: ({userID, mapID}) => new MazeTileQL(games.startGame(userID, mapID)), }; app.use(apiRoot, graphqlHTTP({