- Updated the backend documentation in CONTRIBUTING.md and README.md to reflect changes in application structure and API endpoints. - Enhanced the frontend components in MapView.vue for better handling of context menu actions. - Added new types and interfaces in TypeScript for improved type safety in the frontend. - Introduced new utility classes for managing characters and markers in the map. - Updated .gitignore to include .vscode directory for better development environment management.
83 lines
1.6 KiB
Go
83 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
func (a *App) uploadMarkers(rw http.ResponseWriter, req *http.Request) {
|
|
defer req.Body.Close()
|
|
markers := []struct {
|
|
Name string
|
|
GridID string
|
|
X, Y int
|
|
Image string
|
|
Type string
|
|
Color string
|
|
}{}
|
|
buf, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
log.Println("Error reading marker json: ", err)
|
|
return
|
|
}
|
|
err = json.Unmarshal(buf, &markers)
|
|
if err != nil {
|
|
log.Println("Error decoding marker json: ", err)
|
|
log.Println("Original json: ", string(buf))
|
|
return
|
|
}
|
|
err = a.db.Update(func(tx *bbolt.Tx) error {
|
|
mb, err := tx.CreateBucketIfNotExists([]byte("markers"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
grid, err := mb.CreateBucketIfNotExists([]byte("grid"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
idB, err := mb.CreateBucketIfNotExists([]byte("id"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, mraw := range markers {
|
|
key := []byte(fmt.Sprintf("%s_%d_%d", mraw.GridID, mraw.X, mraw.Y))
|
|
if grid.Get(key) != nil {
|
|
continue
|
|
}
|
|
if mraw.Image == "" {
|
|
mraw.Image = "gfx/terobjs/mm/custom"
|
|
}
|
|
id, err := idB.NextSequence()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
idKey := []byte(strconv.Itoa(int(id)))
|
|
m := Marker{
|
|
Name: mraw.Name,
|
|
ID: int(id),
|
|
GridID: mraw.GridID,
|
|
Position: Position{
|
|
X: mraw.X,
|
|
Y: mraw.Y,
|
|
},
|
|
Image: mraw.Image,
|
|
}
|
|
raw, _ := json.Marshal(m)
|
|
grid.Put(key, raw)
|
|
idB.Put(idKey, key)
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
log.Println("Error update db: ", err)
|
|
return
|
|
}
|
|
}
|