예제 #1
0
파일: utils.go 프로젝트: RickDakan/haunts
func loadDictionaryFromFile(size int) (*gui.Dictionary, error) {
	name := fmt.Sprintf("dict_%d.gob", size)
	f, err := os.Open(filepath.Join(datadir, "fonts", name))
	var d *gui.Dictionary
	if err == nil {
		d, err = gui.LoadDictionary(f)
		f.Close()
	}
	return d, err
}
예제 #2
0
파일: utils.go 프로젝트: dgthunder/magnus
func GetDictionary(font string) *gui.Dictionary {
	dictionary_mutex.Lock()
	defer dictionary_mutex.Unlock()
	if font_dict == nil {
		font_dict = make(map[string]*gui.Dictionary)
	}
	if _, ok := font_dict[font]; !ok {
		path := filepath.Join(datadir, "fonts", font+".gob")
		f, err := os.Open(path)
		if err != nil {
			Error().Printf("Unable to open file '%s': %v\n", path, err)
			return nil
		}
		defer f.Close()
		dict, err := gui.LoadDictionary(f)
		if err != nil {
			Error().Printf("Unable to load dictionary from '%s': %v\n", path, err)
			return nil
		}
		font_dict[font] = dict
	}
	return font_dict[font]
}