~nromdotcom/gemif

ref: 85dc63b9dbb0221579a7fd26c4a1feae4bd39338 gemif/cmd/gemifc/main.go -rw-r--r-- 1.9 KiB
85dc63b9Norm MacLennan chore: upgrade linters and fix linting issues 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main

// yaml.v3 doesn't serialize multi-line strings
// correctly for some reason, so we use v2.
import (
	"flag"
	"fmt"
	"log"
	"os"

	"git.sr.ht/~nromdotcom/gemif/pkg/gamemanager"
)

//nolint:gochecknoglobals
var (
	appName    = "GemIFC"
	appVersion = "0.0.0"
	appCommit  = "local"
	buildTime  = "just now!"
)

func main() {
	versionFlag := flag.Bool("version", false, "Print version information and exit")
	inputPath := flag.String("in", "", "The path of the story source directory")
	outputPath := flag.String("out", "", "The path to write the compile story")
	flag.Parse()

	if *versionFlag {
		fmt.Printf("%s %s (%s) - built %s\n\n", appName, appVersion, appCommit, buildTime)
		os.Exit(0)
	} else if *inputPath == "" || *outputPath == "" {
		fmt.Printf("%v, %v\n\n", inputPath, outputPath)
		flag.PrintDefaults()
		os.Exit(1)
	}

	fmt.Printf("Compiling story %s to %s\n", *inputPath, *outputPath)

	metadata, err := loadMetadata(*inputPath)
	if err != nil {
		log.Fatalf("Couldn't read metadata file: %s", err)
	}

	files, err := findFilesWithExtension(*inputPath, "*.gemif")
	if err != nil {
		log.Fatalf("Couldn't load *.gemif files %s", err)
	}

	storyRooms := []gamemanager.Room{}

	for _, file := range files {
		fileRooms, err := processFile(file)
		if err != nil {
			log.Fatalf("Couldn't process file %s: %s", file, err)
		}

		storyRooms = append(storyRooms, fileRooms...)
	}

	story := gamemanager.Story{
		Metadata: *metadata,
		Rooms:    storyRooms,
	}

	fmt.Printf(`
Finished loading story:
  Name: %s
  Author: %s
  Descriptions: %s
  Number of Rooms: %d

`, story.Metadata.Name, story.Metadata.Author, story.Metadata.Description, len(story.Rooms))

	fmt.Println("Serializing and writing to disk...")

	if err := writeStory(&story, fmt.Sprintf("%s/%s.yml", *outputPath, story.Metadata.ID)); err != nil {
		log.Fatalf("Couldn't save story: %s", err)
	}

	fmt.Println("Done!")
}