room.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package world
  2. import "gitlab.com/beoran/woe/sitef"
  3. import "gitlab.com/beoran/woe/monolog"
  4. // import "fmt"
  5. import "errors"
  6. type Direction string
  7. type Exit struct {
  8. Direction
  9. ToRoomID int
  10. toRoom *Room
  11. }
  12. type Room struct {
  13. Entity
  14. Exits map[Direction]Exit
  15. }
  16. // Load a room from a sitef file.
  17. func LoadRoom(dirname string, id string) (room *Room, err error) {
  18. path := SavePathFor(dirname, "room", id)
  19. records, err := sitef.ParseFilename(path)
  20. if err != nil {
  21. return nil, err
  22. }
  23. if len(records) < 1 {
  24. return nil, errors.New("No room found!")
  25. }
  26. record := records[0]
  27. monolog.Info("Loading Room record: %s %v", path, record)
  28. room = new(Room)
  29. room.Entity.LoadSitef(*record)
  30. /*
  31. account.Name = record.Get("name")
  32. account.Hash = record.Get("hash")
  33. account.Algo = record.Get("algo")
  34. account.Email = record.Get("email")
  35. account.Points = record.GetIntDefault("points", 0)
  36. account.Privilege = Privilege(record.GetIntDefault("privilege",
  37. int(PRIVILEGE_NORMAL)))
  38. var nchars int
  39. nchars = record.GetIntDefault("characters", 0)
  40. _ = nchars
  41. */
  42. monolog.Info("Loaded Room: %s %v", path, room)
  43. return room, nil
  44. }