stuff is wired up, but not quite communicating yet

This commit is contained in:
Chris Sexton 2019-10-05 14:09:28 -04:00
parent 3eee55910f
commit ddea33ef6b
3 changed files with 25 additions and 21 deletions

View File

@ -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<Command>()
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" ]

View File

@ -0,0 +1,15 @@
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/rot.js/0.6.0/rot.js"></script>
<script src="//unpkg.com/vue"></script>
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
<script src="/main.js" async></script>
</head>
<body>
<h1>Dis my dumb game</h1>
<div id="app">
<div id="game"></div>
<button id="south" v-on:click="sendCommand('south')">South</button>
</div>
</body>
</html>

View File

@ -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;