Move stuff out of mcgserver
This commit is contained in:
commit
b00773e81f
4 changed files with 177 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
octgn-data
|
||||
images
|
||||
*.exe
|
||||
static
|
1
tools/genpics/go.mod
Normal file
1
tools/genpics/go.mod
Normal file
|
@ -0,0 +1 @@
|
|||
module git.fromouter.space/mcg/mcgserver/tools/genpics
|
131
tools/genpics/main.go
Normal file
131
tools/genpics/main.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
41
zyg-compose.yml
Normal file
41
zyg-compose.yml
Normal file
|
@ -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
|
Loading…
Reference in a new issue