Example #1
0
func main() {
	license, err := internal.LicenseComment()
	if err != nil {
		log.Fatal(err)
	}

	notice := "DO NOT EDIT: This file is auto-generated by genkeys.go."

	names := []string{}
	namesWithoutMods := []string{}
	codes := []int{}
	for code, name := range keyCodeToName {
		names = append(names, name)
		codes = append(codes, code)
		if name != "Alt" && name != "Control" && name != "Shift" {
			namesWithoutMods = append(namesWithoutMods, name)
		}
	}
	sort.Sort(KeyNames(names))
	sort.Sort(KeyNames(namesWithoutMods))
	sort.Ints(codes)

	for path, tmpl := range map[string]string{
		"keys.go":                  ebitenKeysTmpl,
		"internal/ui/keys.go":      uiKeysTmpl,
		"internal/ui/keys_glfw.go": uiKeysGlfwTmpl,
		"internal/ui/keys_js.go":   uiKeysJSTmpl,
	} {
		f, err := os.Create(path)
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		tmpl, err := template.New(path).Parse(tmpl)
		if err != nil {
			log.Fatal(err)
		}
		// NOTE: According to godoc, maps are automatically sorted by key.
		if err := tmpl.Execute(f, map[string]interface{}{
			"License":             license,
			"Notice":              notice,
			"KeyCodeToName":       keyCodeToName,
			"Codes":               codes,
			"KeyNames":            names,
			"KeyNamesWithoutMods": namesWithoutMods,
		}); err != nil {
			log.Fatal(err)
		}
	}
}
Example #2
0
func outputKeyRectsGo(k map[string]image.Rectangle) error {
	license, err := internal.LicenseComment()
	if err != nil {
		return err
	}
	path := "keyrects.go"

	f, err := os.Create(path)
	if err != nil {
		return err
	}
	defer f.Close()

	tmpl, err := template.New(path).Parse(keyRectTmpl)
	if err != nil {
		return err
	}
	return tmpl.Execute(f, map[string]interface{}{
		"BuildTags":   "// +build example",
		"License":     license,
		"KeyRectsMap": k,
	})
}
Example #3
0
func main() {
	license, err := internal.LicenseComment()
	if err != nil {
		log.Fatal(err)
	}

	notice := "DO NOT EDIT: This file is auto-generated by genkeys.go."

	names := []string{}
	namesWithoutMods := []string{}
	codes := []int{}
	for code, name := range keyCodeToName {
		names = append(names, name)
		codes = append(codes, code)
		if name != "Alt" && name != "Control" && name != "Shift" {
			namesWithoutMods = append(namesWithoutMods, name)
		}
	}
	sort.Sort(KeyNames(names))
	sort.Sort(KeyNames(namesWithoutMods))
	sort.Ints(codes)

	for path, tmpl := range map[string]string{
		"keys.go":                  ebitenKeysTmpl,
		"internal/ui/keys.go":      uiKeysTmpl,
		"internal/ui/keys_glfw.go": uiKeysGlfwTmpl,
		"internal/ui/keys_js.go":   uiKeysJSTmpl,
	} {
		f, err := os.Create(path)
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		tmpl, err := template.New(path).Parse(tmpl)
		if err != nil {
			log.Fatal(err)
		}
		// The build tag can't be included in the templates because of `go vet`.
		// Pass the build tag and extract this in the template to make `go vet` happy.
		buildTag := ""
		switch path {
		case "internal/ui/keys_glfw.go":
			buildTag = "// +build darwin,!arm,!arm64 linux windows" +
				"\n// +build !js" +
				"\n// +build !android" +
				"\n// +build !ios"
		case "internal/ui/keys_js.go":
			buildTag = "// +build js"
		}
		// NOTE: According to godoc, maps are automatically sorted by key.
		if err := tmpl.Execute(f, map[string]interface{}{
			"License":             license,
			"Notice":              notice,
			"BuildTag":            buildTag,
			"KeyCodeToName":       keyCodeToName,
			"Codes":               codes,
			"KeyNames":            names,
			"LastKeyName":         names[len(names)-1],
			"KeyNamesWithoutMods": namesWithoutMods,
		}); err != nil {
			log.Fatal(err)
		}
	}
}