66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"f00860/kartograph-map-editor/pkg/generator"
|
|
"f00860/kartograph-map-editor/pkg/web"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
startWebserver bool
|
|
address string
|
|
port int
|
|
|
|
output string
|
|
world generator.World
|
|
seed string
|
|
|
|
size int
|
|
wastelands int
|
|
mountains int
|
|
ruins int
|
|
)
|
|
|
|
func main() {
|
|
if startWebserver {
|
|
web.Start(address, port)
|
|
return
|
|
}
|
|
|
|
world, err := generator.New(size, wastelands, mountains, ruins, seed)
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
|
|
switch output {
|
|
case "svg":
|
|
fmt.Printf("%s", world.SVG())
|
|
case "ascii":
|
|
fmt.Printf("%s", world.Plot())
|
|
case "json":
|
|
fmt.Printf("%s", world.JSON())
|
|
default:
|
|
fmt.Printf("Output format '%v' not supported", output)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
flag.BoolVar(&startWebserver, "web", false, "Spawn a webserver")
|
|
flag.StringVar(&address, "address", "0.0.0.0", "IP to bind the service to")
|
|
flag.IntVar(&port, "port", 80, "Port to bind the service to")
|
|
|
|
flag.StringVar(&output, "output", "svg", "Output format (svg, ascii, json)")
|
|
flag.StringVar(&seed, "seed", time.Now().String(), "A seed string for the map generation")
|
|
|
|
flag.IntVar(&size, "size", 11, "The map size")
|
|
flag.IntVar(&wastelands, "wastelands", 7, "Number of wastelands to generate")
|
|
flag.IntVar(&mountains, "mountains", 5, "Number of mountains ot generate")
|
|
flag.IntVar(&ruins, "ruins", 6, "Number of ruins to generate")
|
|
|
|
flag.Parse()
|
|
}
|