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