package routes import ( "dk/internal/actions" "dk/internal/middleware" "dk/internal/models/users" "dk/internal/router" "dk/internal/template/components" "strconv" ) func Index(ctx router.Ctx, _ []string) { user := ctx.UserValue("user").(*users.User) if user != nil { redirectTo := "/explore" switch user.Currently { case "In Town": redirectTo = "/town" case "Exploring": redirectTo = "/explore" default: redirectTo = "/explore" } ctx.Redirect(redirectTo, 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.Currently = currently user.X, user.Y = newX, newY if currently == "In Town" { ctx.Redirect("/town", 303) return } ctx.Redirect("/explore", 303) } func Explore(ctx router.Ctx, _ []string) { user := ctx.UserValue("user").(*users.User) if user.Currently != "Exploring" { ctx.Redirect("/", 303) return } components.RenderPage(ctx, "", "explore.html", nil) }