From ddea33ef6bad4794a07628d09a1cd6d69b74105f Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 5 Oct 2019 14:09:28 -0400 Subject: [PATCH] stuff is wired up, but not quite communicating yet --- src/Server/Program.fs | 24 +++++------------------- src/Server/WebRoot/index.html | 15 +++++++++++++++ src/Server/WebRoot/main.js | 7 +++++-- 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 src/Server/WebRoot/index.html diff --git a/src/Server/Program.fs b/src/Server/Program.fs index bcf1621..66e2362 100644 --- a/src/Server/Program.fs +++ b/src/Server/Program.fs @@ -19,37 +19,23 @@ open Game.Game // Web app // --------------------------------- -let indexHandler (name: string) = - let view = Views.index() - htmlView view - -let mapHandler() = - let floor = [ - [ Wall Corner; Wall EW; Wall EW; Wall EW; Wall Corner ]; - [ Wall NS; Floor; Floor; Floor; Wall NS ]; - [ Wall NS; Floor; Floor; Floor; Wall NS ]; - [ Wall NS; Floor; Floor; Floor; Wall NS ]; - [ Wall Corner; Wall EW; Wall EW; Wall EW; Wall Corner ] - ] - json Current.JSON - let moveHandler (next: HttpFunc) (ctx: HttpContext) = task { let! cmd = ctx.BindJsonAsync() - return! (mapHandler()) next ctx + Current.cmd cmd |> ignore + return! (json Current.JSON) next ctx } let webApp = choose [ GET >=> choose [ - route "/" >=> indexHandler "world" - routef "/hello/%s" indexHandler - route "/map" >=> mapHandler() + route "/" >=> htmlFile "WebRoot/index.html" + route "/map" >=> json Current.JSON ] POST >=> choose [ - route "/move" >=> moveHandler + route "/cmd" >=> moveHandler ] setStatusCode 404 >=> text "Not Found" ] diff --git a/src/Server/WebRoot/index.html b/src/Server/WebRoot/index.html new file mode 100644 index 0000000..d71ff1c --- /dev/null +++ b/src/Server/WebRoot/index.html @@ -0,0 +1,15 @@ + + + + + + + + +

Dis my dumb game

+
+
+ +
+ + \ No newline at end of file diff --git a/src/Server/WebRoot/main.js b/src/Server/WebRoot/main.js index a07ecbe..9f6c97b 100644 --- a/src/Server/WebRoot/main.js +++ b/src/Server/WebRoot/main.js @@ -32,8 +32,11 @@ let app = new Vue({ }, // sendCommand will be wired to the various keybinds // each binding should send the game command expected - sendCommand: function (cmd) { - axios.post("/cmd") + sendCommand: function (direction) { + if (direction == 'south') { + direction = {Case: 'South'} + } + axios.post("/cmd", direction) .then(resp => { console.log("Got data from cmd:\n", resp) this.board = resp.data;