main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. )
  7. func main() {
  8. /*SetupApp()
  9. SetupHome()
  10. HOME.Show()
  11. APP.Run()*/
  12. p := Parser{Debug: false}
  13. root, err := p.Load("Test Dummy.txt")
  14. if err != nil {
  15. fmt.Println("parser.load", err)
  16. return
  17. }
  18. /*pay, err := json.MarshalIndent(root, "", " ")
  19. if err != nil {
  20. fmt.Println("marshalindent", err)
  21. return
  22. }
  23. err = os.WriteFile("_debug0.json", pay, 0660)
  24. if err != nil {
  25. fmt.Println("writefile", err)
  26. return
  27. }*/
  28. me := Profile{}
  29. err = me.Parse(root)
  30. if err != nil {
  31. fmt.Println("profile.parse", err)
  32. return
  33. }
  34. //fmt.Printf("%#v\n", me)
  35. pay, err := json.MarshalIndent(me, "", " ")
  36. if err != nil {
  37. fmt.Println("marshalindent", err)
  38. return
  39. }
  40. err = os.WriteFile("_debug.json", pay, 0660)
  41. if err != nil {
  42. fmt.Println("writefile", err)
  43. return
  44. }
  45. me.Ships[0].Attributes.Others["bunks"] = 100
  46. me.Ships[0].Attributes.Others["cargo space"] = 100
  47. me.Ships[0].Attributes.Others["required crew"] = 1
  48. me.Ships[0].Name = "Test Me II"
  49. me.Ships[0].Hull = int(me.Ships[0].Attributes.Others["hull"])
  50. me.Ships[0].Shields = int(me.Ships[0].Attributes.Others["shields"])
  51. me.Ships[0].Fuel = int(me.Ships[0].Attributes.Others["fuel capacity"])
  52. err = me.Update()
  53. if err != nil {
  54. fmt.Println("profile.update", err)
  55. return
  56. }
  57. err = p.Save("+Test Dummy.txt", root)
  58. if err != nil {
  59. fmt.Println("parser.save", err)
  60. return
  61. }
  62. pay, err = json.MarshalIndent(me, "", " ")
  63. if err != nil {
  64. fmt.Println("marshalindent", err)
  65. return
  66. }
  67. err = os.WriteFile("_debug1.json", pay, 0660)
  68. if err != nil {
  69. fmt.Println("writefile", err)
  70. return
  71. }
  72. }