commit b00773e81fc7d994eaa99ff92ada0a4240cddca4 Author: ‮ittaG ordnasselA Date: Wed May 15 15:45:28 2019 +0200 Move stuff out of mcgserver diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01cd5b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +octgn-data +images +*.exe +static \ No newline at end of file diff --git a/tools/genpics/go.mod b/tools/genpics/go.mod new file mode 100644 index 0000000..070a557 --- /dev/null +++ b/tools/genpics/go.mod @@ -0,0 +1 @@ +module git.fromouter.space/mcg/mcgserver/tools/genpics diff --git a/tools/genpics/main.go b/tools/genpics/main.go new file mode 100644 index 0000000..0eb6f50 --- /dev/null +++ b/tools/genpics/main.go @@ -0,0 +1,131 @@ +package main // import "git.fromouter.space/mcg/mcgserver/tools/genpics" + +import ( + "archive/zip" + "encoding/json" + "flag" + "fmt" + "image" + "io" + "os" + "path/filepath" + "strings" + + "image/jpeg" + _ "image/jpeg" + _ "image/png" +) + +type cardMap map[string]string + +func main() { + packfolder := flag.String("packdir", "octgn-data", "Path to folder containing .o8c files") + cardmap := flag.String("mapfile", filepath.Join("octgn-data", "cardmap.json"), "Path to card id map") + outfolder := flag.String("out", filepath.Join("images", "cards"), "Path where to put the extracted/renamed images") + flag.Parse() + + // Read and parse card map + + mapfile, err := os.Open(*cardmap) + checkErr(err, "Could not read card map file") + + var cmap cardMap + checkErr(json.NewDecoder(mapfile).Decode(&cmap), "Could not decode card map file") + + mapfile.Close() + + // Create dir tree + checkErr(os.MkdirAll(filepath.Join(*outfolder, "unknown"), 0755), "Could not create output folder(s)") + + checkErr(filepath.Walk(*packfolder, func(path string, info os.FileInfo, err error) error { + // Skip all non-OCTGN image packs + if strings.ToLower(filepath.Ext(path)) != ".o8c" { + return nil + } + // Open as ZIP + packfile, err := zip.OpenReader(path) + if err != nil { + return err + } + defer packfile.Close() + fmt.Printf("Processing %s:\n", path) + for _, file := range packfile.File { + // Skip folders + if file.FileInfo().IsDir() { + continue + } + // Get filename and conver it, if possible + base := filepath.Base(file.Name) + pieces := strings.Split(base, ".") + translated, ok := cmap[pieces[0]] + if ok { + // Convert boosted card format + if pieces[1] == "Mane Character Boosted" { + translated += "b" + pieces[1] = pieces[2] + } + fmt.Printf(" Found %s -> %s\n", base, translated) + + // If file is jpg/jpeg, copy as it is + ext := strings.ToLower(filepath.Ext(base)) + if ext == ".jpg" || ext == ".jpeg" { + err := copyFile(file, filepath.Join(*outfolder, translated+".jpg")) + if err != nil { + return err + } + } else { + // Non-JPG, needs to be converted + infile, err := file.Open() + if err != nil { + return err + } + defer infile.Close() + img, _, err := image.Decode(infile) + if err != nil { + return err + } + outfile, err := os.Create(filepath.Join(*outfolder, translated+".jpg")) + if err != nil { + return err + } + defer outfile.Close() + err = jpeg.Encode(outfile, img, &jpeg.Options{Quality: 90}) + if err != nil { + return err + } + } + } else { + fmt.Printf(" Unknown %s\n", base) + err := copyFile(file, filepath.Join(*outfolder, "unknown", base)) + if err != nil { + return err + } + } + } + return nil + }), "Error while looking up for archives") +} + +func copyFile(in *zip.File, outpath string) error { + infile, err := in.Open() + if err != nil { + return err + } + defer infile.Close() + + outfile, err := os.Create(outpath) + if err != nil { + return err + } + defer outfile.Close() + + _, err = io.Copy(outfile, infile) + return err +} + +func checkErr(err error, errfmt string, args ...interface{}) { + if err != nil { + fmt.Fprintf(os.Stderr, "[FATAL ERROR] "+errfmt+":\n "+err.Error(), args...) + os.Exit(1) + } +} diff --git a/zyg-compose.yml b/zyg-compose.yml new file mode 100644 index 0000000..9339281 --- /dev/null +++ b/zyg-compose.yml @@ -0,0 +1,41 @@ +version: "2" + +services: + caddy: + image: mcg-caddy + restart: always + networks: + - web + volumes: + - /opt/mcgserver/Caddyfile:/etc/Caddyfile + - /opt/mcgserver/static:/static + labels: + - traefik.enable=true + - traefik.docker.network=web + - traefik.frontend.rule=Host:mlpccg.zyg.ovh + - traefik.port=2015 + + rdb: + image: rethinkdb:latest + restart: always + volumes: + - /opt/mcgserver/rdb-data:/data + ports: + - "127.0.0.1:9000:8080" + networks: + - rdb + + redis: + image: redis:alpine + restart: always + networks: + - redis + +networks: + rdb: + external: false + redis: + external: false + web: + external: + name: web