2022-04-09 12:01:04 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-13 08:28:07 +03:00
|
|
|
"flag"
|
2022-04-09 12:01:04 +03:00
|
|
|
"fmt"
|
2022-04-13 08:28:07 +03:00
|
|
|
"legendsbrowser/analyze"
|
2022-04-13 15:01:20 +03:00
|
|
|
"legendsbrowser/df"
|
2022-04-09 19:37:44 +03:00
|
|
|
"legendsbrowser/server"
|
2022-04-09 12:01:04 +03:00
|
|
|
"net/http"
|
2022-04-11 00:27:37 +03:00
|
|
|
_ "net/http/pprof"
|
2022-04-14 16:49:09 +03:00
|
|
|
"os"
|
2022-04-11 00:27:37 +03:00
|
|
|
"runtime"
|
2022-04-09 12:01:04 +03:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2022-04-13 08:28:07 +03:00
|
|
|
"github.com/pkg/profile"
|
2022-04-09 12:01:04 +03:00
|
|
|
)
|
|
|
|
|
2022-04-13 15:01:20 +03:00
|
|
|
var world *df.DfWorld
|
2022-04-09 12:01:04 +03:00
|
|
|
|
|
|
|
func main() {
|
2022-04-13 15:01:20 +03:00
|
|
|
a := flag.String("a", "", "analyze a file")
|
|
|
|
g := flag.Bool("g", false, "generate model")
|
|
|
|
f := flag.String("f", "", "open a file")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if len(*a) > 0 {
|
|
|
|
analyze.Analyze(*a)
|
|
|
|
}
|
|
|
|
if *g {
|
|
|
|
fmt.Println("Generating")
|
|
|
|
analyze.Generate()
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(*f) > 0 {
|
2022-04-14 16:49:09 +03:00
|
|
|
defer profile.Start(profile.MemProfile).Stop()
|
|
|
|
go func() {
|
|
|
|
http.ListenAndServe(":8081", nil)
|
|
|
|
}()
|
|
|
|
|
2022-04-13 15:01:20 +03:00
|
|
|
w, err := df.Parse(*f)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
2022-04-14 16:49:09 +03:00
|
|
|
os.Exit(1)
|
2022-04-13 15:01:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
world = w
|
2022-04-09 12:01:04 +03:00
|
|
|
|
2022-04-14 16:49:09 +03:00
|
|
|
fmt.Println("Hallo Welt!")
|
|
|
|
runtime.GC()
|
|
|
|
// world.Process()
|
|
|
|
|
|
|
|
// model.ListOtherElements("world", &[]*model.World{&world})
|
|
|
|
// model.ListOtherElements("region", &world.Regions)
|
|
|
|
// model.ListOtherElements("underground regions", &world.UndergroundRegions)
|
|
|
|
// model.ListOtherElements("landmasses", &world.Landmasses)
|
|
|
|
// model.ListOtherElements("sites", &world.Sites)
|
|
|
|
// model.ListOtherElements("world constructions", &world.WorldConstructions)
|
|
|
|
// model.ListOtherElements("artifacts", &world.Artifacts)
|
|
|
|
// model.ListOtherElements("entities", &world.Entities)
|
|
|
|
// model.ListOtherElements("hf", &world.HistoricalFigures)
|
|
|
|
// model.ListOtherElements("events", &world.HistoricalEvents)
|
|
|
|
// model.ListOtherElements("collections", &world.HistoricalEventCollections)
|
|
|
|
// model.ListOtherElements("era", &world.HistoricalEras)
|
|
|
|
// model.ListOtherElements("danceForm", &world.DanceForms)
|
|
|
|
// model.ListOtherElements("musicalForm", &world.MusicalForms)
|
|
|
|
// model.ListOtherElements("poeticForm", &world.PoeticForms)
|
|
|
|
// model.ListOtherElements("written", &world.WrittenContents)
|
|
|
|
|
|
|
|
router := mux.NewRouter().StrictSlash(true)
|
|
|
|
|
|
|
|
server.RegisterResource(router, "region", world.Regions)
|
|
|
|
// server.RegisterResource(router, "undergroundRegion", world.UndergroundRegions)
|
|
|
|
server.RegisterResource(router, "landmass", world.Landmasses)
|
|
|
|
server.RegisterResource(router, "site", world.Sites)
|
|
|
|
server.RegisterResource(router, "worldConstruction", world.WorldConstructions)
|
|
|
|
server.RegisterResource(router, "artifact", world.Artifacts)
|
|
|
|
server.RegisterResource(router, "hf", world.HistoricalFigures)
|
|
|
|
server.RegisterResource(router, "collection", world.HistoricalEventCollections)
|
|
|
|
server.RegisterResource(router, "entity", world.Entities)
|
|
|
|
server.RegisterResource(router, "event", world.HistoricalEvents)
|
|
|
|
// server.RegisterResource(router, "era", world.HistoricalEras)
|
|
|
|
server.RegisterResource(router, "danceForm", world.DanceForms)
|
|
|
|
server.RegisterResource(router, "musicalForm", world.MusicalForms)
|
|
|
|
server.RegisterResource(router, "poeticForm", world.PoeticForms)
|
|
|
|
// server.RegisterResource(router, "written", world.WrittenContents)
|
|
|
|
|
|
|
|
spa := server.SpaHandler{StaticPath: "frontend/dist/legendsbrowser", IndexPath: "index.html"}
|
|
|
|
router.PathPrefix("/").Handler(spa)
|
|
|
|
|
|
|
|
fmt.Println("Serving at :8080")
|
|
|
|
http.ListenAndServe(":8080", router)
|
|
|
|
}
|
2022-04-09 19:37:44 +03:00
|
|
|
|
2022-04-09 12:01:04 +03:00
|
|
|
}
|