finish explore page, fix coord display issue
This commit is contained in:
parent
adcaa609a6
commit
40b09278af
@ -3,18 +3,26 @@ 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 := middleware.GetCurrentUser(ctx)
|
||||
user := ctx.UserValue("user").(*users.User)
|
||||
if user != nil {
|
||||
if user.Currently == "In Town" {
|
||||
ctx.Redirect("/town", 303)
|
||||
return
|
||||
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)
|
||||
@ -48,6 +56,10 @@ func Move(ctx router.Ctx, _ []string) {
|
||||
}
|
||||
|
||||
func Explore(ctx router.Ctx, _ []string) {
|
||||
ctx.SetContentType("text/plain")
|
||||
ctx.SetBodyString("Exploring")
|
||||
user := ctx.UserValue("user").(*users.User)
|
||||
if user.Currently != "Exploring" {
|
||||
ctx.Redirect("/", 303)
|
||||
return
|
||||
}
|
||||
components.RenderPage(ctx, "", "explore.html", nil)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -65,9 +66,7 @@ func (bs *BaseStore[T]) RebuildIndices() {
|
||||
|
||||
func (bs *BaseStore[T]) rebuildIndicesUnsafe() {
|
||||
allItems := make(map[int]*T, len(bs.items))
|
||||
for k, v := range bs.items {
|
||||
allItems[k] = v
|
||||
}
|
||||
maps.Copy(allItems, bs.items)
|
||||
|
||||
for name, builder := range bs.indexBuilders {
|
||||
bs.indices[name] = builder(allItems)
|
||||
@ -354,9 +353,7 @@ func (bs *BaseStore[T]) GetAll() map[int]*T {
|
||||
bs.mu.RLock()
|
||||
defer bs.mu.RUnlock()
|
||||
result := make(map[int]*T, len(bs.items))
|
||||
for k, v := range bs.items {
|
||||
result[k] = v
|
||||
}
|
||||
maps.Copy(result, bs.items)
|
||||
return result
|
||||
}
|
||||
|
||||
|
5
templates/explore.html
Normal file
5
templates/explore.html
Normal file
@ -0,0 +1,5 @@
|
||||
{include "layout.html"}
|
||||
|
||||
{block "content"}
|
||||
You are currently exploring. You've found nothing yet.
|
||||
{/block}
|
@ -8,18 +8,18 @@
|
||||
{user.Currently}
|
||||
{/if}
|
||||
</b></div>
|
||||
<div>{user.X}{if user.X < 0}W{else}E{/if}, {user.Y}{if user.Y < 0}N{else}S{/if}</div>
|
||||
<div>{user.X}{if user.X < 0}W{else}E{/if}, {user.Y}{if user.Y < 0}S{else}N{/if}</div>
|
||||
|
||||
<a href="javascript:open_map_popup()">View Map</a>
|
||||
|
||||
<form id="move-compass" action="/move" method="post" >
|
||||
{csrf}
|
||||
<button id="north" name="direction" value="1">North</button>
|
||||
<button id="north" name="direction" value="0">North</button>
|
||||
<div class="mid">
|
||||
<button id="west" name="direction" value="4">West</button>
|
||||
<button id="east" name="direction" value="2">East</button>
|
||||
<button id="west" name="direction" value="3">West</button>
|
||||
<button id="east" name="direction" value="1">East</button>
|
||||
</div>
|
||||
<button id="south" name="direction" value="3">South</button>
|
||||
<button id="south" name="direction" value="2">South</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user