fifi.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package fifi
  2. import "os"
  3. import "path/filepath"
  4. import al "gitlab.com/beoran/al5go/al"
  5. // Find files
  6. var DataPath string = ""
  7. func isDataPathOK(path string) bool {
  8. fn := filepath.Join(path, "eruta.conf")
  9. file, err := os.Open(fn)
  10. file.Close()
  11. return err == nil
  12. }
  13. func Initialize() bool {
  14. DataPath = os.Getenv("EBS_DATA")
  15. if isDataPathOK(DataPath) {
  16. return true
  17. }
  18. wd, err := os.Getwd()
  19. if err == nil {
  20. DataPath = filepath.Join(wd, "data")
  21. if isDataPathOK(DataPath) {
  22. return true
  23. }
  24. }
  25. return false
  26. }
  27. func Map(name string) string {
  28. return filepath.Join(DataPath, name)
  29. }
  30. /* Fifi contain functionality that helps finding back the file resouces,
  31. such as images, music, etc that theengine needs.
  32. An important concept here is the "virtual path", that is the path under the
  33. location of the data directory. So, for example, if the data of the
  34. app is installed on Linux in /usr/share/app/data,
  35. then a vpath of
  36. font/my_nice_font.ttf
  37. will be resolved as
  38. /usr/share/app/data/font/my_nice_font.ttf.
  39. Or, if, on another OS, the data of the app is installed in
  40. C:\Program Files\App\data
  41. then the same vpath will refer to
  42. C:\Program Files\App\data\font\my_nice_font.ttf.
  43. So Fifi is a way to get OS-independence and location-independence of
  44. the data files all at once.
  45. For save files or scores, the vpath is similar, but relative to the
  46. "writeable" directory of the application.
  47. */
  48. func LoadBitmap(filename string) * al.Bitmap {
  49. return al.LoadBitmap(Map(filename))
  50. }