package routes import ( "dk/internal/actions" "dk/internal/middleware" "dk/internal/router" "dk/internal/template/components" "strconv" ) func Index(ctx router.Ctx, _ []string) { user := middleware.GetCurrentUser(ctx) if user != nil { if user.Currently == "In Town" { ctx.Redirect("/town", 303) return } } components.RenderPage(ctx, "", "intro.html", nil) } func Move(ctx router.Ctx, _ []string) { user := middleware.GetCurrentUser(ctx) dir, err := strconv.Atoi(string(ctx.PostArgs().Peek("direction"))) if err != nil { ctx.SetContentType("text/plain") ctx.SetBodyString("move form parsing error") return } currently, newX, newY, err := actions.Move(user, actions.Direction(dir)) if err != nil { ctx.SetContentType("text/plain") ctx.SetBodyString("move error: " + err.Error()) return } user.Set("Currently", currently) user.Set("X", newX) user.Set("Y", newY) user.Save() if currently == "In Town" { ctx.Redirect("/town", 303) return } ctx.Redirect("/explore", 303) } func Explore(ctx router.Ctx, _ []string) { ctx.SetContentType("text/plain") ctx.SetBodyString("Exploring") }