summaryrefslogtreecommitdiff
path: root/rules/toml.go
blob: 8e13acc79ee0f2e08c2970c02821730defa6a26a (plain)
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
package rules

import (
	"github.com/BurntSushi/toml"
	"os"
	"log"
)

type TOMLConf struct{
	Elements map[string]Set
	Scenes map[string][]string
	metadata toml.MetaData
}

func ReadFile(file string) (TOMLConf, error) {
	var r TOMLConf
	m, err := toml.DecodeFile(file, &r)
	r.metadata = m
	return r, err
}

func GetConf(file string) TOMLConf {
	c, err := ReadFile(file)
	if err != nil {
		log.Println("Error loading file, loading default configuration: ", err)
		c = DefaultConf()
	}
	log.Println("Configuration set")
	return c
}

func DefaultConf() TOMLConf {
	return TOMLConf{
		Elements: map[string]Set{
			"default": Default,
		},
		Scenes: map[string][]string{
			"en": []string{"INT", "EXT", "EST", "INT./EXT", "INT/EXT", "EXT/INT", "EXT./INT", "I/E"},
			"it": []string{"INT", "EST", "INT./EST", "INT/EST", "EST/INT", "EST./INT", "I/E"},
			"nl": []string{"BIN", "BUI", "BI", "BU", "OPEN", "BIN./BUI", "BUI./BIN", "BIN/BUI", "BI/BU"},
			"de": []string{"INT", "EXT", "ETABL", "INT./EXT", "INT/EXT", "EXT/INT", "EXT./INT", "I/E"},
			"fr": []string{"INT", "EXT", "INT./EXT", "INT/EXT", "EXT/INT", "EXT./INT", "I/E"},
			"eo": []string{"EN.", "ENE", "EKST", "EK", "EN/EKST", "EKST/EN", "EKST./EN", "EN./EKST"},
			"ru": []string{"ИНТ", "НАТ", "ИНТ/НАТ", "ИНТ./НАТ", "НАТ/ИНТ", "НАТ./ИНТ", "ЭКСТ", "И/Н", "Н/И"},
		},
	}
}

func Dump(file string) error {
	f, err := os.Create(file)
	if err != nil {
		return err
	}
	return toml.NewEncoder(f).Encode(DefaultConf())
}